init(api): add quote delete handler

This commit is contained in:
Masahiko AMANO 2025-01-06 16:23:03 +03:00
parent 568ffd1615
commit bb23987fff
2 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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)
}
}