diff --git a/handlers/bounty.go b/handlers/bounty.go index a155f6a48..245542d78 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -53,21 +53,16 @@ func (h *bountyHandler) GetBountyById(w http.ResponseWriter, r *http.Request) { bountyId := chi.URLParam(r, "bountyId") if bountyId == "" { w.WriteHeader(http.StatusNotFound) - return } bounties, err := h.db.GetBountyById(bountyId) if err != nil { w.WriteHeader(http.StatusBadRequest) fmt.Println("[bounty] Error", err) - return - } - if len(bounties) == 0 { - w.WriteHeader(http.StatusBadRequest) - return + } else { + var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties) + w.WriteHeader(http.StatusOK) + json.NewEncoder(w).Encode(bountyResponse) } - var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties) - w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(bountyResponse) } func (h *bountyHandler) GetNextBountyByCreated(w http.ResponseWriter, r *http.Request) { diff --git a/handlers/bounty_test.go b/handlers/bounty_test.go index e3c9de01f..6de5aad5f 100644 --- a/handlers/bounty_test.go +++ b/handlers/bounty_test.go @@ -1038,8 +1038,8 @@ func TestGetBountyById(t *testing.T) { handler := http.HandlerFunc(bHandler.GetBountyById) rctx := chi.NewRouteContext() - rctx.URLParams.Add("bountyId", "999") - req, err := http.NewRequestWithContext(context.WithValue(context.Background(), chi.RouteCtxKey, rctx), http.MethodGet, "/bounty/999", nil) + rctx.URLParams.Add("bountyId", "Invalid-id") + req, err := http.NewRequestWithContext(context.WithValue(context.Background(), chi.RouteCtxKey, rctx), http.MethodGet, "/bounty/Invalid-id", nil) assert.NoError(t, err) handler.ServeHTTP(rr, req)