Skip to content

Commit

Permalink
add the new endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Vayras committed May 22, 2024
1 parent e97d55c commit a220fee
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 38 deletions.
11 changes: 11 additions & 0 deletions db/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,14 @@ func (db database) DeleteFeatureStoryByUuid(featureUuid, storyUuid string) error
}
return nil
}

func (db database) GetBountyByFeatureAndPhaseUuid(featureUuid string, phaseUuid string) (Bounty, error) {
bounty := Bounty{}

result := db.db.Model(&Bounty{}).Where("feature_uuid = ? AND phase_uuid = ?", featureUuid, phaseUuid).First(&bounty)
if result.RowsAffected == 0 {
return bounty, errors.New("no bounty found")
}

return bounty, nil
}
1 change: 1 addition & 0 deletions db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,5 @@ type Database interface {
GetFeatureStoryByUuid(featureUuid, storyUuid string) (FeatureStory, error)
DeleteFeatureStoryByUuid(featureUuid, storyUuid string) error
DeleteFeatureByUuid(uuid string) error
GetBountyByFeatureAndPhaseUuid(featureUuid string, phaseUuid string) (Bounty, error)
}
14 changes: 14 additions & 0 deletions handlers/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,17 @@ func (oh *featureHandler) DeleteStory(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"message": "Story deleted successfully"})
}

func (oh *featureHandler) GetBountyByFeatureAndPhaseUuid(w http.ResponseWriter, r *http.Request) {
featureUuid := chi.URLParam(r, "feature_uuid")
phaseUuid := chi.URLParam(r, "phase_uuid")

bounty, err := oh.db.GetBountyByFeatureAndPhaseUuid(featureUuid, phaseUuid)
if err != nil {
w.WriteHeader(http.StatusNotFound)
return
}

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bounty)
}
142 changes: 104 additions & 38 deletions mocks/Database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions routes/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func FeatureRoutes() chi.Router {
r.Get("/{feature_uuid}/story", featureHandlers.GetStoriesByFeatureUuid)
r.Get("/{feature_uuid}/story/{story_uuid}", featureHandlers.GetStoryByUuid)
r.Delete("/{feature_uuid}/story/{story_uuid}", featureHandlers.DeleteStory)
r.Get("/{feature_uuid}/phase/{phase_uuid}/bounty", featureHandlers.GetBountyByFeatureAndPhaseUuid)

})
return r
}

0 comments on commit a220fee

Please sign in to comment.