diff --git a/doc/api.oa3 b/doc/api.oa3 index 881c017b..c8d76dc5 100644 --- a/doc/api.oa3 +++ b/doc/api.oa3 @@ -1944,38 +1944,7 @@ paths: description: account disabled '500': description: internal server error - - /content/channels/{channelId}/size: - get: - tags: - - content - description: Get size object of channel. - operationId: get-channel-size - security: - - bearerAuth: [] - parameters: - - name: channelId - in: path - description: specified channel id - required: true - schema: - type: string - responses: - '200': - description: success - content: - application/json: - schema: - $ref: '#/components/schemas/ChannelSize' - '401': - description: invalid password - '404': - description: channel not found - '410': - description: account disabled - '500': - description: internal server error - + /content/channels/{channelId}/subject/{field}: get: tags: @@ -3180,7 +3149,7 @@ components: id: type: string revision: - type: string + type: int64 data: $ref: '#/components/schemas/ChannelData' @@ -3188,18 +3157,12 @@ components: type: object required: - detailRevision - - topicRevision properties: detailRevision: type: integer format: int64 - topicRevision: - type: integer - format: int64 channelDetail: $ref: '#/components/schemas/ChannelDetail' - channelTopics: - $ref: '#/components/schemas/ChannelSize' ChannelDetail: type: object @@ -3226,19 +3189,6 @@ components: items: type: string - ChannelSize: - type: object - required: - - topicCount - - topicUpdated - properties: - topicCount: - type: integer - format: int32 - topicUpdated: - type: integer - format: int64 - ChannelGroups: type: object required: diff --git a/net/server/internal/api_addChannel.go b/net/server/internal/api_addChannel.go new file mode 100644 index 00000000..9b935d13 --- /dev/null +++ b/net/server/internal/api_addChannel.go @@ -0,0 +1,56 @@ +package databag + +import ( + "net/http" + "gorm.io/gorm" + "github.com/google/uuid" + "databag/internal/store" +) + +func AddChannel(w http.ResponseWriter, r *http.Request) { + + account, code, err := BearerAppToken(r, false) + if err != nil { + ErrResponse(w, code, err) + return + } + + var subject Subject + if err := ParseRequest(r, w, &subject); err != nil { + ErrResponse(w, http.StatusBadRequest, err) + return + } + + slot := &store.ChannelSlot{} + err = store.DB.Transaction(func(tx *gorm.DB) error { + + channel := &store.Channel{} + channel.Data = subject.Data + channel.DataType = subject.DataType + if res := tx.Save(channel).Error; res != nil { + return res + } + + slot.ChannelSlotId = uuid.New().String() + slot.AccountID = account.ID + slot.ChannelID = channel.ID + slot.Revision = account.ChannelRevision + 1 + slot.Channel = channel + if res := tx.Save(slot).Error; res != nil { + return res + } + if res := tx.Model(&account).Update("channel_revision", account.ChannelRevision + 1).Error; res != nil { + return res + } + return nil + }) + if err != nil { + ErrResponse(w, http.StatusInternalServerError, err) + return + } + + SetStatus(account) + WriteResponse(w, getChannelModel(slot, true, true)) +} + + diff --git a/net/server/internal/api_content.go b/net/server/internal/api_content.go index 4babd62b..88a0eb33 100644 --- a/net/server/internal/api_content.go +++ b/net/server/internal/api_content.go @@ -13,11 +13,6 @@ import ( "net/http" ) -func AddChannel(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} - func AddChannelAsset(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusOK) diff --git a/net/server/internal/modelUtil.go b/net/server/internal/modelUtil.go index 9b19b4ea..956adb97 100644 --- a/net/server/internal/modelUtil.go +++ b/net/server/internal/modelUtil.go @@ -145,4 +145,63 @@ func getArticleModel(slot *store.ArticleSlot, showData bool, showGroups bool) *A } } +func getChannelRevisionModel(slot *store.ChannelSlot, showData bool, showGroups bool) *Channel { + + 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, + }, + } +} + +func getChannelModel(slot *store.ChannelSlot, showData bool, showGroups bool) *Channel { + + if !showData || slot.Channel == nil { + return &Channel{ + Id: slot.ChannelSlotId, + Revision: slot.Revision, + } + } + + var channelGroups *ChannelGroups + if showGroups { + var groups []string; + for _, group := range slot.Channel.Groups { + groups = append(groups, group.GroupSlot.GroupSlotId) + } + channelGroups = &ChannelGroups{ Groups: groups } + } + + var cards []string + for _, card := range slot.Channel.Cards { + cards = append(cards, card.CardSlot.CardSlotId) + } + + return &Channel{ + Id: slot.ChannelSlotId, + Revision: slot.Revision, + Data: &ChannelData { + DetailRevision: slot.Channel.DetailRevision, + ChannelDetail: &ChannelDetail{ + DataType: slot.Channel.DataType, + Data: slot.Channel.Data, + Created: slot.Channel.Created, + Updated: slot.Channel.Updated, + Groups: channelGroups, + Cards: cards, + }, + }, + } +} + + diff --git a/net/server/internal/models.go b/net/server/internal/models.go index 64f73314..8a28d119 100644 --- a/net/server/internal/models.go +++ b/net/server/internal/models.go @@ -149,7 +149,7 @@ type Channel struct { Id string `json:"id"` - Revision string `json:"revision"` + Revision int64 `json:"revision"` Data *ChannelData `json:"data"` } @@ -158,11 +158,7 @@ type ChannelData struct { DetailRevision int64 `json:"detailRevision"` - TopicRevision int64 `json:"topicRevision"` - ChannelDetail *ChannelDetail `json:"channelDetail,omitempty"` - - ChannelTopics *ChannelSize `json:"channelTopics,omitempty"` } type ChannelDetail struct { @@ -185,13 +181,6 @@ type ChannelGroups struct { Groups []string `json:"groups"` } -type ChannelSize struct { - - TopicCount int32 `json:"topicCount"` - - TopicUpdated int64 `json:"topicUpdated"` -} - type Claim struct { Token string `json:"token"` diff --git a/net/server/internal/routers.go b/net/server/internal/routers.go index fba08b96..e87eec00 100644 --- a/net/server/internal/routers.go +++ b/net/server/internal/routers.go @@ -551,13 +551,6 @@ var routes = Routes{ GetChannelDetail, }, - Route{ - "GetChannelSize", - strings.ToUpper("Get"), - "/content/channels/{channelId}/size", - GetChannelSize, - }, - Route{ "GetChannelSubjectField", strings.ToUpper("Get"), diff --git a/net/server/internal/store/schema.go b/net/server/internal/store/schema.go index f888b61d..afbfae83 100644 --- a/net/server/internal/store/schema.go +++ b/net/server/internal/store/schema.go @@ -196,11 +196,9 @@ type Channel struct { ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` DetailRevision int64 `gorm:"not null"` DataType string `gorm:"index"` + Data string Created int64 `gorm:"autoCreateTime"` Updated int64 `gorm:"autoUpdateTime"` - SizeRevision int64 `gorm:"not null"` - TopicUpdated int64 - TopicCount int64 Groups []Group `gorm:"many2many:channel_groups;"` Cards []Card `gorm:"many2many:channel_cards;"` ChannelSlot ChannelSlot diff --git a/net/server/internal/ucTopicShare_test.go b/net/server/internal/ucTopicShare_test.go new file mode 100644 index 00000000..2d008e4c --- /dev/null +++ b/net/server/internal/ucTopicShare_test.go @@ -0,0 +1,14 @@ +package databag + +import ( + "testing" + "github.com/stretchr/testify/assert" +) + +func TestTopicShare(t *testing.T) { + + // setup testing group + set, err := AddTestGroup("topicshare") + assert.NoError(t, err) + PrintMsg(set) +}