production.service.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http'
  3. import { Observable } from 'rxjs';
  4. import { Production, ProductionShort, ProductionFile } from './production';
  5. @Injectable({ providedIn: 'root' })
  6. export class ProductionService
  7. {
  8. private baseURL = "http://localhost:8080/demovote-api/v1/production";
  9. constructor(private httpClient: HttpClient) { }
  10. getListProduction(): Observable<ProductionShort[]>{ return this.httpClient.get<ProductionShort[]>(`${this.baseURL}/list`); }
  11. getProductionFile(id: number): Observable<HttpResponse<Blob>>
  12. {
  13. let headers = new HttpHeaders();
  14. headers = headers.append('Accept', 'application/zip');
  15. return this.httpClient.get(`${this.baseURL}/file/${id}`, { headers: headers, observe: 'response', responseType: 'blob' });
  16. }
  17. createProduction(production: Production): Observable<Object>{ return this.httpClient.post(`${this.baseURL}/create`, production); }
  18. getByIdProduction(id: number): Observable<ProductionShort>{ return this.httpClient.get<ProductionShort>(`${this.baseURL}/form/${id}`); }
  19. updateProduction(id: number, production: ProductionShort): Observable<Object>{ return this.httpClient.put(`${this.baseURL}/update/${id}`, production); }
  20. getByIdProductionFile(id: number): Observable<ProductionFile>{ return this.httpClient.get<ProductionFile>(`${this.baseURL}/formfile/${id}`); }
  21. uploadProductionFile(id: number, production: ProductionFile): Observable<Object>{ return this.httpClient.put(`${this.baseURL}/upload/${id}`, production); }
  22. deleteProduction(id: number): Observable<Object>{ return this.httpClient.delete(`${this.baseURL}/delete/${id}`); }
  23. }