feat: add reply functionality to thoughts, including database migration and tests

This commit is contained in:
2025-09-06 16:58:11 +02:00
parent 728bf0e231
commit 0abd275946
7 changed files with 96 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ pub struct Model {
pub id: Uuid,
pub author_id: Uuid,
pub content: String,
pub reply_to_id: Option<Uuid>,
pub created_at: DateTimeWithTimeZone,
}

View File

@@ -1,5 +1,6 @@
use serde::Deserialize;
use utoipa::ToSchema;
use uuid::Uuid;
use validator::Validate;
#[derive(Deserialize, Validate, ToSchema)]
@@ -10,4 +11,6 @@ pub struct CreateThoughtParams {
message = "Content must be between 1 and 128 characters"
))]
pub content: String,
pub reply_to_id: Option<Uuid>,
}

View File

@@ -12,6 +12,7 @@ pub struct ThoughtSchema {
pub author_username: String,
#[schema(example = "This is my first thought! #welcome")]
pub content: String,
pub reply_to_id: Option<Uuid>,
pub created_at: DateTimeWithTimeZoneWrapper,
}
@@ -21,6 +22,7 @@ impl ThoughtSchema {
id: thought.id,
author_username: author.username.clone(),
content: thought.content.clone(),
reply_to_id: thought.reply_to_id,
created_at: thought.created_at.into(),
}
}
@@ -44,6 +46,7 @@ pub struct ThoughtWithAuthor {
pub created_at: sea_orm::prelude::DateTimeWithTimeZone,
pub author_id: Uuid,
pub author_username: String,
pub reply_to_id: Option<Uuid>,
}
impl From<ThoughtWithAuthor> for ThoughtSchema {
@@ -53,6 +56,7 @@ impl From<ThoughtWithAuthor> for ThoughtSchema {
author_username: model.author_username,
content: model.content,
created_at: model.created_at.into(),
reply_to_id: model.reply_to_id,
}
}
}