Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug #2083 Filtering by tags doesn't work #2099

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions services/app/apps/codebattle/lib/codebattle/task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ defmodule Codebattle.Task do
!result
end

@spec get_task_by_tags_for_user(User.t(), list(String.t())) :: t() | nil
def get_task_by_tags_for_user(user, tags) do
@spec get_task_by_tags_for_user(User.t(), list(String.t()), String.t()) :: t() | nil
def get_task_by_tags_for_user(user, tags, level) do
__MODULE__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the default level to nil, meaning a task with a random level will be selected if no level is specified.

|> filter_visibility(user)
|> where([t], t.level == ^level)
|> where([t], fragment("? @> ?", t.tags, ^tags))
|> order_by(fragment("RANDOM()"))
|> limit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ defmodule CodebattleWeb.LobbyChannel do
end

defp maybe_add_task(params, %{"task_tags" => task_tags}, user) when length(task_tags) > 0 do
case Codebattle.Task.get_task_by_tags_for_user(user, task_tags) do
level = Map.get(params, :level)
case Codebattle.Task.get_task_by_tags_for_user(user, task_tags, level) do
nil -> params
task -> Map.put(params, :task, task)
end
Expand Down