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 {
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
}
......
......@@ -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),
......
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)
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter