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::{database::DataContext, schema::User};
5
6#[derive(sqlx::FromRow, Serialize, Deserialize)]
7pub struct Template {
8 id: String,
9 owner_id: i32,
10 name: Option<String>,
11 description: Option<String>,
12 data: String,
13}
14
15#[graphql_object(description = "A reusable options spec you can apply to a game", Context = DataContext)]
16impl Template {
17 ///
18 pub fn id(&self) -> &str {
19 &self.id
20 }
21
22 /// An optional name for the template
23 pub fn name(&self) -> Option<&str> {
24 self.name.as_deref()
25 }
26
27 /// An optional description of the template
28 pub fn description(&self) -> Option<&str> {
29 self.description.as_deref()
30 }
31
32 /// The template data
33 pub fn data(&self) -> &String {
34 &self.data
35 }
36
37 /// The user that created the template
38 pub async fn owner(&self, context: &DataContext) -> FieldResult<User> {
39 context
40 .acquire()
41 .await
42 .get_user_by_id(self.owner_id)
43 .await
44 .map_err(FieldError::from)
45 }
46}