mark guestbook as deleted alongside website

This commit is contained in:
yequari 2025-08-02 10:51:42 -07:00
parent 65801464f1
commit d26f309cf5

View File

@ -12,7 +12,6 @@ type Website struct {
ID int64
ShortId uint64
Name string
// SiteUrl string
Url *url.URL
AuthorName string
UserId int64
@ -317,15 +316,29 @@ func (m *WebsiteModel) Update(w Website) error {
func (m *WebsiteModel) Delete(websiteId int64) error {
stmt := `UPDATE websites SET Deleted = ? WHERE ID = ?`
r, err := m.DB.Exec(stmt, time.Now().UTC(), websiteId)
tx, err := m.DB.Begin()
if err != nil {
return nil
}
t := time.Now().UTC()
_, err = tx.Exec(stmt, t, websiteId)
if err != nil {
if rbErr := tx.Rollback(); rbErr != nil {
return rbErr
}
return err
}
if rows, err := r.RowsAffected(); rows != 1 {
stmt = `UPDATE guestbooks SET Deleted = ? WHERE WebsiteId = ?`
_, err = tx.Exec(stmt, t, websiteId)
if err != nil {
if rbErr := tx.Rollback(); rbErr != nil {
return rbErr
}
return err
}
return errors.New("Failed to update website")
err = tx.Commit()
if err != nil {
return err
}
return nil
}