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

Post works ! Except for tags

parent fa176d83
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -33,6 +33,19 @@ func (pbc *PlayBotCollection) GetByUrl(url string) (*site.Content, error) { ...@@ -33,6 +33,19 @@ func (pbc *PlayBotCollection) GetByUrl(url string) (*site.Content, error) {
} }
func (pbc *PlayBotCollection) InsertPost(post *Post) error { func (pbc *PlayBotCollection) InsertPost(post *Post) error {
err := pbc.Db.Insert(post.Content).Error()
if err != nil {
// TODO: check error type
var content site.Content
err = pbc.Db.Where(&site.Content{Url: post.Content.Url}).First(&content).Error()
if err != nil {
return err
}
post.Content = &content
}
pbc.Db.Insert(post) pbc.Db.Insert(post)
return nil return nil
} }
...@@ -17,7 +17,10 @@ type DbParams struct { ...@@ -17,7 +17,10 @@ type DbParams struct {
} }
type Db interface { type Db interface {
Insert(interface{}) error Insert(interface{}) Db
Error() error
First(interface{}) Db
Where(interface{}) Db
} }
type PlayBotDb struct { type PlayBotDb struct {
...@@ -45,7 +48,24 @@ func NewPlayBotDb(dbParams DbParams) (Db, error) { ...@@ -45,7 +48,24 @@ func NewPlayBotDb(dbParams DbParams) (Db, error) {
return &PlayBotDb{db}, nil return &PlayBotDb{db}, nil
} }
func (pdb *PlayBotDb) Insert(value interface{}) error { func (pdb *PlayBotDb) Insert(value interface{}) Db {
pdb.db.Create(value) return &PlayBotDb{
return nil 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) Where(value interface{}) Db {
return &PlayBotDb{
pdb.db.Where(value),
}
} }
...@@ -7,11 +7,12 @@ import ( ...@@ -7,11 +7,12 @@ import (
) )
type Post struct { type Post struct {
Id int Id int
Date time.Time Date time.Time
Author string `gorm:"column:sender_irc"` Author string `gorm:"column:sender_irc"`
Source string `gorm:"column:chan"` Source string `gorm:"column:chan"`
Content *site.Content Content *site.Content
ContentId int `gorm:"column:content"`
} }
func (Post) TableName() string { func (Post) TableName() string {
......
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