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.ts30
1 files changed, 20 insertions, 10 deletions
diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts
index 9e14106..9232c0c 100644
--- a/ufund-ui/src/app/services/cupboard.service.ts
+++ b/ufund-ui/src/app/services/cupboard.service.ts
@@ -2,6 +2,7 @@ import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Need} from '../models/Need';
import {Observable} from 'rxjs';
+import {AuthService} from './auth.service';
@Injectable({
providedIn: 'root'
@@ -9,35 +10,44 @@ import {Observable} from 'rxjs';
export class CupboardService {
private url = "http://localhost:8080/cupboard"
- private httpOptions = {
- headers: new HttpHeaders({'Content-Type': 'application/json'})
- };
+
+ httpOptions = () => ({
+ headers: new HttpHeaders({
+ 'Content-Type': 'application/json',
+ "jelly-api-key": this.authService.getApiKey()
+ })
+ });
constructor(
- private http: HttpClient
+ private http: HttpClient,
+ private authService: AuthService
) {}
createNeed(need: Need): Observable<boolean> {
- return this.http.post<boolean>(this.url, need, this.httpOptions)
+ return this.http.post<boolean>(this.url, need, this.httpOptions())
}
getNeeds(): Observable<Need[]> {
- return this.http.get<Need[]>(this.url, this.httpOptions)
+ 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)
+ 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)
+ 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)
+ return this.http.put<boolean>(`${this.url}/${id}`, data, this.httpOptions())
}
deleteNeed(id: number): Observable<boolean> {
- return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions)
+ return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions())
+ }
+
+ checkoutNeed(id: number, quantity: number) {
+ return this.http.put(`${this.url}/checkout`, {needID: id, amount: quantity}, this.httpOptions())
}
}