From af41a9811127c07bc67f70a8a9f180c4a89cc9fd Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Sat, 27 Sep 2025 21:05:34 +0700 Subject: [PATCH] feat: Add previous winners field to hackathon DTOs and schema --- .../src/v1/hackathon/hackathon_dto.rs | 24 +++++++++++++++++++ .../src/v1/hackathon/hackathon_repository.rs | 23 ++++++++++++++++++ .../src/v1/hackathon/hackathon_schema.rs | 9 +++++++ 3 files changed, 56 insertions(+) diff --git a/imphnen-hackathon/src/v1/hackathon/hackathon_dto.rs b/imphnen-hackathon/src/v1/hackathon/hackathon_dto.rs index ab486e9..08a2024 100644 --- a/imphnen-hackathon/src/v1/hackathon/hackathon_dto.rs +++ b/imphnen-hackathon/src/v1/hackathon/hackathon_dto.rs @@ -27,6 +27,7 @@ pub struct HackathonCreateRequestDto { pub theme: Option, pub rules: Option, pub prizes: Option>, + pub previous_winners: Option>, pub organizers: Vec, } @@ -55,6 +56,8 @@ pub struct HackathonUpdateRequestDto { #[serde(skip_serializing_if = "Option::is_none")] pub prizes: Option>, #[serde(skip_serializing_if = "Option::is_none")] + pub previous_winners: Option>, + #[serde(skip_serializing_if = "Option::is_none")] pub organizers: Option>, } @@ -74,6 +77,7 @@ pub struct HackathonDto { pub theme: Option, pub rules: Option, pub prizes: Option>, + pub previous_winners: Option>, pub organizers: Vec, pub is_deleted: bool, pub created_at: Option, @@ -89,6 +93,15 @@ pub struct PrizeDto { pub description: Option, pub value: Option, } +#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)] +pub struct WinnerDto { + #[validate(range(min = 1, message = "Position must be at least 1"))] + pub position: u32, + pub team_id: String, + #[validate(length(min = 1, message = "Project name cannot be empty"))] + pub project_name: String, + pub team_name: Option, +} // Hackathon Events DTOs #[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)] @@ -331,6 +344,17 @@ impl From for HackathonDto { }) .collect() }), + previous_winners: schema.previous_winners.map(|winners| { + winners + .into_iter() + .map(|w| WinnerDto { + position: w.position, + team_id: w.team_id, + project_name: w.project_name, + team_name: w.team_name, + }) + .collect() + }), organizers: schema.organizers, is_deleted: schema.is_deleted, created_at: schema.created_at, diff --git a/imphnen-hackathon/src/v1/hackathon/hackathon_repository.rs b/imphnen-hackathon/src/v1/hackathon/hackathon_repository.rs index 498203e..2018ee3 100644 --- a/imphnen-hackathon/src/v1/hackathon/hackathon_repository.rs +++ b/imphnen-hackathon/src/v1/hackathon/hackathon_repository.rs @@ -46,6 +46,16 @@ impl<'a> HackathonRepository<'a> { }) .collect() }); + let previous_winners: Option> = hackathon.previous_winners.map(|w| { + w.into_iter() + .map(|winner| super::hackathon_schema::Winner { + position: winner.position, + team_id: winner.team_id, + project_name: winner.project_name, + team_name: winner.team_name, + }) + .collect() + }); let schema = HackathonSchema { id: Thing::from((table.clone(), id.clone())), @@ -59,6 +69,7 @@ impl<'a> HackathonRepository<'a> { theme: hackathon.theme, rules: hackathon.rules, prizes, + previous_winners, organizers: hackathon.organizers, is_deleted: false, created_at: Some(get_iso_date()), @@ -156,6 +167,18 @@ impl<'a> HackathonRepository<'a> { }) .collect(); existing.prizes = Some(prizes_schema); + if let Some(previous_winners) = updates.previous_winners { + let winners_schema: Vec = previous_winners + .into_iter() + .map(|w| super::hackathon_schema::Winner { + position: w.position, + team_id: w.team_id, + project_name: w.project_name, + team_name: w.team_name, + }) + .collect(); + existing.previous_winners = Some(winners_schema); + } } if let Some(organizers) = updates.organizers { existing.organizers = organizers; diff --git a/imphnen-hackathon/src/v1/hackathon/hackathon_schema.rs b/imphnen-hackathon/src/v1/hackathon/hackathon_schema.rs index 2d2be5b..ccb7c33 100644 --- a/imphnen-hackathon/src/v1/hackathon/hackathon_schema.rs +++ b/imphnen-hackathon/src/v1/hackathon/hackathon_schema.rs @@ -19,6 +19,7 @@ pub struct HackathonSchema { pub theme: Option, pub rules: Option, pub prizes: Option>, + pub previous_winners: Option>, pub organizers: Vec, // User IDs pub is_deleted: bool, pub created_at: Option, @@ -84,6 +85,13 @@ pub struct Prize { pub description: Option, pub value: Option, } +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Winner { + pub position: u32, + pub team_id: String, + pub project_name: String, + pub team_name: Option, +} #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, utoipa::ToSchema)] pub enum HackathonStatus { @@ -143,6 +151,7 @@ impl Default for HackathonSchema { theme: None, rules: None, prizes: None, + previous_winners: None, organizers: vec![], is_deleted: false, created_at: Some(get_iso_date()),