From 1a65783690c425af88282e56d85e03727da19993 Mon Sep 17 00:00:00 2001 From: Patrick <50352812+Mueller-Patrick@users.noreply.github.com> Date: Wed, 26 May 2021 21:30:53 +0200 Subject: [PATCH] BETTERZON-118: Adding service functions for managing favorite shops (#66) --- Frontend/src/app/models/favoriteshop.ts | 5 +++ Frontend/src/app/services/api.service.ts | 49 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Frontend/src/app/models/favoriteshop.ts diff --git a/Frontend/src/app/models/favoriteshop.ts b/Frontend/src/app/models/favoriteshop.ts new file mode 100644 index 0000000..71652b1 --- /dev/null +++ b/Frontend/src/app/models/favoriteshop.ts @@ -0,0 +1,5 @@ +export interface FavoriteShop { + favorite_id: number; + vendor_id: number; + user_id: number; +} diff --git a/Frontend/src/app/services/api.service.ts b/Frontend/src/app/services/api.service.ts index bf3d2aa..b050996 100644 --- a/Frontend/src/app/services/api.service.ts +++ b/Frontend/src/app/services/api.service.ts @@ -6,6 +6,7 @@ import {Price} from '../models/price'; import {Observable, of} from 'rxjs'; import {Vendor} from '../models/vendor'; import {PriceAlarm} from '../models/pricealarm'; +import {FavoriteShop} from '../models/favoriteshop'; @Injectable({ providedIn: 'root' @@ -332,4 +333,52 @@ export class ApiService { process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); } } + + /* ______ _ __ __ + / ____/___ __ ______ _____(_) /____ _____/ /_ ____ ____ _____ + / /_ / __ `/ | / / __ \/ ___/ / __/ _ \ / ___/ __ \/ __ \/ __ \/ ___/ + / __/ / /_/ /| |/ / /_/ / / / / /_/ __/ (__ ) / / / /_/ / /_/ (__ ) + /_/ \__,_/ |___/\____/_/ /_/\__/\___/ /____/_/ /_/\____/ .___/____/ + /_/ + */ + + /** + * Gets a list of all favorite shops + * @return Observable An observable list of favorite shops + */ + getFavoriteShops(): Observable { + try { + return this.http.get((this.apiUrl + '/favoriteshops')); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + /** + * Adds a vendor as a favorite + * @param vendorId The id of the vendor to mark as favorite + * @return Observable The observable response of the api + */ + addFavoriteShop(vendorId: number): Observable { + try { + return this.http.post((this.apiUrl + '/favoriteshops'), JSON.stringify({ + vendor_id: vendorId + })); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + /** + * Deletes a vendor from favorites + * @param vendorId The id of the vendor to delete from favorites + * @return Observable The observable response of the api + */ + deleteFavoriteShop(vendorId: number): Observable { + try { + return this.http.delete((this.apiUrl + '/favoriteshops/' + vendorId)); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } }