-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
from random import shuffle | ||
|
||
import strawberry as sb | ||
|
||
import src.domain.model as domain | ||
from src.adapter.external.graphql import scalar | ||
from src.adapter.external.graphql.tool.context import Info | ||
from src.adapter.external.graphql.type.participant import ParticipantType | ||
|
||
|
||
@sb.type | ||
class RecommendationsQuery: | ||
@sb.field | ||
async def recommendations( | ||
root: RecommendationsQuery, | ||
info: Info[RecommendationsQuery], | ||
user_id: scalar.ObjectID, | ||
allocation_id: scalar.ObjectID, | ||
) -> list[ParticipantType]: # type: ignore | ||
participants = await info.context.participant.service.read_all() | ||
|
||
selected = [ | ||
participant.id | ||
for participant in participants | ||
if participant.user_id != user_id | ||
and participant.allocation_id == allocation_id | ||
and participant.state == domain.ParticipantState.ACTIVE | ||
] | ||
if not selected: | ||
return [] | ||
|
||
shuffle(selected) | ||
|
||
return await info.context.participant.loader.load_many(selected[:10]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters