From 8a2d6c332a089c2dbb7351514499e16f343959ff Mon Sep 17 00:00:00 2001 From: sowgro Date: Wed, 26 Feb 2025 20:41:35 -0500 Subject: Start services and organize project --- ufund-ui/src/app/services/cupboard.service.ts | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 ufund-ui/src/app/services/cupboard.service.ts (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 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 { + return this.http.post( + this.url, need, this.httpOptions) + } + + getNeeds(): Observable { + return this.http.get(this.url, this.httpOptions) + } + + searchNeeds(name: String): Observable { + return this.http.get(`${this.url}/?name=${name}`, this.httpOptions) + } + + getNeed(id: number): Observable { + 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) + } + + deleteNeed(id: number): Observable { + return this.http.put(`${this.url}/${id}`, this.httpOptions) + } +} -- cgit v1.2.3