Skip to content

Commit

Permalink
Merge branch 'master' into fix/org-bounties-query
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdulWahab3181 authored Jan 26, 2024
2 parents 9ba9d6e + cd2bd88 commit 38b994a
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 16 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/add_issues_to_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Since we've separated the frontend from the backend, we must track 2 repos in our bounties platform project. The free version of github only allows the project to reference one repo for free. So we are implementing this workflow to have issues be auto-added to the bounties platform project board from a second repo.

name: Add issues labeled `bounties` to bounties platform project

on:
issues:
types:
- opened

jobs:
add-to-project:
name: Add issue to project
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
project-url: https://github.com/orgs/stakwork/projects/24
github-token: ${{ secrets.ADD_TO_PROJECT }}
labeled: bounties
17 changes: 3 additions & 14 deletions .github/workflows/prjob_tests.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
name: Tests
name: Tests
on:
pull_request:
branches:
- master
jobs:
test-jest:
name: Jest
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn --cwd ./frontend/app install
- name: Tests
run: cd ./frontend/app && NODE_OPTIONS="--max_old_space_size=8192" yarn run test-jest

test-go:
name: Go
name: Go
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install cover
run: go get golang.org/x/tools/cmd/cover
- name: Tests
- name: Tests
run: go test ./... -race -v -coverprofile=coverage.out && ./cover-check.sh coverage.out 8.4
24 changes: 24 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,30 @@ func (db database) GetBountyById(id string) ([]Bounty, error) {
return ms, err
}

func (db database) GetNextBountyById(id string) ([]Bounty, error) {
ms := []Bounty{}
err := db.db.Raw(`SELECT * FROM public.bounty WHERE id > '` + id + `' ORDER BY id ASC LIMIT 1`).Find(&ms).Error
return ms, err
}

func (db database) GetPreviousBountyById(id string) ([]Bounty, error) {
ms := []Bounty{}
err := db.db.Raw(`SELECT * FROM public.bounty WHERE id < '` + id + `' ORDER BY id DESC LIMIT 1`).Find(&ms).Error
return ms, err
}

func (db database) GetNextOrganizationBountyById(uuid string, id string) ([]Bounty, error) {
ms := []Bounty{}
err := db.db.Raw(`SELECT * FROM public.bounty WHERE org_uuid = '` + uuid + `' AND id > '` + id + `' ORDER BY id ASC LIMIT 1`).Find(&ms).Error
return ms, err
}

func (db database) GetPreviousOrganizationBountyById(uuid string, id string) ([]Bounty, error) {
ms := []Bounty{}
err := db.db.Raw(`SELECT * FROM public.bounty WHERE org_uuid = '` + uuid + `' AND id < '` + id + `' ORDER BY id DESC LIMIT 1`).Find(&ms).Error
return ms, err
}

func (db database) GetBountyIndexById(id string) int64 {
var index int64
db.db.Raw(`SELECT position FROM(SELECT *, row_number() over( ORDER BY id DESC) as position FROM public.bounty) result WHERE id = '` + id + `' OR created = '` + id + `'`).Scan(&index)
Expand Down
4 changes: 4 additions & 0 deletions db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type Database interface {
GetAssignedBounties(r *http.Request) ([]Bounty, error)
GetCreatedBounties(r *http.Request) ([]Bounty, error)
GetBountyById(id string) ([]Bounty, error)
GetNextBountyById(id string) ([]Bounty, error)
GetPreviousBountyById(id string) ([]Bounty, error)
GetNextOrganizationBountyById(uuid string, id string) ([]Bounty, error)
GetPreviousOrganizationBountyById(uuid string, id string) ([]Bounty, error)
GetBountyIndexById(id string) int64
GetBountyDataByCreated(created string) ([]Bounty, error)
AddBounty(b Bounty) (Bounty, error)
Expand Down
66 changes: 66 additions & 0 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,72 @@ func GetBountyById(w http.ResponseWriter, r *http.Request) {
}
}

func GetNextBountyById(w http.ResponseWriter, r *http.Request) {
bountyId := chi.URLParam(r, "bountyId")
if bountyId == "" {
w.WriteHeader(http.StatusNotFound)
}
bounties, err := db.DB.GetNextBountyById(bountyId)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
} else {
var bountyResponse []db.BountyResponse = GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
}

func GetPreviousBountyById(w http.ResponseWriter, r *http.Request) {
bountyId := chi.URLParam(r, "bountyId")
if bountyId == "" {
w.WriteHeader(http.StatusNotFound)
}
bounties, err := db.DB.GetPreviousBountyById(bountyId)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
} else {
var bountyResponse []db.BountyResponse = GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
}

func GetOrganizationNextBountyById(w http.ResponseWriter, r *http.Request) {
bountyId := chi.URLParam(r, "bountyId")
uuid := chi.URLParam(r, "uuid")
if bountyId == "" || uuid == "" {
w.WriteHeader(http.StatusNotFound)
}
bounties, err := db.DB.GetNextOrganizationBountyById(uuid, bountyId)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
} else {
var bountyResponse []db.BountyResponse = GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
}

func GetOrganizationPreviousBountyById(w http.ResponseWriter, r *http.Request) {
bountyId := chi.URLParam(r, "bountyId")
uuid := chi.URLParam(r, "uuid")
if bountyId == "" || uuid == "" {
w.WriteHeader(http.StatusNotFound)
}
bounties, err := db.DB.GetPreviousOrganizationBountyById(uuid, bountyId)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
} else {
var bountyResponse []db.BountyResponse = GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
}

func GetBountyIndexById(w http.ResponseWriter, r *http.Request) {
bountyId := chi.URLParam(r, "bountyId")
if bountyId == "" {
Expand Down
Loading

0 comments on commit 38b994a

Please sign in to comment.