diff --git a/bot/collection.go b/bot/collection.go index 5b44615132ab19ebdda4101847c58344144d0834..5597c27e8ca16633cea827b589bc6597b58b1991 100644 --- a/bot/collection.go +++ b/bot/collection.go @@ -43,6 +43,11 @@ func (pbc *PlayBotCollection) InsertPost(post *Post) error { return err } + pbc.Db.Model(&content).Related(&content.Tags) + + if len(post.Content.Tags) > 0 { + content.Tags = append(content.Tags, post.Content.Tags...) + } post.Content = &content } diff --git a/bot/db.go b/bot/db.go index d10c532b71ef8e79cbb51f4d2d3cd54fa10be87c..c4a76e42598a1170772c5ece195857655c4c138a 100644 --- a/bot/db.go +++ b/bot/db.go @@ -17,9 +17,11 @@ type DbParams struct { } type Db interface { - Insert(interface{}) Db Error() error + Insert(interface{}) Db First(interface{}) Db + Model(interface{}) Db + Related(interface{}) Db Where(interface{}) Db } @@ -48,22 +50,34 @@ func NewPlayBotDb(dbParams DbParams) (Db, error) { return &PlayBotDb{db}, nil } +func (pdb *PlayBotDb) Error() error { + return pdb.db.Error +} + func (pdb *PlayBotDb) Insert(value interface{}) Db { return &PlayBotDb{ pdb.db.Create(value), } } -func (pdb *PlayBotDb) Error() error { - return pdb.db.Error -} - func (pdb *PlayBotDb) First(value interface{}) Db { return &PlayBotDb{ pdb.db.First(value), } } +func (pdb *PlayBotDb) Model(value interface{}) Db { + return &PlayBotDb{ + pdb.db.Model(value), + } +} + +func (pdb *PlayBotDb) Related(value interface{}) Db { + return &PlayBotDb{ + pdb.db.Related(value), + } +} + func (pdb *PlayBotDb) Where(value interface{}) Db { return &PlayBotDb{ pdb.db.Where(value), diff --git a/site/content.go b/site/content.go index 3b3829e7dfc270350957c8be57c87fabbb58ea9f..a3d20fc1b70eaac1653b0906896fadbac417b8d0 100644 --- a/site/content.go +++ b/site/content.go @@ -1,5 +1,9 @@ package site +import ( + "log" +) + type Content struct { Author string `gorm:"column:sender"` Duration int @@ -19,7 +23,9 @@ func (Content) TableName() string { } func (c *Content) AddTags(tags []string) { + log.Print(tags) for _, tag := range tags { c.Tags = append(c.Tags, Tag{Tag: tag}) + log.Print(c.Tags) } }