From 16e0e4f9d83257702084b75c1beae924a95de5a4 Mon Sep 17 00:00:00 2001 From: "pakintada@gmail.com" Date: Fri, 2 Feb 2024 17:07:49 +0700 Subject: [PATCH] add topping WIP --- client/src/app/app-routing.module.ts | 13 +- .../src/app/core/layout/layout.component.ts | 10 +- client/src/app/core/models/recipe.model.ts | 2 +- .../src/app/core/services/topping.service.ts | 71 ++++++-- .../material-settings.component.html | 2 +- .../features/toppings/toppings.component.html | 39 ++++ .../features/toppings/toppings.component.ts | 168 ++++++++++++++++++ server/data/data.go | 106 ++++++++++- server/routers/topping.go | 69 +++++++ server/server.go | 4 + server/services/recipe/recipe.go | 2 + 11 files changed, 460 insertions(+), 26 deletions(-) create mode 100644 client/src/app/features/toppings/toppings.component.html create mode 100644 client/src/app/features/toppings/toppings.component.ts create mode 100644 server/routers/topping.go diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts index e6879bd..cfd77d5 100644 --- a/client/src/app/app-routing.module.ts +++ b/client/src/app/app-routing.module.ts @@ -141,10 +141,17 @@ const routes: Routes = [ { path: 'materials', loadComponent: () => - import('./features/material-settings/material-settings.component').then( - (m) => m.MaterialSettingsComponent + import( + './features/material-settings/material-settings.component' + ).then((m) => m.MaterialSettingsComponent), + }, + { + path: 'toppings', + loadComponent: () => + import('./features/toppings/toppings.component').then( + (t) => t.ToppingsComponent ), - } + }, ], }, { diff --git a/client/src/app/core/layout/layout.component.ts b/client/src/app/core/layout/layout.component.ts index bfa31d3..1478473 100644 --- a/client/src/app/core/layout/layout.component.ts +++ b/client/src/app/core/layout/layout.component.ts @@ -34,15 +34,15 @@ export class LayoutComponent implements OnInit, OnDestroy { icon_url: 'assets/icons/recipes.svg', link: '/' + this.current_department + '/recipes', }, - { - name: 'Log', - icon_url: 'assets/icons/logs.svg', - link: '/' + this.current_department + '/log', - }, { name: 'Materials', icon_url: '', link: '/' + this.current_department + '/materials', + }, + { + name: 'Toppings', + icon_url: '', + link: '/' + this.current_department + '/toppings' } ]; date = new Date(); diff --git a/client/src/app/core/models/recipe.model.ts b/client/src/app/core/models/recipe.model.ts index 09de8aa..02016b3 100644 --- a/client/src/app/core/models/recipe.model.ts +++ b/client/src/app/core/models/recipe.model.ts @@ -113,7 +113,7 @@ export interface ToppingGroup { groupID: string; idDefault: string; idInGroup: string; - inUse: string; + inUse: boolean; name: string; otherName: string; } diff --git a/client/src/app/core/services/topping.service.ts b/client/src/app/core/services/topping.service.ts index 22d1ca5..2db4395 100644 --- a/client/src/app/core/services/topping.service.ts +++ b/client/src/app/core/services/topping.service.ts @@ -2,7 +2,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable, count } from 'rxjs'; import { environment } from 'src/environments/environment'; -import { Topping, ToppingSet } from '../models/recipe.model'; +import { Topping, ToppingGroup, ToppingList, ToppingSet } from '../models/recipe.model'; import { RecipeService } from './recipe.service'; import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe'; @@ -10,13 +10,19 @@ import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe'; providedIn: 'root', }) export class ToppingService { - constructor(private _httpClient: HttpClient, private _recipeService: RecipeService) {} + constructor( + private _httpClient: HttpClient, + private _recipeService: RecipeService + ) {} - async getToppings(country: string, filename: string): Promise> { - console.log("getToppings", country); + async getToppings( + country: string, + filename: string + ): Promise> { + console.log('getToppings', country); let asyncCountry = await this._recipeService.getCurrentCountry(); country = getCountryMapSwitcher(asyncCountry); - console.log("getToppingsPreFetch", country, asyncCountry); + console.log('getToppingsPreFetch', country, asyncCountry); return this._httpClient.get( `${environment.api}/recipes/${country}/${filename}/toppings`, { @@ -24,16 +30,20 @@ export class ToppingService { country: country, filename: filename, }, - withCredentials: true + withCredentials: true, } ); } - async getToppingsOfRecipe(country: string, filename: string, productCode: string): Promise> { - console.log("getToppingsOfRecipe", country); + async getToppingsOfRecipe( + country: string, + filename: string, + productCode: string + ): Promise> { + console.log('getToppingsOfRecipe', country); let asyncCountry = await this._recipeService.getCurrentCountry(); country = country || asyncCountry; - console.log("getToppingsOfRecipePreFetch", country, asyncCountry); + console.log('getToppingsOfRecipePreFetch', country, asyncCountry); return this._httpClient.get( `${environment.api}/recipes/${country}/${filename}/${productCode}/toppings`, { @@ -41,8 +51,49 @@ export class ToppingService { country: country, filename: filename, }, - withCredentials: true + withCredentials: true, } ); } + + async getToppingGroups( + country: string, + filename: string + ): Promise> { + console.log('fetching topping group'); + let asyncCountry = await this._recipeService.getCurrentCountry(); + country = getCountryMapSwitcher(asyncCountry); + + return this._httpClient.get( + `${environment.api}/toppings/groups/${country}/${filename}`, + { + params:{ + country: country, + filename: filename + }, + withCredentials: true, + } + ); + } + + async getToppingLists( + country: string, + filename: string + ): Promise> { + console.log('fetching topping list'); + let asyncCountry = await this._recipeService.getCurrentCountry(); + country = getCountryMapSwitcher(asyncCountry); + + return this._httpClient.get( + `${environment.api}/toppings/lists/${country}/${filename}`, + { + params:{ + country: country, + filename: filename + }, + withCredentials: true, + } + ); + } + } diff --git a/client/src/app/features/material-settings/material-settings.component.html b/client/src/app/features/material-settings/material-settings.component.html index 03825c9..d75d589 100644 --- a/client/src/app/features/material-settings/material-settings.component.html +++ b/client/src/app/features/material-settings/material-settings.component.html @@ -39,7 +39,7 @@