Skip to content

Commit 08b05fd

Browse files
committed
delete method with 200 status returns meta too
1 parent 9c6101b commit 08b05fd

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

api.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,11 @@ func (res *resource) handleDelete(w http.ResponseWriter, r *http.Request, ps htt
831831

832832
switch response.StatusCode() {
833833
case http.StatusOK:
834-
// TODO: implement this.. we need meta data as return value
835-
return fmt.Errorf("status 200 OK is currently not implemented for Delete methods")
834+
data := map[string]interface{}{
835+
"meta": response.Metadata(),
836+
}
837+
838+
return marshalResponse(data, w, http.StatusOK, r, res.marshalers)
836839
case http.StatusAccepted:
837840
w.WriteHeader(http.StatusAccepted)
838841
return nil

api_interfaces_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func (s SomeResource) Create(obj interface{}, req Request) (Responder, error) {
5353
func (s SomeResource) Delete(ID string, req Request) (Responder, error) {
5454
switch ID {
5555
case "200":
56-
// TODO: needs to be implemented, function signature is likely to be changed to return meta data
5756
return &Response{Code: http.StatusOK, Meta: map[string]interface{}{"some": "cool stuff"}}, nil
5857
case "202":
5958
return &Response{Code: http.StatusAccepted}, nil
@@ -239,12 +238,14 @@ var _ = Describe("Test return code behavior", func() {
239238

240239
It("returns 200 ok if there is some meta data", func() {
241240
delete("200")
242-
Expect(rec.Code).To(Equal(http.StatusInternalServerError))
243-
var err HTTPError
244-
json.Unmarshal(rec.Body.Bytes(), &err)
245-
Expect(err.Errors[0]).To(Equal(Error{
246-
Title: "status 200 OK is currently not implemented for Delete methods",
247-
Status: strconv.Itoa(http.StatusInternalServerError)}))
241+
Expect(rec.Code).To(Equal(http.StatusOK))
242+
var response map[string]interface{}
243+
json.Unmarshal(rec.Body.Bytes(), &response)
244+
Expect(response).To(Equal(map[string]interface{}{
245+
"meta": map[string]interface{}{
246+
"some": "cool stuff",
247+
},
248+
}))
248249
})
249250

250251
It("returns 202 accepted if deletion is delayed", func() {

0 commit comments

Comments
 (0)