BETTERZON-118: Adding service functions for managing favorite shops (#66)

This commit is contained in:
Patrick 2021-05-26 21:30:53 +02:00 committed by GitHub
parent 6b88c48018
commit 1a65783690
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,5 @@
export interface FavoriteShop {
favorite_id: number;
vendor_id: number;
user_id: number;
}

View File

@ -6,6 +6,7 @@ import {Price} from '../models/price';
import {Observable, of} from 'rxjs'; import {Observable, of} from 'rxjs';
import {Vendor} from '../models/vendor'; import {Vendor} from '../models/vendor';
import {PriceAlarm} from '../models/pricealarm'; import {PriceAlarm} from '../models/pricealarm';
import {FavoriteShop} from '../models/favoriteshop';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -332,4 +333,52 @@ export class ApiService {
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
} }
} }
/* ______ _ __ __
/ ____/___ __ ______ _____(_) /____ _____/ /_ ____ ____ _____
/ /_ / __ `/ | / / __ \/ ___/ / __/ _ \ / ___/ __ \/ __ \/ __ \/ ___/
/ __/ / /_/ /| |/ / /_/ / / / / /_/ __/ (__ ) / / / /_/ / /_/ (__ )
/_/ \__,_/ |___/\____/_/ /_/\__/\___/ /____/_/ /_/\____/ .___/____/
/_/
*/
/**
* Gets a list of all favorite shops
* @return Observable<FavoriteShop[]> An observable list of favorite shops
*/
getFavoriteShops(): Observable<FavoriteShop[]> {
try {
return this.http.get<FavoriteShop[]>((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<any> The observable response of the api
*/
addFavoriteShop(vendorId: number): Observable<any> {
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<any> The observable response of the api
*/
deleteFavoriteShop(vendorId: number): Observable<any> {
try {
return this.http.delete((this.apiUrl + '/favoriteshops/' + vendorId));
} catch (exception) {
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
}
}
} }