pushing label into labelslot

This commit is contained in:
Roland Osborne 2022-02-02 22:52:06 -08:00
parent 9d1f407653
commit a736d0da05
4 changed files with 24 additions and 8 deletions

View File

@ -29,11 +29,17 @@ func AddArticle(w http.ResponseWriter, r *http.Request) {
return
}
var labels []store.Label
if err := store.DB.Where("label_id IN ?", articleAccess.Labels).Find(&labels).Error; err != nil {
var labelSlots []store.LabelSlot
if err := store.DB.Preload("Label").Where("label_slot_id IN ?", articleAccess.Labels).Find(&labelSlots).Error; err != nil {
ErrResponse(w, http.StatusInternalServerError, err)
return
}
var labels []store.Label
for _, slot := range labelSlots {
if slot.Label != nil {
labels = append(labels, *slot.Label)
}
}
// save data and apply transaction
var slot *store.ArticleSlot

View File

@ -31,11 +31,12 @@ func RemoveArticle(w http.ResponseWriter, r *http.Request) {
return res
}
slot.ArticleID = 0
slot.Revision = account.ContentRevision + 1
slot.Article = nil
if res := tx.Save(&slot).Error; res != nil {
return res
}
if res := tx.Model(&account).Update("content_revision", account.ContentRevision).Error; res != nil {
if res := tx.Model(&account).Update("content_revision", account.ContentRevision + 1).Error; res != nil {
return res
}
return nil

View File

@ -71,7 +71,7 @@ func getArticleModel(slot *store.ArticleSlot, contact bool, shared bool) *Articl
var labels []string;
for _, label := range slot.Article.Labels {
labels = append(labels, label.LabelId)
labels = append(labels, label.LabelSlot.LabelSlotId)
}
return &Article{

View File

@ -9,6 +9,8 @@ func AutoMigrate(db *gorm.DB) {
db.AutoMigrate(&Account{});
db.AutoMigrate(&AccountToken{});
db.AutoMigrate(&Group{});
db.AutoMigrate(&LabelSlot{});
db.AutoMigrate(&LabelData{});
db.AutoMigrate(&Label{});
db.AutoMigrate(&CardSlot{});
db.AutoMigrate(&Card{});
@ -117,18 +119,25 @@ type GroupData struct {
Data string
}
type LabelSlot struct {
ID uint
LabelSlotId string `gorm:"not null;index:labelslot,unique"`
AccountID uint `gorm:"not null;index:labelslot,unique"`
Revision int64 `gorm:"not null"`
LabelID uint `gorm:"not null;default:0"`
Label *Label
Account Account
}
type Label struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
LabelId string `gorm:"not null;index:label,unique"`
AccountID uint `gorm:"not null;index:label,unique"`
LabelDataID uint `gorm:"not null;index:labeldata"`
Revision int64 `gorm:"not null"`
DataType string `gorm:"index"`
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
Groups []Group `gorm:"many2many:label_groups;"`
Account Account
LabelData LabelData
LabelSlot LabelSlot
}
type LabelData struct {