Skip to content

Commit ca7d2d7

Browse files
committed
refactor: Problem의 application 모듈 개편(ProblemService -> ProblemCommandService)
- syncProblem 으로 더 비즈니스 친화적 메서드명으로 개선
1 parent 4b6633f commit ca7d2d7

4 files changed

Lines changed: 29 additions & 30 deletions

File tree

module-application/src/main/java/com/mycodingtest/application/collector/BojIngestionService.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.mycodingtest.application.collector;
22

33
import com.mycodingtest.application.collector.dto.CreateProblemAndJudgmentCommand;
4-
import com.mycodingtest.application.judgment.query.JudgmentQueryService;
5-
import com.mycodingtest.domain.common.Platform;
6-
import com.mycodingtest.domain.problem.Problem;
7-
import com.mycodingtest.application.judgment.command.JudgmentCommandService;
84
import com.mycodingtest.application.judgment.command.CreateBojJudgmentCommand;
9-
import com.mycodingtest.application.problem.ProblemService;
10-
import com.mycodingtest.application.problem.dto.CreateProblemCommand;
5+
import com.mycodingtest.application.judgment.command.JudgmentCommandService;
6+
import com.mycodingtest.application.judgment.query.JudgmentQueryService;
7+
import com.mycodingtest.application.problem.command.ProblemCommandService;
8+
import com.mycodingtest.application.problem.command.SyncProblemCommand;
119
import com.mycodingtest.application.review.ReviewService;
1210
import com.mycodingtest.application.review.dto.CreateReviewCommand;
11+
import com.mycodingtest.domain.common.Platform;
1312
import lombok.RequiredArgsConstructor;
1413
import org.springframework.stereotype.Service;
1514
import org.springframework.transaction.annotation.Transactional;
@@ -26,7 +25,7 @@ public class BojIngestionService {
2625

2726
private final JudgmentCommandService judgmentCommandService;
2827
private final JudgmentQueryService judgmentQueryService;
29-
private final ProblemService problemService;
28+
private final ProblemCommandService problemCommandService;
3029
private final ReviewService reviewService;
3130

3231
/**
@@ -40,11 +39,11 @@ public class BojIngestionService {
4039
@Transactional
4140
public void ingest(CreateProblemAndJudgmentCommand command) {
4241
// 1. 문제 엔티티 확보
43-
Problem problem = problemService.getOrCreateProblem(CreateProblemCommand.from(command, Platform.BOJ));
42+
Long syncedProblemId = problemCommandService.syncProblem(SyncProblemCommand.from(command, Platform.BOJ));
4443
// 2. 채점 상세 기록 저장
45-
judgmentCommandService.createJudgmentFromBoj(CreateBojJudgmentCommand.from(command, problem.getId()));
44+
judgmentCommandService.createJudgmentFromBoj(CreateBojJudgmentCommand.from(command, syncedProblemId));
4645
// 3. 리뷰 오답 노트 생성
47-
reviewService.createReview(CreateReviewCommand.from(command, problem.getId()));
46+
reviewService.createReview(CreateReviewCommand.from(command, syncedProblemId));
4847
}
4948

5049
/**

module-application/src/main/java/com/mycodingtest/application/problem/ProblemService.java renamed to module-application/src/main/java/com/mycodingtest/application/problem/command/ProblemCommandService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
package com.mycodingtest.application.problem;
1+
package com.mycodingtest.application.problem.command;
22

3-
import com.mycodingtest.application.problem.dto.CreateProblemCommand;
43
import com.mycodingtest.domain.problem.Problem;
54
import com.mycodingtest.domain.problem.ProblemRepository;
65
import lombok.RequiredArgsConstructor;
76
import org.springframework.stereotype.Service;
87
import org.springframework.transaction.annotation.Transactional;
98

109
/**
11-
* <h3>문제 데이터 서비스 (ProblemService)</h3>
10+
* <h3>문제 데이터 서비스 (ProblemCommandService)</h3>
1211
* <p>
1312
* 플랫폼별 알고리즘 문제 정보를 관리합니다.
1413
* </p>
1514
*/
1615
@Service
1716
@RequiredArgsConstructor
18-
public class ProblemService {
17+
public class ProblemCommandService {
1918

2019
private final ProblemRepository problemRepository;
2120

@@ -27,13 +26,14 @@ public class ProblemService {
2726
* </p>
2827
*/
2928
@Transactional
30-
public Problem getOrCreateProblem(CreateProblemCommand command) {
29+
public Long syncProblem(SyncProblemCommand command) {
3130
return problemRepository.findProblemByproblemNumberAndPlatform(command.problemNumber(), command.platform())
3231
.orElseGet(() -> problemRepository.save(
3332
Problem.from(
3433
command.problemNumber(),
3534
command.problemTitle(),
36-
command.platform())));
35+
command.platform())))
36+
.getId();
3737
}
3838

3939
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.mycodingtest.application.problem.command;
2+
3+
import com.mycodingtest.application.collector.dto.CreateProblemAndJudgmentCommand;
4+
import com.mycodingtest.domain.common.Platform;
5+
6+
public record SyncProblemCommand(
7+
Integer problemNumber,
8+
String problemTitle,
9+
Platform platform
10+
) {
11+
public static SyncProblemCommand from(CreateProblemAndJudgmentCommand command, Platform platform) {
12+
return new SyncProblemCommand(command.problemNumber(), command.problemTitle(), platform);
13+
}
14+
}

module-application/src/main/java/com/mycodingtest/application/problem/dto/CreateProblemCommand.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)