diff --git a/backend/api/handlers.go b/backend/api/handlers.go index 0d4be0d..1cd32c7 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -148,4 +148,21 @@ func quoteAdd(c *gin.Context) { c.JSON(http.StatusCreated, quote) } +func quoteDelete(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") + err := db.QuoteDelete(context.Background(), user_id, quote_id) + if err != nil { + status, message := HandleDBError(err) + c.JSON(status, gin.H{"error": message}) + return + } + c.JSON(http.StatusNoContent, nil) +} + //#endregion Quotes diff --git a/backend/api/routes.go b/backend/api/routes.go index b7daca2..4c668fc 100644 --- a/backend/api/routes.go +++ b/backend/api/routes.go @@ -24,5 +24,6 @@ func RegisterRoutes(r *gin.Engine) { api.GET("/quotes", quotesGet) api.POST("/quotes", quoteAdd) api.GET("/quotes/:id", quoteGet) + api.DELETE("/quotes/:id", quoteDelete) } }