Two teams try and fill in any horizontal, vertical, or diagonal line on a bingo board by playing maps on osu! osu.bingo
osu
at microservice 64 lines 1.5 kB view raw
1use chrono::{DateTime, Utc}; 2use juniper::{FieldError, FieldResult, graphql_object}; 3use serde::{Deserialize, Serialize}; 4 5use crate::{ 6 database::DataContext, 7 schema::{BingoGame, User}, 8}; 9 10#[derive(sqlx::FromRow, Deserialize, Serialize)] 11pub struct Chat { 12 id: String, 13 14 game_id: String, 15 user_id: i32, 16 17 time: DateTime<Utc>, 18 19 text: String, 20 channel: String, 21} 22 23#[graphql_object(description = "A chat message in a lobby", Context = DataContext)] 24impl Chat { 25 /// A unique identifier for the chat message 26 pub fn id(&self) -> &str { 27 &self.id 28 } 29 30 /// The time at which the message was sent 31 pub fn time(&self) -> &DateTime<Utc> { 32 &self.time 33 } 34 35 /// The content of the message 36 pub fn text(&self) -> &str { 37 &self.text 38 } 39 40 /// The channel the message was sent in 41 pub fn channel(&self) -> &str { 42 &self.channel 43 } 44 45 /// The game the chat message was sent in 46 pub async fn game(&self, context: &DataContext) -> FieldResult<BingoGame> { 47 context 48 .acquire() 49 .await 50 .get_game_by_id(&self.game_id) 51 .await 52 .map_err(FieldError::from) 53 } 54 55 /// The user that posted the chat message 56 pub async fn user(&self, context: &DataContext) -> FieldResult<User> { 57 context 58 .acquire() 59 .await 60 .get_user_by_id(self.user_id) 61 .await 62 .map_err(FieldError::from) 63 } 64}