databag/net/server/internal/modelUtil.go

300 lines
6.9 KiB
Go
Raw Normal View History

2022-01-21 00:26:59 +00:00
package databag
import (
"databag/internal/store"
)
2022-02-09 18:30:39 +00:00
func getProfileModel(account *store.Account) *Profile {
return &Profile{
Guid: account.Guid,
Handle: account.Username,
2022-03-18 17:51:21 +00:00
Name: account.AccountDetail.Name,
2022-02-09 18:30:39 +00:00
Description: account.AccountDetail.Description,
Location: account.AccountDetail.Location,
Image: account.AccountDetail.Image,
Revision: account.ProfileRevision,
Version: APP_VERSION,
2022-03-17 21:42:51 +00:00
Node: getStrConfigValue(CONFIG_DOMAIN, ""),
2022-02-09 18:30:39 +00:00
}
}
2022-02-03 06:13:46 +00:00
func getCardModel(slot *store.CardSlot) *Card {
if slot.Card == nil {
return &Card{
2022-02-08 20:24:42 +00:00
Id: 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-08 20:24:42 +00:00
Id: slot.CardSlotId,
2022-02-03 20:11:51 +00:00
Revision: slot.Revision,
2022-02-08 20:24:42 +00:00
Data: &CardData {
2022-02-03 06:13:46 +00:00
NotifiedProfile: slot.Card.NotifiedProfile,
2022-02-08 20:24:42 +00:00
NotifiedArticle: slot.Card.NotifiedArticle,
NotifiedChannel: slot.Card.NotifiedChannel,
NotifiedView: slot.Card.NotifiedView,
ProfileRevision: slot.Card.ProfileRevision,
DetailRevision: slot.Card.DetailRevision,
CardDetail: getCardDetailModel(slot),
CardProfile: getCardProfileModel(slot),
},
}
}
func getCardRevisionModel(slot *store.CardSlot) *Card {
if slot.Card == nil {
return &Card{
Id: slot.CardSlotId,
Revision: slot.Revision,
}
}
return &Card{
Id: slot.CardSlotId,
Revision: slot.Revision,
Data: &CardData {
NotifiedProfile: slot.Card.NotifiedProfile,
NotifiedArticle: slot.Card.NotifiedArticle,
NotifiedChannel: slot.Card.NotifiedChannel,
2022-02-03 06:13:46 +00:00
NotifiedView: slot.Card.NotifiedView,
ProfileRevision: slot.Card.ProfileRevision,
DetailRevision: slot.Card.DetailRevision,
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{
2022-02-08 20:24:42 +00:00
Status: slot.Card.Status,
Token: slot.Card.OutToken,
Notes: slot.Card.Notes,
Groups: groups,
}
}
func getCardProfileModel(slot *store.CardSlot) *CardProfile {
return &CardProfile{
2022-02-08 20:24:42 +00:00
Guid: slot.Card.Guid,
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{
2022-02-08 20:24:42 +00:00
Id: 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-08 20:24:42 +00:00
Id: slot.GroupSlotId,
2022-02-03 20:11:51 +00:00
Revision: slot.Revision,
2022-02-08 20:24:42 +00:00
Data: &GroupData {
2022-02-03 07:48:17 +00:00
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
2022-02-16 08:00:07 +00:00
func getArticleModel(slot *store.ArticleSlot, showData bool, showList bool) *Article {
2022-02-14 20:55:02 +00:00
if !showData || slot.Article == nil {
2022-02-13 07:29:40 +00:00
return &Article{
Id: slot.ArticleSlotId,
Revision: slot.Revision,
}
}
2022-02-16 08:00:07 +00:00
var articleGroups *IdList
if showList {
2022-02-13 07:29:40 +00:00
var groups []string;
for _, group := range slot.Article.Groups {
groups = append(groups, group.GroupSlot.GroupSlotId)
}
2022-02-16 08:00:07 +00:00
articleGroups = &IdList{ Ids: groups }
2022-02-13 07:29:40 +00:00
}
return &Article{
Id: slot.ArticleSlotId,
Revision: slot.Revision,
Data: &ArticleData {
DataType: slot.Article.DataType,
Data: slot.Article.Data,
Created: slot.Article.Created,
Updated: slot.Article.Updated,
Groups: articleGroups,
},
}
}
2022-02-16 08:00:07 +00:00
func getChannelRevisionModel(slot *store.ChannelSlot, showData bool) *Channel {
2022-02-15 22:30:04 +00:00
if !showData || slot.Channel == nil {
return &Channel{
Id: slot.ChannelSlotId,
Revision: slot.Revision,
}
}
return &Channel{
Id: slot.ChannelSlotId,
Revision: slot.Revision,
Data: &ChannelData {
DetailRevision: slot.Channel.DetailRevision,
2022-03-04 20:43:46 +00:00
TopicRevision: slot.Channel.TopicRevision,
2022-02-15 22:30:04 +00:00
},
}
}
2022-02-16 08:00:07 +00:00
func getChannelModel(slot *store.ChannelSlot, showData bool, showList bool) *Channel {
2022-02-15 22:30:04 +00:00
if !showData || slot.Channel == nil {
return &Channel{
Id: slot.ChannelSlotId,
Revision: slot.Revision,
}
}
2022-03-07 23:03:24 +00:00
var contacts *ChannelContacts
2022-02-16 08:00:07 +00:00
if showList {
2022-02-15 22:30:04 +00:00
var groups []string;
for _, group := range slot.Channel.Groups {
groups = append(groups, group.GroupSlot.GroupSlotId)
}
2022-02-16 08:00:07 +00:00
var cards []string;
for _, card := range slot.Channel.Cards {
cards = append(cards, card.CardSlot.CardSlotId)
}
2022-03-07 23:03:24 +00:00
contacts = &ChannelContacts{ Groups: groups, Cards: cards }
2022-02-16 08:00:07 +00:00
}
members := []string{}
2022-02-15 22:30:04 +00:00
for _, card := range slot.Channel.Cards {
2022-02-16 08:00:07 +00:00
members = append(members, card.Guid)
2022-02-15 22:30:04 +00:00
}
return &Channel{
Id: slot.ChannelSlotId,
Revision: slot.Revision,
Data: &ChannelData {
DetailRevision: slot.Channel.DetailRevision,
2022-03-04 20:43:46 +00:00
TopicRevision: slot.Channel.TopicRevision,
2022-02-15 22:30:04 +00:00
ChannelDetail: &ChannelDetail{
DataType: slot.Channel.DataType,
Data: slot.Channel.Data,
Created: slot.Channel.Created,
Updated: slot.Channel.Updated,
2022-03-07 23:03:24 +00:00
Contacts: contacts,
2022-04-09 08:36:03 +00:00
Members: members,
2022-02-15 22:30:04 +00:00
},
},
}
}
2022-02-19 06:33:13 +00:00
func getTopicRevisionModel(slot *store.TopicSlot) *Topic {
2022-02-18 07:56:30 +00:00
2022-02-19 06:33:13 +00:00
if slot.Topic == nil {
2022-02-18 07:56:30 +00:00
return &Topic{
Id: slot.TopicSlotId,
Revision: slot.Revision,
}
}
return &Topic{
Id: slot.TopicSlotId,
Revision: slot.Revision,
Data: &TopicData {
DetailRevision: slot.Topic.DetailRevision,
TagRevision: slot.Topic.TagRevision,
},
}
}
2022-02-18 20:21:15 +00:00
func getTopicDetailModel(slot *store.TopicSlot) *TopicDetail {
2022-02-18 07:56:30 +00:00
2022-02-18 20:21:15 +00:00
if slot.Topic == nil {
return nil
}
2022-03-02 21:19:16 +00:00
transform := APP_TRANSFORMCOMPLETE
for _, asset := range slot.Topic.Assets {
if asset.Status == APP_ASSETERROR {
transform = APP_TRANSFORMERROR
} else if asset.Status == APP_ASSETWAITING && transform == APP_TRANSFORMCOMPLETE {
transform = APP_TRANSFORMINCOMPLETE
}
}
2022-02-18 20:21:15 +00:00
return &TopicDetail{
Guid: slot.Topic.Guid,
DataType: slot.Topic.DataType,
Data: slot.Topic.Data,
Created: slot.Topic.Created,
Updated: slot.Topic.Updated,
Status: slot.Topic.Status,
2022-03-02 21:19:16 +00:00
Transform: transform,
2022-02-18 20:21:15 +00:00
}
}
func getTopicModel(slot *store.TopicSlot) *Topic {
if slot.Topic == nil {
2022-02-18 07:56:30 +00:00
return &Topic{
Id: slot.TopicSlotId,
Revision: slot.Revision,
}
}
return &Topic{
Id: slot.TopicSlotId,
Revision: slot.Revision,
Data: &TopicData {
DetailRevision: slot.Topic.DetailRevision,
2022-02-18 20:21:15 +00:00
TopicDetail: getTopicDetailModel(slot),
2022-02-18 07:56:30 +00:00
TagRevision: slot.Topic.TagRevision,
},
}
}
2022-03-02 22:30:14 +00:00
func getTagModel(slot *store.TagSlot) *Tag {
if slot.Tag == nil {
return &Tag{
Id: slot.TagSlotId,
Revision: slot.Revision,
}
}
return &Tag{
Id: slot.TagSlotId,
Revision: slot.Revision,
Data: &TagData{
Guid: slot.Tag.Guid,
DataType: slot.Tag.DataType,
Data: slot.Tag.Data,
Created: slot.Tag.Created,
Updated: slot.Tag.Updated,
},
}
}
2022-02-18 07:56:30 +00:00