diff --git a/src/main/java/com/first/flash/climbing/solution/application/SolutionService.java b/src/main/java/com/first/flash/climbing/solution/application/SolutionService.java index 9bdb9bf7..02331053 100644 --- a/src/main/java/com/first/flash/climbing/solution/application/SolutionService.java +++ b/src/main/java/com/first/flash/climbing/solution/application/SolutionService.java @@ -8,6 +8,7 @@ import com.first.flash.climbing.solution.domain.dto.SolutionCreateRequestDto; import com.first.flash.climbing.solution.exception.exceptions.SolutionNotFoundException; import java.util.List; +import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,7 +21,7 @@ public class SolutionService { private final SolutionRepository solutionRepository; @Transactional - public SolutionResponseDto saveSolution(final Long problemId, + public SolutionResponseDto saveSolution(final UUID problemId, final SolutionCreateRequestDto createRequestDto) { Solution solution = Solution.of(createRequestDto, problemId); return SolutionResponseDto.toDto(solutionRepository.save(solution)); @@ -28,14 +29,14 @@ public SolutionResponseDto saveSolution(final Long problemId, public Solution findSolutionById(final Long id) { return solutionRepository.findById(id) - .orElseThrow(() -> new SolutionNotFoundException(id)); + .orElseThrow(() -> new SolutionNotFoundException(id)); } - public SolutionsResponseDto findAllSolutionsByProblemId(final Long problemId) { + public SolutionsResponseDto findAllSolutionsByProblemId(final UUID problemId) { List solutions = solutionRepository.findAllByProblemId(problemId) - .stream() - .map(SolutionResponseDto::toDto) - .toList(); + .stream() + .map(SolutionResponseDto::toDto) + .toList(); return new SolutionsResponseDto(solutions, new SolutionMetaResponseDto(solutions.size())); } } diff --git a/src/main/java/com/first/flash/climbing/solution/domain/SolutionRepository.java b/src/main/java/com/first/flash/climbing/solution/domain/SolutionRepository.java index c1db605d..92be91f9 100644 --- a/src/main/java/com/first/flash/climbing/solution/domain/SolutionRepository.java +++ b/src/main/java/com/first/flash/climbing/solution/domain/SolutionRepository.java @@ -2,6 +2,7 @@ import java.util.List; import java.util.Optional; +import java.util.UUID; public interface SolutionRepository { @@ -9,5 +10,5 @@ public interface SolutionRepository { Optional findById(final Long id); - List findAllByProblemId(final Long problemId); + List findAllByProblemId(final UUID problemId); } diff --git a/src/main/java/com/first/flash/climbing/solution/infrastructure/SolutionJpaRepository.java b/src/main/java/com/first/flash/climbing/solution/infrastructure/SolutionJpaRepository.java index 2c2be023..cd1c4764 100644 --- a/src/main/java/com/first/flash/climbing/solution/infrastructure/SolutionJpaRepository.java +++ b/src/main/java/com/first/flash/climbing/solution/infrastructure/SolutionJpaRepository.java @@ -3,6 +3,7 @@ import com.first.flash.climbing.solution.domain.Solution; import java.util.List; import java.util.Optional; +import java.util.UUID; import org.springframework.data.jpa.repository.JpaRepository; public interface SolutionJpaRepository extends JpaRepository { @@ -11,5 +12,5 @@ public interface SolutionJpaRepository extends JpaRepository { Optional findById(final Long id); - List findByProblemId(final Long problemId); + List findByProblemId(final UUID problemId); } diff --git a/src/main/java/com/first/flash/climbing/solution/infrastructure/SolutionRepositoryImpl.java b/src/main/java/com/first/flash/climbing/solution/infrastructure/SolutionRepositoryImpl.java index d3b8b676..6d12dc24 100644 --- a/src/main/java/com/first/flash/climbing/solution/infrastructure/SolutionRepositoryImpl.java +++ b/src/main/java/com/first/flash/climbing/solution/infrastructure/SolutionRepositoryImpl.java @@ -4,6 +4,7 @@ import com.first.flash.climbing.solution.domain.SolutionRepository; import java.util.List; import java.util.Optional; +import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -24,7 +25,7 @@ public Optional findById(final Long id) { } @Override - public List findAllByProblemId(final Long problemId) { + public List findAllByProblemId(final UUID problemId) { return solutionJpaRepository.findByProblemId(problemId); } } diff --git a/src/main/java/com/first/flash/climbing/solution/ui/SolutionController.java b/src/main/java/com/first/flash/climbing/solution/ui/SolutionController.java index 543dbecc..b99cb1ff 100644 --- a/src/main/java/com/first/flash/climbing/solution/ui/SolutionController.java +++ b/src/main/java/com/first/flash/climbing/solution/ui/SolutionController.java @@ -8,6 +8,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -32,7 +33,7 @@ public class SolutionController { @ApiResponse(responseCode = "404", description = "해설을 찾을 수 없음") }) @GetMapping("problems/{problemId}/solutions") - public ResponseEntity getSolutions(@PathVariable final Long problemId) { + public ResponseEntity getSolutions(@PathVariable final UUID problemId) { SolutionsResponseDto response = solutionService.findAllSolutionsByProblemId( problemId); @@ -44,10 +45,11 @@ public ResponseEntity getSolutions(@PathVariable final Lon @ApiResponse(responseCode = "201", description = "성공적으로 해설 영상을 업로드함") }) @PostMapping("problems/{problemId}/solutions") - public ResponseEntity createSolution(@PathVariable final Long problemId, + public ResponseEntity createSolution(@PathVariable final UUID problemId, @RequestBody final SolutionCreateRequestDto solutionCreateRequestDto) { return ResponseEntity.status(HttpStatus.CREATED) - .body(solutionService.saveSolution(problemId, solutionCreateRequestDto)); + .body( + solutionService.saveSolution(problemId, solutionCreateRequestDto)); } } diff --git a/src/test/java/com/first/flash/climbing/solution/application/SolutionServiceTest.java b/src/test/java/com/first/flash/climbing/solution/application/SolutionServiceTest.java index d864419d..89a85334 100644 --- a/src/test/java/com/first/flash/climbing/solution/application/SolutionServiceTest.java +++ b/src/test/java/com/first/flash/climbing/solution/application/SolutionServiceTest.java @@ -11,12 +11,13 @@ import com.first.flash.climbing.solution.domain.dto.SolutionCreateRequestDto; import com.first.flash.climbing.solution.exception.exceptions.SolutionNotFoundException; import com.first.flash.climbing.solution.infrastructure.FakeSolutionRepository; +import java.util.UUID; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class SolutionServiceTest { - private final static Long DEFAULT_PROBLEM_ID = 1L; + private final static UUID DEFAULT_PROBLEM_ID = UUID.randomUUID(); private final static Long NON_EXISTENT_SOLUTION_ID = 999L; private SolutionRepository solutionRepository; @@ -87,4 +88,4 @@ void init() { softly.assertThat(solutionsResponse.meta().count()).isEqualTo(2); }); } -} \ No newline at end of file +} diff --git a/src/test/java/com/first/flash/climbing/solution/infrastructure/FakeSolutionRepository.java b/src/test/java/com/first/flash/climbing/solution/infrastructure/FakeSolutionRepository.java index ed171fc6..fddd470c 100644 --- a/src/test/java/com/first/flash/climbing/solution/infrastructure/FakeSolutionRepository.java +++ b/src/test/java/com/first/flash/climbing/solution/infrastructure/FakeSolutionRepository.java @@ -6,11 +6,12 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.UUID; public class FakeSolutionRepository implements SolutionRepository { private final static Long DEFAULT_OPTIONAL_WEIGHT = 0L; - private final static Long DEFAULT_PROBLEM_ID = 1L; + private final static UUID DEFAULT_PROBLEM_ID = UUID.randomUUID(); final private Map db = new HashMap<>(); private Long id = 0L; @@ -32,9 +33,9 @@ public Optional findById(Long id) { } @Override - public List findAllByProblemId(Long problemId) { + public List findAllByProblemId(final UUID problemId) { return db.values().stream() - .filter(solution -> solution.getProblemId().equals(problemId)) - .toList(); + .filter(solution -> solution.getProblemId().equals(problemId)) + .toList(); } }