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:
@@ -14,6 +14,7 @@ func AddCommentRoutes(router fiber.Router) {
|
||||
api.Post("/:resourceID", createComment)
|
||||
api.Get("/:resourceID", listComments)
|
||||
api.Get("/user/:username", listCommentsWithUser)
|
||||
api.Put("/:commentID", updateComment)
|
||||
}
|
||||
|
||||
func createComment(c fiber.Ctx) error {
|
||||
@@ -89,3 +90,28 @@ func listCommentsWithUser(c fiber.Ctx) error {
|
||||
Message: "Comments retrieved successfully",
|
||||
})
|
||||
}
|
||||
|
||||
func updateComment(c fiber.Ctx) error {
|
||||
userID, ok := c.Locals("uid").(uint)
|
||||
if !ok {
|
||||
return model.NewRequestError("You must be logged in to update comment")
|
||||
}
|
||||
commentIDStr := c.Params("commentID")
|
||||
commentID, err := strconv.Atoi(commentIDStr)
|
||||
if err != nil {
|
||||
return model.NewRequestError("Invalid comment ID")
|
||||
}
|
||||
content := c.FormValue("content")
|
||||
if content == "" {
|
||||
return model.NewRequestError("Content cannot be empty")
|
||||
}
|
||||
comment, err := service.UpdateComment(uint(commentID), userID, content)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.JSON(model.Response[model.CommentView]{
|
||||
Success: true,
|
||||
Data: *comment,
|
||||
Message: "Comment updated successfully",
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user