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

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