Skip to content

Commit 831ff19

Browse files
committed
feat: add Shields.io badges endpoint
- Introduced a new `ShieldsController` to handle requests for Shields.io badges related to bounties. - Added a route in the router for fetching bounty statistics based on organization handle and status. - Implemented JSON response format for badge data, enhancing integration with external services.
1 parent 84d9609 commit 831ff19

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
defmodule AlgoraWeb.API.ShieldsController do
2+
use AlgoraWeb, :controller
3+
4+
alias Algora.Accounts
5+
alias Algora.Bounties
6+
7+
def bounties(conn, %{"org_handle" => org_handle, "status" => status}) do
8+
case Accounts.fetch_user_by(handle: org_handle) do
9+
{:ok, org} ->
10+
stats = Bounties.fetch_stats(org_id: org.id)
11+
12+
{label, message, label_color} =
13+
case status do
14+
"open" ->
15+
{
16+
"💎 Open Bounties",
17+
Money.to_string!(stats.open_bounties_amount, no_fraction_if_integer: true),
18+
"4f46e5"
19+
}
20+
21+
"completed" ->
22+
{
23+
"💰 Rewarded Bounties",
24+
Money.to_string!(stats.total_awarded_amount, no_fraction_if_integer: true),
25+
"15803d"
26+
}
27+
end
28+
29+
json(conn, %{
30+
schemaVersion: 1,
31+
label: label,
32+
message: message,
33+
color: "grey",
34+
labelColor: label_color
35+
})
36+
37+
_ ->
38+
conn
39+
|> put_status(:not_found)
40+
|> json(%{error: "Organization not found"})
41+
end
42+
end
43+
end

lib/algora_web/router.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ defmodule AlgoraWeb.Router do
171171
# Legacy tRPC endpoints
172172
get "/trpc/bounty.list", BountyController, :index
173173
post "/trpc/bounty.list", BountyController, :index
174+
175+
# Shields.io badges
176+
get "/shields/:org_handle/bounties", ShieldsController, :bounties
174177
end
175178

176179
# Other scopes may use custom stacks.

0 commit comments

Comments
 (0)