mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2024-11-12 17:43:57 +00:00
BETTERZON-123: Adding service functions for categories API (#69)
This commit is contained in:
parent
7dc76649fc
commit
6bb1c8f66b
4
Frontend/src/app/models/category.ts
Normal file
4
Frontend/src/app/models/category.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export interface Category {
|
||||
category_id: number;
|
||||
name: string;
|
||||
}
|
|
@ -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<Category> An observable containing a single product
|
||||
*/
|
||||
getCategoryById(id: number): Observable<Category> {
|
||||
try {
|
||||
return this.http.get<Category>((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<Category[]> An observable list of categories
|
||||
*/
|
||||
getCategoryByQuery(query: string): Observable<Category[]> {
|
||||
try {
|
||||
return this.http.get<Category[]>((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<Category[]> An observable list of categories
|
||||
*/
|
||||
getCategories(): Observable<Category[]> {
|
||||
try {
|
||||
return this.http.get<Category[]>((this.apiUrl + '/categories'));
|
||||
} catch (exception) {
|
||||
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user