parent
36cea04523
commit
7ec56d446c
@ -0,0 +1 @@ |
||||
<p>agence-edit works!</p> |
@ -0,0 +1,25 @@ |
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
||||
|
||||
import { AgenceEditComponent } from './agence-edit.component'; |
||||
|
||||
describe('AgenceEditComponent', () => { |
||||
let component: AgenceEditComponent; |
||||
let fixture: ComponentFixture<AgenceEditComponent>; |
||||
|
||||
beforeEach(async () => { |
||||
await TestBed.configureTestingModule({ |
||||
declarations: [ AgenceEditComponent ] |
||||
}) |
||||
.compileComponents(); |
||||
}); |
||||
|
||||
beforeEach(() => { |
||||
fixture = TestBed.createComponent(AgenceEditComponent); |
||||
component = fixture.componentInstance; |
||||
fixture.detectChanges(); |
||||
}); |
||||
|
||||
it('should create', () => { |
||||
expect(component).toBeTruthy(); |
||||
}); |
||||
}); |
@ -0,0 +1,15 @@ |
||||
import { Component, OnInit } from '@angular/core'; |
||||
|
||||
@Component({ |
||||
selector: 'app-agence-edit', |
||||
templateUrl: './agence-edit.component.html', |
||||
styleUrls: ['./agence-edit.component.css'] |
||||
}) |
||||
export class AgenceEditComponent implements OnInit { |
||||
|
||||
constructor() { } |
||||
|
||||
ngOnInit(): void { |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
import { TestBed } from '@angular/core/testing'; |
||||
|
||||
import { AgenceService } from './agence.service'; |
||||
|
||||
describe('AgenceService', () => { |
||||
let service: AgenceService; |
||||
|
||||
beforeEach(() => { |
||||
TestBed.configureTestingModule({}); |
||||
service = TestBed.inject(AgenceService); |
||||
}); |
||||
|
||||
it('should be created', () => { |
||||
expect(service).toBeTruthy(); |
||||
}); |
||||
}); |
@ -0,0 +1,50 @@ |
||||
import { Injectable } from '@angular/core'; |
||||
import {HttpClient, HttpHeaders} from "@angular/common/http"; |
||||
import {MessageService} from "./message.service"; |
||||
import {Observable} from "rxjs"; |
||||
import {Agence} from "./agence"; |
||||
|
||||
@Injectable({ |
||||
providedIn: 'root' |
||||
}) |
||||
export class AgenceService { |
||||
private agencesUrl = 'https://localhost:7125/api/agences'; |
||||
|
||||
httpOptions = { |
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }) |
||||
}; |
||||
|
||||
constructor(private http: HttpClient, |
||||
private messageService : MessageService) { } |
||||
|
||||
private log(message : string){ |
||||
this.messageService.add(`AgenceService : ${message}`) |
||||
} |
||||
|
||||
getAgences():Observable<Agence[]> { |
||||
this.log('get all agences'); |
||||
return this.http.get<Agence[]>(this.agencesUrl); |
||||
} |
||||
|
||||
getAgence(id : number):Observable<Agence>{ |
||||
this.log(`get agence by id : ${id}`); |
||||
return this.http.get<Agence>(this.agencesUrl+"/"+id); |
||||
} |
||||
|
||||
updateAgence(agence : Agence):Observable<any>{ |
||||
let body = JSON.stringify(agence); |
||||
this.log(`update agence ${agence.id}`) |
||||
return this.http.put(this.agencesUrl + "/" + agence.id, body, this.httpOptions); |
||||
} |
||||
|
||||
deleteAgence(agence: Agence) { |
||||
this.log(`delete agence ${agence.id}`) |
||||
return this.http.delete(this.agencesUrl + "/" + agence.id); |
||||
} |
||||
|
||||
addAgence(agence: Agence): Observable<Agence> { |
||||
let body = JSON.stringify(agence); |
||||
this.log(`add agence ${body}`); |
||||
return this.http.post<Agence>(this.agencesUrl, body, this.httpOptions); |
||||
} |
||||
} |
@ -0,0 +1,4 @@ |
||||
export interface Agence { |
||||
name: string; |
||||
id: number; |
||||
} |
@ -0,0 +1,21 @@ |
||||
<div xmlns=""> |
||||
<h2>Mes Agences</h2> |
||||
|
||||
<table *ngFor="let agence of agences"> |
||||
|
||||
<td> {{agence.name}} </td> |
||||
<td></td> |
||||
<td> <a routerLink="{{agence.id}}"> Modifier </a></td> |
||||
</table> |
||||
|
||||
<h3>Ajouter un collaborateur : </h3> |
||||
|
||||
<div> |
||||
<label class="col-2" for="collaborateur-name">Collaborateur name </label> |
||||
<input id="collaborateur-name" [(ngModel)]="agence.name" placeholder="name"> |
||||
</div> |
||||
|
||||
<button class="add-button" (click)="add(agence)"> |
||||
Ajouter une Agence |
||||
</button> |
||||
</div> |
@ -0,0 +1,25 @@ |
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
||||
|
||||
import { AgenceComponent } from './agence.component'; |
||||
|
||||
describe('AgenceComponent', () => { |
||||
let component: AgenceComponent; |
||||
let fixture: ComponentFixture<AgenceComponent>; |
||||
|
||||
beforeEach(async () => { |
||||
await TestBed.configureTestingModule({ |
||||
declarations: [ AgenceComponent ] |
||||
}) |
||||
.compileComponents(); |
||||
}); |
||||
|
||||
beforeEach(() => { |
||||
fixture = TestBed.createComponent(AgenceComponent); |
||||
component = fixture.componentInstance; |
||||
fixture.detectChanges(); |
||||
}); |
||||
|
||||
it('should create', () => { |
||||
expect(component).toBeTruthy(); |
||||
}); |
||||
}); |
@ -0,0 +1,35 @@ |
||||
import { Component, OnInit } from '@angular/core'; |
||||
import {Agence} from "../agence"; |
||||
import {HttpClient} from "@angular/common/http"; |
||||
import {AgenceService} from "../agence.service"; |
||||
|
||||
@Component({ |
||||
selector: 'app-agence', |
||||
templateUrl: './agence.component.html', |
||||
styleUrls: ['./agence.component.css'] |
||||
}) |
||||
export class AgenceComponent implements OnInit { |
||||
agences : Agence[] = []; |
||||
agence = {} as Agence ; |
||||
|
||||
constructor( |
||||
private http : HttpClient, |
||||
private agenceservice: AgenceService, |
||||
) { } |
||||
|
||||
ngOnInit(): void { |
||||
this.getAgences(); |
||||
} |
||||
|
||||
getAgences():void { |
||||
this.agenceservice.getAgences() |
||||
.subscribe(agences => this.agences = agences); |
||||
} |
||||
|
||||
add(agence: Agence): void { |
||||
this.agenceservice.addAgence(agence) |
||||
.subscribe(agence => { |
||||
this.agences.push(agence); |
||||
}); |
||||
} |
||||
} |
Loading…
Reference in new issue