Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import com.ject.studytrip.auth.presentation.dto.request.KakaoSignupRequest;
import com.ject.studytrip.auth.presentation.dto.request.LogoutRequest;
import com.ject.studytrip.member.application.dto.CreateMemberCommand;
import com.ject.studytrip.member.application.service.MemberService;
import com.ject.studytrip.member.application.service.MemberCommandService;
import com.ject.studytrip.member.application.service.MemberQueryService;
import com.ject.studytrip.member.domain.model.Member;
import com.ject.studytrip.member.domain.model.SocialProvider;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,12 +24,13 @@ public class AuthFacade {
private final KakaoLoginService kakaoLoginService;
private final KakaoSignupProfileService kakaoSignupProfileService;
private final TokenService tokenService;
private final MemberService memberService;
private final MemberQueryService memberQueryService;
private final MemberCommandService memberCommandService;

public OAuthLoginOutcome kakaoLogin(KakaoLoginRequest request, String origin) {
KakaoUserInfoResponse info = kakaoLoginService.getKakaoUserInfo(request.code(), origin);

return memberService
return memberQueryService
.getMemberBySocialProviderAndSocialId(SocialProvider.KAKAO, info.kakaoId())
// 가입되어 있는 사용자인 경우 토큰 발급
.map(
Expand All @@ -49,7 +51,7 @@ public TokenInfo kakaoSignup(String signupKey, KakaoSignupRequest request) {
request.nickname(),
request.category());

Member member = memberService.createMemberFromKakao(command);
Member member = memberCommandService.createMemberFromKakao(command);

kakaoSignupProfileService.deleteBySignupKey(signupKey);

Expand All @@ -58,7 +60,7 @@ public TokenInfo kakaoSignup(String signupKey, KakaoSignupRequest request) {

public TokenInfo reissueToken(String refreshToken) {
String memberId = tokenService.getMemberIdByRefreshToken(refreshToken);
String role = memberService.getRoleByMemberId(memberId);
String role = memberQueryService.getRoleByMemberId(memberId);

return tokenService.reissueToken(refreshToken, memberId, role);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
package com.ject.studytrip.cleanup.application.facade;

import com.ject.studytrip.cleanup.application.executor.HardDeleteExecutor;
import com.ject.studytrip.member.application.service.MemberService;
import com.ject.studytrip.mission.application.service.DailyMissionService;
import com.ject.studytrip.mission.application.service.MissionService;
import com.ject.studytrip.pomodoro.application.service.PomodoroService;
import com.ject.studytrip.stamp.application.service.StampService;
import com.ject.studytrip.studylog.application.service.StudyLogDailyMissionService;
import com.ject.studytrip.studylog.application.service.StudyLogService;
import com.ject.studytrip.trip.application.service.DailyGoalService;
import com.ject.studytrip.trip.application.service.TripService;
import com.ject.studytrip.member.application.service.MemberCommandService;
import com.ject.studytrip.mission.application.service.DailyMissionCommandService;
import com.ject.studytrip.mission.application.service.MissionCommandService;
import com.ject.studytrip.pomodoro.application.service.PomodoroCommandService;
import com.ject.studytrip.stamp.application.service.StampCommandService;
import com.ject.studytrip.studylog.application.service.StudyLogCommandService;
import com.ject.studytrip.studylog.application.service.StudyLogDailyMissionCommandService;
import com.ject.studytrip.trip.application.service.DailyGoalCommandService;
import com.ject.studytrip.trip.application.service.TripCommandService;
import java.util.LinkedHashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Component
@RequiredArgsConstructor
public class HardDeleteFacade {
private final PomodoroService pomodoroService;
private final StudyLogDailyMissionService studyLogDailyMissionService;
private final StudyLogService studyLogService;
private final DailyMissionService dailyMissionService;
private final MissionService missionService;
private final StampService stampService;
private final TripService tripService;
private final DailyGoalService dailyGoalService;
private final MemberService memberService;
private final MemberCommandService memberCommandService;
private final TripCommandService tripCommandService;
private final StampCommandService stampCommandService;
private final MissionCommandService missionCommandService;
private final StudyLogCommandService studyLogCommandService;
private final DailyMissionCommandService dailyMissionCommandService;
private final StudyLogDailyMissionCommandService studyLogDailyMissionCommandService;
private final DailyGoalCommandService dailyGoalCommandService;
private final PomodoroCommandService pomodoroCommandService;

private final HardDeleteExecutor executor;

Expand Down Expand Up @@ -59,6 +61,7 @@ public class HardDeleteFacade {
private static final String DAILY_GOALS = "dailyGoals";
private static final String MEMBERS = "members";

@Transactional(propagation = Propagation.REQUIRES_NEW)
public void hardDeleteAll() {
Map<String, Long> phases = new LinkedHashMap<>();

Expand All @@ -78,97 +81,101 @@ private void deletePomodoros(Map<String, Long> phases) {
POMODOROS_OWNED_BY_DELETED_DAILY_GOAL,
executor.run(
POMODOROS_OWNED_BY_DELETED_DAILY_GOAL,
pomodoroService::hardDeletePomodorosOwnedByDeletedDailyGoal));
phases.put(POMODOROS, executor.run(POMODOROS, pomodoroService::hardDeletePomodoros));
pomodoroCommandService::hardDeletePomodorosOwnedByDeletedDailyGoal));
phases.put(POMODOROS, executor.run(POMODOROS, pomodoroCommandService::hardDeletePomodoros));
}

private void deleteStudyLogDailyMissions(Map<String, Long> phases) {
phases.put(
STUDY_LOG_DAILY_MISSIONS_OWNED_BY_DELETED_DAILY_MISSION,
executor.run(
STUDY_LOG_DAILY_MISSIONS_OWNED_BY_DELETED_DAILY_MISSION,
studyLogDailyMissionService
studyLogDailyMissionCommandService
::hardDeleteStudyLogDailyMissionsOwnedByDeletedDailyMission));
phases.put(
STUDY_LOG_DAILY_MISSIONS_OWNED_BY_DELETED_STUDY_LOG,
executor.run(
STUDY_LOG_DAILY_MISSIONS_OWNED_BY_DELETED_STUDY_LOG,
studyLogDailyMissionService
studyLogDailyMissionCommandService
::hardDeleteStudyLogDailyMissionsOwnedByDeletedStudyLog));
phases.put(
STUDY_LOG_DAILY_MISSIONS,
executor.run(
STUDY_LOG_DAILY_MISSIONS,
studyLogDailyMissionService::hardDeleteStudyLogDailyMissions));
studyLogDailyMissionCommandService::hardDeleteStudyLogDailyMissions));
}

private void deleteDailyMissions(Map<String, Long> phases) {
phases.put(
DAILY_MISSIONS_OWNED_BY_DELETED_MISSION,
executor.run(
DAILY_MISSIONS_OWNED_BY_DELETED_MISSION,
dailyMissionService::hardDeleteDailyMissionsOwnedByDeletedMission));
dailyMissionCommandService::hardDeleteDailyMissionsOwnedByDeletedMission));
phases.put(
DAILY_MISSIONS_OWNED_BY_DELETED_DAILY_GOAL,
executor.run(
DAILY_MISSIONS_OWNED_BY_DELETED_DAILY_GOAL,
dailyMissionService::hardDeleteDailyMissionsOwnedByDeletedDailyGoal));
dailyMissionCommandService
::hardDeleteDailyMissionsOwnedByDeletedDailyGoal));
phases.put(
DAILY_MISSIONS,
executor.run(DAILY_MISSIONS, dailyMissionService::hardDeleteDailyMissions));
executor.run(DAILY_MISSIONS, dailyMissionCommandService::hardDeleteDailyMissions));
}

private void deleteStudyLogs(Map<String, Long> phases) {
phases.put(
STUDY_LOGS_OWNED_BY_DELETED_MEMBER,
executor.run(
STUDY_LOGS_OWNED_BY_DELETED_MEMBER,
studyLogService::hardDeleteStudyLogsOwnedByDeletedMember));
studyLogCommandService::hardDeleteStudyLogsOwnedByDeletedMember));
phases.put(
STUDY_LOGS_OWNED_BY_DELETED_DAILY_GOAL,
executor.run(
STUDY_LOGS_OWNED_BY_DELETED_DAILY_GOAL,
studyLogService::hardDeleteStudyLogsOwnedByDeletedDailyGoal));
phases.put(STUDY_LOGS, executor.run(STUDY_LOGS, studyLogService::hardDeleteStudyLogs));
studyLogCommandService::hardDeleteStudyLogsOwnedByDeletedDailyGoal));
phases.put(
STUDY_LOGS, executor.run(STUDY_LOGS, studyLogCommandService::hardDeleteStudyLogs));
}

private void deleteDailyGoals(Map<String, Long> phases) {
phases.put(
DAILY_GOALS_OWNED_BY_DELETED_TRIP,
executor.run(
DAILY_GOALS_OWNED_BY_DELETED_TRIP,
dailyGoalService::hardDeleteDailyGoalsOwnedByDeletedTrip));
phases.put(DAILY_GOALS, executor.run(DAILY_GOALS, dailyGoalService::hardDeleteDailyGoals));
dailyGoalCommandService::hardDeleteDailyGoalsOwnedByDeletedTrip));
phases.put(
DAILY_GOALS,
executor.run(DAILY_GOALS, dailyGoalCommandService::hardDeleteDailyGoals));
}

private void deleteMissions(Map<String, Long> phases) {
phases.put(
MISSIONS_OWNED_BY_DELETED_STAMP,
executor.run(
MISSIONS_OWNED_BY_DELETED_STAMP,
missionService::hardDeleteMissionsOwnedByDeletedStamp));
phases.put(MISSIONS, executor.run(MISSIONS, missionService::hardDeleteMissions));
missionCommandService::hardDeleteMissionsOwnedByDeletedStamp));
phases.put(MISSIONS, executor.run(MISSIONS, missionCommandService::hardDeleteMissions));
}

private void deleteStamps(Map<String, Long> phases) {
phases.put(
STAMPS_OWNED_BY_DELETED_TRIP,
executor.run(
STAMPS_OWNED_BY_DELETED_TRIP,
stampService::hardDeleteStampsOwnedByDeletedTrip));
phases.put(STAMPS, executor.run(STAMPS, stampService::hardDeleteStamps));
stampCommandService::hardDeleteStampsOwnedByDeletedTrip));
phases.put(STAMPS, executor.run(STAMPS, stampCommandService::hardDeleteStamps));
}

private void deleteTrips(Map<String, Long> phases) {
phases.put(
TRIPS_OWNED_BY_DELETED_MEMBER,
executor.run(
TRIPS_OWNED_BY_DELETED_MEMBER,
tripService::hardDeleteTripsOwnedByDeletedMember));
phases.put(TRIPS, executor.run(TRIPS, tripService::hardDeleteTrips));
tripCommandService::hardDeleteTripsOwnedByDeletedMember));
phases.put(TRIPS, executor.run(TRIPS, tripCommandService::hardDeleteTrips));
}

private void deleteMembers(Map<String, Long> phases) {
phases.put(MEMBERS, executor.run(MEMBERS, memberService::hardDeleteMembers));
phases.put(MEMBERS, executor.run(MEMBERS, memberCommandService::hardDeleteMembers));
}
}
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);
}
}
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;
}
}
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";
}
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 src/main/java/com/ject/studytrip/global/config/BatchJobConfig.java
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;
};
}
}
Loading