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

bounty.go handlers GetAllBounties, GetBountyById, & GetBountyIndexById #1526 #1538

Merged
merged 25 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3b633fe
pushed test for Backend [Integration Test] bounty.go handlers GetPers…
gouravmpk Feb 20, 2024
b4e68b8
Revert "pushed test for Backend [Integration Test] bounty.go handlers…
gouravmpk Feb 20, 2024
43a44ed
Added tests for GetPersonAssignedBounties, & GetBountyByCreated
gouravmpk Feb 20, 2024
901f5ed
Merge branch 'master' into testsBounty
gouravmpk Feb 20, 2024
3822030
fixed duplicate test
gouravmpk Feb 20, 2024
19a9624
added TestGetPersonCreatedBounties
gouravmpk Feb 20, 2024
b47846d
initial commit
gouravmpk Feb 20, 2024
78c7f3b
routes
gouravmpk Feb 20, 2024
372491a
TestGetAllBounties
gouravmpk Feb 20, 2024
2c7a75e
TestGetBountyIndexById
gouravmpk Feb 21, 2024
376079d
TestGetBountyByCreated
gouravmpk Feb 21, 2024
3b8745a
Update organizations.go
gouravmpk Feb 21, 2024
911fccb
Update bounty.go
gouravmpk Feb 21, 2024
9852866
Merge branch 'master' into tests#1526
gouravmpk Feb 21, 2024
4816acb
Merge branch 'stakwork:master' into tests#1526
gouravmpk Feb 21, 2024
8e9dec4
Update organizations.go
gouravmpk Feb 21, 2024
21436ee
Merge branch 'master' into tests#1526
gouravmpk Feb 25, 2024
a686e9c
some changes and conflicts fix
gouravmpk Feb 25, 2024
55f6662
test fix
gouravmpk Feb 25, 2024
2fd91c3
fixed
gouravmpk Feb 26, 2024
31b518a
removed get person created bounties
gouravmpk Feb 26, 2024
0b56f3a
renamed the test
gouravmpk Feb 26, 2024
99eea4a
added TestGetAllBounties
gouravmpk Feb 26, 2024
87775ac
change http url req
gouravmpk Feb 27, 2024
d43b4dd
more url req changes
gouravmpk Feb 27, 2024
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
33 changes: 17 additions & 16 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ type bountyHandler struct {

func NewBountyHandler(httpClient HttpClient, db db.Database) *bountyHandler {
return &bountyHandler{
httpClient: httpClient,
db: db,
generateBountyResponse: GenerateBountyResponse,

httpClient: httpClient,
db: db,
}
}

func (h *bountyHandler) GetAllBounties(w http.ResponseWriter, r *http.Request) {
bounties := h.db.GetAllBounties(r)
var bountyResponse []db.BountyResponse = GenerateBountyResponse(bounties)
var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties)

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}

func GetBountyById(w http.ResponseWriter, r *http.Request) {
func (h *bountyHandler) GetBountyById(w http.ResponseWriter, r *http.Request) {
bountyId := chi.URLParam(r, "bountyId")
if bountyId == "" {
w.WriteHeader(http.StatusNotFound)
}
bounties, err := db.DB.GetBountyById(bountyId)
bounties, err := h.db.GetBountyById(bountyId)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
} else {
var bountyResponse []db.BountyResponse = GenerateBountyResponse(bounties)
var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
Expand Down Expand Up @@ -100,12 +100,12 @@ func (h *bountyHandler) GetOrganizationPreviousBountyByCreated(w http.ResponseWr
}
}

func GetBountyIndexById(w http.ResponseWriter, r *http.Request) {
func (h *bountyHandler) GetBountyIndexById(w http.ResponseWriter, r *http.Request) {
bountyId := chi.URLParam(r, "bountyId")
if bountyId == "" {
w.WriteHeader(http.StatusNotFound)
}
bountyIndex := db.DB.GetBountyIndexById(bountyId)
bountyIndex := h.db.GetBountyIndexById(bountyId)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyIndex)
}
Expand All @@ -120,7 +120,8 @@ func (h *bountyHandler) GetBountyByCreated(w http.ResponseWriter, r *http.Reques
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
} else {
var bountyResponse []db.BountyResponse = h.generateBountyResponse(bounties)
var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties)

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
Expand Down Expand Up @@ -151,7 +152,7 @@ func (h *bountyHandler) GetPersonCreatedBounties(w http.ResponseWriter, r *http.
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
} else {
var bountyResponse []db.BountyResponse = h.generateBountyResponse(bounties)
var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
Expand All @@ -163,7 +164,7 @@ func (h *bountyHandler) GetPersonAssignedBounties(w http.ResponseWriter, r *http
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
} else {
var bountyResponse []db.BountyResponse = h.generateBountyResponse(bounties)
var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
Expand Down Expand Up @@ -320,15 +321,15 @@ func UpdatePaymentStatus(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(bounty)
}

func GenerateBountyResponse(bounties []db.Bounty) []db.BountyResponse {
func (h *bountyHandler) GenerateBountyResponse(bounties []db.Bounty) []db.BountyResponse {
var bountyResponse []db.BountyResponse

for i := 0; i < len(bounties); i++ {
bounty := bounties[i]

owner := db.DB.GetPersonByPubkey(bounty.OwnerID)
assignee := db.DB.GetPersonByPubkey(bounty.Assignee)
organization := db.DB.GetOrganizationByUuid(bounty.OrgUuid)
owner := h.db.GetPersonByPubkey(bounty.OwnerID)
assignee := h.db.GetPersonByPubkey(bounty.Assignee)
organization := h.db.GetOrganizationByUuid(bounty.OrgUuid)

b := db.BountyResponse{
Bounty: db.Bounty{
Expand Down
Loading
Loading