aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/services/cupboard.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-ui/src/app/services/cupboard.service.ts')
-rw-r--r--ufund-ui/src/app/services/cupboard.service.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts
new file mode 100644
index 0000000..6e2671a
--- /dev/null
+++ b/ufund-ui/src/app/services/cupboard.service.ts
@@ -0,0 +1,44 @@
+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 = "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)
+ }
+}