init(api): add single quote get handler

This commit is contained in:
Masahiko AMANO 2025-01-06 15:23:19 +03:00
parent 14e88b2e2e
commit 875452004d
2 changed files with 18 additions and 0 deletions

View File

@ -88,4 +88,21 @@ func quotesGet(c *gin.Context) {
c.JSON(http.StatusOK, quotes)
}
func quoteGet(c *gin.Context) {
session := sessions.Default(c)
user_id, ok := session.Get("user_id").(string)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Ты это, залогинься сначала что ли, а то чё как крыса"})
return
}
quote_id := c.Param("id")
quote, err := db.QuoteGet(context.Background(), user_id, quote_id)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
c.JSON(http.StatusOK, quote)
}
//#endregion Quotes

View File

@ -22,5 +22,6 @@ func RegisterRoutes(r *gin.Engine) {
{
api.POST("/auth", userAuth)
api.GET("/quotes", quotesGet)
api.GET("/quotes/:id", quoteGet)
}
}