Two teams try and fill in any horizontal, vertical, or diagonal line on a bingo board by playing maps on osu!
osu.bingo
osu
1use juniper::{FieldError, FieldResult, graphql_object};
2use serde::{Deserialize, Serialize};
3
4use crate::{
5 database::DataContext,
6 schema::{BingoGame, User},
7};
8
9#[derive(sqlx::FromRow, Deserialize, Serialize)]
10pub struct GameUser {
11 id: String,
12
13 game_id: String,
14 user_id: i32,
15
16 team_name: String,
17 host: bool,
18}
19
20#[graphql_object(description = "Represents a user's role in a game", Context = DataContext)]
21impl GameUser {
22 /// A unique identifer for the gameusers
23 pub fn id(&self) -> &str {
24 &self.id
25 }
26
27 /// The name of the team this user is on
28 pub fn team_name(&self) -> &str {
29 &self.team_name.trim()
30 }
31
32 /// Whether or not this user is a host of the game
33 pub fn is_host(&self) -> bool {
34 self.host
35 }
36
37 /// The game this user is a member of
38 pub async fn game(&self, context: &DataContext) -> FieldResult<BingoGame> {
39 context
40 .acquire()
41 .await
42 .get_game_by_id(&self.game_id)
43 .await
44 .map_err(FieldError::from)
45 }
46
47 /// The user associated with this gameuser
48 pub async fn user(&self, context: &DataContext) -> FieldResult<User> {
49 context
50 .acquire()
51 .await
52 .get_user_by_id(self.user_id)
53 .await
54 .map_err(FieldError::from)
55 }
56}