-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: Service 클래스에 CQRS 패턴 및 Redis 적용(#75) #77
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/ject/studytrip/global/batch/scheduler/BatchJobScheduler.java
This file contains hidden or 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,29 @@ | ||
| package com.ject.studytrip.global.batch.scheduler; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.batch.core.Job; | ||
| import org.springframework.batch.core.JobParameters; | ||
| import org.springframework.batch.core.JobParametersBuilder; | ||
| import org.springframework.batch.core.launch.JobLauncher; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Profile("!test") | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class BatchJobScheduler { | ||
| private final JobLauncher jobLauncher; | ||
| private final Job hardDeleteJob; | ||
|
|
||
| // 매일 04:00 (Asia/Seoul) | ||
| @Scheduled(cron = "0 0 4 * * *", zone = "Asia/Seoul") | ||
| public void runHardDeleteJob() throws Exception { | ||
| JobParameters jobParameters = | ||
| new JobParametersBuilder() | ||
| .addLong("ts", System.currentTimeMillis()) | ||
| .toJobParameters(); | ||
|
|
||
| jobLauncher.run(hardDeleteJob, jobParameters); | ||
| } | ||
| } | ||
23 changes: 23 additions & 0 deletions
23
src/main/java/com/ject/studytrip/global/batch/tasklet/HardDeleteTasklet.java
This file contains hidden or 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,23 @@ | ||
| package com.ject.studytrip.global.batch.tasklet; | ||
|
|
||
| import com.ject.studytrip.cleanup.application.facade.HardDeleteFacade; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.batch.core.StepContribution; | ||
| import org.springframework.batch.core.scope.context.ChunkContext; | ||
| import org.springframework.batch.core.step.tasklet.Tasklet; | ||
| import org.springframework.batch.repeat.RepeatStatus; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class HardDeleteTasklet implements Tasklet { | ||
| private final HardDeleteFacade hardDeleteFacade; | ||
|
|
||
| @Override | ||
| public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) | ||
| throws Exception { | ||
| hardDeleteFacade.hardDeleteAll(); | ||
|
|
||
| return RepeatStatus.FINISHED; | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/ject/studytrip/global/common/constants/CacheNameConstants.java
This file contains hidden or 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,15 @@ | ||
| package com.ject.studytrip.global.common.constants; | ||
|
|
||
| public final class CacheNameConstants { | ||
|
|
||
| private CacheNameConstants() {} | ||
|
|
||
| public static final String MEMBER = "member"; | ||
| public static final String TRIP = "trip"; | ||
| public static final String TRIPS = "trips"; | ||
| public static final String STAMP = "stamp"; | ||
| public static final String STAMPS = "stamps"; | ||
| public static final String MISSIONS = "missions"; | ||
| public static final String DAILY_GOAL = "dailyGoal"; | ||
| public static final String STUDY_LOGS = "studyLogs"; | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/ject/studytrip/global/common/factory/CacheKeyFactory.java
This file contains hidden or 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,39 @@ | ||
| package com.ject.studytrip.global.common.factory; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class CacheKeyFactory { | ||
| public static String member(Long memberId) { | ||
| return "member:" + memberId; | ||
| } | ||
|
|
||
| public static String trips(Long memberId, int page, int size) { | ||
| return "member:" + memberId + ":page:" + page + ":size:" + size; | ||
| } | ||
|
|
||
| public static String trip(Long memberId, Long tripId) { | ||
| return "member:" + memberId + ":trip:" + tripId; | ||
| } | ||
|
|
||
| public static String stamps(Long memberId, Long tripId) { | ||
| return "member:" + memberId + ":trip:" + tripId; | ||
| } | ||
|
|
||
| public static String stamp(Long memberId, Long tripId, Long stampId) { | ||
| return "member:" + memberId + ":trip:" + tripId + ":stamp:" + stampId; | ||
| } | ||
|
|
||
| public static String missions(Long memberId, Long tripId, Long stampId) { | ||
| return "member:" + memberId + ":trip:" + tripId + ":stamp:" + stampId; | ||
| } | ||
|
|
||
| public static String dailyGoal(Long memberId, Long tripId, Long dailyGoalId) { | ||
| return "member:" + memberId + ":trip:" + tripId + ":dailyGoal:" + dailyGoalId; | ||
| } | ||
|
|
||
| public static String studyLogs(Long memberId, Long tripId, int page, int size) { | ||
| return "member:" + memberId + ":trip:" + tripId + ":page:" + page + ":size:" + size; | ||
| } | ||
| } |
27 changes: 2 additions & 25 deletions
27
src/main/java/com/ject/studytrip/global/config/BatchJobConfig.java
This file contains hidden or 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,49 +1,26 @@ | ||
| package com.ject.studytrip.global.config; | ||
|
|
||
| import com.ject.studytrip.cleanup.application.facade.HardDeleteFacade; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.batch.core.Job; | ||
| import org.springframework.batch.core.Step; | ||
| import org.springframework.batch.core.job.builder.JobBuilder; | ||
| import org.springframework.batch.core.launch.support.RunIdIncrementer; | ||
| import org.springframework.batch.core.repository.JobRepository; | ||
| import org.springframework.batch.core.step.builder.StepBuilder; | ||
| import org.springframework.batch.core.step.tasklet.Tasklet; | ||
| import org.springframework.batch.repeat.RepeatStatus; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.transaction.PlatformTransactionManager; | ||
|
|
||
| @Configuration | ||
| @RequiredArgsConstructor | ||
| public class BatchJobConfig { | ||
| private final JobRepository jobRepository; | ||
| private final HardDeleteFacade hardDeleteFacade; | ||
| private final PlatformTransactionManager transactionManager; | ||
| private final Step hardDeleteStep; | ||
|
|
||
| private static final String HARD_DELETE_JOB_NAME = "hardDeleteJob"; | ||
| private static final String HARD_DELETE_STEP_NAME = "hardDeleteStep"; | ||
|
|
||
| @Bean | ||
| public Job hardDeleteJob(Step hardDeleteStep) { | ||
| public Job hardDeleteJob(JobRepository jobRepository) { | ||
| return new JobBuilder(HARD_DELETE_JOB_NAME, jobRepository) | ||
| .incrementer(new RunIdIncrementer()) | ||
| .start(hardDeleteStep) | ||
| .build(); | ||
| } | ||
|
|
||
| @Bean | ||
| public Step hardDeleteStep(Tasklet hardDeleteTasklet) { | ||
| return new StepBuilder(HARD_DELETE_STEP_NAME, jobRepository) | ||
| .tasklet(hardDeleteTasklet, transactionManager) | ||
| .build(); | ||
| } | ||
|
|
||
| @Bean | ||
| public Tasklet hardDeleteTasklet() { | ||
| return (contribution, chunkContext) -> { | ||
| hardDeleteFacade.hardDeleteAll(); | ||
| return RepeatStatus.FINISHED; | ||
| }; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.