mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 19:53:21 +02:00
Renamed some variables to match Go name convention
This commit is contained in:
+13
-13
@@ -9,21 +9,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Article struct {
|
type Article struct {
|
||||||
Id_name string `json:"id_name" bson:"id_name"`
|
IdName string `json:"id_name" bson:"id_name"`
|
||||||
Date int64 `json:"date" bson:"date"`
|
Date int64 `json:"date" bson:"date"`
|
||||||
Content interface{} `json:"content" bson:"content"`
|
Content interface{} `json:"content" bson:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DelArticle struct {
|
type DelArticle struct {
|
||||||
Id_name string `json:"id_name" bson:"id_name"`
|
IdName string `json:"id_name" bson:"id_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var ARTICLES_LOCATION = Location{Database: "gohcms", Collection: "articles"}
|
var articlesLocation = Location{Database: "gohcms", Collection: "articles"}
|
||||||
|
|
||||||
// TODO Change to GetArticleList that will find filter json context
|
|
||||||
func GetAllArticles(c *gin.Context) {
|
func GetAllArticles(c *gin.Context) {
|
||||||
|
// TODO Change to GetArticleList that will find filter json context
|
||||||
var articles []Article
|
var articles []Article
|
||||||
documents, err := getDocuments(ARTICLES_LOCATION, bson.D{})
|
documents, err := getDocuments(articlesLocation, bson.D{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
SendBadRequest(c, err.Error())
|
SendBadRequest(c, err.Error())
|
||||||
return
|
return
|
||||||
@@ -40,7 +40,7 @@ func GetAllArticles(c *gin.Context) {
|
|||||||
|
|
||||||
func GetArticle(c *gin.Context) {
|
func GetArticle(c *gin.Context) {
|
||||||
articleID := c.Params.ByName("id")
|
articleID := c.Params.ByName("id")
|
||||||
articles, err := getDocuments(ARTICLES_LOCATION,
|
articles, err := getDocuments(articlesLocation,
|
||||||
bson.D{{Key: "id_name", Value: articleID}})
|
bson.D{{Key: "id_name", Value: articleID}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
SendBadRequest(c, err.Error())
|
SendBadRequest(c, err.Error())
|
||||||
@@ -56,11 +56,11 @@ func GetArticle(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsArticleIdAlreadyUsed(id string) bool {
|
func IsArticleIdAlreadyUsed(id string) bool {
|
||||||
documents, _ := getDocuments(ARTICLES_LOCATION, bson.D{})
|
documents, _ := getDocuments(articlesLocation, bson.D{})
|
||||||
for i := 0; i < len(documents); i++ {
|
for i := 0; i < len(documents); i++ {
|
||||||
var newArticle Article
|
var newArticle Article
|
||||||
bson.Unmarshal(documents[i], &newArticle)
|
bson.Unmarshal(documents[i], &newArticle)
|
||||||
if newArticle.Id_name == id {
|
if newArticle.IdName == id {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ func IsArticleIdAlreadyUsed(id string) bool {
|
|||||||
|
|
||||||
func AddArticle(c *gin.Context) {
|
func AddArticle(c *gin.Context) {
|
||||||
var article Article
|
var article Article
|
||||||
article.Id_name = c.Params.ByName("id")
|
article.IdName = c.Params.ByName("id")
|
||||||
if c.BindJSON(&article) != nil {
|
if c.BindJSON(&article) != nil {
|
||||||
SendBadRequest(c, "Could not correctly parse the article.")
|
SendBadRequest(c, "Could not correctly parse the article.")
|
||||||
return
|
return
|
||||||
@@ -81,12 +81,12 @@ func AddArticle(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if IsArticleIdAlreadyUsed(article.Id_name) {
|
if IsArticleIdAlreadyUsed(article.IdName) {
|
||||||
SendBadRequest(c, "Article ID already used.")
|
SendBadRequest(c, "Article ID already used.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = pushDocument(ARTICLES_LOCATION, document)
|
err = pushDocument(articlesLocation, document)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
SendBadRequest(c, "Could not insert document into DB.")
|
SendBadRequest(c, "Could not insert document into DB.")
|
||||||
return
|
return
|
||||||
@@ -97,7 +97,7 @@ func AddArticle(c *gin.Context) {
|
|||||||
|
|
||||||
func DeleteArticle(c *gin.Context) {
|
func DeleteArticle(c *gin.Context) {
|
||||||
var delArticle DelArticle
|
var delArticle DelArticle
|
||||||
delArticle.Id_name = c.Params.ByName("id")
|
delArticle.IdName = c.Params.ByName("id")
|
||||||
if c.BindJSON(&delArticle) != nil {
|
if c.BindJSON(&delArticle) != nil {
|
||||||
SendBadRequest(c, "Could not correctly parse the article ID.")
|
SendBadRequest(c, "Could not correctly parse the article ID.")
|
||||||
return
|
return
|
||||||
@@ -109,7 +109,7 @@ func DeleteArticle(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCount, err := deleteDocument(ARTICLES_LOCATION, document)
|
deleteCount, err := deleteDocument(articlesLocation, document)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
SendBadRequest(c, "Could not insert document into DB.")
|
SendBadRequest(c, "Could not insert document into DB.")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user