update getting file recipe

This commit is contained in:
Kenta420 2023-10-24 18:01:52 +07:00
parent ea506b8128
commit 3bfbbd778a
10 changed files with 243 additions and 152 deletions

View file

@ -26,7 +26,8 @@ func (mr *MaterialRouter) Route(r chi.Router) {
r.Get("/code", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
version := r.URL.Query().Get("version")
filename := r.URL.Query().Get("filename")
country := r.URL.Query().Get("country")
matIDs := r.URL.Query().Get("mat_ids")
@ -41,7 +42,14 @@ func (mr *MaterialRouter) Route(r chi.Router) {
matIDsUint = append(matIDsUint, matIDUint)
}
material := mr.data.GetMaterialCode(matIDsUint, version)
countryID, err := mr.data.GetCountryIDByName(country)
if err != nil {
http.Error(w, "Country not found", http.StatusNotFound)
return
}
material := mr.data.GetMaterialCode(matIDsUint, countryID, filename)
json.NewEncoder(w).Encode(material)
})
@ -49,9 +57,17 @@ func (mr *MaterialRouter) Route(r chi.Router) {
r.Get("/setting/{mat_id}", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
version := r.URL.Query().Get("version")
filename := r.URL.Query().Get("filename")
country := r.URL.Query().Get("country")
material := mr.data.GetMaterialSetting(version)
countryID, err := mr.data.GetCountryIDByName(country)
if err != nil {
http.Error(w, "Country not found", http.StatusNotFound)
return
}
material := mr.data.GetMaterialSetting(countryID, filename)
matID := chi.URLParam(r, "mat_id")