Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/nav to created #1492

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -764,17 +764,17 @@ func (db database) GetNextBountyById(r *http.Request) ([]Bounty, error) {
}
}

query := `SELECT * FROM public.bounty WHERE id > '` + id + `' 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

err := db.db.Raw(allQuery).Find(&ms).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{}
Expand Down Expand Up @@ -825,17 +825,17 @@ func (db database) GetPreviousBountyById(r *http.Request) ([]Bounty, error) {
}
}

query := `SELECT * FROM public.bounty WHERE id < '` + id + `' 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

err := db.db.Raw(allQuery).Find(&ms).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)
Expand Down Expand Up @@ -887,17 +887,17 @@ func (db database) GetNextOrganizationBountyById(r *http.Request) ([]Bounty, err
}
}

query := `SELECT * FROM public.bounty WHERE org_uuid = '` + uuid + `' AND id > '` + id + `' AND show = true`
orderQuery := "ORDER BY id ASC LIMIT 1"
query := `SELECT * FROM public.bounty WHERE org_uuid = '` + uuid + `' AND created > '` + created + `' AND show = true`
orderQuery := "ORDER BY created ASC LIMIT 1"

allQuery := query + " " + searchQuery + " " + statusQuery + " " + languageQuery + " " + orderQuery

err := db.db.Raw(allQuery).Find(&ms).Error
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)
Expand Down Expand Up @@ -949,8 +949,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

Expand Down
8 changes: 4 additions & 4 deletions db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
88 changes: 44 additions & 44 deletions mocks/Database.go

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

8 changes: 4 additions & 4 deletions routes/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading