From 63362fbe672dee2f1128ffa827b2dc508828a453 Mon Sep 17 00:00:00 2001 From: Patrick <50352812+Mueller-Patrick@users.noreply.github.com> Date: Sat, 29 May 2021 13:51:07 +0200 Subject: [PATCH] BETTERZON-125: Adding service functions for manufacturer API (#70) --- Frontend/src/app/models/manufacturer.ts | 4 ++ Frontend/src/app/services/api.service.ts | 51 +++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 Frontend/src/app/models/manufacturer.ts diff --git a/Frontend/src/app/models/manufacturer.ts b/Frontend/src/app/models/manufacturer.ts new file mode 100644 index 0000000..08e8ea8 --- /dev/null +++ b/Frontend/src/app/models/manufacturer.ts @@ -0,0 +1,4 @@ +export interface Manufacturer { + manufacturer_id: number; + name: string; +} diff --git a/Frontend/src/app/services/api.service.ts b/Frontend/src/app/services/api.service.ts index cdc0b94..4181455 100644 --- a/Frontend/src/app/services/api.service.ts +++ b/Frontend/src/app/services/api.service.ts @@ -9,6 +9,7 @@ import {PriceAlarm} from '../models/pricealarm'; import {FavoriteShop} from '../models/favoriteshop'; import {ContactPerson} from '../models/contactperson'; import {Category} from '../models/category'; +import {Manufacturer} from '../models/manufacturer'; @Injectable({ providedIn: 'root' @@ -493,7 +494,7 @@ export class ApiService { /** * Gets the specified category from the API * @param id The id of the category to get - * @return Observable An observable containing a single product + * @return Observable An observable containing a single category */ getCategoryById(id: number): Observable { try { @@ -509,7 +510,7 @@ export class ApiService { * @param query The search term to match * @return Observable An observable list of categories */ - getCategoryByQuery(query: string): Observable { + getCategoriesByQuery(query: string): Observable { try { return this.http.get((this.apiUrl + '/categories/search/' + query)); } catch (exception) { @@ -528,4 +529,50 @@ export class ApiService { process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); } } + + /* __ ___ ____ __ + / |/ /___ _____ __ __/ __/___ ______/ /___ __________ __________ + / /|_/ / __ `/ __ \/ / / / /_/ __ `/ ___/ __/ / / / ___/ _ \/ ___/ ___/ + / / / / /_/ / / / / /_/ / __/ /_/ / /__/ /_/ /_/ / / / __/ / (__ ) + /_/ /_/\__,_/_/ /_/\__,_/_/ \__,_/\___/\__/\__,_/_/ \___/_/ /____/ + */ + + /** + * Gets the specified manufacturer from the API + * @param id The id of the manufacturer to get + * @return Observable An observable containing a single manufacturer + */ + getManufacturerById(id: number): Observable { + try { + return this.http.get((this.apiUrl + '/manufacturers/' + id)); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + + /** + * Gets a list of manufacturers that match the given search term + * @param query The search term to match + * @return Observable An observable list of manufacturers + */ + getManufacturersByQuery(query: string): Observable { + try { + return this.http.get((this.apiUrl + '/manufacturers/search/' + query)); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + /** + * Gets a list of all manufacturers + * @return Observable An observable list of manufacturer + */ + getManufacturers(): Observable { + try { + return this.http.get((this.apiUrl + '/manufacturers')); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } }