add file select for multiple country
This commit is contained in:
parent
e5eee656d5
commit
652ecbbf1f
9 changed files with 294 additions and 47 deletions
|
|
@ -2,6 +2,7 @@ package routers
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"recipe-manager/data"
|
||||
"recipe-manager/models"
|
||||
|
|
@ -123,7 +124,33 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
|||
})
|
||||
|
||||
r.Get("/versions", func(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(rr.data.AllVersions)
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
// get key from map
|
||||
keys := []string{}
|
||||
for k := range rr.data.AllRecipeFiles {
|
||||
countryName, err := rr.data.GetCountryNameByID(k)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
keys = append(keys, countryName)
|
||||
}
|
||||
json.NewEncoder(w).Encode(keys)
|
||||
})
|
||||
|
||||
r.Get("/versions/{country}", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
countryName := chi.URLParam(r, "country")
|
||||
countryID, err := rr.data.GetCountryIDByName(countryName)
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("Country Name: %s not found!!!", countryName), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
files := []string{}
|
||||
for _, v := range rr.data.AllRecipeFiles[countryID] {
|
||||
files = append(files, v.Name)
|
||||
}
|
||||
json.NewEncoder(w).Encode(files)
|
||||
})
|
||||
|
||||
r.Get("/test/sheet", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue