Skip to content

Commit

Permalink
added endpoint for all user invoices count
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed Jun 5, 2024
1 parent a1dd48b commit aaf3702
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions handlers/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,26 @@ func GetInvoicesCount(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(invoiceCount)
}

func GetAllUserInvoicesCount(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)

if pubKeyFromAuth == "" {
fmt.Println("[workspaces] no pubkey from auth")
w.WriteHeader(http.StatusUnauthorized)
return
}

allCount := int64(0)
workspaces := GetAllUserWorkspaces(pubKeyFromAuth)
for _, space := range workspaces {
invoiceCount := db.DB.GetWorkspaceInvoicesCount(space.Uuid)
allCount += invoiceCount
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(allCount)
}

func (oh *workspaceHandler) DeleteWorkspace(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
Expand Down
1 change: 1 addition & 0 deletions routes/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func WorkspaceRoutes() chi.Router {
r.Get("/poll/invoices/{uuid}", workspaceHandlers.PollBudgetInvoices)
r.Get("/poll/user/invoices", workspaceHandlers.PollUserWorkspacesBudget)
r.Get("/invoices/count/{uuid}", handlers.GetInvoicesCount)
r.Get("/user/invoices/count", handlers.GetAllUserInvoicesCount)
r.Delete("/delete/{uuid}", workspaceHandlers.DeleteWorkspace)

r.Post("/mission", workspaceHandlers.UpdateWorkspace)
Expand Down

0 comments on commit aaf3702

Please sign in to comment.