Skip to content

Commit

Permalink
🐛 Fix deleting a Ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
0x46616c6b committed Jan 3, 2025
1 parent ef72586 commit ae11021
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions internal/storage/sql_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,43 @@ func (s *SqlStorage) SaveTicker(ticker *Ticker) error {
return s.DB.Session(&gorm.Session{FullSaveAssociations: true}).Model(ticker).Updates(ticker.AsMap()).Error
}

// DeleteTicker deletes a ticker and all associated data.
func (s *SqlStorage) DeleteTicker(ticker Ticker) error {
err := s.DeleteTickerUsers(&ticker)
if err != nil {
log.WithError(err).WithField("ticker_id", ticker.ID).Error("failed to delete ticker users")
}

err = s.DeleteUploadsByTicker(ticker)
if err != nil {
log.WithError(err).WithField("ticker_id", ticker.ID).Error("failed to delete ticker uploads")
}

err = s.DeleteMessages(ticker)
if err != nil {
log.WithError(err).WithField("ticker_id", ticker.ID).Error("failed to delete ticker messages")
}

err = s.DB.Delete(TickerMastodon{}, "ticker_id = ?", ticker.ID).Error
if err != nil {
log.WithError(err).WithField("ticker_id", ticker.ID).Error("failed to delete mastodon settings")
}

err = s.DB.Delete(TickerTelegram{}, "ticker_id = ?", ticker.ID).Error
if err != nil {
log.WithError(err).WithField("ticker_id", ticker.ID).Error("failed to delete telegram settings")
}

err = s.DB.Delete(TickerBluesky{}, "ticker_id = ?", ticker.ID).Error
if err != nil {
log.WithError(err).WithField("ticker_id", ticker.ID).Error("failed to delete bluesky settings")
}

err = s.DB.Delete(TickerSignalGroup{}, "ticker_id = ?", ticker.ID).Error
if err != nil {
log.WithError(err).WithField("ticker_id", ticker.ID).Error("failed to delete signal group settings")
}

return s.DB.Delete(&ticker).Error
}

Expand Down

0 comments on commit ae11021

Please sign in to comment.