user details page

This commit is contained in:
2025-05-14 16:48:52 +08:00
parent cbac071dd2
commit 3b7d52a7a8
20 changed files with 450 additions and 64 deletions

View File

@@ -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",
})
}