mirror of
https://github.com/Damillora/Shioriko.git
synced 2025-02-23 01:13:39 +00:00
feat: add post count endpoint
This commit is contained in:
parent
5e713d05c7
commit
54ba5835b9
@ -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)
|
||||
|
@ -33,3 +33,7 @@ type PostPaginationResponse struct {
|
||||
Posts []PostListItem `json:"posts"`
|
||||
Tags []TagListItem `json:"tags"`
|
||||
}
|
||||
|
||||
type PostCountResponse struct {
|
||||
PostCount int `json:"postCount"`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user