43 lines
965 B
TypeScript
43 lines
965 B
TypeScript
// vim: set tw=80 ts=2 sw=2 sts=2 :
|
|
import { Injectable } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import { Observable } from 'rxjs/Rx';
|
|
|
|
import { Account } from './account';
|
|
|
|
@Injectable()
|
|
export class AccountService {
|
|
constructor(
|
|
private http: HttpClient
|
|
) {}
|
|
|
|
private url(id?: Number): string {
|
|
if(id) {
|
|
return `/api/account/${id}`;
|
|
}
|
|
|
|
return `/api/account`;
|
|
}
|
|
|
|
query(): Observable<Account[]> {
|
|
return this.http.get<Account[]>(this.url());
|
|
}
|
|
|
|
get(id: number): Observable<Account> {
|
|
return this.http.get<Account>(this.url(id));
|
|
}
|
|
|
|
create(account: Account): Observable<Account> {
|
|
return this.http.post<Account>(this.url(), account);
|
|
}
|
|
|
|
update(account: Account): Observable<Account> {
|
|
return this.http.post<Account>(this.url(account.id), account);
|
|
}
|
|
|
|
delete(account: Account): Observable<Account> {
|
|
return this.http.delete<Account>(this.url(account.id));
|
|
}
|
|
}
|