diff --git a/src/main/java/com/first/flash/climbing/problem/domain/Problem.java b/src/main/java/com/first/flash/climbing/problem/domain/Problem.java index f1a1bb06..148a0306 100644 --- a/src/main/java/com/first/flash/climbing/problem/domain/Problem.java +++ b/src/main/java/com/first/flash/climbing/problem/domain/Problem.java @@ -2,7 +2,6 @@ import com.first.flash.climbing.problem.domain.vo.DifficultyInfo; import jakarta.persistence.Column; -import jakarta.persistence.Convert; import jakarta.persistence.Entity; import jakarta.persistence.Id; import java.util.UUID; @@ -24,7 +23,6 @@ public class Problem { private static final Boolean DEFAULT_IS_EXPIRED = false; @Id - @Convert(converter = UUIDConverter.class) @Column(columnDefinition = "BINARY(16)") private UUID id; private String imageUrl; diff --git a/src/main/java/com/first/flash/climbing/problem/domain/QueryProblem.java b/src/main/java/com/first/flash/climbing/problem/domain/QueryProblem.java index 58e543fc..40e453db 100644 --- a/src/main/java/com/first/flash/climbing/problem/domain/QueryProblem.java +++ b/src/main/java/com/first/flash/climbing/problem/domain/QueryProblem.java @@ -1,7 +1,6 @@ package com.first.flash.climbing.problem.domain; import jakarta.persistence.Column; -import jakarta.persistence.Convert; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Index; @@ -35,7 +34,6 @@ public class QueryProblem { private static final int DIFFICULTY_LEVEL_WEIGHT = 2; @Id - @Convert(converter = UUIDConverter.class) @Column(columnDefinition = "BINARY(16)") private UUID id; private String imageUrl; 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/Solution.java b/src/main/java/com/first/flash/climbing/solution/domain/Solution.java index ac87272f..50ecb8cd 100644 --- a/src/main/java/com/first/flash/climbing/solution/domain/Solution.java +++ b/src/main/java/com/first/flash/climbing/solution/domain/Solution.java @@ -2,10 +2,12 @@ import com.first.flash.climbing.solution.domain.dto.SolutionCreateRequestDto; import com.first.flash.climbing.solution.domain.vo.SolutionDetail; +import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import java.util.UUID; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -23,10 +25,11 @@ public class Solution { private Long id; SolutionDetail solutionDetail; private Long optionalWeight; - private Long problemId; + @Column(columnDefinition = "BINARY(16)") + private UUID problemId; protected Solution(final String uploader, final String review, final String instagramId, - final String videoUrl, final Long problemId) { + final String videoUrl, final UUID problemId) { this.solutionDetail = SolutionDetail.of(uploader, review, instagramId, videoUrl); this.optionalWeight = DEFAULT_OPTIONAL_WEIGHT; @@ -34,7 +37,7 @@ protected Solution(final String uploader, final String review, final String inst } public static Solution of(final SolutionCreateRequestDto createRequestDto, - final Long problemId) { + final UUID problemId) { return new Solution(createRequestDto.uploader(), createRequestDto.review(), createRequestDto.instagramId(), createRequestDto.videoUrl(), problemId); 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/main/java/com/first/flash/climbing/problem/domain/UUIDConverter.java b/src/main/java/com/first/flash/global/converter/UUIDConverter.java similarity index 93% rename from src/main/java/com/first/flash/climbing/problem/domain/UUIDConverter.java rename to src/main/java/com/first/flash/global/converter/UUIDConverter.java index 1ae038ae..d33b66b6 100644 --- a/src/main/java/com/first/flash/climbing/problem/domain/UUIDConverter.java +++ b/src/main/java/com/first/flash/global/converter/UUIDConverter.java @@ -1,4 +1,4 @@ -package com.first.flash.climbing.problem.domain; +package com.first.flash.global.converter; import jakarta.persistence.AttributeConverter; import jakarta.persistence.Converter; @@ -6,7 +6,7 @@ import java.util.Objects; import java.util.UUID; -@Converter +@Converter(autoApply = true) public class UUIDConverter implements AttributeConverter { @Override 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..c726f859 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,14 @@ 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 + .fromString("0000-0000-0000-0000-0000"); private final static Long NON_EXISTENT_SOLUTION_ID = 999L; private SolutionRepository solutionRepository; @@ -87,4 +89,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..19240d83 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,13 @@ 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 + .fromString("0000-0000-0000-0000-0000"); final private Map db = new HashMap<>(); private Long id = 0L; @@ -32,9 +34,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(); } }