-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 임시 앨범 삭제 기능 구현 #241
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
feat: 임시 앨범 삭제 기능 구현 #241
Changes from 9 commits
b72317e
88f220e
43d4943
1b4431c
4f1daff
4d52d09
7c3c029
d97f82f
3095ee2
ce10248
9fbb8f8
ffbb9f8
f294122
21f9c2c
e19b159
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package org.cherrypic.domain.tempalbum.event; | ||
|
|
||
| import org.cherrypic.tempalbum.entity.TempAlbum; | ||
|
|
||
| public record TempAlbumDeleteEvent(Long tempAlbumId) { | ||
| public static TempAlbumDeleteEvent of(TempAlbum tempAlbum) { | ||
| return new TempAlbumDeleteEvent(tempAlbum.getId()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package org.cherrypic.domain.tempalbum.job; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.cherrypic.domain.tempalbum.service.TempAlbumService; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class TempAlbumExpireJob { | ||
|
|
||
| private final TempAlbumService tempAlbumService; | ||
|
|
||
| public void run() { | ||
| tempAlbumService.expireOverdueTempAlbum(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.cherrypic.domain.tempalbum.repository; | ||
|
|
||
| import java.util.List; | ||
| import org.cherrypic.tempalbum.entity.TempAlbumImage; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Modifying; | ||
| import org.springframework.data.jpa.repository.Query; | ||
|
|
||
| public interface TempAlbumImageRepository extends JpaRepository<TempAlbumImage, Long> { | ||
|
|
||
| @Modifying(clearAutomatically = true) | ||
| @Query("DELETE FROM TempAlbumImage i WHERE i.tempAlbum.id IN :albumIds") | ||
| void deleteAllByTempAlbumIds(List<Long> albumIds); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.cherrypic.domain.tempalbum.repository; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.List; | ||
| import org.cherrypic.tempalbum.entity.TempAlbum; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| public interface TempAlbumRepository extends JpaRepository<TempAlbum, Long> { | ||
|
|
||
| @Query("SELECT t FROM TempAlbum t WHERE t.expiredAt = :now") | ||
| List<TempAlbum> findAllExpiredToday(@Param("now") LocalDate now); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prepared Statement 캐싱을 위해서는 파라미터 바인딩이 필요하지 않나요?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 파라미터 이름이 동일해서 어노테이션 제거해도 될 것 같다고 말씀드린겁니다! |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.cherrypic.domain.tempalbum.schedular; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.cherrypic.domain.tempalbum.job.TempAlbumExpireJob; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class TempAlbumExpireScheduler { | ||
|
|
||
| private final TempAlbumExpireJob tempAlbumExpireJob; | ||
|
|
||
| @Scheduled(cron = "0 0 0 * * *") | ||
| public void runTempAlbumExpirejob() { | ||
| tempAlbumExpireJob.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package org.cherrypic.domain.tempalbum.service; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.cherrypic.domain.tempalbum.repository.TempAlbumImageRepository; | ||
| import org.cherrypic.domain.tempalbum.repository.TempAlbumRepository; | ||
| import org.cherrypic.s3.S3Util; | ||
| import org.cherrypic.tempalbum.entity.TempAlbum; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| public class TempAlbumService { | ||
|
|
||
| private final TempAlbumRepository tempAlbumRepository; | ||
| private final TempAlbumImageRepository tempAlbumImageRepository; | ||
|
|
||
| private final S3Util s3Util; | ||
|
|
||
| public void expireOverdueTempAlbum() { | ||
| List<TempAlbum> tempAlbums = tempAlbumRepository.findAllExpiredToday(LocalDate.now()); | ||
| List<Long> tempAlbumIds = tempAlbums.stream().map(TempAlbum::getId).toList(); | ||
|
|
||
| s3Util.deleteAllTempAlbumImagesInBatch(tempAlbumIds); | ||
| tempAlbumImageRepository.deleteAllByTempAlbumIds(tempAlbumIds); | ||
| tempAlbumRepository.deleteAllInBatch(tempAlbums); | ||
| } | ||
|
ht3064 marked this conversation as resolved.
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.