Refactor ListPosts logic to use time.Time for createdAt and updatedAt; convert timestamps to Unix milliseconds
All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 53s
All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 53s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
Name: Blog
|
||||
Host: 0.0.0.0
|
||||
Port: 8888
|
||||
Timeout: 9999999
|
||||
|
||||
JWT:
|
||||
Secret: "${JWT_SECRET}" # JWT signing secret key
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user