2017-07-13 16:55:02 +02:00
|
|
|
// vim: set tw=80 ts=2 sw=2 sts=2 :
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Observable } from 'rxjs/Rx';
|
|
|
|
|
2017-07-16 10:37:52 +02:00
|
|
|
import { Restangular } from "ngx-restangular";
|
2017-07-13 16:55:02 +02:00
|
|
|
|
|
|
|
import { Account } from './account';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class AccountService {
|
2017-07-16 10:37:52 +02:00
|
|
|
constructor(
|
2017-07-20 22:53:22 +02:00
|
|
|
private restangular: Restangular
|
|
|
|
) {}
|
2017-07-13 16:55:02 +02:00
|
|
|
|
2017-07-16 10:37:52 +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[]> {
|
2017-07-16 10:37:52 +02:00
|
|
|
return this.all().getList();
|
2017-07-13 16:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get(id: number): Observable<Account> {
|
2017-07-16 10:37:52 +02:00
|
|
|
return this.one(id).get();
|
2017-07-13 16:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
create(account: Account): Observable<Account> {
|
2017-07-16 10:37:52 +02:00
|
|
|
return this.all().post(account);
|
2017-07-13 16:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
update(account: Account): Observable<Account> {
|
2017-07-16 10:37:52 +02:00
|
|
|
return this.one(account.id).post(null, account);
|
2017-07-13 16:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
delete(account: Account): Observable<Account> {
|
2017-07-16 10:37:52 +02:00
|
|
|
return this.one(account.id).delete();
|
2017-07-13 16:55:02 +02:00
|
|
|
}
|
|
|
|
}
|