Complete file tree and packages managment rework

This commit is contained in:
Florian Sylvain
2022-12-27 21:00:19 +01:00
parent 39afc0c066
commit 451fd8452b
11 changed files with 153 additions and 161 deletions
+38
View File
@@ -0,0 +1,38 @@
package articles
import (
"github.com/Floriansylvain/GohCMS/internal/database"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
)
type Article struct {
IdName string `json:"id_name" bson:"id_name"`
Date int64 `json:"date" bson:"date"`
Content gin.H `json:"content" bson:"content"`
}
var articlesLocation = database.Location{Database: "gohcms", Collection: "articles"}
func GetAllArticlesBusiness(documents [][]byte) []Article {
var articles = []Article{}
for i := 0; i < len(documents); i++ {
var newArticle Article
bson.Unmarshal(documents[i], &newArticle)
articles = append(articles, newArticle)
}
return articles
}
func IsArticleIdAlreadyUsed(id string, documents [][]byte) bool {
for i := 0; i < len(documents); i++ {
var newArticle Article
bson.Unmarshal(documents[i], &newArticle)
if newArticle.IdName == id {
return true
}
}
return false
}