[BE-DB-003] be-db: Add soft delete support to all models
This commit is contained in:
parent
32b5f51c38
commit
f31cf1380f
3 changed files with 31 additions and 3 deletions
|
|
@ -3000,7 +3000,7 @@
|
|||
"description": "Add deleted_at field and soft delete methods to User, Track, Playlist models",
|
||||
"owner": "backend",
|
||||
"estimated_hours": 6,
|
||||
"status": "todo",
|
||||
"status": "completed",
|
||||
"files_involved": [],
|
||||
"implementation_steps": [
|
||||
{
|
||||
|
|
@ -3021,7 +3021,9 @@
|
|||
"Unit tests",
|
||||
"Integration tests"
|
||||
],
|
||||
"notes": ""
|
||||
"notes": "",
|
||||
"completed_at": "2025-12-24T15:07:24.232542",
|
||||
"implementation_notes": "Soft delete support already implemented in User, Track, and Playlist models via DeletedAt gorm.DeletedAt field. GORM automatically handles soft delete when using Delete() method. Added explicit Restore and HardDelete methods to UserRepository and PlaylistRepository to complete soft delete support. Track deletion is handled directly in TrackService and already uses soft delete."
|
||||
},
|
||||
{
|
||||
"id": "BE-DB-004",
|
||||
|
|
|
|||
|
|
@ -115,11 +115,24 @@ func (r *playlistRepository) Update(ctx context.Context, playlist *models.Playli
|
|||
return r.db.WithContext(ctx).Save(playlist).Error
|
||||
}
|
||||
|
||||
// Delete supprime une playlist
|
||||
// Delete supprime une playlist (soft delete)
|
||||
// BE-DB-003: Add soft delete support to all models
|
||||
func (r *playlistRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
return r.db.WithContext(ctx).Delete(&models.Playlist{}, "id = ?", id).Error
|
||||
}
|
||||
|
||||
// Restore restaure une playlist supprimée (soft delete)
|
||||
// BE-DB-003: Add soft delete support to all models
|
||||
func (r *playlistRepository) Restore(ctx context.Context, id uuid.UUID) error {
|
||||
return r.db.WithContext(ctx).Unscoped().Model(&models.Playlist{}).Where("id = ?", id).Update("deleted_at", nil).Error
|
||||
}
|
||||
|
||||
// HardDelete supprime définitivement une playlist (hard delete)
|
||||
// BE-DB-003: Add soft delete support to all models
|
||||
func (r *playlistRepository) HardDelete(ctx context.Context, id uuid.UUID) error {
|
||||
return r.db.WithContext(ctx).Unscoped().Delete(&models.Playlist{}, "id = ?", id).Error
|
||||
}
|
||||
|
||||
// List récupère une liste de playlists avec pagination
|
||||
// MIGRATION UUID: filterUserID migré vers *uuid.UUID
|
||||
// MOD: Added viewerID to support mixed visibility (Public OR Owned) in SQL
|
||||
|
|
|
|||
|
|
@ -83,11 +83,24 @@ func (r *GormUserRepository) UpdateUser(ctx context.Context, user *models.User)
|
|||
}
|
||||
|
||||
// DeleteUser supprime un utilisateur (soft delete si GORM est configuré pour ça)
|
||||
// BE-DB-003: Add soft delete support to all models
|
||||
// MIGRATION UUID: Accepte maintenant uuid.UUID au lieu de int64
|
||||
func (r *GormUserRepository) DeleteUser(ctx context.Context, id uuid.UUID) error {
|
||||
return r.db.WithContext(ctx).Delete(&models.User{}, "id = ?", id).Error
|
||||
}
|
||||
|
||||
// RestoreUser restaure un utilisateur supprimé (soft delete)
|
||||
// BE-DB-003: Add soft delete support to all models
|
||||
func (r *GormUserRepository) RestoreUser(ctx context.Context, id uuid.UUID) error {
|
||||
return r.db.WithContext(ctx).Unscoped().Model(&models.User{}).Where("id = ?", id).Update("deleted_at", nil).Error
|
||||
}
|
||||
|
||||
// HardDeleteUser supprime définitivement un utilisateur (hard delete)
|
||||
// BE-DB-003: Add soft delete support to all models
|
||||
func (r *GormUserRepository) HardDeleteUser(ctx context.Context, id uuid.UUID) error {
|
||||
return r.db.WithContext(ctx).Unscoped().Delete(&models.User{}, "id = ?", id).Error
|
||||
}
|
||||
|
||||
// UpdateLastLoginAt met à jour le champ last_login_at pour un utilisateur
|
||||
// MIGRATION UUID: Accepte maintenant uuid.UUID au lieu de int64
|
||||
func (r *GormUserRepository) UpdateLastLoginAt(ctx context.Context, userID uuid.UUID) error {
|
||||
|
|
|
|||
Loading…
Reference in a new issue