Skip to content

Commit fc015c7

Browse files
committed
[hotfix] 새끼 문항 제출 안했으면 NOT_STARTED로 내려오기
1 parent d6cd898 commit fc015c7

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

src/main/java/com/moplus/moplus_server/client/problem/controller/ProblemGetController.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientGetResponse;
77
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientThumbnailResponse;
88
import com.moplus.moplus_server.client.problem.dto.response.PublishClientGetResponse;
9-
import com.moplus.moplus_server.client.problem.service.ProblemsGetService;
9+
import com.moplus.moplus_server.client.problem.service.ClientProblemsGetService;
1010
import com.moplus.moplus_server.global.annotation.AuthUser;
1111
import com.moplus.moplus_server.member.domain.Member;
1212
import io.swagger.v3.oas.annotations.Operation;
@@ -25,7 +25,7 @@
2525
@RequiredArgsConstructor
2626
public class ProblemGetController {
2727

28-
private final ProblemsGetService problemsGetService;
28+
private final ClientProblemsGetService clientProblemsGetService;
2929

3030
@GetMapping("problem/all/{year}/{month}")
3131
@Operation(summary = "전체 문제 조회", description = "월별 문제들에 대한 진행도와 정보들을 조회합니다.")
@@ -34,7 +34,7 @@ public ResponseEntity<List<AllProblemGetResponse>> getAllProblem(
3434
@PathVariable("month") int month,
3535
@AuthUser Member member
3636
) {
37-
return ResponseEntity.ok(problemsGetService.getAllProblem(member.getId(), year, month));
37+
return ResponseEntity.ok(clientProblemsGetService.getAllProblem(member.getId(), year, month));
3838
}
3939

4040
@GetMapping("problem/{publishId}")
@@ -43,7 +43,7 @@ public ResponseEntity<PublishClientGetResponse> getProblemsInPublish(
4343
@PathVariable("publishId") Long publishId,
4444
@AuthUser Member member
4545
) {
46-
return ResponseEntity.ok(problemsGetService.getProblemsInPublish(member.getId(), publishId));
46+
return ResponseEntity.ok(clientProblemsGetService.getProblemsInPublish(member.getId(), publishId));
4747
}
4848

4949
@GetMapping("problem/{publishId}/{problemId}")
@@ -53,7 +53,7 @@ public ResponseEntity<ProblemClientGetResponse> getProblem(
5353
@PathVariable("problemId") Long problemId,
5454
@AuthUser Member member
5555
) {
56-
return ResponseEntity.ok(problemsGetService.getProblem(member.getId(), publishId, problemId));
56+
return ResponseEntity.ok(clientProblemsGetService.getProblem(member.getId(), publishId, problemId));
5757
}
5858

5959
@GetMapping("problem/{publishId}/{problemId}/{childProblemId}")
@@ -65,7 +65,7 @@ public ResponseEntity<ChildProblemClientGetResponse> getChildProblem(
6565
@AuthUser Member member
6666
) {
6767
return ResponseEntity.ok(
68-
problemsGetService.getChildProblem(member.getId(), publishId, problemId, childProblemId));
68+
clientProblemsGetService.getChildProblem(member.getId(), publishId, problemId, childProblemId));
6969
}
7070

7171
@GetMapping("problem/thumbnail/{publishId}/{problemId}")
@@ -74,7 +74,7 @@ public ResponseEntity<ProblemClientThumbnailResponse> getProblemThumbnail(
7474
@PathVariable Long publishId,
7575
@PathVariable Long problemId
7676
) {
77-
return ResponseEntity.ok(problemsGetService.getProblemThumbnail(publishId, problemId));
77+
return ResponseEntity.ok(clientProblemsGetService.getProblemThumbnail(publishId, problemId));
7878
}
7979

8080
@GetMapping("problem/child/{publishId}/{problemId}")
@@ -83,6 +83,6 @@ public ResponseEntity<ChildProblemsClientGetResponse> getChildProblems(
8383
@PathVariable Long publishId,
8484
@PathVariable Long problemId
8585
) {
86-
return ResponseEntity.ok(problemsGetService.getChildProblems(publishId, problemId));
86+
return ResponseEntity.ok(clientProblemsGetService.getChildProblems(publishId, problemId));
8787
}
8888
}

src/main/java/com/moplus/moplus_server/client/problem/service/ProblemsGetService.java renamed to src/main/java/com/moplus/moplus_server/client/problem/service/ClientProblemsGetService.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import com.moplus.moplus_server.client.problem.dto.response.ChildProblemClientGetResponse;
77
import com.moplus.moplus_server.client.problem.dto.response.ChildProblemsClientGetResponse;
88
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientGetResponse;
9-
import com.moplus.moplus_server.client.problem.dto.response.ProblemFeedProgressesGetResponse;
109
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientThumbnailResponse;
10+
import com.moplus.moplus_server.client.problem.dto.response.ProblemFeedProgressesGetResponse;
1111
import com.moplus.moplus_server.client.problem.dto.response.PublishClientGetResponse;
1212
import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmit;
1313
import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmitStatus;
@@ -29,14 +29,13 @@
2929
import java.time.LocalDate;
3030
import java.util.ArrayList;
3131
import java.util.List;
32-
import java.util.stream.IntStream;
3332
import lombok.RequiredArgsConstructor;
3433
import org.springframework.stereotype.Service;
3534
import org.springframework.transaction.annotation.Transactional;
3635

3736
@Service
3837
@RequiredArgsConstructor
39-
public class ProblemsGetService {
38+
public class ClientProblemsGetService {
4039

4140
private static final int MIN_MONTH = 1;
4241
private static final int MAX_MONTH = 12;
@@ -134,10 +133,8 @@ public ProblemClientGetResponse getProblem(Long memberId, Long publishId, Long p
134133
.map(ChildProblem::getId)
135134
.toList();
136135

137-
List<ChildProblemSubmitStatus> childProblemStatuses = childProblemSubmitRepository.findAllByMemberIdAndPublishIdAndChildProblemIdIn(
138-
memberId, publishId, childProblemIds).stream()
139-
.map(ChildProblemSubmit::getStatus)
140-
.toList();
136+
List<ChildProblemSubmitStatus> childProblemStatuses = childProblemSubmitRepository
137+
.findAllChildProblemSubmitStatusWithDefault(memberId, publishId, childProblemIds);
141138

142139
return ProblemClientGetResponse.of(problem, problemSubmit.getStatus(), childProblemStatuses, number + 1);
143140
}
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
package com.moplus.moplus_server.client.submit.repository;
22

33
import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmit;
4+
import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmitStatus;
45
import com.moplus.moplus_server.global.error.exception.ErrorCode;
56
import com.moplus.moplus_server.global.error.exception.NotFoundException;
67
import java.util.List;
8+
import java.util.Map;
79
import java.util.Optional;
10+
import java.util.stream.Collectors;
811
import org.springframework.data.jpa.repository.JpaRepository;
912

1013
public interface ChildProblemSubmitRepository extends JpaRepository<ChildProblemSubmit, Long> {
11-
Optional<ChildProblemSubmit> findByMemberIdAndPublishIdAndChildProblemId(Long memberId, Long publishId, Long childProblemId);
14+
Optional<ChildProblemSubmit> findByMemberIdAndPublishIdAndChildProblemId(Long memberId, Long publishId,
15+
Long childProblemId);
1216

13-
default ChildProblemSubmit findByMemberIdAndPublishIdAndChildProblemIdElseThrow(Long memberId, Long publishId, Long childProblemId) {
17+
default ChildProblemSubmit findByMemberIdAndPublishIdAndChildProblemIdElseThrow(Long memberId, Long publishId,
18+
Long childProblemId) {
1419
return findByMemberIdAndPublishIdAndChildProblemId(memberId, publishId, childProblemId).orElseThrow(
1520
() -> new NotFoundException(ErrorCode.CHILD_PROBLEM_SUBMIT_NOT_CONFIRMED));
1621
}
1722

1823
List<ChildProblemSubmit> findAllByMemberIdAndPublishIdAndChildProblemIdIn(Long memberId, Long publishId,
19-
List<Long> childProblemIds);
24+
List<Long> childProblemIds);
25+
26+
default List<ChildProblemSubmitStatus> findAllChildProblemSubmitStatusWithDefault(Long memberId, Long publishId,
27+
List<Long> childProblemIds) {
28+
List<ChildProblemSubmit> submits = findAllByMemberIdAndPublishIdAndChildProblemIdIn(memberId, publishId,
29+
childProblemIds);
30+
31+
// childProblemId를 key로 하는 Map 생성
32+
Map<Long, ChildProblemSubmitStatus> statusMap = submits.stream()
33+
.collect(Collectors.toMap(
34+
ChildProblemSubmit::getChildProblemId,
35+
ChildProblemSubmit::getStatus
36+
));
37+
38+
// 모든 childProblemId에 대해 status 리스트 생성
39+
return childProblemIds.stream()
40+
.map(id -> statusMap.getOrDefault(id, ChildProblemSubmitStatus.NOT_STARTED))
41+
.collect(Collectors.toList());
42+
}
2043
}

0 commit comments

Comments
 (0)