Allow searching languages. Prefer profiles with images/names.

main
Joshua Potter 2023-12-06 16:48:53 -07:00
parent 286b3dd31d
commit 8a3320e279
2 changed files with 14 additions and 4 deletions

View File

@ -60,11 +60,20 @@ defmodule BoardWise.Coaches do
score: score:
fragment( fragment(
""" """
? + ? + ? CASE WHEN ? IS NOT NULL THEN 1000 ELSE 0 END +
CASE WHEN ? IS NOT NULL THEN 500 ELSE 0 END +
? +
? +
? +
(5 * (SELECT COUNT(*) FROM UNNEST(?) WHERE UNNEST = ANY(?)))
""", """,
c.name,
c.image_url,
rating_fragment(c.rapid, ^rapid_gte, ^rapid_lte), rating_fragment(c.rapid, ^rapid_gte, ^rapid_lte),
rating_fragment(c.blitz, ^blitz_gte, ^blitz_lte), rating_fragment(c.blitz, ^blitz_gte, ^blitz_lte),
rating_fragment(c.bullet, ^bullet_gte, ^bullet_lte) rating_fragment(c.bullet, ^bullet_gte, ^bullet_lte),
type(^languages, {:array, :string}),
c.languages
) )
|> selected_as(:score) |> selected_as(:score)
} }

View File

@ -5,14 +5,15 @@ defmodule BoardWise.CoachesTest do
describe "coaches" do describe "coaches" do
alias BoardWise.Coaches.Coach alias BoardWise.Coaches.Coach
alias BoardWise.Coaches.QueryParams
import BoardWise.CoachesFixtures import BoardWise.CoachesFixtures
@invalid_attrs %{blitz: nil, bullet: nil, rapid: nil, site: nil, username: nil} @invalid_attrs %{blitz: nil, bullet: nil, rapid: nil, site: nil, username: nil}
test "page_coaches/2 returns all coaches" do test "list_coaches/2 returns all coaches" do
coach = coach_fixture() coach = coach_fixture()
assert Coaches.page_coaches(1, 1000) == [coach] assert Coaches.list_coaches(%QueryParams{}) == [%{coach | score: 0}]
end end
test "get_coach!/1 returns the coach with given id" do test "get_coach!/1 returns the coach with given id" do