Returns participants for a gamenight

This commit is contained in:
Dennis Brentjes 2025-05-31 22:37:51 +02:00
parent 156be1821a
commit f1d23cb495
5 changed files with 17 additions and 12 deletions

View File

@ -112,7 +112,6 @@ components:
- name
- datetime
- owner_id
- participants
Failure:
title: Failure
type: object

View File

@ -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<DbPool>, _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)?))
}

View File

@ -1,8 +1,3 @@
src
docs
/target/
**/*.rs.bk
Cargo.lock
.openapi-generator
.openapi-generator-ignore
.travis.yml

View File

@ -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<Vec<GamenightParticipants>, DatabaseError> {
pub fn get_participants(conn: &mut DbConnection, id: &Uuid) -> Result<Vec<Uuid>, 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)?)
}

View File

@ -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;