aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/services/cupboard.service.ts
blob: 4a2b4b088038ba7abb5707789cdacf716bdd1c39 (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
36
37
38
39
40
41
42
43
import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Need} from '../models/Need';
import {Observable} from 'rxjs';

@Injectable({
    providedIn: 'root'
})
export class CupboardService {

    private url = "http://localhost:8080/cupboard"
    private httpOptions = {
        headers: new HttpHeaders({'Content-Type': 'application/json'})
    };

    constructor(
        private http: HttpClient
    ) {}

    createNeed(need: Need): Observable<boolean> {
        return this.http.post<boolean>(this.url, need, this.httpOptions)
    }

    getNeeds(): Observable<Need[]> {
        return this.http.get<Need[]>(this.url, this.httpOptions)
    }

    searchNeeds(name: String): Observable<Need[]> {
        return this.http.get<Need[]>(`${this.url}/?name=${name}`, this.httpOptions)
    }

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

    updateNeed(id: number, data: Need): Observable<boolean> {
        return this.http.put<boolean>(`${this.url}/${id}`, data, this.httpOptions)
    }

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