From a220feeb0a00bcc1bb2bbea21bc1d27dafef3eba Mon Sep 17 00:00:00 2001 From: Vayras <89837102+Vayras@users.noreply.github.com> Date: Thu, 23 May 2024 01:58:12 +0530 Subject: [PATCH] add the new endpoint --- db/features.go | 11 ++++ db/interface.go | 1 + handlers/features.go | 14 +++++ mocks/Database.go | 142 +++++++++++++++++++++++++++++++------------ routes/features.go | 2 + 5 files changed, 132 insertions(+), 38 deletions(-) diff --git a/db/features.go b/db/features.go index 038d645c8..390f8f640 100644 --- a/db/features.go +++ b/db/features.go @@ -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 +} diff --git a/db/interface.go b/db/interface.go index 1db38e35d..38ddcf1f0 100644 --- a/db/interface.go +++ b/db/interface.go @@ -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) } diff --git a/handlers/features.go b/handlers/features.go index 1e77f2483..ea56bbc33 100644 --- a/handlers/features.go +++ b/handlers/features.go @@ -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) +} diff --git a/mocks/Database.go b/mocks/Database.go index f34ed728e..71b1d07c4 100644 --- a/mocks/Database.go +++ b/mocks/Database.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.39.1. DO NOT EDIT. +// Code generated by mockery v2.40.1. DO NOT EDIT. package db @@ -452,43 +452,6 @@ func (_c *Database_BountiesPaidPercentage_Call) RunAndReturn(run func(db.Payment return _c } -// DeleteFeatureByUuid provides a mock function with given fields: uuid -func (_m *Database) DeleteFeatureByUuid(uuid string) error { - ret := _m.Called(uuid) - if len(ret) == 0 { - panic("no return value specified for DeleteFeatureByUuid") - } - return ret.Error(0) -} - -// Database_DeleteFeatureByUuid_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteFeatureByUuid' -type Database_DeleteFeatureByUuid_Call struct { - *mock.Call -} - -// DeleteFeatureByUuid is a helper method to define mock.On call -// - uuid string -func (_e *Database_Expecter) DeleteFeatureByUuid(uuid interface{}) *Database_DeleteFeatureByUuid_Call { - return &Database_DeleteFeatureByUuid_Call{Call: _e.mock.On("DeleteFeatureByUuid", uuid)} -} - -func (_c *Database_DeleteFeatureByUuid_Call) Run(run func(uuid string)) *Database_DeleteFeatureByUuid_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *Database_DeleteFeatureByUuid_Call) Return(_a0 error) *Database_DeleteFeatureByUuid_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Database_DeleteFeatureByUuid_Call) RunAndReturn(run func(string) error) *Database_DeleteFeatureByUuid_Call { - _c.Call.Return(run) - return _c -} - // ChangeWorkspaceDeleteStatus provides a mock function with given fields: workspace_uuid, status func (_m *Database) ChangeWorkspaceDeleteStatus(workspace_uuid string, status bool) db.Workspace { ret := _m.Called(workspace_uuid, status) @@ -1604,6 +1567,52 @@ func (_c *Database_DeleteBounty_Call) RunAndReturn(run func(string, string) (db. return _c } +// DeleteFeatureByUuid provides a mock function with given fields: uuid +func (_m *Database) DeleteFeatureByUuid(uuid string) error { + ret := _m.Called(uuid) + + if len(ret) == 0 { + panic("no return value specified for DeleteFeatureByUuid") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { + r0 = rf(uuid) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Database_DeleteFeatureByUuid_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteFeatureByUuid' +type Database_DeleteFeatureByUuid_Call struct { + *mock.Call +} + +// DeleteFeatureByUuid is a helper method to define mock.On call +// - uuid string +func (_e *Database_Expecter) DeleteFeatureByUuid(uuid interface{}) *Database_DeleteFeatureByUuid_Call { + return &Database_DeleteFeatureByUuid_Call{Call: _e.mock.On("DeleteFeatureByUuid", uuid)} +} + +func (_c *Database_DeleteFeatureByUuid_Call) Run(run func(uuid string)) *Database_DeleteFeatureByUuid_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Database_DeleteFeatureByUuid_Call) Return(_a0 error) *Database_DeleteFeatureByUuid_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Database_DeleteFeatureByUuid_Call) RunAndReturn(run func(string) error) *Database_DeleteFeatureByUuid_Call { + _c.Call.Return(run) + return _c +} + // DeleteFeaturePhase provides a mock function with given fields: featureUuid, phaseUuid func (_m *Database) DeleteFeaturePhase(featureUuid string, phaseUuid string) error { ret := _m.Called(featureUuid, phaseUuid) @@ -2519,6 +2528,63 @@ func (_c *Database_GetBountyByCreated_Call) RunAndReturn(run func(uint) (db.NewB return _c } +// GetBountyByFeatureAndPhaseUuid provides a mock function with given fields: featureUuid, phaseUuid +func (_m *Database) GetBountyByFeatureAndPhaseUuid(featureUuid string, phaseUuid string) (db.Bounty, error) { + ret := _m.Called(featureUuid, phaseUuid) + + if len(ret) == 0 { + panic("no return value specified for GetBountyByFeatureAndPhaseUuid") + } + + var r0 db.Bounty + var r1 error + if rf, ok := ret.Get(0).(func(string, string) (db.Bounty, error)); ok { + return rf(featureUuid, phaseUuid) + } + if rf, ok := ret.Get(0).(func(string, string) db.Bounty); ok { + r0 = rf(featureUuid, phaseUuid) + } else { + r0 = ret.Get(0).(db.Bounty) + } + + if rf, ok := ret.Get(1).(func(string, string) error); ok { + r1 = rf(featureUuid, phaseUuid) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Database_GetBountyByFeatureAndPhaseUuid_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBountyByFeatureAndPhaseUuid' +type Database_GetBountyByFeatureAndPhaseUuid_Call struct { + *mock.Call +} + +// GetBountyByFeatureAndPhaseUuid is a helper method to define mock.On call +// - featureUuid string +// - phaseUuid string +func (_e *Database_Expecter) GetBountyByFeatureAndPhaseUuid(featureUuid interface{}, phaseUuid interface{}) *Database_GetBountyByFeatureAndPhaseUuid_Call { + return &Database_GetBountyByFeatureAndPhaseUuid_Call{Call: _e.mock.On("GetBountyByFeatureAndPhaseUuid", featureUuid, phaseUuid)} +} + +func (_c *Database_GetBountyByFeatureAndPhaseUuid_Call) Run(run func(featureUuid string, phaseUuid string)) *Database_GetBountyByFeatureAndPhaseUuid_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string)) + }) + return _c +} + +func (_c *Database_GetBountyByFeatureAndPhaseUuid_Call) Return(_a0 db.Bounty, _a1 error) *Database_GetBountyByFeatureAndPhaseUuid_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Database_GetBountyByFeatureAndPhaseUuid_Call) RunAndReturn(run func(string, string) (db.Bounty, error)) *Database_GetBountyByFeatureAndPhaseUuid_Call { + _c.Call.Return(run) + return _c +} + // GetBountyById provides a mock function with given fields: id func (_m *Database) GetBountyById(id string) ([]db.NewBounty, error) { ret := _m.Called(id) diff --git a/routes/features.go b/routes/features.go index b1343b382..9b17f30dd 100644 --- a/routes/features.go +++ b/routes/features.go @@ -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 }