Removed useless code for DeleteArticleHandler

This commit is contained in:
Florian Sylvain
2022-12-27 18:05:53 +01:00
parent 12d1f67d43
commit e6e15392d1
2 changed files with 5 additions and 20 deletions
-4
View File
@@ -10,10 +10,6 @@ type Article struct {
Content interface{} `json:"content" bson:"content"` Content interface{} `json:"content" bson:"content"`
} }
type DelArticle struct {
IdName string `json:"id_name" bson:"id_name"`
}
var articlesLocation = Location{Database: "gohcms", Collection: "articles"} var articlesLocation = Location{Database: "gohcms", Collection: "articles"}
func GetAllArticlesBusiness(documents [][]byte) []Article { func GetAllArticlesBusiness(documents [][]byte) []Article {
+5 -16
View File
@@ -9,7 +9,7 @@ import (
) )
func GetAllArticlesHandler(c *gin.Context) { func GetAllArticlesHandler(c *gin.Context) {
documents, err := getDocuments(articlesLocation, bson.D{}) documents, err := getDocuments(articlesLocation, gin.H{})
if err != nil { if err != nil {
SendBadRequest(c, err.Error()) SendBadRequest(c, err.Error())
return return
@@ -20,7 +20,7 @@ func GetAllArticlesHandler(c *gin.Context) {
func GetArticleHandler(c *gin.Context) { func GetArticleHandler(c *gin.Context) {
articleID := c.Params.ByName("id") articleID := c.Params.ByName("id")
article, err := getUniqueDocument(articlesLocation, article, err := getUniqueDocument(articlesLocation,
bson.D{{Key: "id_name", Value: articleID}}) gin.H{"id_name": articleID})
if err != nil { if err != nil {
SendBadRequest(c, "The ID provided doesn't match any article.") SendBadRequest(c, "The ID provided doesn't match any article.")
return return
@@ -60,22 +60,11 @@ func AddArticleHandler(c *gin.Context) {
} }
func DeleteArticleHandler(c *gin.Context) { func DeleteArticleHandler(c *gin.Context) {
var delArticle DelArticle id := c.Params.ByName("id")
delArticle.IdName = c.Params.ByName("id")
if c.BindJSON(&delArticle) != nil {
SendBadRequest(c, "Could not correctly parse the article ID.")
return
}
document, err := bson.Marshal(delArticle) deleteCount, err := deleteDocument(articlesLocation, gin.H{"id_name": id})
if err != nil { if err != nil {
SendBadRequest(c, "Could not correctly marshal the article ID.") SendBadRequest(c, "Could not delete document into DB.")
return
}
deleteCount, err := deleteDocument(articlesLocation, document)
if err != nil {
SendBadRequest(c, "Could not insert document into DB.")
return return
} }