feat: Add previous winners field to hackathon DTOs and schema
This commit is contained in:
@@ -27,6 +27,7 @@ pub struct HackathonCreateRequestDto {
|
||||
pub theme: Option<String>,
|
||||
pub rules: Option<String>,
|
||||
pub prizes: Option<Vec<PrizeDto>>,
|
||||
pub previous_winners: Option<Vec<WinnerDto>>,
|
||||
pub organizers: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -55,6 +56,8 @@ pub struct HackathonUpdateRequestDto {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prizes: Option<Vec<PrizeDto>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub previous_winners: Option<Vec<WinnerDto>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub organizers: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
@@ -74,6 +77,7 @@ pub struct HackathonDto {
|
||||
pub theme: Option<String>,
|
||||
pub rules: Option<String>,
|
||||
pub prizes: Option<Vec<PrizeDto>>,
|
||||
pub previous_winners: Option<Vec<WinnerDto>>,
|
||||
pub organizers: Vec<String>,
|
||||
pub is_deleted: bool,
|
||||
pub created_at: Option<String>,
|
||||
@@ -89,6 +93,15 @@ pub struct PrizeDto {
|
||||
pub description: Option<String>,
|
||||
pub value: Option<String>,
|
||||
}
|
||||
#[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<String>,
|
||||
}
|
||||
|
||||
// Hackathon Events DTOs
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
||||
@@ -331,6 +344,17 @@ impl From<HackathonSchema> 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,
|
||||
|
||||
@@ -46,6 +46,16 @@ impl<'a> HackathonRepository<'a> {
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
let previous_winners: Option<Vec<super::hackathon_schema::Winner>> = 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<super::hackathon_schema::Winner> = 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;
|
||||
|
||||
@@ -19,6 +19,7 @@ pub struct HackathonSchema {
|
||||
pub theme: Option<String>,
|
||||
pub rules: Option<String>,
|
||||
pub prizes: Option<Vec<Prize>>,
|
||||
pub previous_winners: Option<Vec<Winner>>,
|
||||
pub organizers: Vec<String>, // User IDs
|
||||
pub is_deleted: bool,
|
||||
pub created_at: Option<String>,
|
||||
@@ -84,6 +85,13 @@ pub struct Prize {
|
||||
pub description: Option<String>,
|
||||
pub value: Option<String>,
|
||||
}
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Winner {
|
||||
pub position: u32,
|
||||
pub team_id: String,
|
||||
pub project_name: String,
|
||||
pub team_name: Option<String>,
|
||||
}
|
||||
|
||||
#[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()),
|
||||
|
||||
Reference in New Issue
Block a user