update
This commit is contained in:
parent
5cf0a8b761
commit
28cdbbc4f9
5 changed files with 84 additions and 1 deletions
|
|
@ -82,3 +82,12 @@ type RecipeDetailMatListRequest struct {
|
||||||
type RecipeDetailMatListResponse struct {
|
type RecipeDetailMatListResponse struct {
|
||||||
Result []RecipeDetailMat `json:"result"`
|
Result []RecipeDetailMat `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetAllRecipeRequest struct {
|
||||||
|
Filename string `json:"filename"`
|
||||||
|
Country string `json:"country"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetAllRecipeResponse struct {
|
||||||
|
Result []RecipeOverview `json:"result"`
|
||||||
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -50,6 +50,31 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
||||||
r.Route("/recipes", func(r chi.Router) {
|
r.Route("/recipes", func(r chi.Router) {
|
||||||
r.Get("/dashboard", rr.dashBoard)
|
r.Get("/dashboard", rr.dashBoard)
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
rr.taoLogger.Log.Debug("RecipeRouter.GetAll", zap.Any("country", country), zap.Any("filename", filename))
|
||||||
|
|
||||||
|
result, err := rr.recipeService.GetAllRecipe(&contracts.GetAllRecipeRequest{
|
||||||
|
Country: country,
|
||||||
|
Filename: filename,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.NewEncoder(w).Encode(result); err != nil {
|
||||||
|
rr.taoLogger.Log.Error("RecipeRouter.GetAll", zap.Error(err))
|
||||||
|
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
r.Get("/overview", rr.overview)
|
r.Get("/overview", rr.overview)
|
||||||
|
|
||||||
r.Get("/{product_code}", rr.getRecipeByProductCode)
|
r.Get("/{product_code}", rr.getRecipeByProductCode)
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,13 @@ func (o *oauthService) AuthURL(state string, stateMap map[string]string) string
|
||||||
o.nonce[state] = make(map[string]string)
|
o.nonce[state] = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
return o.gConfig.AuthCodeURL(state, oauth2.SetAuthURLParam("hd", "forth.co.th"), oauth2.SetAuthURLParam("include_granted_scopes", "true"), oauth2.AccessTypeOffline)
|
authCodeOptions := []oauth2.AuthCodeOption{
|
||||||
|
// oauth2.SetAuthURLParam("hd", "forth.co.th"),
|
||||||
|
oauth2.SetAuthURLParam("include_granted_scopes", "true"),
|
||||||
|
oauth2.AccessTypeOffline,
|
||||||
|
}
|
||||||
|
|
||||||
|
return o.gConfig.AuthCodeURL(state, authCodeOptions...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *oauthService) GetState(state string) (map[string]string, bool) {
|
func (o *oauthService) GetState(state string) (map[string]string, bool) {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import (
|
||||||
type RecipeService interface {
|
type RecipeService interface {
|
||||||
GetRecipeDashboard(request *contracts.RecipeDashboardRequest) (contracts.RecipeDashboardResponse, error)
|
GetRecipeDashboard(request *contracts.RecipeDashboardRequest) (contracts.RecipeDashboardResponse, error)
|
||||||
GetRecipeOverview(request *contracts.RecipeOverviewRequest) (contracts.RecipeOverviewResponse, error)
|
GetRecipeOverview(request *contracts.RecipeOverviewRequest) (contracts.RecipeOverviewResponse, error)
|
||||||
|
GetAllRecipe(request *contracts.GetAllRecipeRequest) (contracts.GetAllRecipeResponse, error)
|
||||||
|
|
||||||
GetRecipeDetail(request *contracts.RecipeDetailRequest) (contracts.RecipeDetailResponse, error)
|
GetRecipeDetail(request *contracts.RecipeDetailRequest) (contracts.RecipeDetailResponse, error)
|
||||||
GetRecipeDetailMat(request *contracts.RecipeDetailRequest) (contracts.RecipeDetailMatListResponse, error)
|
GetRecipeDetailMat(request *contracts.RecipeDetailRequest) (contracts.RecipeDetailMatListResponse, error)
|
||||||
|
|
@ -299,6 +300,48 @@ func (rs *recipeService) GetRecipeOverview(request *contracts.RecipeOverviewRequ
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rs *recipeService) GetAllRecipe(request *contracts.GetAllRecipeRequest) (contracts.GetAllRecipeResponse, error) {
|
||||||
|
countryID, err := rs.db.GetCountryIDByName(request.Country)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return contracts.GetAllRecipeResponse{}, fmt.Errorf("country name: %s not found", request.Country)
|
||||||
|
}
|
||||||
|
recipe := rs.db.GetRecipe(countryID, request.Filename)
|
||||||
|
|
||||||
|
result := contracts.GetAllRecipeResponse{}
|
||||||
|
|
||||||
|
// Map to contracts.RecipeOverview
|
||||||
|
for _, v := range recipe.Recipe01 {
|
||||||
|
result.Result = append(result.Result, contracts.RecipeOverview{
|
||||||
|
ID: v.ID,
|
||||||
|
ProductCode: v.ProductCode,
|
||||||
|
Name: v.Name,
|
||||||
|
OtherName: v.OtherName,
|
||||||
|
Description: v.Description,
|
||||||
|
OtherDescription: v.OtherDescription,
|
||||||
|
LastUpdated: v.LastChange,
|
||||||
|
})
|
||||||
|
|
||||||
|
// submenu
|
||||||
|
if len(v.SubMenu) > 0 {
|
||||||
|
for _, sub := range v.SubMenu {
|
||||||
|
result.Result = append(result.Result, contracts.RecipeOverview{
|
||||||
|
ID: sub.ID,
|
||||||
|
ProductCode: sub.ProductCode,
|
||||||
|
Name: sub.Name,
|
||||||
|
OtherName: sub.OtherName,
|
||||||
|
Description: sub.Description,
|
||||||
|
OtherDescription: sub.OtherDescription,
|
||||||
|
LastUpdated: sub.LastChange,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func NewRecipeService(db *data.Data, taoLogger *logger.TaoLogger) RecipeService {
|
func NewRecipeService(db *data.Data, taoLogger *logger.TaoLogger) RecipeService {
|
||||||
return &recipeService{
|
return &recipeService{
|
||||||
db: db,
|
db: db,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue