fix(CurrentRecipePointer): 🐛 Fix cache recipe
Remove continue last opened version
This commit is contained in:
parent
4219c1cb43
commit
2b8745679f
16 changed files with 481 additions and 174 deletions
|
|
@ -874,7 +874,7 @@ func (d *Data) SetValuesToToppingGroupList(base_topping_group_list []models.Topp
|
|||
}
|
||||
|
||||
func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialSetting {
|
||||
result := make([]models.MaterialSetting, 0)
|
||||
// result := make([]models.MaterialSetting, 0)
|
||||
|
||||
if countryID == "" {
|
||||
// copy(result, d.currentRecipe[countryID].MaterialSetting)
|
||||
|
|
@ -888,12 +888,12 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
|||
return d.CurrentRecipe[countryID].MaterialSetting
|
||||
}
|
||||
|
||||
if recipe, ok := d.recipeMap[filename]; ok {
|
||||
copy(result, recipe.Recipe[countryID].MaterialSetting)
|
||||
d.CurrentFile[countryID] = filename
|
||||
// d.CurrentCountryID[countryID] = countryID
|
||||
return d.CurrentRecipe[countryID].MaterialSetting
|
||||
}
|
||||
// if recipe, ok := d.recipeMap[filename]; ok {
|
||||
// copy(result, recipe.Recipe[countryID].MaterialSetting)
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// // d.CurrentCountryID[countryID] = countryID
|
||||
// return d.CurrentRecipe[countryID].MaterialSetting
|
||||
// }
|
||||
}
|
||||
|
||||
if filename == "default" {
|
||||
|
|
@ -952,11 +952,11 @@ func (d *Data) GetAllToppingGroups(countryID, filename string) []models.ToppingG
|
|||
if filename == "" || filename == d.CurrentFile[countryID] {
|
||||
return d.CurrentRecipe[countryID].Topping.ToppingGroup
|
||||
}
|
||||
if _, ok := d.recipeMap[countryID]; ok {
|
||||
d.CurrentFile[countryID] = filename
|
||||
// if _, ok := d.recipeMap[countryID]; ok {
|
||||
// d.CurrentFile[countryID] = filename
|
||||
|
||||
return d.CurrentRecipe[countryID].Topping.ToppingGroup
|
||||
}
|
||||
// return d.CurrentRecipe[countryID].Topping.ToppingGroup
|
||||
// }
|
||||
}
|
||||
|
||||
if filename == "default" {
|
||||
|
|
@ -1002,10 +1002,10 @@ func (d *Data) GetToppingsList(countryID, filename string) []models.ToppingList
|
|||
if filename == "" || filename == d.CurrentFile[countryID] {
|
||||
return d.CurrentRecipe[countryID].Topping.ToppingList
|
||||
}
|
||||
if _, ok := d.recipeMap[countryID]; ok {
|
||||
d.CurrentFile[countryID] = filename
|
||||
return d.CurrentRecipe[countryID].Topping.ToppingList
|
||||
}
|
||||
// if _, ok := d.recipeMap[countryID]; ok {
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// return d.CurrentRecipe[countryID].Topping.ToppingList
|
||||
// }
|
||||
}
|
||||
|
||||
if filename == "default" {
|
||||
|
|
@ -1040,10 +1040,12 @@ func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []model
|
|||
|
||||
if filename == "" || filename == d.CurrentFile[countryID] {
|
||||
result = d.CurrentRecipe[countryID].MaterialCode
|
||||
} else if recipe, ok := d.recipeMap[filename]; ok {
|
||||
d.CurrentFile[countryID] = filename
|
||||
return recipe.Recipe[countryID].MaterialCode
|
||||
} else {
|
||||
// else if recipe, ok := d.recipeMap[filename]; ok {
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// return recipe.Recipe[countryID].MaterialCode
|
||||
// }
|
||||
// else {
|
||||
|
||||
if filename == "default" {
|
||||
filename = d.CurrentFile[countryID]
|
||||
|
|
@ -1111,10 +1113,11 @@ func (d *Data) GetToppings(countryID, filename string) models.Topping {
|
|||
|
||||
if filename == "" || filename == d.CurrentFile[countryID] {
|
||||
return d.CurrentRecipe[countryID].Topping
|
||||
} else if recipe, ok := d.recipeMap[filename]; ok {
|
||||
d.CurrentFile[countryID] = filename
|
||||
return recipe.Recipe[countryID].Topping
|
||||
}
|
||||
// else if recipe, ok := d.recipeMap[filename]; ok {
|
||||
// d.CurrentFile[countryID] = filename
|
||||
// return recipe.Recipe[countryID].Topping
|
||||
// }
|
||||
|
||||
// if filename == "default" {
|
||||
// filename = d.CurrentFile[countryID]
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/png"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
|
@ -81,7 +84,7 @@ func (r *RedisCli) GetKeyTo(source string, dest interface{}) error {
|
|||
err = json.NewDecoder(bytes.NewBufferString(saved)).Decode(dest)
|
||||
|
||||
if err != nil {
|
||||
// //fmt.Println("GET error ", err)
|
||||
fmt.Println("GET error ", err)
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
@ -136,6 +139,41 @@ func (r *RedisCli) SetKeyTimeout(key string, value interface{}, timeout int) err
|
|||
return err
|
||||
}
|
||||
|
||||
func (r *RedisCli) SetImageToCache(key string, value image.Image) error {
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mValue, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = r.Client.Set(context.Background(), key, mValue, time.Duration(3600)*time.Second).Err()
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *RedisCli) GetCacheImage(key string) (image.Image, error) {
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err := r.Client.Get(context.Background(), key).Result()
|
||||
if err != nil {
|
||||
fmt.Println("GetCacheImage", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cacheImg, err := png.Decode(bytes.NewBufferString(result))
|
||||
if err != nil {
|
||||
fmt.Println("GetCacheImage.Decode", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Println("Cache image return OK!")
|
||||
return cacheImg, nil
|
||||
|
||||
}
|
||||
|
||||
func (r *RedisCli) KeyList() ([]string, error) {
|
||||
// if cannot pass healthcheck, return err
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
|
|
|
|||
49
server/data/socket-client.go
Normal file
49
server/data/socket-client.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// type SocketCli struct {
|
||||
// Client *socketio.Client
|
||||
// }
|
||||
|
||||
func NewSocketCli(user, response_room string) *map[string]interface{} {
|
||||
|
||||
ticketUrl := "http://localhost:3001"
|
||||
|
||||
ticketForm := map[string]string{
|
||||
"user": user,
|
||||
"response_room": response_room,
|
||||
}
|
||||
|
||||
ticketByte, _ := json.Marshal(ticketForm)
|
||||
|
||||
req, err := http.NewRequest("POST", ticketUrl, bytes.NewBuffer(ticketByte))
|
||||
if err != nil {
|
||||
fmt.Println("create request fail: ", err)
|
||||
}
|
||||
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
client := &http.Client{}
|
||||
result, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println("request fail: ", err)
|
||||
}
|
||||
defer result.Body.Close()
|
||||
|
||||
bill := &map[string]interface{}{}
|
||||
decodeErr := json.NewDecoder(result.Body).Decode(bill)
|
||||
if decodeErr != nil {
|
||||
fmt.Println("decode request error: ", decodeErr)
|
||||
}
|
||||
|
||||
if result.StatusCode != http.StatusCreated {
|
||||
fmt.Println("not expected status: ", result.Status)
|
||||
}
|
||||
|
||||
return bill
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue