From e6e15392d1164df7ed075b0347e44323936654cb Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Tue, 27 Dec 2022 18:05:53 +0100 Subject: [PATCH] Removed useless code for DeleteArticleHandler --- internal/articlesBusiness.go | 4 ---- internal/articlesHandlers.go | 21 +++++---------------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/internal/articlesBusiness.go b/internal/articlesBusiness.go index 54c22db..0b2b6f5 100644 --- a/internal/articlesBusiness.go +++ b/internal/articlesBusiness.go @@ -10,10 +10,6 @@ type Article struct { Content interface{} `json:"content" bson:"content"` } -type DelArticle struct { - IdName string `json:"id_name" bson:"id_name"` -} - var articlesLocation = Location{Database: "gohcms", Collection: "articles"} func GetAllArticlesBusiness(documents [][]byte) []Article { diff --git a/internal/articlesHandlers.go b/internal/articlesHandlers.go index c870aff..7e5da79 100644 --- a/internal/articlesHandlers.go +++ b/internal/articlesHandlers.go @@ -9,7 +9,7 @@ import ( ) func GetAllArticlesHandler(c *gin.Context) { - documents, err := getDocuments(articlesLocation, bson.D{}) + documents, err := getDocuments(articlesLocation, gin.H{}) if err != nil { SendBadRequest(c, err.Error()) return @@ -20,7 +20,7 @@ func GetAllArticlesHandler(c *gin.Context) { func GetArticleHandler(c *gin.Context) { articleID := c.Params.ByName("id") article, err := getUniqueDocument(articlesLocation, - bson.D{{Key: "id_name", Value: articleID}}) + gin.H{"id_name": articleID}) if err != nil { SendBadRequest(c, "The ID provided doesn't match any article.") return @@ -60,22 +60,11 @@ func AddArticleHandler(c *gin.Context) { } func DeleteArticleHandler(c *gin.Context) { - var delArticle DelArticle - delArticle.IdName = c.Params.ByName("id") - if c.BindJSON(&delArticle) != nil { - SendBadRequest(c, "Could not correctly parse the article ID.") - return - } + id := c.Params.ByName("id") - document, err := bson.Marshal(delArticle) + deleteCount, err := deleteDocument(articlesLocation, gin.H{"id_name": id}) if err != nil { - SendBadRequest(c, "Could not correctly marshal the article ID.") - return - } - - deleteCount, err := deleteDocument(articlesLocation, document) - if err != nil { - SendBadRequest(c, "Could not insert document into DB.") + SendBadRequest(c, "Could not delete document into DB.") return }