accountant-ui/src/accounts/account.service.ts

47 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-07-13 16:55:02 +02:00
// vim: set tw=80 ts=2 sw=2 sts=2 :
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions, Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { Logger } from "@nsalaun/ng-logger";
import { Restangular } from "ngx-restangular";
2017-07-13 16:55:02 +02:00
import { Account } from './account';
@Injectable()
export class AccountService {
2017-07-14 10:05:09 +02:00
private url = '/api/account/';
2017-07-13 16:55:02 +02:00
constructor(
private logger: Logger,
private restangular: Restangular) {}
2017-07-13 16:55:02 +02:00
private all() {
return this.restangular.all('account');
}
private one(id: number) {
return this.restangular.one('account', id);
}
2017-07-13 16:55:02 +02:00
query(): Observable<Account[]> {
return this.all().getList();
2017-07-13 16:55:02 +02:00
}
get(id: number): Observable<Account> {
return this.one(id).get();
2017-07-13 16:55:02 +02:00
}
create(account: Account): Observable<Account> {
return this.all().post(account);
2017-07-13 16:55:02 +02:00
}
update(account: Account): Observable<Account> {
return this.one(account.id).post(null, account);
2017-07-13 16:55:02 +02:00
}
delete(account: Account): Observable<Account> {
return this.one(account.id).delete();
2017-07-13 16:55:02 +02:00
}
}