Créations des agences

pull/2/head
Clement FERRERE 3 years ago
parent 36cea04523
commit 7ec56d446c
  1. 0
      src/app/agence-edit/agence-edit.component.css
  2. 1
      src/app/agence-edit/agence-edit.component.html
  3. 25
      src/app/agence-edit/agence-edit.component.spec.ts
  4. 15
      src/app/agence-edit/agence-edit.component.ts
  5. 16
      src/app/agence.service.spec.ts
  6. 50
      src/app/agence.service.ts
  7. 4
      src/app/agence.ts
  8. 0
      src/app/agence/agence.component.css
  9. 21
      src/app/agence/agence.component.html
  10. 25
      src/app/agence/agence.component.spec.ts
  11. 35
      src/app/agence/agence.component.ts
  12. 4
      src/app/app-routing.module.ts
  13. 3
      src/app/app.component.html
  14. 4
      src/app/app.module.ts
  15. 1
      src/app/collaborateur.service.ts

@ -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);
});
}
}

@ -3,12 +3,16 @@ import {RouterModule,Routes} from "@angular/router";
import {CollaborateurComponent} from "./collaborateur/collaborateur.component";
import {CollaborateurEditComponent} from "./collaborateur-edit/collaborateur-edit.component";
import {HomeComponent} from "./home/home.component";
import {AgenceComponent} from "./agence/agence.component";
import {AgenceEditComponent} from "./agence-edit/agence-edit.component";
const routes : Routes = [
{path:'', redirectTo:'/home', pathMatch:'full'},
{ path: 'home', component:HomeComponent },
{ path:'collaborateurs',component:CollaborateurComponent },
{ path: 'collaborateurs/:id', component: CollaborateurEditComponent },
{ path:'agences',component:AgenceComponent },
{ path: 'agences/:id', component: AgenceEditComponent },
];
@NgModule({

@ -70,6 +70,9 @@
<nav>
<a class="toolbar-button" routerLink="/collaborateurs">Collaborateurs</a>
</nav>
<nav>
<a class="toolbar-button" routerLink="/agences">Agences</a>
</nav>
</div>
<div class="content" role="main">

@ -10,6 +10,8 @@ import {FormsModule} from "@angular/forms";
import { MessagesComponent } from './messages/messages.component';
import { AppRoutingModule } from './app-routing.module';
import { HomeComponent } from './home/home.component';
import { AgenceComponent } from './agence/agence.component';
import { AgenceEditComponent } from './agence-edit/agence-edit.component';
@NgModule({
declarations: [
@ -18,6 +20,8 @@ import { HomeComponent } from './home/home.component';
CollaborateurEditComponent,
MessagesComponent,
HomeComponent,
AgenceComponent,
AgenceEditComponent,
],
imports: [
BrowserModule,

@ -43,7 +43,6 @@ export class CollaborateurService {
return this.http.delete(this.collaborateursUrl + "/" + collaborateur.id);
}
/** POST: add a new hero to the server */
addCollaborateur(collaborateur: Collaborateur): Observable<Collaborateur> {
let body = JSON.stringify(collaborateur);
this.log(`add collaborateur ${body}`);

Loading…
Cancel
Save