From ea13cf6ab3b71ff5e83fca876ec71fec1f7b00ae Mon Sep 17 00:00:00 2001 From: sowgro Date: Wed, 26 Mar 2025 15:38:46 -0400 Subject: Make frontend work with the new backend checkout system --- ufund-ui/src/app/services/cupboard.service.ts | 30 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'ufund-ui/src/app/services/cupboard.service.ts') 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 { - return this.http.post(this.url, need, this.httpOptions) + return this.http.post(this.url, need, this.httpOptions()) } getNeeds(): Observable { - return this.http.get(this.url, this.httpOptions) + return this.http.get(this.url, this.httpOptions()) } searchNeeds(name: String): Observable { - return this.http.get(`${this.url}/?name=${name}`, this.httpOptions) + return this.http.get(`${this.url}/?name=${name}`, this.httpOptions()) } getNeed(id: number): Observable { - return this.http.get(`${this.url}/${id}`, this.httpOptions) + return this.http.get(`${this.url}/${id}`, this.httpOptions()) } updateNeed(id: number, data: Need): Observable { - return this.http.put(`${this.url}/${id}`, data, this.httpOptions) + return this.http.put(`${this.url}/${id}`, data, this.httpOptions()) } deleteNeed(id: number): Observable { - return this.http.delete(`${this.url}/${id}`, this.httpOptions) + return this.http.delete(`${this.url}/${id}`, this.httpOptions()) + } + + checkoutNeed(id: number, quantity: number) { + return this.http.put(`${this.url}/checkout`, {needID: id, amount: quantity}, this.httpOptions()) } } -- cgit v1.2.3