Refactor blog post logic to standardize field names and improve error handling; implement pagination for post listing and add tag retrieval functionality.
All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 53s

This commit is contained in:
2025-10-25 12:21:17 +08:00
parent e21f9e6d1a
commit aaa89bf8b7
9 changed files with 174 additions and 27 deletions

View File

@@ -30,12 +30,12 @@ func (l *EditPostLogic) EditPost(req *types.EditPostReq) (resp *types.EditPostRe
var coverID sql.NullInt64
// If cover image key is provided, get the file ID from files table
if req.Cover_image_key != "" {
if req.CoverImageKey != "" {
query := `SELECT id FROM files WHERE file_key = $1`
err := l.svcCtx.DB.QueryRowContext(l.ctx, query, req.Cover_image_key).Scan(&coverID.Int64)
err := l.svcCtx.DB.QueryRowContext(l.ctx, query, req.CoverImageKey).Scan(&coverID.Int64)
if err != nil {
if err == sql.ErrNoRows {
l.Errorf("Cover image file not found with key: %s", req.Cover_image_key)
l.Errorf("Cover image file not found with key: %s", req.CoverImageKey)
return nil, fmt.Errorf("cover image not found")
}
l.Errorf("Failed to get cover image file: %v", err)
@@ -46,7 +46,7 @@ func (l *EditPostLogic) EditPost(req *types.EditPostReq) (resp *types.EditPostRe
// Update post with updated_at timestamp
query := `UPDATE posts SET title = $1, content = $2, cover_id = $3, updated_at = CURRENT_TIMESTAMP WHERE id = $4`
result, err := l.svcCtx.DB.ExecContext(l.ctx, query, req.Title, req.Content, coverID, req.Post_id)
result, err := l.svcCtx.DB.ExecContext(l.ctx, query, req.Title, req.Content, coverID, req.PostId)
if err != nil {
l.Errorf("Failed to update post: %v", err)
return nil, err
@@ -59,7 +59,7 @@ func (l *EditPostLogic) EditPost(req *types.EditPostReq) (resp *types.EditPostRe
return nil, err
}
if rowsAffected == 0 {
l.Errorf("Post not found with id: %s", req.Post_id)
l.Errorf("Post not found with id: %s", req.PostId)
return nil, fmt.Errorf("post not found")
}