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 @@ -6,7 +6,7 @@
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientThumbnailResponse;
import com.moplus.moplus_server.client.problem.dto.response.PublishClientGetResponse;
import com.moplus.moplus_server.client.problem.service.ProblemsGetService;
import com.moplus.moplus_server.client.problem.service.ClientProblemsGetService;
import com.moplus.moplus_server.global.annotation.AuthUser;
import com.moplus.moplus_server.member.domain.Member;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -25,7 +25,7 @@
@RequiredArgsConstructor
public class ProblemGetController {

private final ProblemsGetService problemsGetService;
private final ClientProblemsGetService clientProblemsGetService;

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

@GetMapping("problem/{publishId}")
Expand All @@ -43,7 +43,7 @@ public ResponseEntity<PublishClientGetResponse> getProblemsInPublish(
@PathVariable("publishId") Long publishId,
@AuthUser Member member
) {
return ResponseEntity.ok(problemsGetService.getProblemsInPublish(member.getId(), publishId));
return ResponseEntity.ok(clientProblemsGetService.getProblemsInPublish(member.getId(), publishId));
}

@GetMapping("problem/{publishId}/{problemId}")
Expand All @@ -53,7 +53,7 @@ public ResponseEntity<ProblemClientGetResponse> getProblem(
@PathVariable("problemId") Long problemId,
@AuthUser Member member
) {
return ResponseEntity.ok(problemsGetService.getProblem(member.getId(), publishId, problemId));
return ResponseEntity.ok(clientProblemsGetService.getProblem(member.getId(), publishId, problemId));
}

@GetMapping("problem/{publishId}/{problemId}/{childProblemId}")
Expand All @@ -65,7 +65,7 @@ public ResponseEntity<ChildProblemClientGetResponse> getChildProblem(
@AuthUser Member member
) {
return ResponseEntity.ok(
problemsGetService.getChildProblem(member.getId(), publishId, problemId, childProblemId));
clientProblemsGetService.getChildProblem(member.getId(), publishId, problemId, childProblemId));
}

@GetMapping("problem/thumbnail/{publishId}/{problemId}")
Expand All @@ -74,7 +74,7 @@ public ResponseEntity<ProblemClientThumbnailResponse> getProblemThumbnail(
@PathVariable Long publishId,
@PathVariable Long problemId
) {
return ResponseEntity.ok(problemsGetService.getProblemThumbnail(publishId, problemId));
return ResponseEntity.ok(clientProblemsGetService.getProblemThumbnail(publishId, problemId));
}

@GetMapping("problem/child/{publishId}/{problemId}")
Expand All @@ -83,6 +83,6 @@ public ResponseEntity<ChildProblemsClientGetResponse> getChildProblems(
@PathVariable Long publishId,
@PathVariable Long problemId
) {
return ResponseEntity.ok(problemsGetService.getChildProblems(publishId, problemId));
return ResponseEntity.ok(clientProblemsGetService.getChildProblems(publishId, problemId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.moplus.moplus_server.client.problem.dto.response.ChildProblemClientGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.ChildProblemsClientGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.ProblemFeedProgressesGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientThumbnailResponse;
import com.moplus.moplus_server.client.problem.dto.response.ProblemFeedProgressesGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.PublishClientGetResponse;
import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmit;
import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmitStatus;
Expand All @@ -29,14 +29,13 @@
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class ProblemsGetService {
public class ClientProblemsGetService {

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

List<ChildProblemSubmitStatus> childProblemStatuses = childProblemSubmitRepository.findAllByMemberIdAndPublishIdAndChildProblemIdIn(
memberId, publishId, childProblemIds).stream()
.map(ChildProblemSubmit::getStatus)
.toList();
List<ChildProblemSubmitStatus> childProblemStatuses = childProblemSubmitRepository
.findAllChildProblemSubmitStatusWithDefault(memberId, publishId, childProblemIds);

return ProblemClientGetResponse.of(problem, problemSubmit.getStatus(), childProblemStatuses, number + 1);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
package com.moplus.moplus_server.client.submit.repository;

import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmit;
import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmitStatus;
import com.moplus.moplus_server.global.error.exception.ErrorCode;
import com.moplus.moplus_server.global.error.exception.NotFoundException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ChildProblemSubmitRepository extends JpaRepository<ChildProblemSubmit, Long> {
Optional<ChildProblemSubmit> findByMemberIdAndPublishIdAndChildProblemId(Long memberId, Long publishId, Long childProblemId);
Optional<ChildProblemSubmit> findByMemberIdAndPublishIdAndChildProblemId(Long memberId, Long publishId,
Long childProblemId);

default ChildProblemSubmit findByMemberIdAndPublishIdAndChildProblemIdElseThrow(Long memberId, Long publishId, Long childProblemId) {
default ChildProblemSubmit findByMemberIdAndPublishIdAndChildProblemIdElseThrow(Long memberId, Long publishId,
Long childProblemId) {
return findByMemberIdAndPublishIdAndChildProblemId(memberId, publishId, childProblemId).orElseThrow(
() -> new NotFoundException(ErrorCode.CHILD_PROBLEM_SUBMIT_NOT_CONFIRMED));
}

List<ChildProblemSubmit> findAllByMemberIdAndPublishIdAndChildProblemIdIn(Long memberId, Long publishId,
List<Long> childProblemIds);
List<Long> childProblemIds);

default List<ChildProblemSubmitStatus> findAllChildProblemSubmitStatusWithDefault(Long memberId, Long publishId,
List<Long> childProblemIds) {
List<ChildProblemSubmit> submits = findAllByMemberIdAndPublishIdAndChildProblemIdIn(memberId, publishId,
childProblemIds);

// childProblemId를 key로 하는 Map 생성
Map<Long, ChildProblemSubmitStatus> statusMap = submits.stream()
.collect(Collectors.toMap(
ChildProblemSubmit::getChildProblemId,
ChildProblemSubmit::getStatus
));

// 모든 childProblemId에 대해 status 리스트 생성
return childProblemIds.stream()
.map(id -> statusMap.getOrDefault(id, ChildProblemSubmitStatus.NOT_STARTED))
.collect(Collectors.toList());
}
}