mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
Add comment update functionality with UI integration
This commit is contained in:
@@ -69,3 +69,18 @@ func ListCommentsWithUser(username string, page int) ([]model.CommentWithResourc
|
||||
}
|
||||
return res, totalPages, nil
|
||||
}
|
||||
|
||||
func UpdateComment(commentID, userID uint, content string) (*model.CommentView, error) {
|
||||
comment, err := dao.GetCommentByID(commentID)
|
||||
if err != nil {
|
||||
return nil, model.NewNotFoundError("Comment not found")
|
||||
}
|
||||
if comment.UserID != userID {
|
||||
return nil, model.NewRequestError("You can only update your own comments")
|
||||
}
|
||||
updated, err := dao.UpdateCommentContent(commentID, content)
|
||||
if err != nil {
|
||||
return nil, model.NewInternalServerError("Error updating comment")
|
||||
}
|
||||
return updated.ToView(), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user