databag/net/server/internal/modelUtil.go

90 lines
2.0 KiB
Go
Raw Normal View History

2022-01-21 00:26:59 +00:00
package databag
import (
"databag/internal/store"
)
func getCardModel(card *store.Card) *Card {
// populate group id list
var groups []string;
for _, group := range card.Groups {
groups = append(groups, group.GroupId)
}
return &Card{
CardId: card.CardId,
NotifiedProfile: card.NotifiedProfile,
NotifiedContent: card.NotifiedContent,
NotifiedView: card.NotifiedView,
2022-01-21 00:26:59 +00:00
CardProfile: &CardProfile{
Guid: card.Guid,
Handle: card.Username,
Name: card.Name,
Description: card.Description,
Location: card.Location,
Revision: card.ProfileRevision,
ImageSet: card.Image != "",
Version: card.Version,
Node: card.Node,
},
CardData: &CardData {
Revision: card.DataRevision,
Status: card.Status,
Notes: card.Notes,
2022-01-21 23:08:52 +00:00
Token: card.OutToken,
2022-01-21 00:26:59 +00:00
Groups: groups,
},
}
}
2022-01-25 05:22:33 +00:00
func getGroupModel(group *store.Group) *Group {
return &Group{
GroupId: group.GroupId,
Revision: group.Revision,
DataType: group.DataType,
Data: group.GroupData.Data,
2022-01-25 05:22:33 +00:00
Created: group.Created,
Updated: group.Updated,
}
}
2022-01-28 07:01:17 +00:00
func getArticleModel(slot *store.ArticleSlot, contact bool, shared bool) *Article {
2022-01-28 07:01:17 +00:00
if !shared || slot.Article == nil {
return &Article{
ArticleId: slot.ArticleSlotId,
}
} else {
2022-01-28 07:01:17 +00:00
var groups []string;
2022-02-02 07:55:16 +00:00
if !contact {
for _, group := range slot.Article.Groups {
2022-02-02 07:55:16 +00:00
groups = append(groups, group.GroupId)
}
}
var labels []string;
for _, label := range slot.Article.Labels {
2022-02-02 07:55:16 +00:00
labels = append(labels, label.LabelId)
}
2022-01-28 07:01:17 +00:00
return &Article{
ArticleId: slot.ArticleSlotId,
ArticleData: &ArticleData{
DataType: slot.Article.DataType,
Data: slot.Article.Data,
Status: slot.Article.Status,
Labels: labels,
Groups: groups,
TagCount: slot.Article.TagCount,
Created: slot.Article.Created,
Updated: slot.Article.Updated,
TagUpdated: slot.Article.TagUpdated,
TagRevision: slot.Article.TagRevision,
},
}
2022-01-28 07:01:17 +00:00
}
}