BLOG-104 Implement CRUD functionality for Posts #108

Merged
squid merged 5 commits from BLOG-104_post_create_and_update_routes into main 2025-08-02 14:35:27 +08:00
4 changed files with 14 additions and 14 deletions
Showing only changes of commit d69482116c - Show all commits

View File

@ -12,8 +12,8 @@ pub struct CreatePostRequestDto {
pub content: String, pub content: String,
pub label_ids: Vec<i32>, pub label_ids: Vec<i32>,
#[schema(required)] #[schema(required, format = DateTime)]
pub published_time: Option<i64>, pub published_time: Option<String>,
} }
impl CreatePostRequestDto { impl CreatePostRequestDto {
@ -28,8 +28,8 @@ impl CreatePostRequestDto {
labels: Vec::new(), labels: Vec::new(),
published_time: self published_time: self
.published_time .published_time
.map(|micros| DateTime::<Utc>::from_timestamp_micros(micros)) .and_then(|time_str| DateTime::parse_from_rfc3339(&time_str).ok())
.flatten(), .map(|dt| dt.with_timezone(&Utc)),
}, },
content: self.content, content: self.content,
} }

View File

@ -12,7 +12,9 @@ pub struct PostInfoResponseDto {
pub description: String, pub description: String,
pub preview_image_url: String, pub preview_image_url: String,
pub labels: Vec<LabelResponseDto>, pub labels: Vec<LabelResponseDto>,
pub published_time: Option<i64>,
#[schema(format = DateTime)]
pub published_time: Option<String>,
} }
impl From<PostInfo> for PostInfoResponseDto { impl From<PostInfo> for PostInfoResponseDto {
@ -27,9 +29,7 @@ impl From<PostInfo> for PostInfoResponseDto {
.into_iter() .into_iter()
.map(LabelResponseDto::from) .map(LabelResponseDto::from)
.collect(), .collect(),
published_time: entity published_time: entity.published_time.map(|datetime| datetime.to_rfc3339()),
.published_time
.map(|datetime| datetime.timestamp_micros()),
} }
} }
} }

View File

@ -12,8 +12,8 @@ pub struct UpdatePostRequestDto {
pub content: String, pub content: String,
pub label_ids: Vec<i32>, pub label_ids: Vec<i32>,
#[schema(required)] #[schema(required, format = DateTime)]
pub published_time: Option<i64>, pub published_time: Option<String>,
} }
impl UpdatePostRequestDto { impl UpdatePostRequestDto {
@ -28,8 +28,8 @@ impl UpdatePostRequestDto {
labels: Vec::new(), labels: Vec::new(),
published_time: self published_time: self
.published_time .published_time
.map(|micros| DateTime::<Utc>::from_timestamp_micros(micros)) .and_then(|time_str| DateTime::parse_from_rfc3339(&time_str).ok())
.flatten(), .map(|dt| dt.with_timezone(&Utc)),
}, },
content: self.content, content: self.content,
} }

View File

@ -8,7 +8,7 @@ export const PostInfoResponseSchema = z.object({
description: z.string(), description: z.string(),
preview_image_url: z.url(), preview_image_url: z.url(),
labels: z.array(LabelResponseSchema), labels: z.array(LabelResponseSchema),
published_time: z.number().int() published_time: z.iso.datetime()
}); });
export class PostInfoResponseDto { export class PostInfoResponseDto {
@ -43,7 +43,7 @@ export class PostInfoResponseDto {
description: parsedJson.description, description: parsedJson.description,
previewImageUrl: new URL(parsedJson.preview_image_url), previewImageUrl: new URL(parsedJson.preview_image_url),
labels: parsedJson.labels.map((label) => LabelResponseDto.fromJson(label)), labels: parsedJson.labels.map((label) => LabelResponseDto.fromJson(label)),
publishedTime: new Date(parsedJson.published_time / 1000) publishedTime: new Date(parsedJson.published_time)
}); });
} }