Split business logic from routes handler logic

This commit is contained in:
Florian Sylvain
2022-12-19 23:42:09 +01:00
parent 907f53a721
commit 9ec29372b9
3 changed files with 131 additions and 4 deletions
+40
View File
@@ -0,0 +1,40 @@
package internal
import (
"go.mongodb.org/mongo-driver/bson"
)
type Article struct {
IdName string `json:"id_name" bson:"id_name"`
Date int64 `json:"date" bson:"date"`
Content interface{} `json:"content" bson:"content"`
}
type DelArticle struct {
IdName string `json:"id_name" bson:"id_name"`
}
var articlesLocation = 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
}