From 9fab597506c072e6aa23f5cc6c8aff63f4afbe18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20devkcud=20Albanese=20Junior?= Date: Sat, 26 Oct 2024 21:18:23 -0300 Subject: [PATCH] fix: Delete project image only if present --- internal/service/repository/project.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/service/repository/project.go b/internal/service/repository/project.go index 4fbbbfc..8df4d29 100644 --- a/internal/service/repository/project.go +++ b/internal/service/repository/project.go @@ -801,9 +801,11 @@ func (pr *projectRepository) UnsafeDelete(id uint) error { return err } - if err := aws.DeleteProjectImage(project.BannerURL); err != nil { - tx.Rollback() - return err + if project.BannerURL != "" { + if err := aws.DeleteProjectImage(project.BannerURL); err != nil { + tx.Rollback() + return err + } } if err := tx.Unscoped().Delete(&project).Error; err != nil { @@ -899,9 +901,11 @@ func (pr *projectRepository) ClearTrash(userID uint) error { } for _, project := range projects { - if err := aws.DeleteProjectImage(project.BannerURL); err != nil { - tx.Rollback() - return err + if project.BannerURL != "" { + if err := aws.DeleteProjectImage(project.BannerURL); err != nil { + tx.Rollback() + return err + } } }