user.service.ts 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient, HttpResponse } from '@angular/common/http';
  3. import { Observable } from 'rxjs';
  4. import { SERVER_API_URL } from 'app/app.constants';
  5. import { createRequestOption } from 'app/shared/util/request-util';
  6. import { IUser } from './user.model';
  7. @Injectable({ providedIn: 'root' })
  8. export class UserService {
  9. public resourceUrl = SERVER_API_URL + 'api/users';
  10. constructor(private http: HttpClient) {}
  11. create(user: IUser): Observable<HttpResponse<IUser>> {
  12. return this.http.post<IUser>(this.resourceUrl, user, { observe: 'response' });
  13. }
  14. update(user: IUser): Observable<HttpResponse<IUser>> {
  15. return this.http.put<IUser>(this.resourceUrl, user, { observe: 'response' });
  16. }
  17. find(login: string): Observable<HttpResponse<IUser>> {
  18. return this.http.get<IUser>(`${this.resourceUrl}/${login}`, { observe: 'response' });
  19. }
  20. query(req?: any): Observable<HttpResponse<IUser[]>> {
  21. const options = createRequestOption(req);
  22. return this.http.get<IUser[]>(this.resourceUrl, { params: options, observe: 'response' });
  23. }
  24. delete(login: string): Observable<HttpResponse<any>> {
  25. return this.http.delete(`${this.resourceUrl}/${login}`, { observe: 'response' });
  26. }
  27. authorities(): Observable<string[]> {
  28. return this.http.get<string[]>(SERVER_API_URL + 'api/users/authorities');
  29. }
  30. }