diff --git a/Frontend/src/app/models/category.ts b/Frontend/src/app/models/category.ts new file mode 100644 index 0000000..a909167 --- /dev/null +++ b/Frontend/src/app/models/category.ts @@ -0,0 +1,4 @@ +export interface Category { + category_id: number; + name: string; +} diff --git a/Frontend/src/app/services/api.service.ts b/Frontend/src/app/services/api.service.ts index 77e3424..cdc0b94 100644 --- a/Frontend/src/app/services/api.service.ts +++ b/Frontend/src/app/services/api.service.ts @@ -8,6 +8,7 @@ import {Vendor} from '../models/vendor'; import {PriceAlarm} from '../models/pricealarm'; import {FavoriteShop} from '../models/favoriteshop'; import {ContactPerson} from '../models/contactperson'; +import {Category} from '../models/category'; @Injectable({ providedIn: 'root' @@ -479,4 +480,52 @@ export class ApiService { process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); } } + + + /* ______ __ _ + / ____/___ _/ /____ ____ _____ _____(_)__ _____ + / / / __ `/ __/ _ \/ __ `/ __ \/ ___/ / _ \/ ___/ + / /___/ /_/ / /_/ __/ /_/ / /_/ / / / / __(__ ) + \____/\__,_/\__/\___/\__, /\____/_/ /_/\___/____/ + /____/ + */ + + /** + * Gets the specified category from the API + * @param id The id of the category to get + * @return Observable An observable containing a single product + */ + getCategoryById(id: number): Observable { + try { + return this.http.get((this.apiUrl + '/categories/' + id)); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + + /** + * Gets a list of categories that match the given search term + * @param query The search term to match + * @return Observable An observable list of categories + */ + getCategoryByQuery(query: string): Observable { + try { + return this.http.get((this.apiUrl + '/categories/search/' + query)); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + /** + * Gets a list of all categories + * @return Observable An observable list of categories + */ + getCategories(): Observable { + try { + return this.http.get((this.apiUrl + '/categories')); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } }