-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DPMBE-106] user profile 수정 시 사용하지 않는 이미지는 삭제한다 (#161)
* feat: user profile 수정 시 사용하지 않는 이미지는 삭제한다 * remove: imageFileExtension 사용하지 않아서 제거 * refactor: UserProfileImageUpdatedEvent 발행 Domain으로 이동하고 Kotlin takeIf 문법 사용 * style: spotless * style: 주석해제 & s3Service로 이름 변경
- Loading branch information
Showing
10 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...ow-Api/src/main/kotlin/com/depromeet/whatnow/api/user/dto/request/UpdateProfileRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package com.depromeet.whatnow.api.user.dto.request | ||
|
||
data class UpdateProfileRequest( | ||
val profileImage: String, | ||
val username: String, | ||
val profileImage: String, | ||
val isDefaultImg: Boolean, | ||
val imageKey: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
.../src/main/kotlin/com/depromeet/whatnow/events/domainEvent/UserProfileImageUpdatedEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.depromeet.whatnow.events.domainEvent | ||
|
||
import com.depromeet.whatnow.common.aop.event.DomainEvent | ||
|
||
class UserProfileImageUpdatedEvent( | ||
val userId: Long, | ||
val imageKey: String, | ||
) : DomainEvent() |
28 changes: 28 additions & 0 deletions
28
...c/main/kotlin/com/depromeet/whatnow/events/handler/UserProfileImageUpdatedEventHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.depromeet.whatnow.events.handler | ||
|
||
import com.depromeet.whatnow.annotation.Handler | ||
import com.depromeet.whatnow.config.s3.S3Service | ||
import com.depromeet.whatnow.domains.image.adapter.UserImageAdapter | ||
import com.depromeet.whatnow.events.domainEvent.UserProfileImageUpdatedEvent | ||
import org.springframework.scheduling.annotation.Async | ||
import org.springframework.transaction.event.TransactionPhase | ||
import org.springframework.transaction.event.TransactionalEventListener | ||
|
||
@Handler | ||
class UserProfileImageUpdatedEventHandler( | ||
val s3Service: S3Service, | ||
val userImageAdapter: UserImageAdapter, | ||
) { | ||
@Async | ||
@TransactionalEventListener(classes = [UserProfileImageUpdatedEvent::class], phase = TransactionPhase.AFTER_COMMIT) | ||
fun handleRegisterUserEvent(userProfileImageUpdatedEvent: UserProfileImageUpdatedEvent) { | ||
val userId = userProfileImageUpdatedEvent.userId | ||
val imageKey = userProfileImageUpdatedEvent.imageKey | ||
|
||
userImageAdapter.findAllByUserId(userId) | ||
.filter { it.imageKey != imageKey } | ||
.map { | ||
s3Service.deleteForUser(userId, it.imageKey, it.fileExtension) | ||
} | ||
} | ||
} |