Feature:
SectionPrinter is now working Migration: Section, Printers, SectionPrinters working
This commit is contained in:
50
bookie/src/app/section-printers/section-printer.service.ts
Normal file
50
bookie/src/app/section-printers/section-printer.service.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {SectionPrinter, SectionPrinterItem} from '../core/section-printer';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
const url = '/v1/section-printers';
|
||||
const serviceName = 'SectionPrinterService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SectionPrinterService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
|
||||
get(id: string): Observable<SectionPrinter> {
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<SectionPrinter>>this.http.get<SectionPrinter>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
}
|
||||
|
||||
item(id: string, menuCategoryId: string): Observable<SectionPrinterItem> {
|
||||
const options = {params: new HttpParams().set('m', menuCategoryId)};
|
||||
return <Observable<SectionPrinterItem>>this.http.get<SectionPrinterItem>(`${url}/${id}`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
save(item: SectionPrinter): Observable<SectionPrinter> {
|
||||
return <Observable<SectionPrinter>>this.http.post<SectionPrinter>(`${url}/${item.id}`, item, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
}
|
||||
|
||||
delete(id: string): Observable<SectionPrinter> {
|
||||
return <Observable<SectionPrinter>>this.http.delete<SectionPrinter>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user