import { Injectable } from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; import {Observable} from 'rxjs'; import {User} from '../models/User'; @Injectable({ providedIn: 'root' }) export class UsersService { private currentUserID? : number private url = "http://localhost:8080/users" private httpOptions = { headers: new HttpHeaders({'Content-Type': 'application/json'}) }; constructor( private http: HttpClient ) {} createUser(data: User): Observable { return this.http.post(this.url, data, this.httpOptions) } getUser(id: number): Observable { return this.http.get(`${this.url}/${id}`, this.httpOptions) } updateUser(id: number): Observable { return this.http.put(`${this.url}/${id}`, this.httpOptions) } deleteUser(id: number): Observable { return this.http.delete(`${this.url}/${id}`, this.httpOptions) } getCurrentUser(): Observable | undefined { return this.currentUserID ? this.getUser(this.currentUserID) : undefined } }