From b681a5a9af67b4d10af044e9579adefed57e651f Mon Sep 17 00:00:00 2001 From: Kenta420-Poom Date: Thu, 21 Sep 2023 17:28:37 +0700 Subject: [PATCH] update recipe model --- client/src/app/core/models/recipe.model.ts | 153 +++++++++++++---- client/src/app/core/services/jwt.service.ts | 16 -- .../src/app/core/services/recipe.service.ts | 16 ++ .../dashboard/dashboard.component.html | 37 ++++- .../features/dashboard/dashboard.component.ts | 23 ++- server/data/data.go | 13 +- server/models/recipe.go | 157 +++++++++++++----- 7 files changed, 301 insertions(+), 114 deletions(-) delete mode 100644 client/src/app/core/services/jwt.service.ts create mode 100644 client/src/app/core/services/recipe.service.ts diff --git a/client/src/app/core/models/recipe.model.ts b/client/src/app/core/models/recipe.model.ts index bed04bd..f6e43e7 100644 --- a/client/src/app/core/models/recipe.model.ts +++ b/client/src/app/core/models/recipe.model.ts @@ -1,54 +1,141 @@ export interface Recipe { + Timestamp: Date; + MachineSetting: MachineSetting; + Recipe01: Recipe01[]; + Topping: Topping; + MaterailCode: MaterailCode[]; +} + +export interface MachineSetting { + RecipeTag: string; + StrTextShowError: string[]; + configNumber: string; + temperatureMax: string; + temperatureMin: string; +} + +export interface MaterailCode { + PackageDescription: string; + RefillValuePerStep: string; + materialID: string; + materialCode: string; +} + +export interface Recipe01 { Description: string; - ExtendID: number; - OnTOP: boolean; - LastChange: Date; - MenuStatus: number; + ExtendID: string; + OnTOP: string; + LastChange: string; + MenuStatus: string; RemainingCups: string; StringParam: string; TextForWarningBeforePay: string[]; - cashPrice: number; + cashPrice: string; changerecipe: string; - disable: boolean; - disable_by_cup: boolean; - disable_by_ice: boolean; - EncoderCount: number; - id: number; - isUse: boolean; - isShow: boolean; + disable: string; + disable_by_cup: string; + disable_by_ice: string; + EncoderCount: string; + id: string; + isUse: string; + isShow: string; name: string; - nonCashPrice: number; + nonCashPrice: string; otherDescription: string; otherName: string; productCode: string; recipes: MatRecipe[]; - SubMenu: Recipe[]; + SubMenu: Recipe01[]; ToppingSet: ToppingSet[]; - total_time: number; - total_weight: number; + total_time: string; + total_weight: string; uriData: string; - useGram: boolean; - weight_float: number; + useGram: string; + weight_float: string; +} + +export interface Topping { + ToppingGroup: ToppingGroup; + ToppingList: ToppingList; +} + +export interface ToppingGroup { + Desc: string; + groupID: string; + idDefault: string; + idInGroup: string; + inUse: string; + name: string; + otherName: string; +} + +export interface ToppingList { + ExtendID: string; + OnTOP: string; + MenuStatus: string; + cashPrice: string; + disable: string; + disable_by_cup: string; + disable_by_ice: string; + EncoderCount: string; + id: string; + isUse: string; + isShow: string; + stringParam: string; + name: string; + nonCashPrice: string; + otherName: string; + productCode: string; + recipes: string; + total_time: string; + total_weight: string; + useGram: string; + weight_float: string; } export interface MatRecipe { - MixOrder: number; - FeedParameter: number; - FeedPattern: number; - isUse: boolean; - materialPathId: number; - powderGram: number; - powderTime: number; - stirTime: number; - syrupGram: number; - syrupTime: number; - waterCold: number; - waterYield: number; + MixOrder: string; + FeedParameter: string; + FeedPattern: string; + isUse: string; + materialPathId: string; + powderGram: string; + powderTime: string; + stirTime: string; + syrupGram: string; + syrupTime: string; + waterCold: string; + waterYield: string; } export interface ToppingSet { - ListGroupID: number[]; - defaultIDSelect: number; + ListGroupID: string; + defaultIDSelect: string; groupID: string; - isUse: boolean; + isUse: string; +} + +export interface MaterialSetting { + AlarmIDWhenOffline: string; + BeanChannel: string; + CanisterType: string; + DrainTimer: string; + IsEquipment: string; + LeavesChannel: string; + LowToOffline: string; + MaterialStatus: string; + PowderChannel: string; + RefillUnitGram: string; + RefillUnitMilliliters: string; + RefillUnitPCS: string; + ScheduleDrainType: string; + SodaChannel: string; + StockAdjust: string; + SyrupChannel: string; + id: string; + idAlternate: string; + isUse: string; + pay_rettry_max_count: string; + feed_mode: string; + MaterialParameter: string; } diff --git a/client/src/app/core/services/jwt.service.ts b/client/src/app/core/services/jwt.service.ts deleted file mode 100644 index 954def4..0000000 --- a/client/src/app/core/services/jwt.service.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Injectable } from '@angular/core'; - -@Injectable({ providedIn: 'root' }) -export class JwtService { - getToken(): string | null { - return window.localStorage['jwtToken']; - } - - saveToken(token: string): void { - window.localStorage['jwtToken'] = token; - } - - destroyToken(): void { - window.localStorage.removeItem('jwtToken'); - } -} diff --git a/client/src/app/core/services/recipe.service.ts b/client/src/app/core/services/recipe.service.ts new file mode 100644 index 0000000..c87dfb1 --- /dev/null +++ b/client/src/app/core/services/recipe.service.ts @@ -0,0 +1,16 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { BehaviorSubject, Observable, distinctUntilChanged } from 'rxjs'; +import { Recipe } from '../models/recipe.model'; +import { environment } from 'src/environments/environment'; + +@Injectable({ providedIn: 'root' }) +export class RecipeService { + constructor(private _httpClient: HttpClient) {} + + getRecipes(): Observable { + return this._httpClient.get(environment.api + '/recipes', { + withCredentials: true, + }); + } +} diff --git a/client/src/app/features/dashboard/dashboard.component.html b/client/src/app/features/dashboard/dashboard.component.html index 3577e16..77188d1 100644 --- a/client/src/app/features/dashboard/dashboard.component.html +++ b/client/src/app/features/dashboard/dashboard.component.html @@ -5,7 +5,22 @@ > + > +
+
+ Recipe Version {{ recipes?.MachineSetting?.configNumber }} | + {{"{{File name}}"}} +
+
+ Last Updated: + {{ recipes?.Timestamp | date : "dd-MMM-yyyy hh:mm:ss" }} +
+
+ @@ -48,19 +63,31 @@ {{ recipe.name }} {{ recipe.otherName }} - {{ recipe.Description }} - {{ recipe.LastChange }} + {{ recipe.Description }} + {{ recipe.LastChange | date : "dd-MMM-yyyy hh:mm:ss" }} + + + Edit + Edit (environment.api + '/recipes', { - withCredentials: true, - }) - .subscribe(({ Recipe01 }) => { - this.recipes = Recipe01.slice(0, 10); - console.log(this.recipes); - this.isLoaded = true; - }); + this._recipeService.getRecipes().subscribe((recipes) => { + this.recipes = recipes; + this.isLoaded = true; + console.log(this.recipes); + }); } } diff --git a/server/data/data.go b/server/data/data.go index 5a41e39..8393d46 100644 --- a/server/data/data.go +++ b/server/data/data.go @@ -4,9 +4,10 @@ import ( "encoding/json" "log" "os" + "recipe-manager/models" ) -func readFile() map[string]interface{} { +func readFile() *models.Recipe { file, err := os.Open("data/data.json") if err != nil { @@ -16,7 +17,7 @@ func readFile() map[string]interface{} { defer file.Close() - var data map[string]interface{} + var data *models.Recipe err = json.NewDecoder(file).Decode(&data) @@ -29,7 +30,7 @@ func readFile() map[string]interface{} { } type Data struct { - recipe map[string]interface{} + recipe *models.Recipe } func NewData() *Data { @@ -38,10 +39,10 @@ func NewData() *Data { } } -func (d *Data) GetRecipe() map[string]interface{} { +func (d *Data) GetRecipe() *models.Recipe { return d.recipe } -func (d *Data) GetRecipe01() []interface{} { - return d.recipe["Recipe01"].([]interface{}) +func (d *Data) GetRecipe01() []models.Recipe01 { + return d.recipe.Recipe01 } diff --git a/server/models/recipe.go b/server/models/recipe.go index 0373aac..4282067 100644 --- a/server/models/recipe.go +++ b/server/models/recipe.go @@ -1,7 +1,7 @@ package models type Recipe struct { - Timestamps string `json:"timestamps"` + Timestamp string `json:"Timestamp"` MachineSetting MatchineSetting `json:"MachineSetting"` Recipe01 []Recipe01 `json:"Recipe01"` Topping Topping `json:"Topping"` @@ -23,46 +23,121 @@ type MaterailCode struct { MaterialCode string `json:"materialCode"` } -// export interface MaterialSetting { -// AlarmIDWhenOffline: number; -// BeanChannel: boolean; -// CanisterType?: string; -// DrainTimer: number; -// IsEquipment: boolean; -// LeavesChannel: boolean; -// LowToOffline: number; -// MaterialDescrption?: string; -// MaterialStatus: number; -// PowderChannel: boolean; -// RefillUnitGram: boolean; -// RefillUnitMilliliters: boolean; -// RefillUnitPCS: boolean; -// ScheduleDrainType: number; -// SodaChannel: boolean; -// StockAdjust: number; -// StrTextShowError: string[]; -// SyrupChannel: boolean; -// id: number; -// idAlternate: number; -// isUse: boolean; -// materialOtherName: string; -// materialName: string; -// pathOtherName?: string; -// pay_rettry_max_count: number; -// RawMaterialUnit?: string; -// RawMaterialData?: RawMaterialDatum[]; -// MaterialComment?: string; -// MaterialStatusLastUpdate?: string; -// feed_mode?: string; -// MaterialParameter?: string; -// } - type MaterialSetting struct { - AlarmIDWhenOffline int `json:"AlarmIDWhenOffline"` - BeanChannel bool `json:"BeanChannel"` - CanisterType string `json:"CanisterType"` - DrainTimer int `json:"DrainTimer"` + AlarmIDWhenOffline int `json:"AlarmIDWhenOffline"` + BeanChannel bool `json:"BeanChannel"` + CanisterType string `json:"CanisterType"` + DrainTimer int `json:"DrainTimer"` + IsEquipment bool `json:"IsEquipment"` + LeavesChannel bool `json:"LeavesChannel"` + LowToOffline int `json:"LowToOffline"` + MaterialStatus int `json:"MaterialStatus"` + PowderChannel bool `json:"PowderChannel"` + RefillUnitGram bool `json:"RefillUnitGram"` + RefillUnitMilliliters bool `json:"RefillUnitMilliliters"` + RefillUnitPCS bool `json:"RefillUnitPCS"` + ScheduleDrainType int `json:"ScheduleDrainType"` + SodaChannel bool `json:"SodaChannel"` + StockAdjust int `json:"StockAdjust"` + SyrupChannel bool `json:"SyrupChannel"` + ID int `json:"id"` + IDAlternate int `json:"idAlternate"` + IsUse bool `json:"isUse"` + PayRettryMaxCount int `json:"pay_rettry_max_count"` + FeedMode string `json:"feed_mode"` + MaterialParameter string `json:"MaterialParameter"` } -type Recipe01 struct{} -type Topping struct{} +type Recipe01 struct { + Description string `json:"Description"` + ExtendID int `json:"ExtendID"` + OnTOP bool `json:"OnTOP"` + LastChange string `json:"LastChange"` + MenuStatus int `json:"MenuStatus"` + RemainingCups string `json:"RemainingCups"` + StringParam string `json:"StringParam"` + TextForWarningBeforePay []string `json:"TextForWarningBeforePay"` + CashPrice int `json:"cashPrice"` + Changerecipe string `json:"changerecipe"` + Disable bool `json:"disable"` + Disable_by_cup bool `json:"disable_by_cup"` + Disable_by_ice bool `json:"disable_by_ice"` + EncoderCount int `json:"EncoderCount"` + ID int `json:"id"` + IsUse bool `json:"isUse"` + IsShow bool `json:"isShow"` + Name string `json:"name"` + NonCashPrice int `json:"nonCashPrice"` + OtherDescription string `json:"otherDescription"` + OtherName string `json:"otherName"` + ProductCode string `json:"productCode"` + Recipes []MatRecipe `json:"recipes"` + SubMenu []Recipe01 `json:"SubMenu"` + ToppingSet []ToppingSet `json:"ToppingSet"` + Total_time int `json:"total_time"` + Total_weight int `json:"total_weight"` + UriData string `json:"uriData"` + UseGram bool `json:"useGram"` + Weight_float int `json:"weight_float"` +} + +type MatRecipe struct { + MixOrder int `json:"MixOrder"` + FeedParameter int `json:"FeedParameter"` + FeedPattern int `json:"FeedPattern"` + IsUse bool `json:"isUse"` + MaterialPathId int `json:"materialPathId"` + PowderGram int `json:"powderGram"` + PowderTime int `json:"powderTime"` + StirTime int `json:"stirTime"` + SyrupGram int `json:"syrupGram"` + SyrupTime int `json:"syrupTime"` + WaterCold int `json:"waterCold"` + WaterYield int `json:"waterYield"` +} + +type ToppingSet struct { + ListGroupID []int `json:"ListGroupID"` + DefaultIDSelect int `json:"defaultIDSelect"` + GroupID string `json:"groupID"` + IsUse bool `json:"isUse"` +} + +type Topping struct { + ToppingGroup []ToppingGroup `json:"ToppingGroup"` + ToppingList []ToppingList `json:"ToppingList"` +} + +type ToppingGroup struct { + Desc string `json:"Desc"` + GroupID int `json:"groupID"` + IDDefault int `json:"idDefault"` + IDInGroup string `json:"idInGroup"` + InUse bool `json:"inUse"` + Name string `json:"name"` + OtherName string `json:"otherName"` +} + +type ToppingList struct { + ExtendID int `json:"ExtendID"` + OnTOP bool `json:"OnTOP"` + MenuStatus int `json:"MenuStatus"` + CashPrice int `json:"cashPrice"` + Disable bool `json:"disable"` + Disable_by_cup bool `json:"disable_by_cup"` + Disable_by_ice bool `json:"disable_by_ice"` + EncoderCount int `json:"EncoderCount"` + ID int `json:"id"` + IsUse bool `json:"isUse"` + IsShow bool `json:"isShow"` + StringParam string `json:"stringParam"` + Name string `json:"name"` + NonCashPrice int `json:"nonCashPrice"` + OtherName string `json:"otherName"` + ProductCode string `json:"productCode"` + Recipes []MatRecipe `json:"recipes"` + Total_time int `json:"total_time"` + Total_weight int `json:"total_weight"` + UseGram bool `json:"useGram"` + Weight_float int `json:"weight_float"` +}