diff --git a/backend/api/handlers.go b/backend/api/handlers.go index bfff4ac..9effb8a 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -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 diff --git a/backend/api/routes.go b/backend/api/routes.go index 106b256..08f8ba6 100644 --- a/backend/api/routes.go +++ b/backend/api/routes.go @@ -22,5 +22,6 @@ func RegisterRoutes(r *gin.Engine) { { api.POST("/auth", userAuth) api.GET("/quotes", quotesGet) + api.GET("/quotes/:id", quoteGet) } }