Added route to get Article by ID

This commit is contained in:
Florian Sylvain
2022-10-20 13:29:59 +02:00
parent 0dd12627cf
commit 3b41b12d5e
3 changed files with 27 additions and 3 deletions
+15 -1
View File
@@ -38,6 +38,19 @@ func GetAllArticles(c *gin.Context) {
c.JSON(http.StatusOK, articles)
}
func GetArticle(c *gin.Context) {
articleID := c.Params.ByName("id")
articles, err := getDocuments(ARTICLES_LOCATION,
bson.D{{Key: "id_name", Value: articleID}})
if err != nil {
SendErrorMessageToClient(c, err.Error())
return
}
var parsedArticle Article
bson.Unmarshal(articles[0], &parsedArticle)
c.JSON(http.StatusOK, parsedArticle)
}
func IsArticleIdAlreadyUsed(id string) bool {
documents, _ := getDocuments(ARTICLES_LOCATION, bson.D{})
for i := 0; i < len(documents); i++ {
@@ -96,5 +109,6 @@ func DeleteArticle(c *gin.Context) {
return
}
SendOkMessageToClient(c, fmt.Sprintf("%d articles were successfully deleted!", deleteCount))
SendOkMessageToClient(c,
fmt.Sprintf("%d articles were successfully deleted!", deleteCount))
}