Blacked and isorted the python files
Prettied and eslinted the typescript/html files
This commit is contained in:
@ -1,65 +1,70 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { GuestBook, GuestBookList } from './guest-book';
|
||||
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
|
||||
import { GuestBook } from './guest-book';
|
||||
import { GuestBookList } from './guest-book-list';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
|
||||
const url = '/api/guest-book';
|
||||
const serviceName = 'GuestBookService';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class GuestBookService {
|
||||
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<GuestBook> {
|
||||
const getUrl: string = (id === null) ? url : `${url}/${id}`;
|
||||
return <Observable<GuestBook>>this.http.get<GuestBook>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return <Observable<GuestBook>>(
|
||||
this.http
|
||||
.get<GuestBook>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
|
||||
);
|
||||
}
|
||||
|
||||
list(date: string): Observable<GuestBookList> {
|
||||
const options = {params: new HttpParams().set('q', (date === null) ? '' : date)};
|
||||
return <Observable<GuestBookList>>this.http.get<GuestBookList>(`${url}/list`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
const options = { params: new HttpParams().set('q', date === null ? '' : date) };
|
||||
return <Observable<GuestBookList>>(
|
||||
this.http
|
||||
.get<GuestBookList>(`${url}/list`, options)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list')))
|
||||
);
|
||||
}
|
||||
|
||||
save(guestBook: GuestBook): Observable<GuestBook> {
|
||||
return <Observable<GuestBook>>this.http.post<GuestBook>(url, guestBook, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
return <Observable<GuestBook>>(
|
||||
this.http
|
||||
.post<GuestBook>(url, guestBook, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save')))
|
||||
);
|
||||
}
|
||||
|
||||
update(guestBook: GuestBook): Observable<GuestBook> {
|
||||
return <Observable<GuestBook>>this.http.put<GuestBook>(`${url}/${guestBook.id}`, guestBook, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
return <Observable<GuestBook>>(
|
||||
this.http
|
||||
.put<GuestBook>(`${url}/${guestBook.id}`, guestBook, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update')))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(guestBook: GuestBook): Observable<GuestBook> {
|
||||
if (!guestBook.id) {
|
||||
return this.save(guestBook);
|
||||
} else {
|
||||
return this.update(guestBook);
|
||||
}
|
||||
return this.update(guestBook);
|
||||
}
|
||||
|
||||
delete(id: string): Observable<GuestBook> {
|
||||
return <Observable<GuestBook>>this.http.delete<GuestBook>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
return <Observable<GuestBook>>(
|
||||
this.http
|
||||
.delete<GuestBook>(`${url}/${id}`, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user