From 44931f6d5b12fc01a6b89d3ad254318436ece546 Mon Sep 17 00:00:00 2001 From: elraphty Date: Tue, 6 Feb 2024 13:10:41 +0100 Subject: [PATCH 1/2] made changes to nav --- db/db.go | 27 +++++++------- db/interface.go | 8 ++--- handlers/bounty.go | 16 ++++----- mocks/Database.go | 88 +++++++++++++++++++++++----------------------- routes/bounty.go | 8 ++--- 5 files changed, 74 insertions(+), 73 deletions(-) diff --git a/db/db.go b/db/db.go index cd2478953..22b5547ba 100644 --- a/db/db.go +++ b/db/db.go @@ -712,8 +712,8 @@ func (db database) GetBountyById(id string) ([]Bounty, error) { return ms, err } -func (db database) GetNextBountyById(r *http.Request) ([]Bounty, error) { - id := chi.URLParam(r, "bountyId") +func (db database) GetNextBountyByCreated(r *http.Request) ([]Bounty, error) { + created := chi.URLParam(r, "created") keys := r.URL.Query() _, _, _, _, search := utils.GetPaginationParams(r) ms := []Bounty{} @@ -764,7 +764,7 @@ func (db database) GetNextBountyById(r *http.Request) ([]Bounty, error) { } } - query := `SELECT * FROM public.bounty WHERE id > '` + id + `' AND show = true` + query := `SELECT * FROM public.bounty WHERE id > '` + created + `' AND show = true` orderQuery := "ORDER BY id ASC LIMIT 1" allQuery := query + " " + searchQuery + " " + statusQuery + " " + languageQuery + " " + orderQuery @@ -773,8 +773,8 @@ func (db database) GetNextBountyById(r *http.Request) ([]Bounty, error) { return ms, err } -func (db database) GetPreviousBountyById(r *http.Request) ([]Bounty, error) { - id := chi.URLParam(r, "bountyId") +func (db database) GetPreviousBountyByCreated(r *http.Request) ([]Bounty, error) { + created := chi.URLParam(r, "created") keys := r.URL.Query() _, _, _, _, search := utils.GetPaginationParams(r) ms := []Bounty{} @@ -825,7 +825,7 @@ func (db database) GetPreviousBountyById(r *http.Request) ([]Bounty, error) { } } - query := `SELECT * FROM public.bounty WHERE id < '` + id + `' AND show = true` + query := `SELECT * FROM public.bounty WHERE id < '` + created + `' AND show = true` orderQuery := "ORDER BY id DESC LIMIT 1" allQuery := query + " " + searchQuery + " " + statusQuery + " " + languageQuery + " " + orderQuery @@ -834,8 +834,8 @@ func (db database) GetPreviousBountyById(r *http.Request) ([]Bounty, error) { return ms, err } -func (db database) GetNextOrganizationBountyById(r *http.Request) ([]Bounty, error) { - id := chi.URLParam(r, "bountyId") +func (db database) GetNextOrganizationBountyByCreated(r *http.Request) ([]Bounty, error) { + created := chi.URLParam(r, "created") uuid := chi.URLParam(r, "uuid") keys := r.URL.Query() _, _, _, _, search := utils.GetPaginationParams(r) @@ -887,7 +887,8 @@ func (db database) GetNextOrganizationBountyById(r *http.Request) ([]Bounty, err } } - query := `SELECT * FROM public.bounty WHERE org_uuid = '` + uuid + `' AND id > '` + id + `' AND show = true` + fmt.Println("Org UUID", uuid) + query := `SELECT * FROM public.bounty WHERE org_uuid = '` + uuid + `' AND created > '` + created + `' AND show = true` orderQuery := "ORDER BY id ASC LIMIT 1" allQuery := query + " " + searchQuery + " " + statusQuery + " " + languageQuery + " " + orderQuery @@ -896,8 +897,8 @@ func (db database) GetNextOrganizationBountyById(r *http.Request) ([]Bounty, err return ms, err } -func (db database) GetPreviousOrganizationBountyById(r *http.Request) ([]Bounty, error) { - id := chi.URLParam(r, "bountyId") +func (db database) GetPreviousOrganizationBountyByCreated(r *http.Request) ([]Bounty, error) { + created := chi.URLParam(r, "created") uuid := chi.URLParam(r, "uuid") keys := r.URL.Query() _, _, _, _, search := utils.GetPaginationParams(r) @@ -949,8 +950,8 @@ func (db database) GetPreviousOrganizationBountyById(r *http.Request) ([]Bounty, } } - query := `SELECT * FROM public.bounty WHERE org_uuid = '` + uuid + `' AND id < '` + id + `' AND show = true` - orderQuery := "ORDER BY id DESC LIMIT 1" + query := `SELECT * FROM public.bounty WHERE org_uuid = '` + uuid + `' AND created < '` + created + `' AND show = true` + orderQuery := "ORDER BY created DESC LIMIT 1" allQuery := query + " " + searchQuery + " " + statusQuery + " " + languageQuery + " " + orderQuery diff --git a/db/interface.go b/db/interface.go index f6b0c09df..9074de96b 100644 --- a/db/interface.go +++ b/db/interface.go @@ -35,10 +35,10 @@ type Database interface { GetAssignedBounties(r *http.Request) ([]Bounty, error) GetCreatedBounties(r *http.Request) ([]Bounty, error) GetBountyById(id string) ([]Bounty, error) - GetNextBountyById(r *http.Request) ([]Bounty, error) - GetPreviousBountyById(r *http.Request) ([]Bounty, error) - GetNextOrganizationBountyById(r *http.Request) ([]Bounty, error) - GetPreviousOrganizationBountyById(r *http.Request) ([]Bounty, error) + GetNextBountyByCreated(r *http.Request) ([]Bounty, error) + GetPreviousBountyByCreated(r *http.Request) ([]Bounty, error) + GetNextOrganizationBountyByCreated(r *http.Request) ([]Bounty, error) + GetPreviousOrganizationBountyByCreated(r *http.Request) ([]Bounty, error) GetBountyIndexById(id string) int64 GetBountyDataByCreated(created string) ([]Bounty, error) AddBounty(b Bounty) (Bounty, error) diff --git a/handlers/bounty.go b/handlers/bounty.go index eceeff414..3104cf9ba 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -54,8 +54,8 @@ func GetBountyById(w http.ResponseWriter, r *http.Request) { } } -func GetNextBountyById(w http.ResponseWriter, r *http.Request) { - bounties, err := db.DB.GetNextBountyById(r) +func GetNextBountyByCreated(w http.ResponseWriter, r *http.Request) { + bounties, err := db.DB.GetNextBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) fmt.Println("Error", err) @@ -66,8 +66,8 @@ func GetNextBountyById(w http.ResponseWriter, r *http.Request) { } } -func GetPreviousBountyById(w http.ResponseWriter, r *http.Request) { - bounties, err := db.DB.GetPreviousBountyById(r) +func GetPreviousBountyByCreated(w http.ResponseWriter, r *http.Request) { + bounties, err := db.DB.GetPreviousBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) fmt.Println("Error", err) @@ -78,8 +78,8 @@ func GetPreviousBountyById(w http.ResponseWriter, r *http.Request) { } } -func GetOrganizationNextBountyById(w http.ResponseWriter, r *http.Request) { - bounties, err := db.DB.GetNextOrganizationBountyById(r) +func GetOrganizationNextBountyByCreated(w http.ResponseWriter, r *http.Request) { + bounties, err := db.DB.GetNextOrganizationBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) fmt.Println("Error", err) @@ -90,8 +90,8 @@ func GetOrganizationNextBountyById(w http.ResponseWriter, r *http.Request) { } } -func GetOrganizationPreviousBountyById(w http.ResponseWriter, r *http.Request) { - bounties, err := db.DB.GetPreviousOrganizationBountyById(r) +func GetOrganizationPreviousBountyByCreated(w http.ResponseWriter, r *http.Request) { + bounties, err := db.DB.GetPreviousOrganizationBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) fmt.Println("Error", err) diff --git a/mocks/Database.go b/mocks/Database.go index 14154ec1d..f95c967fe 100644 --- a/mocks/Database.go +++ b/mocks/Database.go @@ -3007,12 +3007,12 @@ func (_c *Database_GetLnUser_Call) RunAndReturn(run func(string) int64) *Databas return _c } -// GetNextBountyById provides a mock function with given fields: r -func (_m *Database) GetNextBountyById(r *http.Request) ([]db.Bounty, error) { +// GetNextBountyByCreated provides a mock function with given fields: r +func (_m *Database) GetNextBountyByCreated(r *http.Request) ([]db.Bounty, error) { ret := _m.Called(r) if len(ret) == 0 { - panic("no return value specified for GetNextBountyById") + panic("no return value specified for GetNextBountyByCreated") } var r0 []db.Bounty @@ -3037,40 +3037,40 @@ func (_m *Database) GetNextBountyById(r *http.Request) ([]db.Bounty, error) { return r0, r1 } -// Database_GetNextBountyById_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNextBountyById' -type Database_GetNextBountyById_Call struct { +// Database_GetNextBountyByCreated_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNextBountyByCreated' +type Database_GetNextBountyByCreated_Call struct { *mock.Call } -// GetNextBountyById is a helper method to define mock.On call +// GetNextBountyByCreated is a helper method to define mock.On call // - r *http.Request -func (_e *Database_Expecter) GetNextBountyById(r interface{}) *Database_GetNextBountyById_Call { - return &Database_GetNextBountyById_Call{Call: _e.mock.On("GetNextBountyById", r)} +func (_e *Database_Expecter) GetNextBountyByCreated(r interface{}) *Database_GetNextBountyByCreated_Call { + return &Database_GetNextBountyByCreated_Call{Call: _e.mock.On("GetNextBountyByCreated", r)} } -func (_c *Database_GetNextBountyById_Call) Run(run func(r *http.Request)) *Database_GetNextBountyById_Call { +func (_c *Database_GetNextBountyByCreated_Call) Run(run func(r *http.Request)) *Database_GetNextBountyByCreated_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*http.Request)) }) return _c } -func (_c *Database_GetNextBountyById_Call) Return(_a0 []db.Bounty, _a1 error) *Database_GetNextBountyById_Call { +func (_c *Database_GetNextBountyByCreated_Call) Return(_a0 []db.Bounty, _a1 error) *Database_GetNextBountyByCreated_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Database_GetNextBountyById_Call) RunAndReturn(run func(*http.Request) ([]db.Bounty, error)) *Database_GetNextBountyById_Call { +func (_c *Database_GetNextBountyByCreated_Call) RunAndReturn(run func(*http.Request) ([]db.Bounty, error)) *Database_GetNextBountyByCreated_Call { _c.Call.Return(run) return _c } -// GetNextOrganizationBountyById provides a mock function with given fields: r -func (_m *Database) GetNextOrganizationBountyById(r *http.Request) ([]db.Bounty, error) { +// GetNextOrganizationBountyByCreated provides a mock function with given fields: r +func (_m *Database) GetNextOrganizationBountyByCreated(r *http.Request) ([]db.Bounty, error) { ret := _m.Called(r) if len(ret) == 0 { - panic("no return value specified for GetNextOrganizationBountyById") + panic("no return value specified for GetNextOrganizationBountyByCreated") } var r0 []db.Bounty @@ -3095,30 +3095,30 @@ func (_m *Database) GetNextOrganizationBountyById(r *http.Request) ([]db.Bounty, return r0, r1 } -// Database_GetNextOrganizationBountyById_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNextOrganizationBountyById' -type Database_GetNextOrganizationBountyById_Call struct { +// Database_GetNextOrganizationBountyByCreated_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNextOrganizationBountyByCreated' +type Database_GetNextOrganizationBountyByCreated_Call struct { *mock.Call } -// GetNextOrganizationBountyById is a helper method to define mock.On call +// GetNextOrganizationBountyByCreated is a helper method to define mock.On call // - r *http.Request -func (_e *Database_Expecter) GetNextOrganizationBountyById(r interface{}) *Database_GetNextOrganizationBountyById_Call { - return &Database_GetNextOrganizationBountyById_Call{Call: _e.mock.On("GetNextOrganizationBountyById", r)} +func (_e *Database_Expecter) GetNextOrganizationBountyByCreated(r interface{}) *Database_GetNextOrganizationBountyByCreated_Call { + return &Database_GetNextOrganizationBountyByCreated_Call{Call: _e.mock.On("GetNextOrganizationBountyByCreated", r)} } -func (_c *Database_GetNextOrganizationBountyById_Call) Run(run func(r *http.Request)) *Database_GetNextOrganizationBountyById_Call { +func (_c *Database_GetNextOrganizationBountyByCreated_Call) Run(run func(r *http.Request)) *Database_GetNextOrganizationBountyByCreated_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*http.Request)) }) return _c } -func (_c *Database_GetNextOrganizationBountyById_Call) Return(_a0 []db.Bounty, _a1 error) *Database_GetNextOrganizationBountyById_Call { +func (_c *Database_GetNextOrganizationBountyByCreated_Call) Return(_a0 []db.Bounty, _a1 error) *Database_GetNextOrganizationBountyByCreated_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Database_GetNextOrganizationBountyById_Call) RunAndReturn(run func(*http.Request) ([]db.Bounty, error)) *Database_GetNextOrganizationBountyById_Call { +func (_c *Database_GetNextOrganizationBountyByCreated_Call) RunAndReturn(run func(*http.Request) ([]db.Bounty, error)) *Database_GetNextOrganizationBountyByCreated_Call { _c.Call.Return(run) return _c } @@ -4220,12 +4220,12 @@ func (_c *Database_GetPersonByUuid_Call) RunAndReturn(run func(string) db.Person return _c } -// GetPreviousBountyById provides a mock function with given fields: r -func (_m *Database) GetPreviousBountyById(r *http.Request) ([]db.Bounty, error) { +// GetPreviousBountyByCreated provides a mock function with given fields: r +func (_m *Database) GetPreviousBountyByCreated(r *http.Request) ([]db.Bounty, error) { ret := _m.Called(r) if len(ret) == 0 { - panic("no return value specified for GetPreviousBountyById") + panic("no return value specified for GetPreviousBountyByCreated") } var r0 []db.Bounty @@ -4250,40 +4250,40 @@ func (_m *Database) GetPreviousBountyById(r *http.Request) ([]db.Bounty, error) return r0, r1 } -// Database_GetPreviousBountyById_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPreviousBountyById' -type Database_GetPreviousBountyById_Call struct { +// Database_GetPreviousBountyByCreated_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPreviousBountyByCreated' +type Database_GetPreviousBountyByCreated_Call struct { *mock.Call } -// GetPreviousBountyById is a helper method to define mock.On call +// GetPreviousBountyByCreated is a helper method to define mock.On call // - r *http.Request -func (_e *Database_Expecter) GetPreviousBountyById(r interface{}) *Database_GetPreviousBountyById_Call { - return &Database_GetPreviousBountyById_Call{Call: _e.mock.On("GetPreviousBountyById", r)} +func (_e *Database_Expecter) GetPreviousBountyByCreated(r interface{}) *Database_GetPreviousBountyByCreated_Call { + return &Database_GetPreviousBountyByCreated_Call{Call: _e.mock.On("GetPreviousBountyByCreated", r)} } -func (_c *Database_GetPreviousBountyById_Call) Run(run func(r *http.Request)) *Database_GetPreviousBountyById_Call { +func (_c *Database_GetPreviousBountyByCreated_Call) Run(run func(r *http.Request)) *Database_GetPreviousBountyByCreated_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*http.Request)) }) return _c } -func (_c *Database_GetPreviousBountyById_Call) Return(_a0 []db.Bounty, _a1 error) *Database_GetPreviousBountyById_Call { +func (_c *Database_GetPreviousBountyByCreated_Call) Return(_a0 []db.Bounty, _a1 error) *Database_GetPreviousBountyByCreated_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Database_GetPreviousBountyById_Call) RunAndReturn(run func(*http.Request) ([]db.Bounty, error)) *Database_GetPreviousBountyById_Call { +func (_c *Database_GetPreviousBountyByCreated_Call) RunAndReturn(run func(*http.Request) ([]db.Bounty, error)) *Database_GetPreviousBountyByCreated_Call { _c.Call.Return(run) return _c } -// GetPreviousOrganizationBountyById provides a mock function with given fields: r -func (_m *Database) GetPreviousOrganizationBountyById(r *http.Request) ([]db.Bounty, error) { +// GetPreviousOrganizationBountyByCreated provides a mock function with given fields: r +func (_m *Database) GetPreviousOrganizationBountyByCreated(r *http.Request) ([]db.Bounty, error) { ret := _m.Called(r) if len(ret) == 0 { - panic("no return value specified for GetPreviousOrganizationBountyById") + panic("no return value specified for GetPreviousOrganizationBountyByCreated") } var r0 []db.Bounty @@ -4308,30 +4308,30 @@ func (_m *Database) GetPreviousOrganizationBountyById(r *http.Request) ([]db.Bou return r0, r1 } -// Database_GetPreviousOrganizationBountyById_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPreviousOrganizationBountyById' -type Database_GetPreviousOrganizationBountyById_Call struct { +// Database_GetPreviousOrganizationBountyByCreated_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPreviousOrganizationBountyByCreated' +type Database_GetPreviousOrganizationBountyByCreated_Call struct { *mock.Call } -// GetPreviousOrganizationBountyById is a helper method to define mock.On call +// GetPreviousOrganizationBountyByCreated is a helper method to define mock.On call // - r *http.Request -func (_e *Database_Expecter) GetPreviousOrganizationBountyById(r interface{}) *Database_GetPreviousOrganizationBountyById_Call { - return &Database_GetPreviousOrganizationBountyById_Call{Call: _e.mock.On("GetPreviousOrganizationBountyById", r)} +func (_e *Database_Expecter) GetPreviousOrganizationBountyByCreated(r interface{}) *Database_GetPreviousOrganizationBountyByCreated_Call { + return &Database_GetPreviousOrganizationBountyByCreated_Call{Call: _e.mock.On("GetPreviousOrganizationBountyByCreated", r)} } -func (_c *Database_GetPreviousOrganizationBountyById_Call) Run(run func(r *http.Request)) *Database_GetPreviousOrganizationBountyById_Call { +func (_c *Database_GetPreviousOrganizationBountyByCreated_Call) Run(run func(r *http.Request)) *Database_GetPreviousOrganizationBountyByCreated_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*http.Request)) }) return _c } -func (_c *Database_GetPreviousOrganizationBountyById_Call) Return(_a0 []db.Bounty, _a1 error) *Database_GetPreviousOrganizationBountyById_Call { +func (_c *Database_GetPreviousOrganizationBountyByCreated_Call) Return(_a0 []db.Bounty, _a1 error) *Database_GetPreviousOrganizationBountyByCreated_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Database_GetPreviousOrganizationBountyById_Call) RunAndReturn(run func(*http.Request) ([]db.Bounty, error)) *Database_GetPreviousOrganizationBountyById_Call { +func (_c *Database_GetPreviousOrganizationBountyByCreated_Call) RunAndReturn(run func(*http.Request) ([]db.Bounty, error)) *Database_GetPreviousOrganizationBountyByCreated_Call { _c.Call.Return(run) return _c } diff --git a/routes/bounty.go b/routes/bounty.go index ddb4c5545..a169c04ee 100644 --- a/routes/bounty.go +++ b/routes/bounty.go @@ -16,10 +16,10 @@ func BountyRoutes() chi.Router { r.Get("/all", bountyHandler.GetAllBounties) r.Get("/id/{bountyId}", handlers.GetBountyById) r.Get("/index/{bountyId}", handlers.GetBountyIndexById) - r.Get("/next/{bountyId}", handlers.GetNextBountyById) - r.Get("/previous/{bountyId}", handlers.GetPreviousBountyById) - r.Get("/org/next/{uuid}/{bountyId}", handlers.GetOrganizationNextBountyById) - r.Get("/org/previous/{uuid}/{bountyId}", handlers.GetOrganizationPreviousBountyById) + r.Get("/next/{created}", handlers.GetNextBountyByCreated) + r.Get("/previous/{created}", handlers.GetPreviousBountyByCreated) + r.Get("/org/next/{uuid}/{created}", handlers.GetOrganizationNextBountyByCreated) + r.Get("/org/previous/{uuid}/{created}", handlers.GetOrganizationPreviousBountyByCreated) r.Get("/created/{created}", handlers.GetBountyByCreated) r.Get("/count/{personKey}/{tabType}", handlers.GetUserBountyCount) r.Get("/count", handlers.GetBountyCount) From e72bd58557e137b3e72510da1a03183500a9d9b2 Mon Sep 17 00:00:00 2001 From: elraphty Date: Tue, 6 Feb 2024 13:23:33 +0100 Subject: [PATCH 2/2] changed order to created --- db/db.go | 11 +++++------ db/structs.go | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/db/db.go b/db/db.go index 22b5547ba..a71466fae 100644 --- a/db/db.go +++ b/db/db.go @@ -764,8 +764,8 @@ func (db database) GetNextBountyByCreated(r *http.Request) ([]Bounty, error) { } } - query := `SELECT * FROM public.bounty WHERE id > '` + created + `' AND show = true` - orderQuery := "ORDER BY id ASC LIMIT 1" + query := `SELECT * FROM public.bounty WHERE created > '` + created + `' AND show = true` + orderQuery := "ORDER BY created ASC LIMIT 1" allQuery := query + " " + searchQuery + " " + statusQuery + " " + languageQuery + " " + orderQuery @@ -825,8 +825,8 @@ func (db database) GetPreviousBountyByCreated(r *http.Request) ([]Bounty, error) } } - query := `SELECT * FROM public.bounty WHERE id < '` + created + `' AND show = true` - orderQuery := "ORDER BY id DESC LIMIT 1" + query := `SELECT * FROM public.bounty WHERE created < '` + created + `' AND show = true` + orderQuery := "ORDER BY created DESC LIMIT 1" allQuery := query + " " + searchQuery + " " + statusQuery + " " + languageQuery + " " + orderQuery @@ -887,9 +887,8 @@ func (db database) GetNextOrganizationBountyByCreated(r *http.Request) ([]Bounty } } - fmt.Println("Org UUID", uuid) query := `SELECT * FROM public.bounty WHERE org_uuid = '` + uuid + `' AND created > '` + created + `' AND show = true` - orderQuery := "ORDER BY id ASC LIMIT 1" + orderQuery := "ORDER BY created ASC LIMIT 1" allQuery := query + " " + searchQuery + " " + statusQuery + " " + languageQuery + " " + orderQuery diff --git a/db/structs.go b/db/structs.go index 03c882e15..479548717 100644 --- a/db/structs.go +++ b/db/structs.go @@ -116,9 +116,9 @@ type Person struct { PriceToMeet int64 `json:"price_to_meet"` NewTicketTime int64 `json:"new_ticket_time", gorm: "-:all"` TwitterConfirmed bool `json:"twitter_confirmed"` + ReferredBy uint `json:"referred_by"` Extras PropertyMap `json:"extras", type: jsonb not null default '{}'::jsonb` GithubIssues PropertyMap `json:"github_issues", type: jsonb not null default '{}'::jsonb` - ReferredBy uint `json:"referred_by"` } type GormDataTypeInterface interface {