diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6c1d9a3..74a998c 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -12,6 +12,8 @@ import { HomeComponent } from './components/home/home.component'; import { AgenceComponent } from './components/agence/agence.component'; import { AgenceEditComponent } from './components/agence/agence-edit/agence-edit.component'; import { CollaborateurDetailComponent } from './components/collaborateur/collaborateur-detail/collaborateur-detail.component'; +import { BusinessunitComponent } from './components/businessunit/businessunit.component'; +import { BusinessunitEditComponent } from './components/businessunit/businessunit-edit/businessunit-edit.component'; @NgModule({ declarations: [ @@ -21,7 +23,9 @@ import { CollaborateurDetailComponent } from './components/collaborateur/collabo HomeComponent, AgenceComponent, AgenceEditComponent, - CollaborateurDetailComponent + CollaborateurDetailComponent, + BusinessunitComponent, + BusinessunitEditComponent ], imports: [ BrowserModule, diff --git a/src/app/interfaces/businessunit.ts b/src/app/interfaces/businessunit.ts new file mode 100644 index 0000000..0b1b86a --- /dev/null +++ b/src/app/interfaces/businessunit.ts @@ -0,0 +1,5 @@ +export interface Businessunit { + name: string; + id: number; + agenceId : number; +} diff --git a/src/app/services/businessunit.service.ts b/src/app/services/businessunit.service.ts new file mode 100644 index 0000000..bd17c09 --- /dev/null +++ b/src/app/services/businessunit.service.ts @@ -0,0 +1,40 @@ +import { Injectable } from '@angular/core'; +import {HttpClient, HttpHeaders} from "@angular/common/http"; +import {Observable} from "rxjs"; +import {Businessunit} from "../interfaces/businessunit"; +import {businessunitsUrl} from "../../ressources/routes/routes"; + +@Injectable({ + providedIn: 'root' +}) +export class BusinessunitService { + private businessunitsUrl = businessunitsUrl; + + httpOptions = { + headers: new HttpHeaders({ 'Content-Type': 'application/json' }) + }; + + constructor(private http: HttpClient) { } + + getBusinessunits():Observable { + return this.http.get(this.businessunitsUrl); + } + + getBusinessunit(id : number):Observable{ + return this.http.get(this.businessunitsUrl+"/"+id); + } + + updateBusinessunit(businessunit : Businessunit):Observable{ + let body = JSON.stringify(businessunit); + return this.http.put(this.businessunitsUrl + "/" + businessunit.id, body, this.httpOptions); + } + + deleteBusinessunit(businessunit: Businessunit) { + return this.http.delete(this.businessunitsUrl + "/" + businessunit.id); + } + + addBusinessunit(businessunit: Businessunit): Observable { + let body = JSON.stringify(businessunit); + return this.http.post(this.businessunitsUrl, body, this.httpOptions); + } +} diff --git a/src/ressources/routes/routes.ts b/src/ressources/routes/routes.ts index 1eb9e54..83e2c54 100644 --- a/src/ressources/routes/routes.ts +++ b/src/ressources/routes/routes.ts @@ -1,2 +1,3 @@ export const collaborateursUrl = 'https://localhost:7125/api/collaborateurs'; export const agencesUrl = 'https://localhost:7125/api/agences'; +export const businessunitsUrl = 'https://localhost:7125/api/businessunits';