From 8a3320e27921e3f4f31d7ad54505b8afcfdb9d0a Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Wed, 6 Dec 2023 16:48:53 -0700 Subject: [PATCH] Allow searching languages. Prefer profiles with images/names. --- lib/boardwise/coaches.ex | 13 +++++++++++-- test/boardwise/coaches_test.exs | 5 +++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/boardwise/coaches.ex b/lib/boardwise/coaches.ex index 85d4b3c..c9d6b37 100644 --- a/lib/boardwise/coaches.ex +++ b/lib/boardwise/coaches.ex @@ -60,11 +60,20 @@ defmodule BoardWise.Coaches do score: 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.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) } diff --git a/test/boardwise/coaches_test.exs b/test/boardwise/coaches_test.exs index b2c8fbc..1fa8aef 100644 --- a/test/boardwise/coaches_test.exs +++ b/test/boardwise/coaches_test.exs @@ -5,14 +5,15 @@ defmodule BoardWise.CoachesTest do describe "coaches" do alias BoardWise.Coaches.Coach + alias BoardWise.Coaches.QueryParams import BoardWise.CoachesFixtures @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() - assert Coaches.page_coaches(1, 1000) == [coach] + assert Coaches.list_coaches(%QueryParams{}) == [%{coach | score: 0}] end test "get_coach!/1 returns the coach with given id" do