1/**
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { HttpClient } from '@angular/common/http';
17import { Injectable } from '@angular/core';
18
19import { catchError } from 'rxjs/operators';
20import { Observable } from 'rxjs';
21
22import { environment } from '../../../environments/environment';
23import { ScheduleWrapper } from '../../model/schedule_wrapper';
24import { ServiceBase } from '../../shared/servicebase';
25import { ScheduleSuspendResponse, ScheduleSuspendResponseWrapper } from '../../model/schedule';
26
27
28@Injectable()
29export class ScheduleService extends ServiceBase {
30  // url: string;
31  constructor(public httpClient: HttpClient) {
32    super(httpClient);
33    this.url = environment['baseURL'] + '/schedule/v1/';
34  }
35
36  getSchedules(size: number,
37               offset: number,
38               filterInfo: string,
39               sort: string,
40               direction: string): Observable<ScheduleWrapper> {
41    const url = this.url + 'get';
42    return this.httpClient.post<ScheduleWrapper>(url,  {size: size, offset: offset, filter: filterInfo, sort: sort, direction: direction})
43      .pipe(catchError(this.handleError));
44  }
45
46  suspendSchedule(schedules: ScheduleSuspendResponse[]): Observable<ScheduleSuspendResponseWrapper> {
47    const url = this.url + 'suspend';
48    return this.httpClient.post<ScheduleSuspendResponseWrapper>(url, {schedules: schedules})
49      .pipe(catchError(this.handleError));
50  }
51}
52