aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/services/users.service.ts
blob: 1b6dfb665a87448e6b1dee194de4d0a9c21770c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 url = "http://localhost:8080/users"
    private httpOptions = {
        headers: new HttpHeaders({'Content-Type': 'application/json'})
    };

    constructor(
        private http: HttpClient
    ) {}

    createUser(data: User): Observable<User> {
        return this.http.post<User>(this.url, data, this.httpOptions)
    }

    getUser(id: number): Observable<User> {
        return this.http.get<User>(`${this.url}/${id}`, this.httpOptions)
    }

    updateUser(id: number): Observable<User> {
        return this.http.put<User>(`${this.url}/${id}`, this.httpOptions)
    }

    deleteUser(id: number): Observable<boolean> {
        return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions)
    }
}