From 54ba5835b95e808cea2a566ac166e73e738e489a Mon Sep 17 00:00:00 2001 From: Damillora Date: Sat, 22 Feb 2025 13:02:06 +0000 Subject: [PATCH] feat: add post count endpoint --- pkg/app/post_routes.go | 10 ++++++++++ pkg/models/responses.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/pkg/app/post_routes.go b/pkg/app/post_routes.go index 8d6d4d6..6f3d331 100644 --- a/pkg/app/post_routes.go +++ b/pkg/app/post_routes.go @@ -19,6 +19,10 @@ func InitializePostRoutes(g *gin.Engine) { unprotected.GET("/", postGet) unprotected.GET("/:id", postGetOne) } + count := g.Group("/api/post-count") + { + count.GET("/", postCount) + } protected := g.Group("/api/post").Use(middleware.AuthMiddleware()) { protected.POST("/create", postCreate) @@ -80,7 +84,13 @@ func postGet(c *gin.Context) { Tags: tagFilters, }) } +func postCount(c *gin.Context) { + postPages := services.CountPostPages() + c.JSON(http.StatusOK, models.PostCountResponse{ + PostCount: postPages, + }) +} func postGetOne(c *gin.Context) { id := c.Param("id") post, err := services.GetPost(id) diff --git a/pkg/models/responses.go b/pkg/models/responses.go index c102881..c27bf6c 100644 --- a/pkg/models/responses.go +++ b/pkg/models/responses.go @@ -33,3 +33,7 @@ type PostPaginationResponse struct { Posts []PostListItem `json:"posts"` Tags []TagListItem `json:"tags"` } + +type PostCountResponse struct { + PostCount int `json:"postCount"` +}