Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix deleting messages #277

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/bridge/mock_Bridge.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions internal/storage/mock_Storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 5 additions & 12 deletions internal/storage/sql_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,14 @@
}

func (s *SqlStorage) DeleteMessage(message Message) error {
var err error
err = s.DB.Delete(&message).Error
if err != nil {
return err
}

if len(message.Attachments) > 0 {
err = s.DeleteAttachmentsByMessage(message)
err := s.DB.Where("message_id = ?", message.ID).Delete(&Attachment{}).Error
if err != nil {
log.WithError(err).WithField("message_id", message.ID).Error("failed to delete attachments")
}

Check warning on line 284 in internal/storage/sql_storage.go

View check run for this annotation

Codecov / codecov/patch

internal/storage/sql_storage.go#L283-L284

Added lines #L283 - L284 were not covered by tests
}

return err
return s.DB.Delete(&message).Error
}

func (s *SqlStorage) DeleteMessages(ticker Ticker) error {
Expand All @@ -305,10 +302,6 @@
return s.DB.Where("ticker_id = ?", ticker.ID).Delete(&Message{}).Error
}

func (s *SqlStorage) DeleteAttachmentsByMessage(message Message) error {
return s.DB.Where("message_id = ?", message.ID).Delete(&Attachment{}).Error
}

func (s *SqlStorage) GetInactiveSettings() InactiveSettings {
var setting Setting
err := s.DB.First(&setting, "name = ?", SettingInactiveName).Error
Expand Down
1 change: 0 additions & 1 deletion internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type Storage interface {
SaveMessage(message *Message) error
DeleteMessage(message Message) error
DeleteMessages(ticker Ticker) error
DeleteAttachmentsByMessage(message Message) error
GetInactiveSettings() InactiveSettings
GetRefreshIntervalSettings() RefreshIntervalSettings
SaveInactiveSettings(inactiveSettings InactiveSettings) error
Expand Down
Loading