From 36173c61176077f8c809a88db2466440875cc02e Mon Sep 17 00:00:00 2001 From: Patrick <50352812+Mueller-Patrick@users.noreply.github.com> Date: Wed, 26 May 2021 20:51:19 +0200 Subject: [PATCH 1/3] BETTERZON-111: Adding service functions for login and registration (#64) --- Frontend/src/app/services/api.service.ts | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Frontend/src/app/services/api.service.ts b/Frontend/src/app/services/api.service.ts index 640b317..c38581a 100644 --- a/Frontend/src/app/services/api.service.ts +++ b/Frontend/src/app/services/api.service.ts @@ -207,4 +207,48 @@ export class ApiService { process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); } } + + + /* __ __ + / / / /_______ __________ + / / / / ___/ _ \/ ___/ ___/ + / /_/ (__ ) __/ / (__ ) + \____/____/\___/_/ /____/ + */ + + /** + * Registers a new user with the API + * @param username The username for the new user + * @param password The password for the new user + * @param email The email address for the new user + * @return Observable The observable response of the api + */ + registerUser(username: string, password: string, email: string): Observable { + try { + return this.http.post((this.apiUrl + '/users/register'), JSON.stringify({ + username, + password, + email + })); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + /** + * Logs a user in with the api + * @param username The username of the user to log in + * @param password The password of the user to log in + * @return Observable The observable response of the api + */ + loginUser(username: string, password: string): Observable { + try { + return this.http.post((this.apiUrl + '/users/login'), JSON.stringify({ + username, + password + })); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } } From 6b88c48018cd5619a43dbabc1ea661664efc21b4 Mon Sep 17 00:00:00 2001 From: Patrick <50352812+Mueller-Patrick@users.noreply.github.com> Date: Wed, 26 May 2021 21:13:17 +0200 Subject: [PATCH 2/3] BETTERZON-112: Adding service functions for managing vendor shops (#65) --- Backend/src/models/vendors/vendors.router.ts | 6 +- Frontend/src/app/services/api.service.ts | 97 ++++++++++++++++++-- 2 files changed, 92 insertions(+), 11 deletions(-) diff --git a/Backend/src/models/vendors/vendors.router.ts b/Backend/src/models/vendors/vendors.router.ts index 89d02fd..20d2086 100644 --- a/Backend/src/models/vendors/vendors.router.ts +++ b/Backend/src/models/vendors/vendors.router.ts @@ -86,7 +86,7 @@ vendorsRouter.get('/search/:term', async (req: Request, res: Response) => { } }); -// PUT /manage/deactivatelisting +// PUT vendors/manage/deactivatelisting vendorsRouter.put('/manage/deactivatelisting', async (req: Request, res: Response) => { try { // Authenticate user @@ -110,7 +110,7 @@ vendorsRouter.put('/manage/deactivatelisting', async (req: Request, res: Respons } }); -// PUT /manage/shop/deactivate/:id +// PUT vendors/manage/shop/deactivate/:id vendorsRouter.put('/manage/shop/deactivate/:id', async (req: Request, res: Response) => { try { // Authenticate user @@ -133,7 +133,7 @@ vendorsRouter.put('/manage/shop/deactivate/:id', async (req: Request, res: Respo } }); -// PUT /manage/shop/activate/:id +// PUT vendors/manage/shop/activate/:id vendorsRouter.put('/manage/shop/activate/:id', async (req: Request, res: Response) => { try { // Authenticate user diff --git a/Frontend/src/app/services/api.service.ts b/Frontend/src/app/services/api.service.ts index c38581a..bf3d2aa 100644 --- a/Frontend/src/app/services/api.service.ts +++ b/Frontend/src/app/services/api.service.ts @@ -31,7 +31,7 @@ export class ApiService { * @param id The id of the product to get * @return Observable An observable containing a single product */ - getProduct(id): Observable { + getProduct(id: number): Observable { try { return this.http.get((this.apiUrl + '/products/' + id)); } catch (exception) { @@ -45,7 +45,7 @@ export class ApiService { * @param query The search term to match * @return Observable An observable list of products */ - getProductsByQuery(query): Observable { + getProductsByQuery(query: string): Observable { try { return this.http.get((this.apiUrl + '/products/search/' + query)); } catch (exception) { @@ -90,10 +90,10 @@ export class ApiService { * @param productId The product id of the product to fetch the prices for * @return Observable An observable list of prices */ - getLowestPrices(productId): Observable { + getLowestPrices(productId: number): Observable { try { let params = new HttpParams(); - params = params.append('product', productId); + params = params.append('product', productId.toString()); params = params.append('type', 'lowest'); return this.http.get((this.apiUrl + '/prices'), {params}); } catch (exception) { @@ -106,10 +106,10 @@ export class ApiService { * @param productId The product id of the product to get the price for * @return Observable An observable containing a single price */ - getAmazonPrice(productId): Observable { + getAmazonPrice(productId: number): Observable { try { let params = new HttpParams(); - params = params.append('product', productId); + params = params.append('product', productId.toString()); params = params.append('vendor', '1'); params = params.append('type', 'newest'); return this.http.get((this.apiUrl + '/prices'), {params}); @@ -123,10 +123,10 @@ export class ApiService { * @param productId The product id of the product to fetch the prices for * @return Observable An observable list of prices */ - getCurrentPricePerVendor(productId): Observable { + getCurrentPricePerVendor(productId: number): Observable { try { let params = new HttpParams(); - params = params.append('product', productId); + params = params.append('product', productId.toString()); params = params.append('type', 'newest'); return this.http.get((this.apiUrl + '/prices'), {params}); } catch (exception) { @@ -154,6 +154,87 @@ export class ApiService { } } + /** + * Gets a list of all managed vendors + * @return Observable An observable list of vendors + */ + getManagedVendors(): Observable { + try { + return this.http.get((this.apiUrl + '/vendors/managed')); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + /** + * Get the specific vendor info by vendor id + * @param id The id of the vendor to get information for + * @return Observable An observable containing a single vendor + */ + getVendorById(id: number): Observable { + try { + return this.http.get((this.apiUrl + '/vendors/' + id)); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + /** + * Gets a list of vendors that match the given search term + * @param query The search term to match + * @return Observable An observable list of vendors + */ + getVendorsByQuery(query: string): Observable { + try { + return this.http.get((this.apiUrl + '/vendors/search/' + query)); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + /** + * Deactivates the specified product listing for the specified vendor + * @param vendorId The vendor id of the vendor to deactivate the product for + * @param productId The product id of the product to deactivate + * @return Observable The observable response of the api + */ + deactivateSingleVendorListing(vendorId: number, productId: number): Observable { + try { + return this.http.put((this.apiUrl + '/vendors/manage/deactivatelisting'), JSON.stringify({ + vendor_id: vendorId, + product_id: productId + })); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + /** + * Deactivates the specified vendor completely + * @param vendorId The vendor id of the vendor to deactivate + * @return Observable The observable response of the api + */ + deactivateVendor(vendorId: number): Observable { + try { + return this.http.put((this.apiUrl + '/vendors/manage/shop/deactivate/' + vendorId), JSON.stringify({})); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + + /** + * Activates the specified vendor completely + * @param vendorId The vendor id of the vendor to activate + * @return Observable The observable response of the api + */ + activateVendor(vendorId: number): Observable { + try { + return this.http.put((this.apiUrl + '/vendors/manage/shop/activate/' + vendorId), JSON.stringify({})); + } catch (exception) { + process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); + } + } + /* ____ _ ___ __ / __ \_____(_)_______ / | / /___ __________ ___ _____ 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 3/3] 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`); + } + } }