init(api): add getting total quotes count
This commit is contained in:
parent
37d40497d1
commit
02b848a737
@ -162,6 +162,17 @@ func quotesGet(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, quotes)
|
c.JSON(http.StatusOK, quotes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func quotesCount(c *gin.Context) {
|
||||||
|
user_id := c.GetString("user_id")
|
||||||
|
count, err := db.QuotesCount(context.Background(), user_id)
|
||||||
|
if err != nil {
|
||||||
|
status, message := handleDBError(err)
|
||||||
|
c.JSON(status, gin.H{"error": message})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"count": count})
|
||||||
|
}
|
||||||
|
|
||||||
func quoteGet(c *gin.Context) {
|
func quoteGet(c *gin.Context) {
|
||||||
user_id := c.GetString("user_id")
|
user_id := c.GetString("user_id")
|
||||||
quote_id := c.Param("id")
|
quote_id := c.Param("id")
|
||||||
|
|||||||
@ -26,6 +26,7 @@ func RegisterRoutes(r *gin.Engine) {
|
|||||||
api.DELETE("/auth", userLogout)
|
api.DELETE("/auth", userLogout)
|
||||||
|
|
||||||
api.GET("/quotes", MiddlewareAuth, quotesGet)
|
api.GET("/quotes", MiddlewareAuth, quotesGet)
|
||||||
|
api.GET("/quotes/count", MiddlewareAuth, quotesCount)
|
||||||
api.POST("/quotes", MiddlewareAuth, quoteAdd)
|
api.POST("/quotes", MiddlewareAuth, quoteAdd)
|
||||||
api.GET("/quotes/:id", MiddlewareAuth, quoteGet)
|
api.GET("/quotes/:id", MiddlewareAuth, quoteGet)
|
||||||
api.PATCH("/quotes/:id", MiddlewareAuth, quoteUpdate)
|
api.PATCH("/quotes/:id", MiddlewareAuth, quoteUpdate)
|
||||||
|
|||||||
@ -134,6 +134,12 @@ func QuotesGet(ctx context.Context, user_id string, filter string, sort string,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func QuotesCount(ctx context.Context, user_id string) (count int, err error) {
|
||||||
|
row := ConnPool.QueryRow(ctx, "SELECT count(*) FROM quotes_get($1)", user_id)
|
||||||
|
err = row.Scan(&count)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func QuoteGet(ctx context.Context, user_id string, quote_id string) (quote models.Quote, err error) {
|
func QuoteGet(ctx context.Context, user_id string, quote_id string) (quote models.Quote, err error) {
|
||||||
row := ConnPool.QueryRow(ctx, "SELECT * FROM quote_get($1, $2)", user_id, quote_id)
|
row := ConnPool.QueryRow(ctx, "SELECT * FROM quote_get($1, $2)", user_id, quote_id)
|
||||||
err = row.Scan("e.ID, "e.Text, "e.Author, "e.Datetime, "e.Creator.ID, "e.Creator.Name, "e.Creator.Login, "e.Creator.Role, "e.Creator.TelegramID)
|
err = row.Scan("e.ID, "e.Text, "e.Author, "e.Datetime, "e.Creator.ID, "e.Creator.Name, "e.Creator.Login, "e.Creator.Role, "e.Creator.TelegramID)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user