Added entryID arg to Update*() methods. So IDs could be changed.
This commit is contained in:
parent
6abae1d7ca
commit
b94b5caf4c
@ -181,14 +181,14 @@ func (d *SQLiteDatabase) NewEntry(entry *guestbook.Entry) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SQLiteDatabase) UpdateEntry(entry *guestbook.Entry) (bool, error) {
|
func (d *SQLiteDatabase) UpdateEntry(entryID int64, entry *guestbook.Entry) (bool, error) {
|
||||||
tx, err := d.db.Begin()
|
tx, err := d.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
res, err := tx.Stmt(stmtUpdateEntry).Exec(entry.Name, entry.Message, entry.Website, entry.HideWebsite, entry.ID)
|
res, err := tx.Stmt(stmtUpdateEntry).Exec(entry.ID, entry.Name, entry.Message, entry.Website, entry.HideWebsite, entryID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -239,14 +239,14 @@ func (d *SQLiteDatabase) NewReply(reply *guestbook.Reply) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEntry
|
// UpdateEntry
|
||||||
func (d *SQLiteDatabase) UpdateReply(reply *guestbook.Reply) (bool, error) {
|
func (d *SQLiteDatabase) UpdateReply(entryID int64, reply *guestbook.Reply) (bool, error) {
|
||||||
tx, err := d.db.Begin()
|
tx, err := d.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
res, err := tx.Stmt(stmtUpdateReply).Exec(reply.Created, reply.Message, reply.ID)
|
res, err := tx.Stmt(stmtUpdateReply).Exec(reply.ID, reply.Created, reply.Message, entryID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ type Guestbook interface {
|
|||||||
Entries(page, pageSize int64) ([]*Entry, error)
|
Entries(page, pageSize int64) ([]*Entry, error)
|
||||||
Count() (int64, error)
|
Count() (int64, error)
|
||||||
NewEntry(entry *Entry) error
|
NewEntry(entry *Entry) error
|
||||||
UpdateEntry(entry *Entry) (bool, error)
|
UpdateEntry(entryID int64, entry *Entry) (bool, error)
|
||||||
DeleteEntry(entryID int64) error
|
DeleteEntry(entryID int64) error
|
||||||
NewReply(reply *Reply) error
|
NewReply(reply *Reply) error
|
||||||
UpdateReply(reply *Reply) (bool, error)
|
UpdateReply(entryID int64, reply *Reply) (bool, error)
|
||||||
DeleteReply(entryID int64) error
|
DeleteReply(entryID int64) error
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user