databag/net/server/internal/modelUtil.go

150 lines
3.4 KiB
Go
Raw Normal View History

2022-01-21 00:26:59 +00:00
package databag
import (
"databag/internal/store"
)
2022-02-03 06:13:46 +00:00
func getCardModel(slot *store.CardSlot) *Card {
if slot.Card == nil {
return &Card{
CardId: slot.CardSlotId,
Revision: slot.Revision,
2022-02-03 06:13:46 +00:00
}
}
2022-01-21 00:26:59 +00:00
return &Card{
2022-02-03 06:13:46 +00:00
CardId: slot.CardSlotId,
2022-02-03 20:11:51 +00:00
Revision: slot.Revision,
CardData: &CardData {
2022-02-03 06:13:46 +00:00
NotifiedProfile: slot.Card.NotifiedProfile,
NotifiedContent: slot.Card.NotifiedContent,
2022-02-03 19:18:50 +00:00
NotifiedLabel: slot.Card.NotifiedLabel,
2022-02-03 06:13:46 +00:00
NotifiedView: slot.Card.NotifiedView,
ProfileRevision: slot.Card.ProfileRevision,
DetailRevision: slot.Card.DetailRevision,
Guid: slot.Card.Guid,
2022-02-03 06:13:46 +00:00
Status: slot.Card.Status,
Token: slot.Card.OutToken,
2022-01-21 00:26:59 +00:00
},
}
}
func getCardDetailModel(slot *store.CardSlot) *CardDetail {
var groups []string;
for _, group := range slot.Card.Groups {
groups = append(groups, group.GroupSlot.GroupSlotId)
}
return &CardDetail{
Revision: slot.Card.DetailRevision,
Notes: slot.Card.Notes,
Groups: groups,
}
}
func getCardProfileModel(slot *store.CardSlot) *CardProfile {
return &CardProfile{
Revision: slot.Card.ProfileRevision,
Handle: slot.Card.Username,
Name: slot.Card.Name,
Description: slot.Card.Description,
Location: slot.Card.Location,
ImageSet: slot.Card.Image != "",
Version: slot.Card.Version,
Node: slot.Card.Node,
}
}
2022-02-03 07:48:17 +00:00
func getGroupModel(slot *store.GroupSlot) *Group {
if slot.Group == nil {
return &Group{
GroupId: slot.GroupSlotId,
Revision: slot.Revision,
2022-02-03 07:48:17 +00:00
}
}
2022-01-25 05:22:33 +00:00
return &Group{
2022-02-03 07:48:17 +00:00
GroupId: slot.GroupSlotId,
2022-02-03 20:11:51 +00:00
Revision: slot.Revision,
2022-02-03 07:48:17 +00:00
GroupData: &GroupData {
DataType: slot.Group.DataType,
Data: slot.Group.GroupData.Data,
Created: slot.Group.Created,
Updated: slot.Group.Updated,
},
2022-01-25 05:22:33 +00:00
}
}
2022-01-28 07:01:17 +00:00
func getLabelModel(slot *store.LabelSlot, includeData bool, includeGroups bool) *Label {
if !includeData || slot.Label == nil {
return &Label{
LabelId: slot.LabelSlotId,
Revision: slot.Revision,
}
}
var groups *[]string
if includeGroups {
groups = &[]string{}
for _, group := range slot.Label.Groups {
*groups = append(*groups, group.GroupSlot.GroupSlotId)
}
}
return &Label{
LabelId: slot.LabelSlotId,
Revision: slot.Revision,
LabelData: &LabelData{
DataType: slot.Label.DataType,
Data: slot.Label.LabelData.Data,
Created: slot.Label.Created,
Updated: slot.Label.Updated,
Groups: groups,
},
}
}
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,
2022-02-03 20:11:51 +00:00
Revision: slot.Revision,
}
2022-02-03 06:13:46 +00:00
}
2022-01-28 07:01:17 +00:00
var groups []string
2022-02-03 06:13:46 +00:00
if !contact {
for _, group := range slot.Article.Groups {
2022-02-03 07:48:17 +00:00
groups = append(groups, group.GroupSlot.GroupSlotId)
2022-02-02 07:55:16 +00:00
}
2022-02-03 06:13:46 +00:00
}
2022-02-02 07:55:16 +00:00
var labels []string
2022-02-03 06:13:46 +00:00
for _, label := range slot.Article.Labels {
2022-02-03 06:52:06 +00:00
labels = append(labels, label.LabelSlot.LabelSlotId)
2022-02-03 06:13:46 +00:00
}
2022-01-28 07:01:17 +00:00
2022-02-03 06:13:46 +00:00
return &Article{
ArticleId: slot.ArticleSlotId,
2022-02-03 20:11:51 +00:00
Revision: slot.Revision,
2022-02-03 06:13:46 +00:00
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
}
}