mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
Removed useless code for DeleteArticleHandler
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user