feat: add post count endpoint

This commit is contained in:
Damillora 2025-02-22 13:02:06 +00:00
parent 5e713d05c7
commit 54ba5835b9
2 changed files with 14 additions and 0 deletions

View File

@ -19,6 +19,10 @@ func InitializePostRoutes(g *gin.Engine) {
unprotected.GET("/", postGet) unprotected.GET("/", postGet)
unprotected.GET("/:id", postGetOne) unprotected.GET("/:id", postGetOne)
} }
count := g.Group("/api/post-count")
{
count.GET("/", postCount)
}
protected := g.Group("/api/post").Use(middleware.AuthMiddleware()) protected := g.Group("/api/post").Use(middleware.AuthMiddleware())
{ {
protected.POST("/create", postCreate) protected.POST("/create", postCreate)
@ -80,7 +84,13 @@ func postGet(c *gin.Context) {
Tags: tagFilters, Tags: tagFilters,
}) })
} }
func postCount(c *gin.Context) {
postPages := services.CountPostPages()
c.JSON(http.StatusOK, models.PostCountResponse{
PostCount: postPages,
})
}
func postGetOne(c *gin.Context) { func postGetOne(c *gin.Context) {
id := c.Param("id") id := c.Param("id")
post, err := services.GetPost(id) post, err := services.GetPost(id)

View File

@ -33,3 +33,7 @@ type PostPaginationResponse struct {
Posts []PostListItem `json:"posts"` Posts []PostListItem `json:"posts"`
Tags []TagListItem `json:"tags"` Tags []TagListItem `json:"tags"`
} }
type PostCountResponse struct {
PostCount int `json:"postCount"`
}