Skip to content

Commit 4173d44

Browse files
committed
feat: enhance bounties query with limit options and add tech listing functionality
1 parent b3e1c03 commit 4173d44

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

lib/algora/bounties/bounties.ex

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule Algora.Bounties do
2626
def base_query, do: Bounty
2727

2828
@type criterion ::
29-
{:limit, non_neg_integer()}
29+
{:limit, non_neg_integer() | :infinity}
3030
| {:ticket_id, String.t()}
3131
| {:owner_id, String.t()}
3232
| {:status, :open | :paid}
@@ -919,6 +919,9 @@ defmodule Algora.Bounties do
919919
@spec apply_criteria(Ecto.Queryable.t(), [criterion()]) :: Ecto.Queryable.t()
920920
defp apply_criteria(query, criteria) do
921921
Enum.reduce(criteria, query, fn
922+
{:limit, :infinity}, query ->
923+
query
924+
922925
{:limit, limit}, query ->
923926
from([b] in query, limit: ^limit)
924927

@@ -973,7 +976,7 @@ defmodule Algora.Bounties do
973976
end)
974977
end
975978

976-
def list_bounties_with(base_query, criteria \\ []) do
979+
def list_bounties_query(base_query, criteria \\ []) do
977980
criteria = Keyword.merge([order: :date, limit: 10], criteria)
978981

979982
base_bounties = select(base_query, [b], b.id)
@@ -987,6 +990,11 @@ defmodule Algora.Bounties do
987990
|> where([b], not is_nil(b.amount))
988991
|> where([b], b.status != :cancelled)
989992
|> apply_criteria(criteria)
993+
end
994+
995+
def list_bounties_with(base_query, criteria \\ []) do
996+
base_query
997+
|> list_bounties_query(criteria)
990998
# TODO: sort by b.paid_at if criteria[:status] == :paid
991999
|> order_by([b], desc: b.inserted_at, desc: b.id)
9921000
|> select([b, o: o, t: t, ro: ro, r: r], %{
@@ -1021,6 +1029,16 @@ defmodule Algora.Bounties do
10211029
|> Repo.all()
10221030
end
10231031

1032+
def list_tech(criteria \\ []) do
1033+
base_query()
1034+
|> list_bounties_query(Keyword.put(criteria, :limit, :infinity))
1035+
|> where([b, r: r], not is_nil(r.language))
1036+
|> group_by([b, r: r], r.language)
1037+
|> select([b, r: r], {r.language, count(r.language)})
1038+
|> order_by([b, r: r], desc: count(r.language))
1039+
|> Repo.all()
1040+
end
1041+
10241042
@spec list_claims(list(String.t())) :: [Claim.t()]
10251043
def list_claims(ticket_ids) do
10261044
Repo.all(

lib/algora_web/live/bounties_live.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ defmodule AlgoraWeb.BountiesLive do
1414
Bounties.subscribe()
1515
end
1616

17-
techs = Accounts.list_techs()
18-
selected_techs = []
19-
2017
query_opts =
2118
[
2219
status: :open,
@@ -28,6 +25,9 @@ defmodule AlgoraWeb.BountiesLive do
2825
[amount_gt: Money.new(:USD, 500)]
2926
end
3027

28+
techs = Bounties.list_tech(query_opts)
29+
selected_techs = []
30+
3131
query_opts = if selected_techs == [], do: query_opts, else: Keyword.put(query_opts, :tech_stack, selected_techs)
3232

3333
{:ok,
@@ -43,13 +43,13 @@ defmodule AlgoraWeb.BountiesLive do
4343
<div class="container mx-auto max-w-7xl space-y-6 p-6 lg:px-8">
4444
<.section title="Bounties" subtitle="Open bounties for you">
4545
<div class="-mt-4 mb-4 flex flex-wrap gap-2">
46-
<%= for tech <- @techs do %>
46+
<%= for {tech, count} <- @techs do %>
4747
<div phx-click="toggle_tech" phx-value-tech={tech} class="cursor-pointer">
4848
<.badge
4949
variant={if tech in @selected_techs, do: "success", else: "outline"}
5050
class="hover:bg-white/[4%] transition-colors"
5151
>
52-
{tech}
52+
{tech} ({count})
5353
</.badge>
5454
</div>
5555
<% end %>

0 commit comments

Comments
 (0)