Skip to content

Commit

Permalink
add pagination, sorting and 3 summary fields to endpoint Get Features…
Browse files Browse the repository at this point in the history
… for workspace
  • Loading branch information
MahtabBukhari committed May 27, 2024
1 parent d4a0dd3 commit 10f3e22
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 13 deletions.
6 changes: 6 additions & 0 deletions db/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,9 @@ func (db database) GetPhaseByUuid(phaseUuid string) (FeaturePhase, error) {
}
return phase, nil
}

func (db database) GetBountiesByPhaseUuid(phaseUuid string) []Bounty {
bounties := []Bounty{}
db.db.Model(&Bounty{}).Where("phase_uuid = ?", phaseUuid).Find(&bounties)
return bounties
}
1 change: 1 addition & 0 deletions db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@ type Database interface {
DeleteFeatureByUuid(uuid string) error
GetBountyByFeatureAndPhaseUuid(featureUuid string, phaseUuid string) (Bounty, error)
GetPhaseByUuid(phaseUuid string) (FeaturePhase, error)
GetBountiesByPhaseUuid(phaseUuid string) []Bounty
}
29 changes: 16 additions & 13 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,19 +569,22 @@ type WorkspaceRepositories struct {
}

type WorkspaceFeatures struct {
ID uint `json:"id"`
Uuid string `gorm:"not null" json:"uuid"`
WorkspaceUuid string `gorm:"not null" json:"workspace_uuid"`
Name string `gorm:"not null" json:"name"`
Brief string `json:"brief"`
Requirements string `json:"requirements"`
Architecture string `json:"architecture"`
Url string `json:"url"`
Priority int `json:"priority"`
Created *time.Time `json:"created"`
Updated *time.Time `json:"updated"`
CreatedBy string `json:"created_by"`
UpdatedBy string `json:"updated_by"`
ID uint `json:"id"`
Uuid string `gorm:"not null" json:"uuid"`
WorkspaceUuid string `gorm:"not null" json:"workspace_uuid"`
Name string `gorm:"not null" json:"name"`
Brief string `json:"brief"`
Requirements string `json:"requirements"`
Architecture string `json:"architecture"`
Url string `json:"url"`
Priority int `json:"priority"`
Created *time.Time `json:"created"`
Updated *time.Time `json:"updated"`
CreatedBy string `json:"created_by"`
UpdatedBy string `json:"updated_by"`
BountiesCountCompleted int `json:"bounties_count_completed"`
BountiesCountAssigned int `json:"bounties_count_assigned"`
BountiesCountOpen int `json:"bounties_count_open"`
}

type FeaturePhase struct {
Expand Down
24 changes: 24 additions & 0 deletions handlers/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,30 @@ func (oh *workspaceHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r
uuid := chi.URLParam(r, "workspace_uuid")
workspaceFeatures := oh.db.GetFeaturesByWorkspaceUuid(uuid, r)

for i, feature := range workspaceFeatures {

phases := oh.db.GetPhasesByFeatureUuid(feature.Uuid)

var totalCompleted, totalAssigned, totalOpen int

for _, phase := range phases {
bounties := oh.db.GetBountiesByPhaseUuid(phase.Uuid)
for _, bounty := range bounties {
if bounty.Completed {
totalCompleted++
} else if bounty.Assignee != "" {
totalAssigned++
} else {
totalOpen++
}
}
}

workspaceFeatures[i].BountiesCountCompleted = totalCompleted
workspaceFeatures[i].BountiesCountAssigned = totalAssigned
workspaceFeatures[i].BountiesCountOpen = totalOpen
}

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(workspaceFeatures)
}
40 changes: 40 additions & 0 deletions mocks/Database.go

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

0 comments on commit 10f3e22

Please sign in to comment.