Fixed: fixed bug scrcpy and shell is disconnect when switch page
This commit is contained in:
parent
9543d4541c
commit
0fe469b5c6
43 changed files with 1378 additions and 1366 deletions
6
server/models/v2/material.go
Normal file
6
server/models/v2/material.go
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package v2
|
||||
|
||||
type MaterialDashboard struct {
|
||||
Lebel string `json:"lebel"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
16
server/models/v2/recipe.go
Normal file
16
server/models/v2/recipe.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package v2
|
||||
|
||||
/*
|
||||
This is the recipe model that specificly for API v2 version.
|
||||
But some of the model of recipe can be used in the main version of the API.
|
||||
*/
|
||||
|
||||
type DashboardRecipe struct {
|
||||
ProductCode string `json:"productCode"`
|
||||
InUse bool `json:"inUse"`
|
||||
Name string `json:"name"`
|
||||
NameENG string `json:"nameEng"`
|
||||
Image string `json:"image"`
|
||||
LastUpdated string `json:"lastUpdated"`
|
||||
SubRecipe []*DashboardRecipe `json:"subRecipe,omitempty"`
|
||||
}
|
||||
|
|
@ -185,10 +185,25 @@ func (ar *AuthRouter) Route(r chi.Router) {
|
|||
json.NewEncoder(w).Encode(value)
|
||||
})
|
||||
|
||||
r.Get("/refresh", func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Post("/refresh", func(w http.ResponseWriter, r *http.Request) {
|
||||
// get refresh token from query string
|
||||
refreshToken := r.URL.Query().Get("refresh_token")
|
||||
redirectTo := r.URL.Query().Get("redirect_to")
|
||||
|
||||
// get refresh token from body and redirect_to from body and mashal it to struct
|
||||
var refreshToken string
|
||||
var redirectTo string
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(&struct {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
RedirectTo string `json:"redirect_to"`
|
||||
}{refreshToken, redirectTo})
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, "Error decoding body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// refreshToken := r.URL.Query().Get("refresh_token")
|
||||
// redirectTo := r.URL.Query().Get("redirect_to")
|
||||
if refreshToken == "" {
|
||||
http.Error(w, "Refresh token not found", http.StatusBadRequest)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
|||
r.Get("/{country}/{filename}/all", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
country := r.URL.Query().Get("country")
|
||||
filename := r.URL.Query().Get("filename")
|
||||
country := chi.URLParam(r, "country")
|
||||
filename := chi.URLParam(r, "filename")
|
||||
|
||||
rr.taoLogger.Log.Debug("RecipeRouter.GetAll", zap.Any("country", country), zap.Any("filename", filename))
|
||||
|
||||
|
|
|
|||
52
server/routers/v2/material.go
Normal file
52
server/routers/v2/material.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package v2
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"recipe-manager/data"
|
||||
modelsV2 "recipe-manager/models/v2"
|
||||
"recipe-manager/services/logger"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
type materialRouter struct {
|
||||
data *data.Data
|
||||
taoLogger *logger.TaoLogger
|
||||
}
|
||||
|
||||
func NewMaterialRouter(data *data.Data, taoLogger *logger.TaoLogger) *materialRouter {
|
||||
return &materialRouter{
|
||||
data: data,
|
||||
taoLogger: taoLogger,
|
||||
}
|
||||
}
|
||||
|
||||
func (mr *materialRouter) Route(r chi.Router) {
|
||||
r.Route("/materials", func(r chi.Router) {
|
||||
r.Get("/dashboard", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
countryID := r.URL.Query().Get("country_id")
|
||||
filename := r.URL.Query().Get("filename")
|
||||
|
||||
materials := mr.data.GetMaterialSetting(countryID, filename)
|
||||
|
||||
result := make([]modelsV2.MaterialDashboard, 0, len(materials))
|
||||
for _, material := range materials {
|
||||
|
||||
dashboardMaterial := modelsV2.MaterialDashboard{
|
||||
Lebel: material.MaterialName,
|
||||
Value: strconv.Itoa(int(material.ID)),
|
||||
}
|
||||
|
||||
result = append(result, dashboardMaterial)
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(result); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
69
server/routers/v2/recipe.go
Normal file
69
server/routers/v2/recipe.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package v2
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"recipe-manager/data"
|
||||
modelsV2 "recipe-manager/models/v2"
|
||||
"recipe-manager/services/logger"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
type recipeRouter struct {
|
||||
data *data.Data
|
||||
taoLogger *logger.TaoLogger
|
||||
}
|
||||
|
||||
func NewRecipeRouter(data *data.Data, taoLogger *logger.TaoLogger) *recipeRouter {
|
||||
return &recipeRouter{
|
||||
data: data,
|
||||
taoLogger: taoLogger,
|
||||
}
|
||||
}
|
||||
|
||||
func (rr *recipeRouter) Route(r chi.Router) {
|
||||
r.Route("/recipes", func(r chi.Router) {
|
||||
r.Get("/dashboard", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
countryID := r.URL.Query().Get("country_id")
|
||||
filename := r.URL.Query().Get("filename")
|
||||
|
||||
recipes := rr.data.GetRecipe(countryID, filename)
|
||||
|
||||
result := make([]modelsV2.DashboardRecipe, 0, len(recipes.Recipe01))
|
||||
for _, recipe := range recipes.Recipe01 {
|
||||
|
||||
dashboardRecipe := modelsV2.DashboardRecipe{
|
||||
ProductCode: recipe.ProductCode,
|
||||
Name: recipe.Name,
|
||||
NameENG: recipe.OtherName,
|
||||
InUse: recipe.IsUse,
|
||||
LastUpdated: recipe.LastChange,
|
||||
Image: "",
|
||||
}
|
||||
|
||||
if recipe.SubMenu != nil && len(recipe.SubMenu) > 0 {
|
||||
dashboardRecipe.SubRecipe = make([]*modelsV2.DashboardRecipe, 0, len(recipe.SubMenu))
|
||||
for _, subMenu := range recipe.SubMenu {
|
||||
dashboardRecipe.SubRecipe = append(dashboardRecipe.SubRecipe, &modelsV2.DashboardRecipe{
|
||||
ProductCode: subMenu.ProductCode,
|
||||
Name: subMenu.Name,
|
||||
NameENG: subMenu.OtherName,
|
||||
InUse: subMenu.IsUse,
|
||||
LastUpdated: recipe.LastChange,
|
||||
Image: "",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, dashboardRecipe)
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(result); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import (
|
|||
"recipe-manager/middlewares"
|
||||
"recipe-manager/models"
|
||||
"recipe-manager/routers"
|
||||
routersV2 "recipe-manager/routers/v2"
|
||||
"recipe-manager/services/logger"
|
||||
"recipe-manager/services/oauth"
|
||||
"recipe-manager/services/recipe"
|
||||
|
|
@ -142,6 +143,19 @@ func (s *Server) createHandler() {
|
|||
|
||||
})
|
||||
|
||||
// Protected Group V2
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Route("/v2", func(r chi.Router) {
|
||||
r.Use(func(next http.Handler) http.Handler {
|
||||
return middlewares.Authorize(s.oauth, userService, next)
|
||||
})
|
||||
|
||||
// Recipe Router
|
||||
rr := routersV2.NewRecipeRouter(s.data, s.taoLogger)
|
||||
rr.Route(r)
|
||||
})
|
||||
})
|
||||
|
||||
// routers.NewToppingRouter(s.data, s.taoLogger).Route(r)
|
||||
|
||||
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue