Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit 9732985

Browse files
committed
fix input data according to review
1 parent 39abd0c commit 9732985

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

db.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,12 @@ func (database *Database) getByIds(w http.ResponseWriter, r *http.Request) {
217217
_, r.URL.Path = ShiftPath(r.URL.Path)
218218
col, r.URL.Path = ShiftPath(r.URL.Path)
219219

220-
var body map[string][]string
221-
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
222-
http.Error(w, err.Error(), http.StatusInternalServerError)
223-
return
224-
}
225-
ids, ok := body["ids"]
226-
if !ok {
227-
http.Error(w, "ids should be provided", http.StatusBadRequest)
220+
var ids []string
221+
if err := parseBody(r.Body, &ids); err != nil {
222+
http.Error(w, err.Error(), http.StatusBadRequest)
228223
return
229224
}
225+
230226
if len(ids) < 1 {
231227
http.Error(w, "ids list can not be empty", http.StatusBadRequest)
232228
return

db_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,7 @@ func TestDBBulkUpdate(t *testing.T) {
260260
}
261261

262262
func TestDBGetByIds(t *testing.T) {
263-
var data = new(struct {
264-
Ids []string `json:"ids"`
265-
})
263+
var data []string
266264

267265
tasks := []Task{
268266
{
@@ -289,7 +287,7 @@ func TestDBGetByIds(t *testing.T) {
289287
if err := parseBody(resp.Body, &saved); err != nil {
290288
t.Fatal(err)
291289
}
292-
data.Ids = append(data.Ids, saved.ID)
290+
data = append(data, saved.ID)
293291
createdTasks = append(createdTasks, saved)
294292
}
295293

0 commit comments

Comments
 (0)