From f1d23cb49544590f9280da9066db57d10ca19a24 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Sat, 31 May 2025 22:37:51 +0200 Subject: [PATCH] Returns participants for a gamenight --- backend-actix/gamenight-api.yaml | 1 - backend-actix/src/request/gamenight_handlers.rs | 13 +++++++++++-- gamenight-api-client-rs/.gitignore | 5 ----- gamenight-database/src/gamenight_participants.rs | 8 +++++--- gamenight-database/src/lib.rs | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/backend-actix/gamenight-api.yaml b/backend-actix/gamenight-api.yaml index ebba8dd..9a37e49 100644 --- a/backend-actix/gamenight-api.yaml +++ b/backend-actix/gamenight-api.yaml @@ -112,7 +112,6 @@ components: - name - datetime - owner_id - - participants Failure: title: Failure type: object diff --git a/backend-actix/src/request/gamenight_handlers.rs b/backend-actix/src/request/gamenight_handlers.rs index 2d6a45b..f35629b 100644 --- a/backend-actix/src/request/gamenight_handlers.rs +++ b/backend-actix/src/request/gamenight_handlers.rs @@ -4,6 +4,7 @@ use uuid::Uuid; use gamenight_database::{gamenight::Gamenight, DbPool, GetConnection}; +use crate::models; use crate::request::authorization::AuthUser; use crate::request::requests::GamenightGet; use crate::request::requests::GamenightPost; @@ -53,9 +54,17 @@ pub async fn gamenight_get(pool: web::Data, _user: AuthUser, gamenight_d let mut conn = pool.get_conn(); let gamenight = gamenight_database::gamenight::get_gamenight(&mut conn, gamenight_data.into_inner().into())?; - //let participants = schema::user::get_participants(&mut conn, gamenight_id); + let participants = gamenight_database::gamenight_participants::get_participants(&mut conn, &gamenight.id)?; + + let model = models::gamenight::Gamenight{ + id: gamenight.id.to_string(), + datetime: gamenight.datetime.to_rfc3339(), + name: gamenight.name, + owner_id: gamenight.owner_id.to_string(), + participants: Some(participants.iter().map(|x| {x.to_string()}).collect()) + }; Ok(HttpResponse::Ok() .content_type(ContentType::json()) - .body(serde_json::to_string(&gamenight)?)) + .body(serde_json::to_string(&model)?)) } \ No newline at end of file diff --git a/gamenight-api-client-rs/.gitignore b/gamenight-api-client-rs/.gitignore index 5a5d79a..6aa1064 100644 --- a/gamenight-api-client-rs/.gitignore +++ b/gamenight-api-client-rs/.gitignore @@ -1,8 +1,3 @@ -src -docs /target/ **/*.rs.bk Cargo.lock -.openapi-generator -.openapi-generator-ignore -.travis.yml diff --git a/gamenight-database/src/gamenight_participants.rs b/gamenight-database/src/gamenight_participants.rs index d88b083..e3bd08b 100644 --- a/gamenight-database/src/gamenight_participants.rs +++ b/gamenight-database/src/gamenight_participants.rs @@ -1,10 +1,11 @@ -use diesel::{ExpressionMethods, Insertable, PgConnection, QueryDsl, Queryable, RunQueryDsl}; +use diesel::{ExpressionMethods, Insertable, QueryDsl, Queryable, RunQueryDsl}; use serde::{Serialize, Deserialize}; use uuid::Uuid; use crate::schema::gamenight_participant; use super::error::DatabaseError; +use super::DbConnection; #[derive(Serialize, Deserialize, Debug, Insertable, Queryable)] #[diesel(belongs_to(Gamenight))] @@ -15,8 +16,9 @@ pub struct GamenightParticipants { pub user_id: Uuid, } -pub fn gamenight_participants(conn: &mut PgConnection, id: Uuid) -> Result, DatabaseError> { +pub fn get_participants(conn: &mut DbConnection, id: &Uuid) -> Result, DatabaseError> { Ok(gamenight_participant::table - .filter(gamenight_participant::gamenight_id.eq(id)) + .filter(gamenight_participant::gamenight_id.eq(&id)) + .select(gamenight_participant::user_id) .get_results(conn)?) } \ No newline at end of file diff --git a/gamenight-database/src/lib.rs b/gamenight-database/src/lib.rs index efcc8cd..7fc77da 100644 --- a/gamenight-database/src/lib.rs +++ b/gamenight-database/src/lib.rs @@ -16,7 +16,7 @@ use diesel_migrations::MigrationHarness; pub use user::login; pub use user::register; pub use gamenight::gamenights; -pub use gamenight_participants::gamenight_participants; +pub use gamenight_participants::get_participants; pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!(); pub type DbConnection = PgConnection;