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";
|
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-14 10:05:09 +02:00
|
|
|
private url = '/api/account/';
|
2017-07-13 16:55:02 +02:00
|
|
|
|
2017-07-16 10:37:52 +02:00
|
|
|
constructor(
|
|
|
|
private logger: Logger,
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|