Skip to content
Extraits de code Groupes Projets
Valider da0646a6 rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

Fix db tags

parent 9a79d575
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -43,6 +43,11 @@ func (pbc *PlayBotCollection) InsertPost(post *Post) error { ...@@ -43,6 +43,11 @@ func (pbc *PlayBotCollection) InsertPost(post *Post) error {
return err 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 post.Content = &content
} }
......
...@@ -17,9 +17,11 @@ type DbParams struct { ...@@ -17,9 +17,11 @@ type DbParams struct {
} }
type Db interface { type Db interface {
Insert(interface{}) Db
Error() error Error() error
Insert(interface{}) Db
First(interface{}) Db First(interface{}) Db
Model(interface{}) Db
Related(interface{}) Db
Where(interface{}) Db Where(interface{}) Db
} }
...@@ -48,22 +50,34 @@ func NewPlayBotDb(dbParams DbParams) (Db, error) { ...@@ -48,22 +50,34 @@ func NewPlayBotDb(dbParams DbParams) (Db, error) {
return &PlayBotDb{db}, nil return &PlayBotDb{db}, nil
} }
func (pdb *PlayBotDb) Error() error {
return pdb.db.Error
}
func (pdb *PlayBotDb) Insert(value interface{}) Db { func (pdb *PlayBotDb) Insert(value interface{}) Db {
return &PlayBotDb{ return &PlayBotDb{
pdb.db.Create(value), pdb.db.Create(value),
} }
} }
func (pdb *PlayBotDb) Error() error {
return pdb.db.Error
}
func (pdb *PlayBotDb) First(value interface{}) Db { func (pdb *PlayBotDb) First(value interface{}) Db {
return &PlayBotDb{ return &PlayBotDb{
pdb.db.First(value), 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 { func (pdb *PlayBotDb) Where(value interface{}) Db {
return &PlayBotDb{ return &PlayBotDb{
pdb.db.Where(value), pdb.db.Where(value),
......
package site package site
import (
"log"
)
type Content struct { type Content struct {
Author string `gorm:"column:sender"` Author string `gorm:"column:sender"`
Duration int Duration int
...@@ -19,7 +23,9 @@ func (Content) TableName() string { ...@@ -19,7 +23,9 @@ func (Content) TableName() string {
} }
func (c *Content) AddTags(tags []string) { func (c *Content) AddTags(tags []string) {
log.Print(tags)
for _, tag := range tags { for _, tag := range tags {
c.Tags = append(c.Tags, Tag{Tag: tag}) c.Tags = append(c.Tags, Tag{Tag: tag})
log.Print(c.Tags)
} }
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter