add select department
This commit is contained in:
parent
17030c72ce
commit
c5d54ad5c5
9 changed files with 79 additions and 8 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"path"
|
||||
"recipe-manager/contracts"
|
||||
"recipe-manager/data"
|
||||
"recipe-manager/enums/permissions"
|
||||
"recipe-manager/helpers"
|
||||
"recipe-manager/models"
|
||||
"recipe-manager/services/logger"
|
||||
|
|
@ -61,6 +62,39 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
|||
|
||||
r.Get("/saved/{country}/{filename_version_only}", rr.getSavedRecipes)
|
||||
|
||||
r.Get("/departments", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
// return departments that user can access
|
||||
|
||||
u := r.Context().Value("user").(*models.User)
|
||||
var result []string
|
||||
|
||||
if u.Permissions.IsHavePermission(permissions.ThaiPermission) {
|
||||
result = append(result, "tha")
|
||||
}
|
||||
|
||||
if u.Permissions.IsHavePermission(permissions.MalayPermission) {
|
||||
result = append(result, "mys")
|
||||
}
|
||||
|
||||
if u.Permissions.IsHavePermission(permissions.AusPermission) {
|
||||
result = append(result, "aus")
|
||||
}
|
||||
|
||||
if u.Permissions.IsHavePermission(permissions.Alpha3Permission) {
|
||||
result = append(result, "alpha")
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(&contracts.Response[[]string]{
|
||||
Result: result,
|
||||
}); err != nil {
|
||||
rr.taoLogger.Log.Error("RecipeRouter.GetDepartments", zap.Error(err))
|
||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
r.Get("/countries", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
// get key from map
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue