Added owning games and not willing to travel with them.

This commit is contained in:
2025-12-30 21:18:16 +01:00
parent ff88029a4b
commit 0c256846f6
45 changed files with 595 additions and 92 deletions

View File

@@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`
alter table owned_game drop constraint FK_owned_games_location_id;
alter table owned_game drop column location_id;

View File

@@ -0,0 +1,6 @@
-- Your SQL goes here
ALTER TABLE owned_game
ADD location_id UUID;
ALTER TABLE owned_game
ADD CONSTRAINT FK_owned_games_location_id FOREIGN KEY(location_id) REFERENCES location(id);

View File

@@ -1,10 +1,10 @@
use crate::schema::game;
use diesel::{
ExpressionMethods, Insertable, PgConnection, QueryDsl, Queryable, RunQueryDsl, dsl::insert_into,
ExpressionMethods, Insertable, QueryDsl, Queryable, RunQueryDsl, dsl::insert_into,
};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::DbConnection;
use super::error::DatabaseError;
#[derive(Serialize, Deserialize, Debug, Insertable, Queryable)]
@@ -14,20 +14,20 @@ pub struct Game {
pub name: String,
}
pub fn games(conn: &mut PgConnection) -> Result<Vec<Game>, DatabaseError> {
pub fn games(conn: &mut DbConnection) -> Result<Vec<Game>, DatabaseError> {
Ok(game::table.load::<Game>(conn)?)
}
pub fn load_game(conn: &mut PgConnection, id: Uuid) -> Result<Game, DatabaseError> {
pub fn load_game(conn: &mut DbConnection, id: Uuid) -> Result<Game, DatabaseError> {
Ok(game::table.find(id).get_result(conn)?)
}
pub fn insert_game(conn: &mut PgConnection, game: Game) -> Result<usize, DatabaseError> {
Ok(insert_into(game::table).values(&game).execute(conn)?)
pub fn insert_game(conn: &mut DbConnection, game: &Game) -> Result<usize, DatabaseError> {
Ok(insert_into(game::table).values(game).execute(conn)?)
}
pub fn rename_game(
conn: &mut PgConnection,
conn: &mut DbConnection,
id: Uuid,
name: String,
) -> Result<usize, DatabaseError> {

View File

@@ -12,6 +12,7 @@ use uuid::Uuid;
pub struct OwnedGame {
pub user_id: Uuid,
pub game_id: Uuid,
pub location_id: Option<Uuid>
}
pub fn own_game(conn: &mut PgConnection, owned_game: OwnedGame) -> Result<usize, DatabaseError> {

View File

@@ -69,6 +69,7 @@ diesel::table! {
owned_game (user_id, game_id) {
user_id -> Uuid,
game_id -> Uuid,
location_id -> Nullable<Uuid>,
}
}
@@ -99,6 +100,7 @@ diesel::joinable!(location_owner -> client (user_id));
diesel::joinable!(location_owner -> location (location_id));
diesel::joinable!(owned_game -> client (user_id));
diesel::joinable!(owned_game -> game (game_id));
diesel::joinable!(owned_game -> location (location_id));
diesel::joinable!(pwd -> client (user_id));
diesel::allow_tables_to_appear_in_same_query!(