From 116adb792286280d5746c6a245eb0c7a4f177f42 Mon Sep 17 00:00:00 2001 From: cialloo Date: Sun, 26 Oct 2025 17:22:40 +0800 Subject: [PATCH] Refactor ListPosts logic to use time.Time for createdAt and updatedAt; convert timestamps to Unix milliseconds --- app/etc/blog.yaml | 1 + app/internal/logic/listpostslogic.go | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/etc/blog.yaml b/app/etc/blog.yaml index b618c71..f4c9641 100644 --- a/app/etc/blog.yaml +++ b/app/etc/blog.yaml @@ -1,6 +1,7 @@ Name: Blog Host: 0.0.0.0 Port: 8888 +Timeout: 9999999 JWT: Secret: "${JWT_SECRET}" # JWT signing secret key diff --git a/app/internal/logic/listpostslogic.go b/app/internal/logic/listpostslogic.go index 026a9b4..8a5a65c 100644 --- a/app/internal/logic/listpostslogic.go +++ b/app/internal/logic/listpostslogic.go @@ -114,13 +114,18 @@ func (l *ListPostsLogic) ListPosts(req *types.ListPostsReq) (resp *types.ListPos for rows.Next() { var post types.ListPostsRespPosts var coverID sql.NullInt64 + var createdAt, updatedAt time.Time - err := rows.Scan(&post.PostId, &post.Title, &post.CreatedAt, &post.UpdatedAt, &coverID) + err := rows.Scan(&post.PostId, &post.Title, &createdAt, &updatedAt, &coverID) if err != nil { l.Errorf("Failed to scan post: %v", err) continue } + // Convert timestamps to Unix milliseconds + post.CreatedAt = createdAt.UnixMilli() + post.UpdatedAt = updatedAt.UnixMilli() + // If cover image exists, get its URL if coverID.Valid { coverQuery := `SELECT file_key FROM files WHERE id = $1` @@ -143,10 +148,6 @@ func (l *ListPostsLogic) ListPosts(req *types.ListPostsReq) (resp *types.ListPos } } - // Convert timestamps to Unix milliseconds - post.CreatedAt = post.CreatedAt * 1000 - post.UpdatedAt = post.UpdatedAt * 1000 - posts = append(posts, post) }