1
0

Added entryID arg to Update*() methods. So IDs could be changed.

This commit is contained in:
Alexander Andreev 2022-10-21 04:37:28 +04:00
parent 6abae1d7ca
commit b94b5caf4c
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F
2 changed files with 6 additions and 6 deletions

View File

@ -181,14 +181,14 @@ func (d *SQLiteDatabase) NewEntry(entry *guestbook.Entry) error {
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()
if err != nil {
return false, err
}
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 {
return false, err
}
@ -239,14 +239,14 @@ func (d *SQLiteDatabase) NewReply(reply *guestbook.Reply) (err error) {
}
// 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()
if err != nil {
return false, err
}
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 {
return false, err
}

View File

@ -6,10 +6,10 @@ type Guestbook interface {
Entries(page, pageSize int64) ([]*Entry, error)
Count() (int64, error)
NewEntry(entry *Entry) error
UpdateEntry(entry *Entry) (bool, error)
UpdateEntry(entryID int64, entry *Entry) (bool, error)
DeleteEntry(entryID int64) error
NewReply(reply *Reply) error
UpdateReply(reply *Reply) (bool, error)
UpdateReply(entryID int64, reply *Reply) (bool, error)
DeleteReply(entryID int64) error
Close() error
}