Skip to content

Commit

Permalink
Merge pull request #1625 from stakwork/fix/admin_bounties_organization
Browse files Browse the repository at this point in the history
Fixed workspace name not being displayed
  • Loading branch information
elraphty authored Apr 30, 2024
2 parents 3ea8f77 + 4ff090d commit a341797
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 63 deletions.
2 changes: 1 addition & 1 deletion db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type Database interface {
NewHuntersPaid(r PaymentDateRange) int64
TotalHuntersPaid(r PaymentDateRange) int64
GetPersonByPubkey(pubkey string) Person
GetBountiesByDateRange(r PaymentDateRange, re *http.Request) []Bounty
GetBountiesByDateRange(r PaymentDateRange, re *http.Request) []NewBounty
GetBountiesByDateRangeCount(r PaymentDateRange, re *http.Request) int64
GetBountiesProviders(r PaymentDateRange, re *http.Request) []Person
PersonUniqueNameFromName(name string) (string, error)
Expand Down
4 changes: 2 additions & 2 deletions db/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func CalculateAverageDays(paidCount int64, paidSum uint) uint {
return 0
}

func (db database) GetBountiesByDateRange(r PaymentDateRange, re *http.Request) []Bounty {
func (db database) GetBountiesByDateRange(r PaymentDateRange, re *http.Request) []NewBounty {
offset, limit, sortBy, direction, _ := utils.GetPaginationParams(re)
keys := re.URL.Query()
open := keys.Get("Open")
Expand Down Expand Up @@ -203,7 +203,7 @@ func (db database) GetBountiesByDateRange(r PaymentDateRange, re *http.Request)
query := `SELECT * FROM public.bounty WHERE created >= '` + r.StartDate + `' AND created <= '` + r.EndDate + `'` + providerCondition
allQuery := query + " " + statusQuery + " " + orderQuery + " " + limitQuery

b := []Bounty{}
b := []NewBounty{}
db.db.Raw(allQuery).Find(&b)
return b
}
Expand Down
58 changes: 31 additions & 27 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,38 +429,42 @@ type BountyOwners struct {
}

type BountyData struct {
Bounty
NewBounty
BountyId uint `json:"bounty_id"`
BountyCreated int64 `json:"bounty_created"`
BountyUpdated *time.Time `json:"bounty_updated"`
BountyDescription string `json:"bounty_description"`
Person
AssigneeAlias string `json:"assignee_alias"`
AssigneeId uint `json:"assignee_id"`
AssigneeImg string `json:"assignee_img"`
AssigneeCreated *time.Time `json:"assignee_created"`
AssigneeUpdated *time.Time `json:"assignee_updated"`
AssigneeDescription string `json:"assignee_description"`
AssigneeRouteHint string `json:"assignee_route_hint"`
BountyOwnerId uint `json:"bounty_owner_id"`
OwnerUuid string `json:"owner_uuid"`
OwnerKey string `json:"owner_key"`
OwnerAlias string `json:"owner_alias"`
OwnerUniqueName string `json:"owner_unique_name"`
OwnerDescription string `json:"owner_description"`
OwnerTags pq.StringArray `gorm:"type:text[]" json:"owner_tags" null`
OwnerImg string `json:"owner_img"`
OwnerCreated *time.Time `json:"owner_created"`
OwnerUpdated *time.Time `json:"owner_updated"`
OwnerLastLogin int64 `json:"owner_last_login"`
OwnerRouteHint string `json:"owner_route_hint"`
OwnerContactKey string `json:"owner_contact_key"`
OwnerPriceToMeet int64 `json:"owner_price_to_meet"`
OwnerTwitterConfirmed bool `json:"owner_twitter_confirmed"`
OrganizationName string `json:"organization_name"`
OrganizationImg string `json:"organization_img"`
WorkspaceUuid string `json:"organization_uuid"`
WorkspaceDescription string `json:"description"`
AssigneeAlias string `json:"assignee_alias"`
AssigneeId uint `json:"assignee_id"`
AssigneeImg string `json:"assignee_img"`
AssigneeCreated *time.Time `json:"assignee_created"`
AssigneeUpdated *time.Time `json:"assignee_updated"`
AssigneeDescription string `json:"assignee_description"`
AssigneeRouteHint string `json:"assignee_route_hint"`
BountyOwnerId uint `json:"bounty_owner_id"`
OwnerUuid string `json:"owner_uuid"`
OwnerKey string `json:"owner_key"`
OwnerAlias string `json:"owner_alias"`
OwnerUniqueName string `json:"owner_unique_name"`
OwnerDescription string `json:"owner_description"`
OwnerTags pq.StringArray `gorm:"type:text[]" json:"owner_tags" null`
OwnerImg string `json:"owner_img"`
OwnerCreated *time.Time `json:"owner_created"`
OwnerUpdated *time.Time `json:"owner_updated"`
OwnerLastLogin int64 `json:"owner_last_login"`
OwnerRouteHint string `json:"owner_route_hint"`
OwnerContactKey string `json:"owner_contact_key"`
OwnerPriceToMeet int64 `json:"owner_price_to_meet"`
OwnerTwitterConfirmed bool `json:"owner_twitter_confirmed"`
OrganizationName string `json:"organization_name"`
OrganizationImg string `json:"organization_img"`
OrganizationUuid string `json:"organization_uuid"`
OrganizationDescription string `json:"description"`
WorkspaceName string `json:"workspace_name"`
WorkspaceImg string `json:"workspace_img"`
WorkspaceUuid string `json:"workspace_uuid"`
WorkspaceDescription string `json:"workspace_description"`
}

type BountyResponse struct {
Expand Down
54 changes: 29 additions & 25 deletions handlers/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,46 +300,50 @@ func MetricsCsv(w http.ResponseWriter, r *http.Request) {
}
}

func (mh *metricHandler) GetMetricsBountiesData(metricBounties []db.Bounty) []db.BountyData {
func (mh *metricHandler) GetMetricsBountiesData(metricBounties []db.NewBounty) []db.BountyData {
var metricBountiesData []db.BountyData
for _, bounty := range metricBounties {
bountyOwner := mh.db.GetPersonByPubkey(bounty.OwnerID)
bountyAssignee := mh.db.GetPersonByPubkey(bounty.Assignee)
organization := mh.db.GetWorkspaceByUuid(bounty.OrgUuid)
workspace := mh.db.GetWorkspaceByUuid(bounty.WorkspaceUuid)

bountyData := db.BountyData{
Bounty: bounty,
BountyId: bounty.ID,
Person: bountyOwner,
BountyCreated: bounty.Created,
BountyDescription: bounty.Description,
BountyUpdated: bounty.Updated,
AssigneeId: bountyAssignee.ID,
AssigneeImg: bountyAssignee.Img,
AssigneeAlias: bountyAssignee.OwnerAlias,
AssigneeDescription: bountyAssignee.Description,
AssigneeRouteHint: bountyAssignee.OwnerRouteHint,
BountyOwnerId: bountyOwner.ID,
OwnerUuid: bountyOwner.Uuid,
OwnerDescription: bountyOwner.Description,
OwnerUniqueName: bountyOwner.UniqueName,
OwnerImg: bountyOwner.Img,
OrganizationName: organization.Name,
OrganizationImg: organization.Img,
WorkspaceUuid: organization.Uuid,
WorkspaceDescription: organization.Description,
NewBounty: bounty,
BountyId: bounty.ID,
Person: bountyOwner,
BountyCreated: bounty.Created,
BountyDescription: bounty.Description,
BountyUpdated: bounty.Updated,
AssigneeId: bountyAssignee.ID,
AssigneeImg: bountyAssignee.Img,
AssigneeAlias: bountyAssignee.OwnerAlias,
AssigneeDescription: bountyAssignee.Description,
AssigneeRouteHint: bountyAssignee.OwnerRouteHint,
BountyOwnerId: bountyOwner.ID,
OwnerUuid: bountyOwner.Uuid,
OwnerDescription: bountyOwner.Description,
OwnerUniqueName: bountyOwner.UniqueName,
OwnerImg: bountyOwner.Img,
OrganizationName: workspace.Name,
OrganizationImg: workspace.Img,
OrganizationUuid: workspace.Uuid,
OrganizationDescription: workspace.Description,
WorkspaceName: workspace.Name,
WorkspaceImg: workspace.Img,
WorkspaceUuid: workspace.Uuid,
WorkspaceDescription: workspace.Description,
}
metricBountiesData = append(metricBountiesData, bountyData)
}
return metricBountiesData
}

func getMetricsBountyCsv(metricBounties []db.Bounty) []db.MetricsBountyCsv {
func getMetricsBountyCsv(metricBounties []db.NewBounty) []db.MetricsBountyCsv {
var metricBountiesCsv []db.MetricsBountyCsv
for _, bounty := range metricBounties {
bountyOwner := db.DB.GetPersonByPubkey(bounty.OwnerID)
bountyAssignee := db.DB.GetPersonByPubkey(bounty.Assignee)
organization := db.DB.GetWorkspaceByUuid(bounty.OrgUuid)
workspace := db.DB.GetWorkspaceByUuid(bounty.WorkspaceUuid)

bountyLink := fmt.Sprintf("https://community.sphinx.chat/bounty/%d", bounty.ID)
bountyStatus := "Open"
Expand All @@ -353,7 +357,7 @@ func getMetricsBountyCsv(metricBounties []db.Bounty) []db.MetricsBountyCsv {
tm := time.Unix(bounty.Created, 0)
bountyCsv := db.MetricsBountyCsv{
DatePosted: &tm,
Organization: organization.Name,
Organization: workspace.Name,
BountyAmount: bounty.Price,
Provider: bountyOwner.OwnerAlias,
Hunter: bountyAssignee.OwnerAlias,
Expand Down
4 changes: 2 additions & 2 deletions handlers/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestMetricsBounties(t *testing.T) {
t.Fatal(err)
}

bounties := []db.Bounty{
bounties := []db.NewBounty{
{
ID: 1,
OwnerID: "owner-1",
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestMetricsBounties(t *testing.T) {
req.URL.RawQuery = "provider=provider1,provider2"

// Mock bounties data for multiple providers
bounties := []db.Bounty{
bounties := []db.NewBounty{
{
ID: 1,
OwnerID: "provider1",
Expand Down
12 changes: 6 additions & 6 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 a341797

Please sign in to comment.