From 687a5fb36359b7fea2bb67d6018b94ef5c9dc8ef Mon Sep 17 00:00:00 2001 From: elraphty Date: Tue, 30 Apr 2024 15:15:25 +0100 Subject: [PATCH] fixed workspace name not being displayed --- db/interface.go | 2 +- db/metrics.go | 4 +-- db/structs.go | 58 +++++++++++++++++++++------------------- handlers/metrics.go | 54 ++++++++++++++++++++----------------- handlers/metrics_test.go | 12 ++++----- mocks/Database.go | 12 ++++----- 6 files changed, 75 insertions(+), 67 deletions(-) diff --git a/db/interface.go b/db/interface.go index e3cc95163..9a8b88112 100644 --- a/db/interface.go +++ b/db/interface.go @@ -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) diff --git a/db/metrics.go b/db/metrics.go index ae6389f8d..b2a91bc94 100644 --- a/db/metrics.go +++ b/db/metrics.go @@ -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") @@ -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 } diff --git a/db/structs.go b/db/structs.go index 6ab15f38d..446b76b92 100644 --- a/db/structs.go +++ b/db/structs.go @@ -429,38 +429,42 @@ type BountyOwners struct { } type BountyData struct { - Bounty + 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 { diff --git a/handlers/metrics.go b/handlers/metrics.go index 2a0140cb5..8d24aab2f 100644 --- a/handlers/metrics.go +++ b/handlers/metrics.go @@ -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, + 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: 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" @@ -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, diff --git a/handlers/metrics_test.go b/handlers/metrics_test.go index 38695f8ac..62e0eb05b 100644 --- a/handlers/metrics_test.go +++ b/handlers/metrics_test.go @@ -148,7 +148,7 @@ func TestMetricsBounties(t *testing.T) { t.Fatal(err) } - bounties := []db.Bounty{ + bounties := []db.NewBounty{ { ID: 1, OwnerID: "owner-1", @@ -169,9 +169,9 @@ func TestMetricsBounties(t *testing.T) { assert.Equal(t, http.StatusOK, rr.Code) assert.Equal(t, res[0].BountyId, uint(1)) - assert.Equal(t, res[0].OwnerID, "owner-1") - assert.Equal(t, res[0].Price, uint(100)) - assert.Equal(t, res[0].Title, "bounty 1") + assert.Equal(t, res[0].Bounty.OwnerID, "owner-1") + assert.Equal(t, res[0].Bounty.Price, uint(100)) + assert.Equal(t, res[0].Bounty.Title, "bounty 1") assert.Equal(t, res[0].BountyDescription, "test bounty") assert.Equal(t, res[0].BountyCreated, int64(1112)) }) @@ -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", @@ -230,7 +230,7 @@ func TestMetricsBounties(t *testing.T) { // Assert that the response contains bounties only from the selected providers for _, bounty := range res { - assert.Contains(t, []string{"provider1", "provider2"}, bounty.OwnerID) + assert.Contains(t, []string{"provider1", "provider2"}, bounty.Bounty.OwnerID) } }) } diff --git a/mocks/Database.go b/mocks/Database.go index 784a2492a..7b3961287 100644 --- a/mocks/Database.go +++ b/mocks/Database.go @@ -1775,19 +1775,19 @@ func (_c *Database_GetBotsByOwner_Call) RunAndReturn(run func(string) []db.Bot) } // GetBountiesByDateRange provides a mock function with given fields: r, re -func (_m *Database) GetBountiesByDateRange(r db.PaymentDateRange, re *http.Request) []db.Bounty { +func (_m *Database) GetBountiesByDateRange(r db.PaymentDateRange, re *http.Request) []db.NewBounty { ret := _m.Called(r, re) if len(ret) == 0 { panic("no return value specified for GetBountiesByDateRange") } - var r0 []db.Bounty - if rf, ok := ret.Get(0).(func(db.PaymentDateRange, *http.Request) []db.Bounty); ok { + var r0 []db.NewBounty + if rf, ok := ret.Get(0).(func(db.PaymentDateRange, *http.Request) []db.NewBounty); ok { r0 = rf(r, re) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]db.Bounty) + r0 = ret.Get(0).([]db.NewBounty) } } @@ -1813,12 +1813,12 @@ func (_c *Database_GetBountiesByDateRange_Call) Run(run func(r db.PaymentDateRan return _c } -func (_c *Database_GetBountiesByDateRange_Call) Return(_a0 []db.Bounty) *Database_GetBountiesByDateRange_Call { +func (_c *Database_GetBountiesByDateRange_Call) Return(_a0 []db.NewBounty) *Database_GetBountiesByDateRange_Call { _c.Call.Return(_a0) return _c } -func (_c *Database_GetBountiesByDateRange_Call) RunAndReturn(run func(db.PaymentDateRange, *http.Request) []db.Bounty) *Database_GetBountiesByDateRange_Call { +func (_c *Database_GetBountiesByDateRange_Call) RunAndReturn(run func(db.PaymentDateRange, *http.Request) []db.NewBounty) *Database_GetBountiesByDateRange_Call { _c.Call.Return(run) return _c }