mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 20:49:16 +00:00
adding channel test
This commit is contained in:
parent
fa5fba5b5b
commit
0b192ad629
52
doc/api.oa3
52
doc/api.oa3
@ -1945,37 +1945,6 @@ paths:
|
|||||||
'500':
|
'500':
|
||||||
description: internal server error
|
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}:
|
/content/channels/{channelId}/subject/{field}:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
@ -3180,7 +3149,7 @@ components:
|
|||||||
id:
|
id:
|
||||||
type: string
|
type: string
|
||||||
revision:
|
revision:
|
||||||
type: string
|
type: int64
|
||||||
data:
|
data:
|
||||||
$ref: '#/components/schemas/ChannelData'
|
$ref: '#/components/schemas/ChannelData'
|
||||||
|
|
||||||
@ -3188,18 +3157,12 @@ components:
|
|||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
- detailRevision
|
- detailRevision
|
||||||
- topicRevision
|
|
||||||
properties:
|
properties:
|
||||||
detailRevision:
|
detailRevision:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
topicRevision:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
channelDetail:
|
channelDetail:
|
||||||
$ref: '#/components/schemas/ChannelDetail'
|
$ref: '#/components/schemas/ChannelDetail'
|
||||||
channelTopics:
|
|
||||||
$ref: '#/components/schemas/ChannelSize'
|
|
||||||
|
|
||||||
ChannelDetail:
|
ChannelDetail:
|
||||||
type: object
|
type: object
|
||||||
@ -3226,19 +3189,6 @@ components:
|
|||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
ChannelSize:
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- topicCount
|
|
||||||
- topicUpdated
|
|
||||||
properties:
|
|
||||||
topicCount:
|
|
||||||
type: integer
|
|
||||||
format: int32
|
|
||||||
topicUpdated:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
|
|
||||||
ChannelGroups:
|
ChannelGroups:
|
||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
|
56
net/server/internal/api_addChannel.go
Normal file
56
net/server/internal/api_addChannel.go
Normal file
@ -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))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -13,11 +13,6 @@ import (
|
|||||||
"net/http"
|
"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) {
|
func AddChannelAsset(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
@ -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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ type Channel struct {
|
|||||||
|
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
|
|
||||||
Revision string `json:"revision"`
|
Revision int64 `json:"revision"`
|
||||||
|
|
||||||
Data *ChannelData `json:"data"`
|
Data *ChannelData `json:"data"`
|
||||||
}
|
}
|
||||||
@ -158,11 +158,7 @@ type ChannelData struct {
|
|||||||
|
|
||||||
DetailRevision int64 `json:"detailRevision"`
|
DetailRevision int64 `json:"detailRevision"`
|
||||||
|
|
||||||
TopicRevision int64 `json:"topicRevision"`
|
|
||||||
|
|
||||||
ChannelDetail *ChannelDetail `json:"channelDetail,omitempty"`
|
ChannelDetail *ChannelDetail `json:"channelDetail,omitempty"`
|
||||||
|
|
||||||
ChannelTopics *ChannelSize `json:"channelTopics,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChannelDetail struct {
|
type ChannelDetail struct {
|
||||||
@ -185,13 +181,6 @@ type ChannelGroups struct {
|
|||||||
Groups []string `json:"groups"`
|
Groups []string `json:"groups"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChannelSize struct {
|
|
||||||
|
|
||||||
TopicCount int32 `json:"topicCount"`
|
|
||||||
|
|
||||||
TopicUpdated int64 `json:"topicUpdated"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Claim struct {
|
type Claim struct {
|
||||||
|
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
|
@ -551,13 +551,6 @@ var routes = Routes{
|
|||||||
GetChannelDetail,
|
GetChannelDetail,
|
||||||
},
|
},
|
||||||
|
|
||||||
Route{
|
|
||||||
"GetChannelSize",
|
|
||||||
strings.ToUpper("Get"),
|
|
||||||
"/content/channels/{channelId}/size",
|
|
||||||
GetChannelSize,
|
|
||||||
},
|
|
||||||
|
|
||||||
Route{
|
Route{
|
||||||
"GetChannelSubjectField",
|
"GetChannelSubjectField",
|
||||||
strings.ToUpper("Get"),
|
strings.ToUpper("Get"),
|
||||||
|
@ -196,11 +196,9 @@ type Channel struct {
|
|||||||
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
||||||
DetailRevision int64 `gorm:"not null"`
|
DetailRevision int64 `gorm:"not null"`
|
||||||
DataType string `gorm:"index"`
|
DataType string `gorm:"index"`
|
||||||
|
Data string
|
||||||
Created int64 `gorm:"autoCreateTime"`
|
Created int64 `gorm:"autoCreateTime"`
|
||||||
Updated int64 `gorm:"autoUpdateTime"`
|
Updated int64 `gorm:"autoUpdateTime"`
|
||||||
SizeRevision int64 `gorm:"not null"`
|
|
||||||
TopicUpdated int64
|
|
||||||
TopicCount int64
|
|
||||||
Groups []Group `gorm:"many2many:channel_groups;"`
|
Groups []Group `gorm:"many2many:channel_groups;"`
|
||||||
Cards []Card `gorm:"many2many:channel_cards;"`
|
Cards []Card `gorm:"many2many:channel_cards;"`
|
||||||
ChannelSlot ChannelSlot
|
ChannelSlot ChannelSlot
|
||||||
|
14
net/server/internal/ucTopicShare_test.go
Normal file
14
net/server/internal/ucTopicShare_test.go
Normal file
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user