diff --git a/routers/datasets.go b/routers/datasets.go index ac91efc..a224c2c 100644 --- a/routers/datasets.go +++ b/routers/datasets.go @@ -119,6 +119,15 @@ func DatasetsItemPatch(w http.ResponseWriter, r *http.Request) { if info, ok := form["info"].(string); ok { dataset.Info = info } + if images, ok := form["images"].([]interface{}); ok { + var image_list ImageList + for _, image := range images { + if image, ok := image.(string); ok { + image_list = append(image_list, image) + } + } + dataset.Images = image_list + } if err := configs.ORMDB().Save(&dataset).Error; err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("500 - Internal Server Error")) diff --git a/test.sh b/test.sh index 35bd194..c4ee3a3 100755 --- a/test.sh +++ b/test.sh @@ -46,7 +46,7 @@ echo "dataset_id: $dataset_id" # 修改數據集, images 中增加 url (PATCH /api/datasets/:id) -response=$(curl -X PATCH -H "Content-Type: application/json" -d '{"images":[{"url":"https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"}]}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/datasets/$dataset_id) +response=$(curl -X PATCH -H "Content-Type: application/json" -d '{"images":["https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"]}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/datasets/$dataset_id) [[ ${response: -3} -eq 200 ]] && { echo "修改數據集成功: ${response%???}"; } || exit_service "修改數據集失敗: ${response%???}"