patch datasets
This commit is contained in:
@@ -110,36 +110,6 @@ func DatasetsItemPatch(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.Write(utils.ToJSON(dataset))
|
||||
})
|
||||
|
||||
dataset := Dataset{ID: utils.ParamInt(mux.Vars(r)["dataset_id"], 0)}
|
||||
// 取出更新数据
|
||||
var dataset_new Dataset
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte("500 - Internal Server Error"))
|
||||
return
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if err = json.Unmarshal(body, &dataset_new); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte("500 - Internal Server Error"))
|
||||
return
|
||||
}
|
||||
|
||||
// 合併字段
|
||||
if dataset_new.Name != "" {
|
||||
dataset.Name = dataset_new.Name
|
||||
}
|
||||
|
||||
// 執行更新
|
||||
if err := configs.ORMDB().Model(&dataset).Updates(dataset_new).Error; err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write([]byte("404 - Not Found"))
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.Write(utils.ToJSON(dataset))
|
||||
}
|
||||
|
||||
func DatasetsItemDelete(w http.ResponseWriter, r *http.Request) {
|
||||
|
Reference in New Issue
Block a user