Skip to content

Commit a81ec80

Browse files
committed
[fix/#94] 오늘 이후 발행은 조회 안되도록 수정
1 parent f39d543 commit a81ec80

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/main/java/com/moplus/moplus_server/client/submit/service/ClientGetService.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ public class ClientGetService {
4242
private final ChildProblemSubmitRepository childProblemSubmitRepository;
4343
private final ChildProblemRepository childProblemRepository;
4444

45-
4645
@Transactional(readOnly = true)
4746
public CommentaryGetResponse getCommentary(Long publishId, Long problemId) {
4847
Long memberId = 1L;
4948

49+
// 발행 조회
50+
Publish publish = publishRepository.findByIdElseThrow(publishId);
51+
denyAccessToFuturePublish(publish);
52+
5053
// 문항 제출 조회
5154
ProblemSubmit problemSubmit = problemSubmitRepository.findByMemberIdAndPublishIdAndProblemIdElseThrow(memberId,
5255
publishId, problemId);
@@ -93,7 +96,10 @@ public List<AllProblemGetResponse> getAllProblem(int year, int month) {
9396
LocalDate endDate = startDate.withDayOfMonth(startDate.lengthOfMonth());
9497

9598
// 해당 월 모든 Publish 조회
96-
List<Publish> publishes = publishRepository.findByPublishedDateBetween(startDate, endDate);
99+
// 오늘 이후 발행이 있다면 필터링
100+
List<Publish> publishes = publishRepository.findByPublishedDateBetween(startDate, endDate).stream()
101+
.filter(publish -> !publish.getPublishedDate().isAfter(LocalDate.now()))
102+
.toList();
97103

98104
List<AllProblemGetResponse> result = new ArrayList<>();
99105

@@ -104,7 +110,7 @@ public List<AllProblemGetResponse> getAllProblem(int year, int month) {
104110
// 날짜별 사용자 제출 정보 조회
105111
List<ProblemSubmit> submissions = problemSubmitRepository.findByMemberIdAndPublishId(memberId, publishId);
106112
List<ProblemSubmitStatus> problemStatuses = submissions.stream()
107-
.map(ProblemSubmit::getStatus)
113+
.map(ProblemSubmit::getStatus )
108114
.toList();
109115

110116
// 사용자 제출 정보 바탕으로 진행도 결정
@@ -128,6 +134,10 @@ private String getMainProblemImageUrl(Long problemSetId) {
128134
public ProblemClientGetResponse getProblem(Long publishId, Long problemId) {
129135
Long memberId = 1L;
130136

137+
// 발행 조회
138+
Publish publish = publishRepository.findByIdElseThrow(publishId);
139+
denyAccessToFuturePublish(publish);
140+
131141
// 문항조회
132142
Problem problem = problemRepository.findByIdElseThrow(problemId);
133143

@@ -152,6 +162,10 @@ public ProblemClientGetResponse getProblem(Long publishId, Long problemId) {
152162
public ChildProblemClientGetResponse getChildProblem(Long publishId, Long problemId, Long childProblemId) {
153163
Long memberId = 1L;
154164

165+
// 발행 조회
166+
Publish publish = publishRepository.findByIdElseThrow(publishId);
167+
denyAccessToFuturePublish(publish);
168+
155169
// 문항/새끼문항 조회
156170
Problem problem = problemRepository.findByIdElseThrow(problemId);
157171
ChildProblem childProblem = childProblemRepository.findByIdElseThrow(childProblemId);
@@ -170,4 +184,10 @@ public ChildProblemClientGetResponse getChildProblem(Long publishId, Long proble
170184

171185
return ChildProblemClientGetResponse.of(problem.getNumber(), sequence, childProblem.getImageUrl(), childProblemSubmit.getStatus());
172186
}
187+
188+
private void denyAccessToFuturePublish(Publish publish){
189+
if (publish.getPublishedDate().isAfter(LocalDate.now())) {
190+
throw new InvalidValueException(ErrorCode.FUTURE_PUBLISH_NOT_ACCESSIBLE);
191+
}
192+
}
173193
}

src/main/java/com/moplus/moplus_server/global/error/exception/ErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public enum ErrorCode {
7676
ALREADY_PUBLISHED_ERROR(HttpStatus.BAD_REQUEST, "이미 발행된 문항세트는 컨펌해제할 수 없습니다."),
7777
PROBLEM_SET_DELETED(HttpStatus.BAD_REQUEST, "삭제된 문항세트는 발행할 수 없습니다"),
7878
PROBLEM_SET_NOT_CONFIRMED(HttpStatus.BAD_REQUEST, "컨펌되지 않은 문항세트는 발행할 수 없습니다"),
79+
FUTURE_PUBLISH_NOT_ACCESSIBLE(HttpStatus.BAD_REQUEST, "오늘 이후의 발행을 조회할 수 없습니다."),
7980

8081
// 문항 제출
8182
PROBLEM_SUBMIT_NOT_CONFIRMED(HttpStatus.NOT_FOUND, "문항 제출 정보를 찾을 수 없습니다."),

0 commit comments

Comments
 (0)