mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
updating foreign key to allow for batch delete
This commit is contained in:
parent
d84425df09
commit
1355d51dfa
@ -27,9 +27,17 @@ func AddChannelTopic(w http.ResponseWriter, r *http.Request) {
|
||||
topicSlot := &store.TopicSlot{}
|
||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
// add new record
|
||||
topicSlot.TopicSlotId = uuid.New().String()
|
||||
topicSlot.AccountID = act.ID
|
||||
topicSlot.ChannelID = channelSlot.Channel.ID
|
||||
topicSlot.Revision = act.ChannelRevision + 1
|
||||
if res := tx.Save(topicSlot).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
|
||||
topic := &store.Topic{}
|
||||
topic.ChannelID = channelSlot.Channel.ID
|
||||
topic.TopicSlotID = topicSlot.ID
|
||||
topic.Data = subject.Data
|
||||
topic.DataType = subject.DataType
|
||||
topic.TagCount = 0
|
||||
@ -44,15 +52,8 @@ func AddChannelTopic(w http.ResponseWriter, r *http.Request) {
|
||||
if res := tx.Save(topic).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
topicSlot.TopicSlotId = uuid.New().String()
|
||||
topicSlot.AccountID = act.ID
|
||||
topicSlot.ChannelID = channelSlot.Channel.ID
|
||||
topicSlot.TopicID = topic.ID
|
||||
topicSlot.Revision = act.ChannelRevision + 1
|
||||
|
||||
topicSlot.Topic = topic
|
||||
if res := tx.Save(topicSlot).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
|
||||
// update parent revision
|
||||
if res := tx.Model(&channelSlot).Update("revision", act.ChannelRevision + 1).Error; res != nil {
|
||||
|
@ -37,14 +37,16 @@ func GetChannelTopics(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
} else {
|
||||
var slots []store.TopicSlot
|
||||
if err := store.DB.Preload("Topic").Where("channel_id = ? AND topic_id != 0", channelSlot.Channel.ID).Find(&slots).Error; err != nil {
|
||||
if err := store.DB.Preload("Topic").Where("channel_id = ?", channelSlot.Channel.ID).Find(&slots).Error; err != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
for _, slot := range slots {
|
||||
if slot.Topic != nil {
|
||||
response = append(response, getTopicModel(&slot))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Set("Topic-Revision", strconv.FormatInt(channelSlot.Revision, 10))
|
||||
WriteResponse(w, response)
|
||||
|
@ -212,7 +212,6 @@ type TopicSlot struct {
|
||||
AccountID uint `gorm:"not null;index:topicaccount,unique"`
|
||||
ChannelID uint `gorm:"not null;index:topicchannel,unique"`
|
||||
Revision int64 `gorm:"not null"`
|
||||
TopicID uint `gorm:"not null;default:0"`
|
||||
Topic *Topic
|
||||
Channel *Channel
|
||||
Account Account
|
||||
@ -222,6 +221,7 @@ type Topic struct {
|
||||
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
||||
DetailRevision int64 `gorm:"not null"`
|
||||
ChannelID uint
|
||||
TopicSlotID uint `gorm:"not null;index:topictopicslot,unique"`
|
||||
Guid string
|
||||
DataType string `gorm:"index"`
|
||||
Data string
|
||||
|
@ -130,7 +130,6 @@ func TestTopicShare(t *testing.T) {
|
||||
tags = &[]Tag{}
|
||||
assert.NoError(t, ApiTestMsg(GetChannelTopicTags, "GET", "/content/channels/{channelId}/topics/{topicId}",
|
||||
¶ms, nil, APP_TOKENCONTACT, set.C.A.Token, tags, nil))
|
||||
PrintMsg(tags)
|
||||
assert.Equal(t, 0, len(*tags))
|
||||
|
||||
// get list of assets
|
||||
|
Loading…
Reference in New Issue
Block a user