databag/net/server/internal/modelUtil.go

330 lines
7.4 KiB
Go
Raw Normal View History

2022-01-21 00:26:59 +00:00
package databag
import (
2022-07-22 19:28:14 +00:00
"databag/internal/store"
2022-01-21 00:26:59 +00:00
)
2022-02-09 18:30:39 +00:00
func getProfileModel(account *store.Account) *Profile {
2022-07-22 19:28:14 +00:00
return &Profile{
GUID: account.GUID,
Handle: account.Username,
Name: account.AccountDetail.Name,
Description: account.AccountDetail.Description,
Location: account.AccountDetail.Location,
Image: account.AccountDetail.Image,
Revision: account.ProfileRevision,
Version: APPVersion,
Node: getStrConfigValue(CNFDomain, ""),
}
2022-02-09 18:30:39 +00:00
}
2022-02-03 06:13:46 +00:00
func getCardModel(slot *store.CardSlot) *Card {
2022-07-22 19:28:14 +00:00
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,
NotifiedView: slot.Card.NotifiedView,
ProfileRevision: slot.Card.ProfileRevision,
DetailRevision: slot.Card.DetailRevision,
CardDetail: getCardDetailModel(slot),
CardProfile: getCardProfileModel(slot),
},
}
2022-02-08 20:24:42 +00:00
}
func getCardRevisionModel(slot *store.CardSlot) *Card {
2022-07-22 19:28:14 +00:00
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,
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 {
2022-07-22 19:28:14 +00:00
var groups []string
for _, group := range slot.Card.Groups {
groups = append(groups, group.GroupSlot.GroupSlotID)
}
return &CardDetail{
Status: slot.Card.Status,
Token: slot.Card.OutToken,
Notes: slot.Card.Notes,
Groups: groups,
}
}
func getCardProfileModel(slot *store.CardSlot) *CardProfile {
2022-07-22 19:28:14 +00:00
return &CardProfile{
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 {
2022-07-22 19:28:14 +00:00
if slot.Group == nil {
return &Group{
ID: slot.GroupSlotID,
Revision: slot.Revision,
}
}
return &Group{
ID: slot.GroupSlotID,
Revision: slot.Revision,
Data: &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
2022-02-16 08:00:07 +00:00
func getArticleModel(slot *store.ArticleSlot, showData bool, showList bool) *Article {
2022-07-22 19:28:14 +00:00
if !showData || slot.Article == nil {
return &Article{
ID: slot.ArticleSlotID,
Revision: slot.Revision,
}
}
var articleGroups *IDList
if showList {
var groups []string
for _, group := range slot.Article.Groups {
groups = append(groups, group.GroupSlot.GroupSlotID)
}
articleGroups = &IDList{IDs: groups}
}
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-13 07:29:40 +00:00
}
2022-02-16 08:00:07 +00:00
func getChannelRevisionModel(slot *store.ChannelSlot, showData bool) *Channel {
2022-02-15 22:30:04 +00:00
2022-07-22 19:28:14 +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,
TopicRevision: slot.Channel.TopicRevision,
},
}
2022-02-15 22:30:04 +00:00
}
func getChannelDetailModel(slot *store.ChannelSlot, showList bool) *ChannelDetail {
2022-02-15 22:30:04 +00:00
2022-07-22 19:28:14 +00:00
if slot.Channel == nil {
return nil
}
var contacts *ChannelContacts
if showList {
var groups []string
for _, group := range slot.Channel.Groups {
groups = append(groups, group.GroupSlot.GroupSlotID)
}
var cards []string
for _, card := range slot.Channel.Cards {
cards = append(cards, card.CardSlot.CardSlotID)
}
contacts = &ChannelContacts{Groups: groups, Cards: cards}
}
members := []string{}
for _, card := range slot.Channel.Cards {
members = append(members, card.GUID)
}
return &ChannelDetail{
DataType: slot.Channel.DataType,
Data: slot.Channel.Data,
Created: slot.Channel.Created,
Updated: slot.Channel.Updated,
Contacts: contacts,
Members: members,
}
}
2022-05-09 21:08:54 +00:00
func getChannelSummaryModel(slot *store.ChannelSlot) *ChannelSummary {
2022-07-22 19:28:14 +00:00
if slot.Channel == nil {
return nil
}
topicDetail := TopicDetail{}
if len(slot.Channel.Topics) > 0 {
topicDetail.GUID = slot.Channel.Topics[0].GUID
topicDetail.DataType = slot.Channel.Topics[0].DataType
topicDetail.Data = slot.Channel.Topics[0].Data
topicDetail.Created = slot.Channel.Topics[0].Created
topicDetail.Updated = slot.Channel.Topics[0].Updated
topicDetail.Status = slot.Channel.Topics[0].Status
}
return &ChannelSummary{
LastTopic: &topicDetail,
}
2022-05-09 21:08:54 +00:00
}
func getChannelModel(slot *store.ChannelSlot, showData bool, showList bool) *Channel {
2022-07-22 19:28:14 +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,
TopicRevision: slot.Channel.TopicRevision,
ChannelDetail: getChannelDetailModel(slot, showList),
ChannelSummary: getChannelSummaryModel(slot),
},
}
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-07-22 19:28:14 +00:00
if slot.Topic == nil {
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 07:56:30 +00:00
}
2022-02-18 20:21:15 +00:00
func getTopicDetailModel(slot *store.TopicSlot) *TopicDetail {
2022-02-18 07:56:30 +00:00
2022-07-22 19:28:14 +00:00
if slot.Topic == nil {
return nil
}
transform := APPTransformComplete
for _, asset := range slot.Topic.Assets {
if asset.Status == APPAssetError {
transform = APPTransformError
} else if asset.Status == APPAssetWaiting && transform == APPTransformComplete {
transform = APPTransformIncomplete
}
}
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,
Transform: transform,
}
2022-02-18 20:21:15 +00:00
}
func getTopicModel(slot *store.TopicSlot) *Topic {
2022-07-22 19:28:14 +00:00
if slot.Topic == nil {
return &Topic{
ID: slot.TopicSlotID,
Revision: slot.Revision,
}
}
return &Topic{
ID: slot.TopicSlotID,
Revision: slot.Revision,
Data: &TopicData{
DetailRevision: slot.Topic.DetailRevision,
TopicDetail: getTopicDetailModel(slot),
TagRevision: slot.Topic.TagRevision,
},
}
2022-02-18 07:56:30 +00:00
}
2022-03-02 22:30:14 +00:00
func getTagModel(slot *store.TagSlot) *Tag {
2022-07-22 19:28:14 +00:00
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-03-02 22:30:14 +00:00
}