Added Location and location ownership/rights to gamenight.

This commit is contained in:
2025-12-24 14:48:54 +01:00
parent 8a48119c80
commit ff88029a4b
57 changed files with 3034 additions and 995 deletions

View File

@@ -1,28 +1,38 @@
use diesel::{dsl::{delete, insert_into}, prelude::{Insertable, Queryable}, BoolExpressionMethods, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
use serde::{Serialize, Deserialize};
use uuid::Uuid;
use crate::{schema::owned_game, user::DatabaseError};
use diesel::{
BoolExpressionMethods, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl,
dsl::{delete, insert_into},
prelude::{Insertable, Queryable},
};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Serialize, Deserialize, Debug, Insertable, Queryable)]
#[diesel(table_name = owned_game)]
pub struct OwnedGame {
pub user_id: Uuid,
pub game_id: Uuid
pub game_id: Uuid,
}
pub fn own_game(conn: &mut PgConnection, owned_game: OwnedGame) -> Result<usize, DatabaseError>{
Ok(insert_into(owned_game::table).values(&owned_game).execute(conn)?)
pub fn own_game(conn: &mut PgConnection, owned_game: OwnedGame) -> Result<usize, DatabaseError> {
Ok(insert_into(owned_game::table)
.values(&owned_game)
.execute(conn)?)
}
pub fn disown_game(conn: &mut PgConnection, owned_game: OwnedGame) -> Result<usize, DatabaseError> {
Ok(delete(owned_game::table)
.filter(owned_game::user_id.eq(&owned_game.user_id)
.and(owned_game::game_id.eq(&owned_game.game_id))
).execute(conn)?)
.filter(
owned_game::user_id
.eq(&owned_game.user_id)
.and(owned_game::game_id.eq(&owned_game.game_id)),
)
.execute(conn)?)
}
pub fn owned_games(conn: &mut PgConnection, uuid: Uuid) -> Result<Vec<Uuid>, DatabaseError> {
Ok(owned_game::table.select(owned_game::game_id)
Ok(owned_game::table
.select(owned_game::game_id)
.filter(owned_game::user_id.eq(uuid))
.get_results(conn)?)
}
}