@@ -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 (
0 commit comments