added filtering and cronjob soft delete for old events
This commit is contained in:
1 parent
75d5d0bb0f
commit
1701eb5070
4 files changed
+76
-5
No files matched your search
@@ -19,6 +19,7 @@ import (
|
||||
type EventRepository interface {
|
||||
Save(event *models.Event) error
|
||||
FindAll() ([]models.Event, error)
|
||||
SoftDeleteEndedBefore(cutoffDate string) (int64, error)
|
||||
}
|
||||
|
||||
type eventRepository struct {
|
||||
@@ -101,6 +102,18 @@ func (r *eventRepository) FindAll() ([]models.Event, error) {
|
||||
return events, result.Error
|
||||
}
|
||||
|
||||
// SoftDeleteEndedBefore marks events whose end_date is before cutoffDate
|
||||
// (an exclusive "YYYY-MM-DD" boundary, the same lexicographic string
|
||||
// comparison the frontend uses for its own date filtering) as deleted.
|
||||
// .Delete() on a gorm.Model sets deleted_at rather than removing the row,
|
||||
// consistent with how the frontend already treats soft-deleted events.
|
||||
// Events with a blank end_date are left alone — there's nothing to
|
||||
// compare, so leaving them is safer than guessing they're stale.
|
||||
func (r *eventRepository) SoftDeleteEndedBefore(cutoffDate string) (int64, error) {
|
||||
result := r.db.Where("end_date <> '' AND end_date < ?", cutoffDate).Delete(&models.Event{})
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
|
||||
func (r *eventRepository) saveMediaFile(filename string, url string, mediaType string, extension string) error {
|
||||
mediaFilePath := fmt.Sprintf("./public/storage/%s/%s%s", strings.ToLower(mediaType), filename, extension)
|
||||
|
||||
|
||||
Reference in new issue
Block a user