mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
user details page
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"nysoure/server/model"
|
||||
"nysoure/server/service"
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
func AddCommentRoutes(router fiber.Router) {
|
||||
api := router.Group("/comments")
|
||||
api.Post("/:resourceID", createComment)
|
||||
api.Get("/:resourceID", listComments)
|
||||
api.Get("/user/:username", listCommentsWithUser)
|
||||
}
|
||||
|
||||
func createComment(c fiber.Ctx) error {
|
||||
@@ -60,3 +62,22 @@ func listComments(c fiber.Ctx) error {
|
||||
Message: "Comments retrieved successfully",
|
||||
})
|
||||
}
|
||||
|
||||
func listCommentsWithUser(c fiber.Ctx) error {
|
||||
username := c.Params("username")
|
||||
pageStr := c.Query("page", "1")
|
||||
page, err := strconv.Atoi(pageStr)
|
||||
if err != nil {
|
||||
return model.NewRequestError("Invalid page number")
|
||||
}
|
||||
comments, totalPages, err := service.ListCommentsWithUser(username, page)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.JSON(model.PageResponse[model.CommentWithResourceView]{
|
||||
Success: true,
|
||||
Data: comments,
|
||||
TotalPages: totalPages,
|
||||
Message: "Comments retrieved successfully",
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user