aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/services/cupboard.service.ts
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-03-27 18:55:39 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-03-27 18:55:39 -0400
commitd6f4aad157baad7d9b25d56ce056b80805e88f5f (patch)
tree1b4a3df94389afb1637ea59fe47ba3a327c89561 /ufund-ui/src/app/services/cupboard.service.ts
parent96f833352eff7b9428daf2add988ecd0a2b41d92 (diff)
parentddbd1cc688aa98fb275ad72a750fbaaf53e6c0ae (diff)
downloadJellySolutions-d6f4aad157baad7d9b25d56ce056b80805e88f5f.tar.gz
JellySolutions-d6f4aad157baad7d9b25d56ce056b80805e88f5f.tar.bz2
JellySolutions-d6f4aad157baad7d9b25d56ce056b80805e88f5f.zip
Merge branch 'main' into css
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())
}
}