From 595fe60fc4608aae946a1ff1d9bb27f7b663bde8 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sat, 29 Jul 2017 17:51:44 +0200 Subject: [PATCH] Add Operation Service. --- src/operations/operation.module.ts | 4 ++- src/operations/operation.service.ts | 43 +++++++++++++++++++++++++++++ src/operations/operation.ts | 9 ++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/operations/operation.service.ts create mode 100644 src/operations/operation.ts diff --git a/src/operations/operation.module.ts b/src/operations/operation.module.ts index c8ad79c..3ed1d67 100644 --- a/src/operations/operation.module.ts +++ b/src/operations/operation.module.ts @@ -10,7 +10,8 @@ import { RestangularModule } from 'ngx-restangular'; import { BalanceChartComponent } from './balanceChart.component'; import { CategoryChartComponent } from './categoryChart.component'; -import { CategoryService } from './category.service' +import { CategoryService } from './category.service'; +import { OperationService } from './operation.service'; @NgModule({ imports: [ @@ -22,6 +23,7 @@ import { CategoryService } from './category.service' ], providers: [ CategoryService, + OperationService, ], declarations: [ BalanceChartComponent, diff --git a/src/operations/operation.service.ts b/src/operations/operation.service.ts new file mode 100644 index 0000000..0a211fb --- /dev/null +++ b/src/operations/operation.service.ts @@ -0,0 +1,43 @@ +// vim: set tw=80 ts=2 sw=2 sts=2 : + +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/Rx'; + +import { Restangular } from "ngx-restangular"; + +import { Operation } from './operation'; + +@Injectable() +export class OperationService { + constructor( + private restangular: Restangular + ) {} + + private all() { + return this.restangular.all('operation'); + } + + private one(id: number) { + return this.restangular.one('operation', id); + } + + query(): Observable { + return this.all().getList(); + } + + get(id: number): Observable { + return this.one(id).get(); + } + + create(operation: Operation): Observable { + return this.all().post(operation); + } + + update(operation: Operation): Observable { + return this.one(operation.id).post(null, operation); + } + + delete(operation: Operation): Observable { + return this.one(operation.id).delete(); + } +} diff --git a/src/operations/operation.ts b/src/operations/operation.ts new file mode 100644 index 0000000..82afb7d --- /dev/null +++ b/src/operations/operation.ts @@ -0,0 +1,9 @@ +// vim: set tw=80 ts=2 sw=2 sts=2: + +export class Operation { + id: number; + operation_date: string; + label: string; + value: number; + category: string; +}