From ac82c1c5f7b26cf4b584173347cd9e0b57093793 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Sat, 12 Aug 2023 18:05:30 +0900 Subject: [PATCH 001/119] =?UTF-8?q?[refactor]=20MemberRepository=20Id?= =?UTF-8?q?=EB=A1=9C=20=ED=9A=8C=EC=9B=90=20=EC=A1=B0=ED=9A=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/application/MemberService.java | 6 +---- .../dev/tripdraw/application/PostService.java | 20 +++++--------- .../dev/tripdraw/application/TripService.java | 23 ++++++---------- .../domain/member/MemberRepository.java | 10 +++++++ .../domain/member/MemberRepositoryTest.java | 27 +++++++++++++++++++ 5 files changed, 52 insertions(+), 34 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/application/MemberService.java b/backend/src/main/java/dev/tripdraw/application/MemberService.java index 5bdbfcfe0..93d98db0d 100644 --- a/backend/src/main/java/dev/tripdraw/application/MemberService.java +++ b/backend/src/main/java/dev/tripdraw/application/MemberService.java @@ -1,14 +1,11 @@ package dev.tripdraw.application; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; - import dev.tripdraw.application.oauth.AuthTokenManager; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; import dev.tripdraw.domain.post.PostRepository; import dev.tripdraw.domain.trip.TripRepository; import dev.tripdraw.dto.member.MemberSearchResponse; -import dev.tripdraw.exception.member.MemberException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -41,8 +38,7 @@ public boolean existsById(Long memberId) { @Transactional(readOnly = true) public MemberSearchResponse findByCode(String code) { Long memberId = authTokenManager.extractMemberId(code); - Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); + Member member = memberRepository.getById(memberId); return MemberSearchResponse.from(member); } diff --git a/backend/src/main/java/dev/tripdraw/application/PostService.java b/backend/src/main/java/dev/tripdraw/application/PostService.java index 39d4376ef..bb685f5a9 100644 --- a/backend/src/main/java/dev/tripdraw/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/application/PostService.java @@ -1,7 +1,6 @@ package dev.tripdraw.application; import static dev.tripdraw.domain.file.FileType.POST_IMAGE; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUNT; import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; @@ -22,7 +21,6 @@ import dev.tripdraw.dto.post.PostResponse; import dev.tripdraw.dto.post.PostUpdateRequest; import dev.tripdraw.dto.post.PostsResponse; -import dev.tripdraw.exception.member.MemberException; import dev.tripdraw.exception.post.PostException; import dev.tripdraw.exception.trip.TripException; import java.util.List; @@ -59,7 +57,7 @@ public PostCreateResponse addAtCurrentPoint( PostAndPointCreateRequest postAndPointCreateRequest, MultipartFile file ) { - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = findValidatedTripById(postAndPointCreateRequest.tripId(), member); Point point = postAndPointCreateRequest.toPoint(); @@ -89,7 +87,7 @@ public PostCreateResponse addAtExistingLocation( PostRequest postRequest, MultipartFile file ) { - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = findValidatedTripById(postRequest.tripId(), member); Point point = trip.findPointById(postRequest.pointId()); @@ -105,13 +103,13 @@ public PostCreateResponse addAtExistingLocation( public PostResponse read(LoginUser loginUser, Long postId) { Post post = findPostById(postId); - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); return PostResponse.from(post); } public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); findValidatedTripById(tripId, member); List posts = postRepository.findAllByTripId(tripId); @@ -120,7 +118,7 @@ public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdateRequest, MultipartFile file) { Post post = findPostById(postId); - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); post.changeTitle(postUpdateRequest.title()); @@ -130,7 +128,7 @@ public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdat public void delete(LoginUser loginUser, Long postId) { Post post = findPostById(postId); - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); postRepository.deleteById(postId); @@ -145,18 +143,12 @@ private void updateFileOfPost(MultipartFile file, Post post) { } private Trip findValidatedTripById(Long tripId, Member member) { - Trip trip = tripRepository.findById(tripId) .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); trip.validateAuthorization(member); return trip; } - private Member findMemberById(Long memberId) { - return memberRepository.findById(memberId) - .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); - } - private Post findPostById(Long postId) { return postRepository.findById(postId) .orElseThrow(() -> new PostException(POST_NOT_FOUNT)); diff --git a/backend/src/main/java/dev/tripdraw/application/TripService.java b/backend/src/main/java/dev/tripdraw/application/TripService.java index 96ee7706a..546d9fa83 100644 --- a/backend/src/main/java/dev/tripdraw/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/application/TripService.java @@ -1,6 +1,5 @@ package dev.tripdraw.application; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; import dev.tripdraw.application.draw.RouteImageGenerator; @@ -17,7 +16,6 @@ import dev.tripdraw.dto.trip.TripResponse; import dev.tripdraw.dto.trip.TripUpdateRequest; import dev.tripdraw.dto.trip.TripsSearchResponse; -import dev.tripdraw.exception.member.MemberException; import dev.tripdraw.exception.trip.TripException; import java.util.List; import org.springframework.stereotype.Service; @@ -42,14 +40,14 @@ public TripService( } public TripCreateResponse create(LoginUser loginUser) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = Trip.from(member); Trip savedTrip = tripRepository.save(trip); return TripCreateResponse.from(savedTrip); } public PointCreateResponse addPoint(LoginUser loginUser, PointCreateRequest pointCreateRequest) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(pointCreateRequest.tripId()); Point point = pointCreateRequest.toPoint(); @@ -61,7 +59,7 @@ public PointCreateResponse addPoint(LoginUser loginUser, PointCreateRequest poin } public void deletePoint(LoginUser loginUser, Long pointId, Long tripId) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(tripId); trip.validateAuthorization(member); @@ -69,11 +67,6 @@ public void deletePoint(LoginUser loginUser, Long pointId, Long tripId) { trip.deletePointById(pointId); } - private Member getById(Long memberId) { - return memberRepository.findById(memberId) - .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); - } - private Trip getByTripId(Long tripId) { return tripRepository.findById(tripId) .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); @@ -81,7 +74,7 @@ private Trip getByTripId(Long tripId) { @Transactional(readOnly = true) public TripResponse readTripById(LoginUser loginUser, Long id) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(id); trip.validateAuthorization(member); return TripResponse.from(trip); @@ -89,13 +82,13 @@ public TripResponse readTripById(LoginUser loginUser, Long id) { @Transactional(readOnly = true) public TripsSearchResponse readAllTrips(LoginUser loginUser) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); List trips = tripRepository.findAllByMemberId(member.id()); return TripsSearchResponse.from(trips); } public void updateTripById(LoginUser loginUser, Long tripId, TripUpdateRequest tripUpdateRequest) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(tripId); trip.validateAuthorization(member); @@ -116,7 +109,7 @@ private String generateRouteImage(Trip trip) { @Transactional(readOnly = true) public PointResponse readPointByTripAndPointId(LoginUser loginUser, Long tripId, Long pointId) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(tripId); trip.validateAuthorization(member); @@ -125,7 +118,7 @@ public PointResponse readPointByTripAndPointId(LoginUser loginUser, Long tripId, } public void delete(LoginUser loginUser, Long tripId) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(tripId); trip.validateAuthorization(member); diff --git a/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java b/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java index 4397dc932..36f880a49 100644 --- a/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java +++ b/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java @@ -1,10 +1,20 @@ package dev.tripdraw.domain.member; +import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; + import dev.tripdraw.domain.oauth.OauthType; +import dev.tripdraw.exception.member.MemberException; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.lang.NonNull; public interface MemberRepository extends JpaRepository { Optional findByOauthIdAndOauthType(String oauthId, OauthType oauthType); + + @NonNull + default Member getById(@NonNull Long id) { + return findById(id) + .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); + } } diff --git a/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java index 944f465a8..dc713c6c4 100644 --- a/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java @@ -1,8 +1,12 @@ package dev.tripdraw.domain.member; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; +import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import dev.tripdraw.exception.member.MemberException; import java.util.Optional; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -39,4 +43,27 @@ class MemberRepositoryTest { // expect assertThat(foundMember).isEmpty(); } + + @Test + void 회원_ID로_회원을_조회한다() { + // given + Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + + // when + Member foundMember = memberRepository.getById(member.id()); + + // then + assertThat(foundMember).isEqualTo(member); + } + + @Test + void 회원_ID로_회원을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { + // given + Long memberId = MIN_VALUE; + + // expect + assertThatThrownBy(() -> memberRepository.getById(memberId)) + .isInstanceOf(MemberException.class) + .hasMessage(MEMBER_NOT_FOUND.getMessage()); + } } From 5a3b052a1850127887a7dea53cd2e8ebcef010cb Mon Sep 17 00:00:00 2001 From: Combi153 Date: Sat, 12 Aug 2023 18:21:08 +0900 Subject: [PATCH 002/119] =?UTF-8?q?[refactor]=20TripRepository=20Id?= =?UTF-8?q?=EB=A1=9C=20=EC=97=AC=ED=96=89=20=EC=A1=B0=ED=9A=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/application/PostService.java | 5 +--- .../dev/tripdraw/application/TripService.java | 20 +++++--------- .../tripdraw/domain/trip/TripRepository.java | 8 ++++++ .../domain/trip/TripRepositoryTest.java | 27 +++++++++++++++++++ 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/application/PostService.java b/backend/src/main/java/dev/tripdraw/application/PostService.java index bb685f5a9..496bbad2b 100644 --- a/backend/src/main/java/dev/tripdraw/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/application/PostService.java @@ -2,7 +2,6 @@ import static dev.tripdraw.domain.file.FileType.POST_IMAGE; import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUNT; -import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; import dev.tripdraw.application.draw.RouteImageGenerator; import dev.tripdraw.application.file.FileUploader; @@ -22,7 +21,6 @@ import dev.tripdraw.dto.post.PostUpdateRequest; import dev.tripdraw.dto.post.PostsResponse; import dev.tripdraw.exception.post.PostException; -import dev.tripdraw.exception.trip.TripException; import java.util.List; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -143,8 +141,7 @@ private void updateFileOfPost(MultipartFile file, Post post) { } private Trip findValidatedTripById(Long tripId, Member member) { - Trip trip = tripRepository.findById(tripId) - .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); + Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); return trip; } diff --git a/backend/src/main/java/dev/tripdraw/application/TripService.java b/backend/src/main/java/dev/tripdraw/application/TripService.java index 546d9fa83..f73807705 100644 --- a/backend/src/main/java/dev/tripdraw/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/application/TripService.java @@ -1,7 +1,5 @@ package dev.tripdraw.application; -import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; - import dev.tripdraw.application.draw.RouteImageGenerator; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; @@ -16,7 +14,6 @@ import dev.tripdraw.dto.trip.TripResponse; import dev.tripdraw.dto.trip.TripUpdateRequest; import dev.tripdraw.dto.trip.TripsSearchResponse; -import dev.tripdraw.exception.trip.TripException; import java.util.List; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -48,7 +45,7 @@ public TripCreateResponse create(LoginUser loginUser) { public PointCreateResponse addPoint(LoginUser loginUser, PointCreateRequest pointCreateRequest) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(pointCreateRequest.tripId()); + Trip trip = tripRepository.getById(pointCreateRequest.tripId()); Point point = pointCreateRequest.toPoint(); trip.validateAuthorization(member); @@ -61,21 +58,16 @@ public PointCreateResponse addPoint(LoginUser loginUser, PointCreateRequest poin public void deletePoint(LoginUser loginUser, Long pointId, Long tripId) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(tripId); + Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); trip.deletePointById(pointId); } - private Trip getByTripId(Long tripId) { - return tripRepository.findById(tripId) - .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); - } - @Transactional(readOnly = true) public TripResponse readTripById(LoginUser loginUser, Long id) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(id); + Trip trip = tripRepository.getById(id); trip.validateAuthorization(member); return TripResponse.from(trip); } @@ -89,7 +81,7 @@ public TripsSearchResponse readAllTrips(LoginUser loginUser) { public void updateTripById(LoginUser loginUser, Long tripId, TripUpdateRequest tripUpdateRequest) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(tripId); + Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); trip.changeName(tripUpdateRequest.name()); @@ -110,7 +102,7 @@ private String generateRouteImage(Trip trip) { @Transactional(readOnly = true) public PointResponse readPointByTripAndPointId(LoginUser loginUser, Long tripId, Long pointId) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(tripId); + Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); Point point = trip.findPointById(pointId); @@ -119,7 +111,7 @@ public PointResponse readPointByTripAndPointId(LoginUser loginUser, Long tripId, public void delete(LoginUser loginUser, Long tripId) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(tripId); + Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); tripRepository.delete(trip); diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java b/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java index abf2c4982..6f3f6cc97 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java +++ b/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java @@ -1,5 +1,8 @@ package dev.tripdraw.domain.trip; +import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; + +import dev.tripdraw.exception.trip.TripException; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; @@ -8,4 +11,9 @@ public interface TripRepository extends JpaRepository { List findAllByMemberId(Long memberId); void deleteByMemberId(Long memberId); + + default Trip getById(Long tripId) { + return findById(tripId) + .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); + } } diff --git a/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java index 1be8898f6..b99b08e15 100644 --- a/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java @@ -1,11 +1,15 @@ package dev.tripdraw.domain.trip; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; +import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.exception.trip.TripException; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; @@ -69,4 +73,27 @@ void setUp() { // then assertThat(tripRepository.findById(trip.id())).isEmpty(); } + + @Test + void 여행_ID로_여행을_조회한다() { + // given + Trip trip = tripRepository.save(new Trip(TripName.from("제주도 여행"), member)); + + // when + Trip foundTrip = tripRepository.getById(trip.id()); + + // then + assertThat(foundTrip).isEqualTo(trip); + } + + @Test + void 여행_ID로_여행을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { + // given + Long tripId = MIN_VALUE; + + // expect + assertThatThrownBy(() -> tripRepository.getById(tripId)) + .isInstanceOf(TripException.class) + .hasMessage(TRIP_NOT_FOUND.getMessage()); + } } From 90ac3e6221d3fec9a7cd1c06fbef605932a227fb Mon Sep 17 00:00:00 2001 From: Combi153 Date: Sat, 12 Aug 2023 18:26:55 +0900 Subject: [PATCH 003/119] =?UTF-8?q?[refactor]=20PostRepository=20Id?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=90=EC=83=81=20=EC=A1=B0=ED=9A=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/application/PostService.java | 13 +++------ .../domain/member/MemberRepository.java | 4 +-- .../tripdraw/domain/post/PostRepository.java | 8 ++++++ .../tripdraw/domain/trip/TripRepository.java | 4 +-- .../domain/member/MemberRepositoryTest.java | 6 ++--- .../domain/post/PostRepositoryTest.java | 27 +++++++++++++++++++ .../domain/trip/TripRepositoryTest.java | 4 +-- 7 files changed, 46 insertions(+), 20 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/application/PostService.java b/backend/src/main/java/dev/tripdraw/application/PostService.java index 496bbad2b..f5c464f19 100644 --- a/backend/src/main/java/dev/tripdraw/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/application/PostService.java @@ -1,7 +1,6 @@ package dev.tripdraw.application; import static dev.tripdraw.domain.file.FileType.POST_IMAGE; -import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUNT; import dev.tripdraw.application.draw.RouteImageGenerator; import dev.tripdraw.application.file.FileUploader; @@ -20,7 +19,6 @@ import dev.tripdraw.dto.post.PostResponse; import dev.tripdraw.dto.post.PostUpdateRequest; import dev.tripdraw.dto.post.PostsResponse; -import dev.tripdraw.exception.post.PostException; import java.util.List; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -100,7 +98,7 @@ public PostCreateResponse addAtExistingLocation( } public PostResponse read(LoginUser loginUser, Long postId) { - Post post = findPostById(postId); + Post post = postRepository.getById(postId); Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); return PostResponse.from(post); @@ -115,7 +113,7 @@ public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { } public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdateRequest, MultipartFile file) { - Post post = findPostById(postId); + Post post = postRepository.getById(postId); Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); @@ -125,7 +123,7 @@ public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdat } public void delete(LoginUser loginUser, Long postId) { - Post post = findPostById(postId); + Post post = postRepository.getById(postId); Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); @@ -146,11 +144,6 @@ private Trip findValidatedTripById(Long tripId, Member member) { return trip; } - private Post findPostById(Long postId) { - return postRepository.findById(postId) - .orElseThrow(() -> new PostException(POST_NOT_FOUNT)); - } - private Post registerFileToPost(MultipartFile file, Post post) { if (file == null) { return post; diff --git a/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java b/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java index 36f880a49..34031f00c 100644 --- a/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java +++ b/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java @@ -6,14 +6,12 @@ import dev.tripdraw.exception.member.MemberException; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.lang.NonNull; public interface MemberRepository extends JpaRepository { Optional findByOauthIdAndOauthType(String oauthId, OauthType oauthType); - @NonNull - default Member getById(@NonNull Long id) { + default Member getById(Long id) { return findById(id) .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); } diff --git a/backend/src/main/java/dev/tripdraw/domain/post/PostRepository.java b/backend/src/main/java/dev/tripdraw/domain/post/PostRepository.java index 5f8feddc5..a0c70fb82 100644 --- a/backend/src/main/java/dev/tripdraw/domain/post/PostRepository.java +++ b/backend/src/main/java/dev/tripdraw/domain/post/PostRepository.java @@ -1,5 +1,8 @@ package dev.tripdraw.domain.post; +import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUNT; + +import dev.tripdraw.exception.post.PostException; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; @@ -8,4 +11,9 @@ public interface PostRepository extends JpaRepository { List findAllByTripId(Long tripId); void deleteByMemberId(Long memberId); + + default Post getById(Long id) { + return findById(id) + .orElseThrow(() -> new PostException(POST_NOT_FOUNT)); + } } diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java b/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java index 6f3f6cc97..1b0dd11cf 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java +++ b/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java @@ -12,8 +12,8 @@ public interface TripRepository extends JpaRepository { void deleteByMemberId(Long memberId); - default Trip getById(Long tripId) { - return findById(tripId) + default Trip getById(Long id) { + return findById(id) .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); } } diff --git a/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java index dc713c6c4..acb3e4c37 100644 --- a/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java @@ -55,14 +55,14 @@ class MemberRepositoryTest { // then assertThat(foundMember).isEqualTo(member); } - + @Test void 회원_ID로_회원을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { // given - Long memberId = MIN_VALUE; + Long wrongId = MIN_VALUE; // expect - assertThatThrownBy(() -> memberRepository.getById(memberId)) + assertThatThrownBy(() -> memberRepository.getById(wrongId)) .isInstanceOf(MemberException.class) .hasMessage(MEMBER_NOT_FOUND.getMessage()); } diff --git a/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java index e0c61bb1d..3848a4c74 100644 --- a/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java @@ -1,7 +1,10 @@ package dev.tripdraw.domain.post; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUNT; +import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; @@ -9,6 +12,7 @@ import dev.tripdraw.domain.trip.Trip; import dev.tripdraw.domain.trip.TripName; import dev.tripdraw.domain.trip.TripRepository; +import dev.tripdraw.exception.post.PostException; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.BeforeEach; @@ -69,4 +73,27 @@ void setUp() { // then assertThat(postRepository.findById(post.id())).isEmpty(); } + + @Test + void 감상_ID로_감상을_조회한다() { + // given + Post post = postRepository.save(new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, trip.id())); + + // when + Post foundPost = postRepository.getById(post.id()); + + // then + assertThat(foundPost).isEqualTo(post); + } + + @Test + void 감상_ID로_감상을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { + // given + Long wrongId = MIN_VALUE; + + // expect + assertThatThrownBy(() -> postRepository.getById(wrongId)) + .isInstanceOf(PostException.class) + .hasMessage(POST_NOT_FOUNT.getMessage()); + } } diff --git a/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java index b99b08e15..1560ff08d 100644 --- a/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java @@ -89,10 +89,10 @@ void setUp() { @Test void 여행_ID로_여행을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { // given - Long tripId = MIN_VALUE; + Long wrongId = MIN_VALUE; // expect - assertThatThrownBy(() -> tripRepository.getById(tripId)) + assertThatThrownBy(() -> tripRepository.getById(wrongId)) .isInstanceOf(TripException.class) .hasMessage(TRIP_NOT_FOUND.getMessage()); } From 92df74825d93b126d41ac97186210def1e8ff5d6 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Thu, 17 Aug 2023 18:15:16 +0900 Subject: [PATCH 004/119] =?UTF-8?q?[chore]=20github=20action=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EB=B3=80=EA=B2=BD=20(#323)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 6 ++++++ .github/workflows/backend-prod-cd.yml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index 4c807bee2..766890b7a 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -10,6 +10,12 @@ jobs: runs-on: self-hosted steps: + - name: 서브모듈 checkout + uses: actions/checkout@v3 + with: + token: ${{ secrets.TRIP_DRAW_TOKEN }} + submodules: true + - name: 배포 스크립트 실행 run: | cd diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index 5f9ed6300..0c513a1d4 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -10,6 +10,12 @@ jobs: runs-on: backend-prod-cd steps: + - name: 서브모듈 checkout + uses: actions/checkout@v3 + with: + token: ${{ secrets.TRIP_DRAW_TOKEN }} + submodules: true + - name: 배포 스크립트 실행 run: | cd From ba59ede04d5418a30e9692dab884fe4921deed20 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 17 Aug 2023 18:34:04 +0900 Subject: [PATCH 005/119] =?UTF-8?q?[chore]=20CD=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#325)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 4 ++-- .github/workflows/backend-prod-cd.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index 766890b7a..9e54b3640 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -10,11 +10,11 @@ jobs: runs-on: self-hosted steps: - - name: 서브모듈 checkout + - name: 서브 모듈 checkout uses: actions/checkout@v3 with: token: ${{ secrets.TRIP_DRAW_TOKEN }} - submodules: true + submodules: recursive - name: 배포 스크립트 실행 run: | diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index 0c513a1d4..1e0b79934 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -10,11 +10,11 @@ jobs: runs-on: backend-prod-cd steps: - - name: 서브모듈 checkout + - name: 서브 모듈 checkout uses: actions/checkout@v3 with: token: ${{ secrets.TRIP_DRAW_TOKEN }} - submodules: true + submodules: recursive - name: 배포 스크립트 실행 run: | From e5f8bffe52cf900802a71b3edcbf31627bcbbfb6 Mon Sep 17 00:00:00 2001 From: Herb Date: Thu, 17 Aug 2023 19:08:35 +0900 Subject: [PATCH 006/119] =?UTF-8?q?[chome]=20CD=20yml=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 4 ++++ .github/workflows/backend-prod-cd.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index 9e54b3640..7b37044d0 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -10,6 +10,10 @@ jobs: runs-on: self-hosted steps: + - name: 수정 권한 부여 + run: | + sudo chown -R ubuntu:ubuntu ${{ secrets.HOME }} + - name: 서브 모듈 checkout uses: actions/checkout@v3 with: diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index 1e0b79934..e0156167d 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -10,6 +10,10 @@ jobs: runs-on: backend-prod-cd steps: + - name: 수정 권한 부여 + run: | + sudo chown -R ubuntu:ubuntu ${{ secrets.HOME }} + - name: 서브 모듈 checkout uses: actions/checkout@v3 with: From 3761f875540fcec74272a86da9b3781250cd6ed7 Mon Sep 17 00:00:00 2001 From: Herb Date: Thu, 17 Aug 2023 19:15:04 +0900 Subject: [PATCH 007/119] =?UTF-8?q?[chore]=20=EB=B0=B0=ED=8F=AC=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=88=98=EC=A0=95(#325)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 10 ---------- .github/workflows/backend-prod-cd.yml | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index 7b37044d0..4c807bee2 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -10,16 +10,6 @@ jobs: runs-on: self-hosted steps: - - name: 수정 권한 부여 - run: | - sudo chown -R ubuntu:ubuntu ${{ secrets.HOME }} - - - name: 서브 모듈 checkout - uses: actions/checkout@v3 - with: - token: ${{ secrets.TRIP_DRAW_TOKEN }} - submodules: recursive - - name: 배포 스크립트 실행 run: | cd diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index e0156167d..5f9ed6300 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -10,16 +10,6 @@ jobs: runs-on: backend-prod-cd steps: - - name: 수정 권한 부여 - run: | - sudo chown -R ubuntu:ubuntu ${{ secrets.HOME }} - - - name: 서브 모듈 checkout - uses: actions/checkout@v3 - with: - token: ${{ secrets.TRIP_DRAW_TOKEN }} - submodules: recursive - - name: 배포 스크립트 실행 run: | cd From 9daed87b59b2c860d7b0e28807a9ed9f6e5fa8f0 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Thu, 31 Aug 2023 16:14:10 +0900 Subject: [PATCH 008/119] =?UTF-8?q?[chore]=20conflict=20=ED=95=B4=EA=B2=B0?= =?UTF-8?q?=20(#224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/application/MemberService.java | 5 +--- .../dev/tripdraw/application/PostService.java | 20 +++++--------- .../dev/tripdraw/application/TripService.java | 23 ++++++---------- .../domain/member/MemberRepository.java | 10 +++++++ .../tripdraw/domain/trip/TripRepository.java | 3 ++- .../domain/member/MemberRepositoryTest.java | 27 +++++++++++++++++++ 6 files changed, 54 insertions(+), 34 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/application/MemberService.java b/backend/src/main/java/dev/tripdraw/application/MemberService.java index 86b550f41..5eac66b33 100644 --- a/backend/src/main/java/dev/tripdraw/application/MemberService.java +++ b/backend/src/main/java/dev/tripdraw/application/MemberService.java @@ -1,7 +1,5 @@ package dev.tripdraw.application; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; - import dev.tripdraw.application.oauth.AuthTokenManager; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; @@ -31,8 +29,7 @@ public boolean existsById(Long memberId) { @Transactional(readOnly = true) public MemberSearchResponse findByCode(String code) { Long memberId = authTokenManager.extractMemberId(code); - Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); + Member member = memberRepository.getById(memberId); return MemberSearchResponse.from(member); } diff --git a/backend/src/main/java/dev/tripdraw/application/PostService.java b/backend/src/main/java/dev/tripdraw/application/PostService.java index 112e8dddf..4033713e4 100644 --- a/backend/src/main/java/dev/tripdraw/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/application/PostService.java @@ -1,7 +1,6 @@ package dev.tripdraw.application; import static dev.tripdraw.domain.file.FileType.POST_IMAGE; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUND; import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; @@ -22,7 +21,6 @@ import dev.tripdraw.dto.post.PostResponse; import dev.tripdraw.dto.post.PostUpdateRequest; import dev.tripdraw.dto.post.PostsResponse; -import dev.tripdraw.exception.member.MemberException; import dev.tripdraw.exception.post.PostException; import dev.tripdraw.exception.trip.TripException; import java.util.Comparator; @@ -50,7 +48,7 @@ public PostCreateResponse addAtCurrentPoint( PostAndPointCreateRequest postAndPointCreateRequest, MultipartFile file ) { - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = findValidatedTripById(postAndPointCreateRequest.tripId(), member); Point point = postAndPointCreateRequest.toPoint(); @@ -70,7 +68,7 @@ public PostCreateResponse addAtExistingLocation( PostRequest postRequest, MultipartFile file ) { - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = findValidatedTripById(postRequest.tripId(), member); Point point = trip.findPointById(postRequest.pointId()); @@ -85,13 +83,13 @@ public PostCreateResponse addAtExistingLocation( public PostResponse read(LoginUser loginUser, Long postId) { Post post = findPostById(postId); - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); return PostResponse.from(post); } public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); findValidatedTripById(tripId, member); List posts = postRepository.findAllByTripId(tripId).stream() @@ -102,7 +100,7 @@ public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdateRequest, MultipartFile file) { Post post = findPostById(postId); - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); post.changeTitle(postUpdateRequest.title()); @@ -112,7 +110,7 @@ public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdat public void delete(LoginUser loginUser, Long postId) { Post post = findPostById(postId); - Member member = findMemberById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); postRepository.deleteById(postId); @@ -127,18 +125,12 @@ private void updateFileOfPost(MultipartFile file, Post post) { } private Trip findValidatedTripById(Long tripId, Member member) { - Trip trip = tripRepository.findById(tripId) .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); trip.validateAuthorization(member); return trip; } - private Member findMemberById(Long memberId) { - return memberRepository.findById(memberId) - .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); - } - private Post findPostById(Long postId) { return postRepository.findById(postId) .orElseThrow(() -> new PostException(POST_NOT_FOUND)); diff --git a/backend/src/main/java/dev/tripdraw/application/TripService.java b/backend/src/main/java/dev/tripdraw/application/TripService.java index eb16dba38..cbd347698 100644 --- a/backend/src/main/java/dev/tripdraw/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/application/TripService.java @@ -1,6 +1,5 @@ package dev.tripdraw.application; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; import dev.tripdraw.domain.member.Member; @@ -17,7 +16,6 @@ import dev.tripdraw.dto.trip.TripResponse; import dev.tripdraw.dto.trip.TripUpdateRequest; import dev.tripdraw.dto.trip.TripsSearchResponse; -import dev.tripdraw.exception.member.MemberException; import dev.tripdraw.exception.trip.TripException; import java.util.List; import lombok.RequiredArgsConstructor; @@ -35,14 +33,14 @@ public class TripService { private final ApplicationEventPublisher applicationEventPublisher; public TripCreateResponse create(LoginUser loginUser) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = Trip.from(member); Trip savedTrip = tripRepository.save(trip); return TripCreateResponse.from(savedTrip); } public PointCreateResponse addPoint(LoginUser loginUser, PointCreateRequest pointCreateRequest) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(pointCreateRequest.tripId()); Point point = pointCreateRequest.toPoint(); @@ -54,7 +52,7 @@ public PointCreateResponse addPoint(LoginUser loginUser, PointCreateRequest poin } public void deletePoint(LoginUser loginUser, Long pointId, Long tripId) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(tripId); trip.validateAuthorization(member); @@ -62,11 +60,6 @@ public void deletePoint(LoginUser loginUser, Long pointId, Long tripId) { trip.deletePointById(pointId); } - private Member getById(Long memberId) { - return memberRepository.findById(memberId) - .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); - } - private Trip getByTripId(Long tripId) { return tripRepository.findById(tripId) .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); @@ -74,7 +67,7 @@ private Trip getByTripId(Long tripId) { @Transactional(readOnly = true) public TripResponse readTripById(LoginUser loginUser, Long id) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(id); trip.validateAuthorization(member); return TripResponse.from(trip); @@ -82,13 +75,13 @@ public TripResponse readTripById(LoginUser loginUser, Long id) { @Transactional(readOnly = true) public TripsSearchResponse readAllTrips(LoginUser loginUser) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); List trips = tripRepository.findAllByMemberId(member.id()); return TripsSearchResponse.from(trips); } public void updateTripById(LoginUser loginUser, Long tripId, TripUpdateRequest tripUpdateRequest) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(tripId); trip.validateAuthorization(member); @@ -100,7 +93,7 @@ public void updateTripById(LoginUser loginUser, Long tripId, TripUpdateRequest t @Transactional(readOnly = true) public PointResponse readPointByTripAndPointId(LoginUser loginUser, Long tripId, Long pointId) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(tripId); trip.validateAuthorization(member); @@ -109,7 +102,7 @@ public PointResponse readPointByTripAndPointId(LoginUser loginUser, Long tripId, } public void delete(LoginUser loginUser, Long tripId) { - Member member = getById(loginUser.memberId()); + Member member = memberRepository.getById(loginUser.memberId()); Trip trip = getByTripId(tripId); trip.validateAuthorization(member); diff --git a/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java b/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java index 8d3bcf2a5..307ce6321 100644 --- a/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java +++ b/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java @@ -1,12 +1,22 @@ package dev.tripdraw.domain.member; +import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; + import dev.tripdraw.domain.oauth.OauthType; +import dev.tripdraw.exception.member.MemberException; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.lang.NonNull; public interface MemberRepository extends JpaRepository { Optional findByOauthIdAndOauthType(String oauthId, OauthType oauthType); boolean existsByNickname(String nickname); + + @NonNull + default Member getById(@NonNull Long id) { + return findById(id) + .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); + } } diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java b/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java index 3abfc0765..705e94611 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java +++ b/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java @@ -7,6 +7,7 @@ import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface TripRepository extends JpaRepository { @@ -15,7 +16,7 @@ public interface TripRepository extends JpaRepository { void deleteByMemberId(Long memberId); @Query("SELECT t FROM Trip t JOIN FETCH t.route.points where t.id = :tripId") - Optional findTripWithPoints(Long tripId); + Optional findTripWithPoints(@Param("tripId") Long tripId); default Trip getTripWithPoints(Long tripId) { return findTripWithPoints(tripId) diff --git a/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java index 1ec293db9..a627dbe6d 100644 --- a/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java @@ -1,8 +1,12 @@ package dev.tripdraw.domain.member; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; +import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import dev.tripdraw.exception.member.MemberException; import java.util.Optional; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -42,6 +46,29 @@ class MemberRepositoryTest { assertThat(foundMember).isEmpty(); } + @Test + void 회원_ID로_회원을_조회한다() { + // given + Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + + // when + Member foundMember = memberRepository.getById(member.id()); + + // then + assertThat(foundMember).isEqualTo(member); + } + + @Test + void 회원_ID로_회원을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { + // given + Long memberId = MIN_VALUE; + + // expect + assertThatThrownBy(() -> memberRepository.getById(memberId)) + .isInstanceOf(MemberException.class) + .hasMessage(MEMBER_NOT_FOUND.message()); + } + @ParameterizedTest @CsvSource({"통후추, true", "순후추, false"}) void 닉네임이_존재하는지_확인한다(String nickname, boolean expected) { From 7684a9e0834a9ad349951e3c2a139767820bdcf1 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Sat, 12 Aug 2023 18:21:08 +0900 Subject: [PATCH 009/119] =?UTF-8?q?[chore]=20conflict=20=ED=95=B4=EA=B2=B0?= =?UTF-8?q?=20(#224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/application/PostService.java | 4 +-- .../dev/tripdraw/application/TripService.java | 19 +++++-------- .../tripdraw/domain/trip/TripRepository.java | 5 ++++ .../domain/trip/TripRepositoryTest.java | 27 +++++++++++++++++++ 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/application/PostService.java b/backend/src/main/java/dev/tripdraw/application/PostService.java index 4033713e4..ef490bce2 100644 --- a/backend/src/main/java/dev/tripdraw/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/application/PostService.java @@ -1,6 +1,7 @@ package dev.tripdraw.application; import static dev.tripdraw.domain.file.FileType.POST_IMAGE; +import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUNT; import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUND; import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; @@ -125,8 +126,7 @@ private void updateFileOfPost(MultipartFile file, Post post) { } private Trip findValidatedTripById(Long tripId, Member member) { - Trip trip = tripRepository.findById(tripId) - .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); + Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); return trip; } diff --git a/backend/src/main/java/dev/tripdraw/application/TripService.java b/backend/src/main/java/dev/tripdraw/application/TripService.java index cbd347698..fea55e4db 100644 --- a/backend/src/main/java/dev/tripdraw/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/application/TripService.java @@ -2,6 +2,7 @@ import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; +import dev.tripdraw.application.draw.RouteImageGenerator; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; import dev.tripdraw.domain.trip.Point; @@ -16,7 +17,6 @@ import dev.tripdraw.dto.trip.TripResponse; import dev.tripdraw.dto.trip.TripUpdateRequest; import dev.tripdraw.dto.trip.TripsSearchResponse; -import dev.tripdraw.exception.trip.TripException; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; @@ -41,7 +41,7 @@ public TripCreateResponse create(LoginUser loginUser) { public PointCreateResponse addPoint(LoginUser loginUser, PointCreateRequest pointCreateRequest) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(pointCreateRequest.tripId()); + Trip trip = tripRepository.getById(pointCreateRequest.tripId()); Point point = pointCreateRequest.toPoint(); trip.validateAuthorization(member); @@ -54,21 +54,16 @@ public PointCreateResponse addPoint(LoginUser loginUser, PointCreateRequest poin public void deletePoint(LoginUser loginUser, Long pointId, Long tripId) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(tripId); + Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); trip.deletePointById(pointId); } - private Trip getByTripId(Long tripId) { - return tripRepository.findById(tripId) - .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); - } - @Transactional(readOnly = true) public TripResponse readTripById(LoginUser loginUser, Long id) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(id); + Trip trip = tripRepository.getById(id); trip.validateAuthorization(member); return TripResponse.from(trip); } @@ -82,7 +77,7 @@ public TripsSearchResponse readAllTrips(LoginUser loginUser) { public void updateTripById(LoginUser loginUser, Long tripId, TripUpdateRequest tripUpdateRequest) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(tripId); + Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); trip.changeName(tripUpdateRequest.name()); @@ -94,7 +89,7 @@ public void updateTripById(LoginUser loginUser, Long tripId, TripUpdateRequest t @Transactional(readOnly = true) public PointResponse readPointByTripAndPointId(LoginUser loginUser, Long tripId, Long pointId) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(tripId); + Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); Point point = trip.findPointById(pointId); @@ -103,7 +98,7 @@ public PointResponse readPointByTripAndPointId(LoginUser loginUser, Long tripId, public void delete(LoginUser loginUser, Long tripId) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = getByTripId(tripId); + Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); tripRepository.delete(trip); diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java b/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java index 705e94611..c6cd25d59 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java +++ b/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java @@ -15,6 +15,11 @@ public interface TripRepository extends JpaRepository { void deleteByMemberId(Long memberId); + default Trip getById(Long tripId) { + return findById(tripId) + .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); + } + @Query("SELECT t FROM Trip t JOIN FETCH t.route.points where t.id = :tripId") Optional findTripWithPoints(@Param("tripId") Long tripId); diff --git a/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java index f6bd8d274..5b0bde475 100644 --- a/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java @@ -1,11 +1,15 @@ package dev.tripdraw.domain.trip; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; +import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.exception.trip.TripException; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.BeforeEach; @@ -90,4 +94,27 @@ void setUp() { // then assertThat(tripRepository.findById(trip.id())).isEmpty(); } + + @Test + void 여행_ID로_여행을_조회한다() { + // given + Trip trip = tripRepository.save(new Trip(TripName.from("제주도 여행"), member)); + + // when + Trip foundTrip = tripRepository.getById(trip.id()); + + // then + assertThat(foundTrip).isEqualTo(trip); + } + + @Test + void 여행_ID로_여행을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { + // given + Long tripId = MIN_VALUE; + + // expect + assertThatThrownBy(() -> tripRepository.getById(tripId)) + .isInstanceOf(TripException.class) + .hasMessage(TRIP_NOT_FOUND.getMessage()); + } } From 88447c8eb40aa83862c63393c2ef673d18930d61 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Sat, 12 Aug 2023 18:26:55 +0900 Subject: [PATCH 010/119] =?UTF-8?q?[chore]=20conflict=20=ED=95=B4=EA=B2=B0?= =?UTF-8?q?=20(#224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/application/PostService.java | 16 +++-------- .../tripdraw/domain/trip/TripRepository.java | 4 +-- .../domain/member/MemberRepositoryTest.java | 4 +-- .../domain/post/PostRepositoryTest.java | 27 ++++++++++++++----- .../domain/trip/TripRepositoryTest.java | 6 ++--- 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/application/PostService.java b/backend/src/main/java/dev/tripdraw/application/PostService.java index ef490bce2..5fe0886e7 100644 --- a/backend/src/main/java/dev/tripdraw/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/application/PostService.java @@ -1,9 +1,6 @@ package dev.tripdraw.application; import static dev.tripdraw.domain.file.FileType.POST_IMAGE; -import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUNT; -import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUND; -import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; import dev.tripdraw.application.file.FileUploader; import dev.tripdraw.domain.file.FileType; @@ -22,8 +19,6 @@ import dev.tripdraw.dto.post.PostResponse; import dev.tripdraw.dto.post.PostUpdateRequest; import dev.tripdraw.dto.post.PostsResponse; -import dev.tripdraw.exception.post.PostException; -import dev.tripdraw.exception.trip.TripException; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -83,7 +78,7 @@ public PostCreateResponse addAtExistingLocation( } public PostResponse read(LoginUser loginUser, Long postId) { - Post post = findPostById(postId); + Post post = postRepository.getById(postId); Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); return PostResponse.from(post); @@ -100,7 +95,7 @@ public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { } public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdateRequest, MultipartFile file) { - Post post = findPostById(postId); + Post post = postRepository.getById(postId); Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); @@ -110,7 +105,7 @@ public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdat } public void delete(LoginUser loginUser, Long postId) { - Post post = findPostById(postId); + Post post = postRepository.getById(postId); Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); @@ -131,11 +126,6 @@ private Trip findValidatedTripById(Long tripId, Member member) { return trip; } - private Post findPostById(Long postId) { - return postRepository.findById(postId) - .orElseThrow(() -> new PostException(POST_NOT_FOUND)); - } - private Post registerFileToPost(MultipartFile file, Post post) { if (file == null) { return post; diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java b/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java index c6cd25d59..2dcad78f9 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java +++ b/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java @@ -15,8 +15,8 @@ public interface TripRepository extends JpaRepository { void deleteByMemberId(Long memberId); - default Trip getById(Long tripId) { - return findById(tripId) + default Trip getById(Long id) { + return findById(id) .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); } diff --git a/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java index a627dbe6d..173111f8f 100644 --- a/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java @@ -61,10 +61,10 @@ class MemberRepositoryTest { @Test void 회원_ID로_회원을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { // given - Long memberId = MIN_VALUE; + Long wrongId = MIN_VALUE; // expect - assertThatThrownBy(() -> memberRepository.getById(memberId)) + assertThatThrownBy(() -> memberRepository.getById(wrongId)) .isInstanceOf(MemberException.class) .hasMessage(MEMBER_NOT_FOUND.message()); } diff --git a/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java index fb251a4de..3f8c3b7fd 100644 --- a/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java @@ -1,7 +1,10 @@ package dev.tripdraw.domain.post; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUND; +import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; @@ -9,13 +12,10 @@ import dev.tripdraw.domain.trip.Trip; import dev.tripdraw.domain.trip.TripName; import dev.tripdraw.domain.trip.TripRepository; +import dev.tripdraw.exception.post.PostException; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.BeforeEach; -import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUND; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import dev.tripdraw.exception.post.PostException; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -75,9 +75,24 @@ void setUp() { } @Test - void 감상_ID에_대한_감상이_존재하지_않는다면_예외를_던진다() { + void 감상_ID로_감상을_조회한다() { + // given + Post post = postRepository.save(new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, trip.id())); + + // when + Post foundPost = postRepository.getById(post.id()); + + // then + assertThat(foundPost).isEqualTo(post); + } + + @Test + void 감상_ID로_감상을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { + // given + Long wrongId = MIN_VALUE; + // expect - assertThatThrownBy(() -> postRepository.getById(1L)) + assertThatThrownBy(() -> postRepository.getById(wrongId)) .isInstanceOf(PostException.class) .hasMessage(POST_NOT_FOUND.message()); } diff --git a/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java index 5b0bde475..25d282fc0 100644 --- a/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java @@ -110,11 +110,11 @@ void setUp() { @Test void 여행_ID로_여행을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { // given - Long tripId = MIN_VALUE; + Long wrongId = MIN_VALUE; // expect - assertThatThrownBy(() -> tripRepository.getById(tripId)) + assertThatThrownBy(() -> tripRepository.getById(wrongId)) .isInstanceOf(TripException.class) - .hasMessage(TRIP_NOT_FOUND.getMessage()); + .hasMessage(TRIP_NOT_FOUND.message()); } } From 5dd7d29b0771834aafe38ede6acbbde747a68d93 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 31 Aug 2023 17:00:38 +0900 Subject: [PATCH 011/119] =?UTF-8?q?[refactor]=20trip=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20(#223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Combi153 Co-authored-by: Jaeyoung22 --- .../tripdraw/application/MemberService.java | 2 +- .../dev/tripdraw/application/PostService.java | 6 ++-- .../draw/PostCreateEventHandler.java | 4 +-- .../draw/TripUpdateEventHandler.java | 6 ++-- .../java/dev/tripdraw/domain/post/Post.java | 2 +- .../dto/post/PostAndPointCreateRequest.java | 2 +- .../dev/tripdraw/dto/post/PostRequest.java | 2 +- .../dev/tripdraw/dto/post/PostResponse.java | 2 +- .../{ => trip}/application/TripService.java | 24 ++++++------- .../{domain/trip => trip/domain}/Point.java | 8 ++--- .../{domain/trip => trip/domain}/Route.java | 8 ++--- .../{domain/trip => trip/domain}/Trip.java | 10 +++--- .../trip => trip/domain}/TripName.java | 2 +- .../trip => trip/domain}/TripRepository.java | 6 ++-- .../trip => trip/domain}/TripStatus.java | 2 +- .../trip => trip/domain}/TripUpdateEvent.java | 2 +- .../trip => trip/dto}/PointCreateRequest.java | 4 +-- .../dto}/PointCreateResponse.java | 4 +-- .../{dto/trip => trip/dto}/PointResponse.java | 4 +-- .../trip => trip/dto}/TripCreateResponse.java | 4 +-- .../{dto/trip => trip/dto}/TripResponse.java | 6 ++-- .../trip => trip/dto}/TripSearchResponse.java | 4 +-- .../trip => trip/dto}/TripUpdateRequest.java | 4 +-- .../dto}/TripsSearchResponse.java | 4 +-- .../exception}/TripException.java | 2 +- .../exception}/TripExceptionType.java | 2 +- .../presentation}/TripController.java | 18 +++++----- .../application/MemberServiceTest.java | 8 ++--- .../tripdraw/application/PostServiceTest.java | 14 ++++---- ...PostCreateEventHandlerIntegrationTest.java | 2 +- .../draw/PostCreateEventHandlerTest.java | 2 +- ...TripUpdateEventHandlerIntegrationTest.java | 4 +-- .../draw/TripUpdateEventHandlerTest.java | 6 ++-- .../domain/post/PostRepositoryTest.java | 8 ++--- .../dev/tripdraw/domain/post/PostTest.java | 6 ++-- ...PostResponseAndPointCreateRequestTest.java | 2 +- .../controller/AuthControllerTest.java | 3 +- .../controller/MemberControllerTest.java | 11 +++--- .../controller/PostControllerTest.java | 11 +++--- .../controller => test}/ControllerTest.java | 4 +-- .../java/dev/tripdraw/test/TestFixture.java | 8 ++--- .../application/TripServiceTest.java | 35 ++++++++++--------- .../trip => trip/domain}/PointTest.java | 8 ++--- .../trip => trip/domain}/RouteTest.java | 10 +++--- .../trip => trip/domain}/TripNameTest.java | 4 +-- .../domain}/TripRepositoryTest.java | 6 ++-- .../trip => trip/domain}/TripTest.java | 12 +++---- .../dto}/PointCreateRequestTest.java | 4 +-- .../dto}/TripSearchResponseTest.java | 8 ++--- .../presentation}/TripControllerTest.java | 27 +++++++------- 50 files changed, 176 insertions(+), 171 deletions(-) rename backend/src/main/java/dev/tripdraw/{ => trip}/application/TripService.java (86%) rename backend/src/main/java/dev/tripdraw/{domain/trip => trip/domain}/Point.java (90%) rename backend/src/main/java/dev/tripdraw/{domain/trip => trip/domain}/Route.java (87%) rename backend/src/main/java/dev/tripdraw/{domain/trip => trip/domain}/Trip.java (93%) rename backend/src/main/java/dev/tripdraw/{domain/trip => trip/domain}/TripName.java (94%) rename backend/src/main/java/dev/tripdraw/{domain/trip => trip/domain}/TripRepository.java (85%) rename backend/src/main/java/dev/tripdraw/{domain/trip => trip/domain}/TripStatus.java (59%) rename backend/src/main/java/dev/tripdraw/{domain/trip => trip/domain}/TripUpdateEvent.java (58%) rename backend/src/main/java/dev/tripdraw/{dto/trip => trip/dto}/PointCreateRequest.java (92%) rename backend/src/main/java/dev/tripdraw/{dto/trip => trip/dto}/PointCreateResponse.java (80%) rename backend/src/main/java/dev/tripdraw/{dto/trip => trip/dto}/PointResponse.java (93%) rename backend/src/main/java/dev/tripdraw/{dto/trip => trip/dto}/TripCreateResponse.java (80%) rename backend/src/main/java/dev/tripdraw/{dto/trip => trip/dto}/TripResponse.java (92%) rename backend/src/main/java/dev/tripdraw/{dto/trip => trip/dto}/TripSearchResponse.java (93%) rename backend/src/main/java/dev/tripdraw/{dto/trip => trip/dto}/TripUpdateRequest.java (81%) rename backend/src/main/java/dev/tripdraw/{dto/trip => trip/dto}/TripsSearchResponse.java (88%) rename backend/src/main/java/dev/tripdraw/{exception/trip => trip/exception}/TripException.java (87%) rename backend/src/main/java/dev/tripdraw/{exception/trip => trip/exception}/TripExceptionType.java (97%) rename backend/src/main/java/dev/tripdraw/{presentation/controller => trip/presentation}/TripController.java (92%) rename backend/src/test/java/dev/tripdraw/{presentation/controller => test}/ControllerTest.java (91%) rename backend/src/test/java/dev/tripdraw/{ => trip}/application/TripServiceTest.java (89%) rename backend/src/test/java/dev/tripdraw/{domain/trip => trip/domain}/PointTest.java (88%) rename backend/src/test/java/dev/tripdraw/{domain/trip => trip/domain}/RouteTest.java (91%) rename backend/src/test/java/dev/tripdraw/{domain/trip => trip/domain}/TripNameTest.java (93%) rename backend/src/test/java/dev/tripdraw/{domain/trip => trip/domain}/TripRepositoryTest.java (96%) rename backend/src/test/java/dev/tripdraw/{domain/trip => trip/domain}/TripTest.java (96%) rename backend/src/test/java/dev/tripdraw/{dto/trip => trip/dto}/PointCreateRequestTest.java (92%) rename backend/src/test/java/dev/tripdraw/{dto/trip => trip/dto}/TripSearchResponseTest.java (86%) rename backend/src/test/java/dev/tripdraw/{presentation/controller => trip/presentation}/TripControllerTest.java (95%) diff --git a/backend/src/main/java/dev/tripdraw/application/MemberService.java b/backend/src/main/java/dev/tripdraw/application/MemberService.java index a5b5bee2a..669bc4e0e 100644 --- a/backend/src/main/java/dev/tripdraw/application/MemberService.java +++ b/backend/src/main/java/dev/tripdraw/application/MemberService.java @@ -4,7 +4,7 @@ import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; import dev.tripdraw.domain.post.PostRepository; -import dev.tripdraw.domain.trip.TripRepository; +import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.dto.member.MemberSearchResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/backend/src/main/java/dev/tripdraw/application/PostService.java b/backend/src/main/java/dev/tripdraw/application/PostService.java index 5fe0886e7..db96b7107 100644 --- a/backend/src/main/java/dev/tripdraw/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/application/PostService.java @@ -9,9 +9,9 @@ import dev.tripdraw.domain.post.Post; import dev.tripdraw.domain.post.PostCreateEvent; import dev.tripdraw.domain.post.PostRepository; -import dev.tripdraw.domain.trip.Point; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripRepository; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.dto.auth.LoginUser; import dev.tripdraw.dto.post.PostAndPointCreateRequest; import dev.tripdraw.dto.post.PostCreateResponse; diff --git a/backend/src/main/java/dev/tripdraw/application/draw/PostCreateEventHandler.java b/backend/src/main/java/dev/tripdraw/application/draw/PostCreateEventHandler.java index 1c3ee3c90..ee8bbbbf7 100644 --- a/backend/src/main/java/dev/tripdraw/application/draw/PostCreateEventHandler.java +++ b/backend/src/main/java/dev/tripdraw/application/draw/PostCreateEventHandler.java @@ -5,8 +5,8 @@ import dev.tripdraw.domain.post.Post; import dev.tripdraw.domain.post.PostCreateEvent; import dev.tripdraw.domain.post.PostRepository; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripRepository; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; import java.util.List; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; diff --git a/backend/src/main/java/dev/tripdraw/application/draw/TripUpdateEventHandler.java b/backend/src/main/java/dev/tripdraw/application/draw/TripUpdateEventHandler.java index d24db745f..c0a49d2d1 100644 --- a/backend/src/main/java/dev/tripdraw/application/draw/TripUpdateEventHandler.java +++ b/backend/src/main/java/dev/tripdraw/application/draw/TripUpdateEventHandler.java @@ -2,9 +2,9 @@ import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripRepository; -import dev.tripdraw.domain.trip.TripUpdateEvent; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; +import dev.tripdraw.trip.domain.TripUpdateEvent; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.transaction.event.TransactionalEventListener; diff --git a/backend/src/main/java/dev/tripdraw/domain/post/Post.java b/backend/src/main/java/dev/tripdraw/domain/post/Post.java index bcafa9cdc..be2ec0a4c 100644 --- a/backend/src/main/java/dev/tripdraw/domain/post/Post.java +++ b/backend/src/main/java/dev/tripdraw/domain/post/Post.java @@ -7,7 +7,7 @@ import dev.tripdraw.domain.common.BaseEntity; import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.trip.Point; +import dev.tripdraw.trip.domain.Point; import dev.tripdraw.exception.post.PostException; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/backend/src/main/java/dev/tripdraw/dto/post/PostAndPointCreateRequest.java b/backend/src/main/java/dev/tripdraw/dto/post/PostAndPointCreateRequest.java index 056bd77ff..3c43edbb9 100644 --- a/backend/src/main/java/dev/tripdraw/dto/post/PostAndPointCreateRequest.java +++ b/backend/src/main/java/dev/tripdraw/dto/post/PostAndPointCreateRequest.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.post.Post; -import dev.tripdraw.domain.trip.Point; +import dev.tripdraw.trip.domain.Point; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; diff --git a/backend/src/main/java/dev/tripdraw/dto/post/PostRequest.java b/backend/src/main/java/dev/tripdraw/dto/post/PostRequest.java index 2a7fd4fd0..0bd95d11a 100644 --- a/backend/src/main/java/dev/tripdraw/dto/post/PostRequest.java +++ b/backend/src/main/java/dev/tripdraw/dto/post/PostRequest.java @@ -2,7 +2,7 @@ import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.post.Post; -import dev.tripdraw.domain.trip.Point; +import dev.tripdraw.trip.domain.Point; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; diff --git a/backend/src/main/java/dev/tripdraw/dto/post/PostResponse.java b/backend/src/main/java/dev/tripdraw/dto/post/PostResponse.java index ebdd836be..cc70ca5a9 100644 --- a/backend/src/main/java/dev/tripdraw/dto/post/PostResponse.java +++ b/backend/src/main/java/dev/tripdraw/dto/post/PostResponse.java @@ -1,7 +1,7 @@ package dev.tripdraw.dto.post; import dev.tripdraw.domain.post.Post; -import dev.tripdraw.dto.trip.PointResponse; +import dev.tripdraw.trip.dto.PointResponse; import io.swagger.v3.oas.annotations.media.Schema; public record PostResponse( diff --git a/backend/src/main/java/dev/tripdraw/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java similarity index 86% rename from backend/src/main/java/dev/tripdraw/application/TripService.java rename to backend/src/main/java/dev/tripdraw/trip/application/TripService.java index 0f53be8ca..d86f833c9 100644 --- a/backend/src/main/java/dev/tripdraw/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -1,19 +1,19 @@ -package dev.tripdraw.application; +package dev.tripdraw.trip.application; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; -import dev.tripdraw.domain.trip.Point; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripRepository; -import dev.tripdraw.domain.trip.TripUpdateEvent; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; +import dev.tripdraw.trip.domain.TripUpdateEvent; import dev.tripdraw.dto.auth.LoginUser; -import dev.tripdraw.dto.trip.PointCreateRequest; -import dev.tripdraw.dto.trip.PointCreateResponse; -import dev.tripdraw.dto.trip.PointResponse; -import dev.tripdraw.dto.trip.TripCreateResponse; -import dev.tripdraw.dto.trip.TripResponse; -import dev.tripdraw.dto.trip.TripUpdateRequest; -import dev.tripdraw.dto.trip.TripsSearchResponse; +import dev.tripdraw.trip.dto.PointCreateRequest; +import dev.tripdraw.trip.dto.PointCreateResponse; +import dev.tripdraw.trip.dto.PointResponse; +import dev.tripdraw.trip.dto.TripCreateResponse; +import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripUpdateRequest; +import dev.tripdraw.trip.dto.TripsSearchResponse; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/Point.java b/backend/src/main/java/dev/tripdraw/trip/domain/Point.java similarity index 90% rename from backend/src/main/java/dev/tripdraw/domain/trip/Point.java rename to backend/src/main/java/dev/tripdraw/trip/domain/Point.java index d4cc5e6bc..ab1eec951 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/Point.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Point.java @@ -1,12 +1,12 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_ALREADY_DELETED; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_ALREADY_HAS_POST; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_HAS_POST; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; import dev.tripdraw.domain.common.BaseEntity; -import dev.tripdraw.exception.trip.TripException; +import dev.tripdraw.trip.exception.TripException; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/Route.java b/backend/src/main/java/dev/tripdraw/trip/domain/Route.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/domain/trip/Route.java rename to backend/src/main/java/dev/tripdraw/trip/domain/Route.java index 59bdb48c4..49428d735 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/Route.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Route.java @@ -1,13 +1,13 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_NOT_FOUND; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_NOT_IN_TRIP; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_IN_TRIP; import static jakarta.persistence.CascadeType.PERSIST; import static jakarta.persistence.CascadeType.REMOVE; import static jakarta.persistence.FetchType.LAZY; import static lombok.AccessLevel.PROTECTED; -import dev.tripdraw.exception.trip.TripException; +import dev.tripdraw.trip.exception.TripException; import jakarta.persistence.Embeddable; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/Trip.java b/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java similarity index 93% rename from backend/src/main/java/dev/tripdraw/domain/trip/Trip.java rename to backend/src/main/java/dev/tripdraw/trip/domain/Trip.java index d95634424..2ed6e9a0c 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/Trip.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java @@ -1,15 +1,15 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; -import static dev.tripdraw.domain.trip.TripStatus.ONGOING; -import static dev.tripdraw.exception.trip.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; -import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_INVALID_STATUS; +import static dev.tripdraw.trip.domain.TripStatus.ONGOING; +import static dev.tripdraw.trip.exception.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; +import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_INVALID_STATUS; import static jakarta.persistence.FetchType.LAZY; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; import dev.tripdraw.domain.common.BaseEntity; import dev.tripdraw.domain.member.Member; -import dev.tripdraw.exception.trip.TripException; +import dev.tripdraw.trip.exception.TripException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/TripName.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripName.java similarity index 94% rename from backend/src/main/java/dev/tripdraw/domain/trip/TripName.java rename to backend/src/main/java/dev/tripdraw/trip/domain/TripName.java index 44c4f8afc..dc275406a 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/TripName.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripName.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; import static lombok.AccessLevel.PROTECTED; diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java similarity index 85% rename from backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java rename to backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java index 2dcad78f9..edb45c393 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/TripRepository.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java @@ -1,8 +1,8 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; -import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; +import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; -import dev.tripdraw.exception.trip.TripException; +import dev.tripdraw.trip.exception.TripException; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/TripStatus.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripStatus.java similarity index 59% rename from backend/src/main/java/dev/tripdraw/domain/trip/TripStatus.java rename to backend/src/main/java/dev/tripdraw/trip/domain/TripStatus.java index 7d1b6aa9c..0764edb7a 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/TripStatus.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripStatus.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; public enum TripStatus { ONGOING, FINISHED diff --git a/backend/src/main/java/dev/tripdraw/domain/trip/TripUpdateEvent.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripUpdateEvent.java similarity index 58% rename from backend/src/main/java/dev/tripdraw/domain/trip/TripUpdateEvent.java rename to backend/src/main/java/dev/tripdraw/trip/domain/TripUpdateEvent.java index 74c54c641..909f525f0 100644 --- a/backend/src/main/java/dev/tripdraw/domain/trip/TripUpdateEvent.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripUpdateEvent.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; public record TripUpdateEvent(Long tripId) { } diff --git a/backend/src/main/java/dev/tripdraw/dto/trip/PointCreateRequest.java b/backend/src/main/java/dev/tripdraw/trip/dto/PointCreateRequest.java similarity index 92% rename from backend/src/main/java/dev/tripdraw/dto/trip/PointCreateRequest.java rename to backend/src/main/java/dev/tripdraw/trip/dto/PointCreateRequest.java index 44f9636f2..6d7dff2bd 100644 --- a/backend/src/main/java/dev/tripdraw/dto/trip/PointCreateRequest.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/PointCreateRequest.java @@ -1,9 +1,9 @@ -package dev.tripdraw.dto.trip; +package dev.tripdraw.trip.dto; import static com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING; import com.fasterxml.jackson.annotation.JsonFormat; -import dev.tripdraw.domain.trip.Point; +import dev.tripdraw.trip.domain.Point; import io.swagger.v3.oas.annotations.media.Schema; import java.time.LocalDateTime; diff --git a/backend/src/main/java/dev/tripdraw/dto/trip/PointCreateResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/PointCreateResponse.java similarity index 80% rename from backend/src/main/java/dev/tripdraw/dto/trip/PointCreateResponse.java rename to backend/src/main/java/dev/tripdraw/trip/dto/PointCreateResponse.java index de0e6ae6f..bc56aae64 100644 --- a/backend/src/main/java/dev/tripdraw/dto/trip/PointCreateResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/PointCreateResponse.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.trip; +package dev.tripdraw.trip.dto; -import dev.tripdraw.domain.trip.Point; +import dev.tripdraw.trip.domain.Point; import io.swagger.v3.oas.annotations.media.Schema; public record PointCreateResponse( diff --git a/backend/src/main/java/dev/tripdraw/dto/trip/PointResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/PointResponse.java similarity index 93% rename from backend/src/main/java/dev/tripdraw/dto/trip/PointResponse.java rename to backend/src/main/java/dev/tripdraw/trip/dto/PointResponse.java index 295c384a2..64756af23 100644 --- a/backend/src/main/java/dev/tripdraw/dto/trip/PointResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/PointResponse.java @@ -1,9 +1,9 @@ -package dev.tripdraw.dto.trip; +package dev.tripdraw.trip.dto; import static com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING; import com.fasterxml.jackson.annotation.JsonFormat; -import dev.tripdraw.domain.trip.Point; +import dev.tripdraw.trip.domain.Point; import io.swagger.v3.oas.annotations.media.Schema; import java.time.LocalDateTime; diff --git a/backend/src/main/java/dev/tripdraw/dto/trip/TripCreateResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripCreateResponse.java similarity index 80% rename from backend/src/main/java/dev/tripdraw/dto/trip/TripCreateResponse.java rename to backend/src/main/java/dev/tripdraw/trip/dto/TripCreateResponse.java index a545839d4..81c442cb2 100644 --- a/backend/src/main/java/dev/tripdraw/dto/trip/TripCreateResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripCreateResponse.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.trip; +package dev.tripdraw.trip.dto; -import dev.tripdraw.domain.trip.Trip; +import dev.tripdraw.trip.domain.Trip; import io.swagger.v3.oas.annotations.media.Schema; public record TripCreateResponse( diff --git a/backend/src/main/java/dev/tripdraw/dto/trip/TripResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripResponse.java similarity index 92% rename from backend/src/main/java/dev/tripdraw/dto/trip/TripResponse.java rename to backend/src/main/java/dev/tripdraw/trip/dto/TripResponse.java index 79fe8d083..146fd3c94 100644 --- a/backend/src/main/java/dev/tripdraw/dto/trip/TripResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripResponse.java @@ -1,7 +1,7 @@ -package dev.tripdraw.dto.trip; +package dev.tripdraw.trip.dto; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripStatus; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripStatus; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; diff --git a/backend/src/main/java/dev/tripdraw/dto/trip/TripSearchResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java similarity index 93% rename from backend/src/main/java/dev/tripdraw/dto/trip/TripSearchResponse.java rename to backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java index 98ae56860..105522c2f 100644 --- a/backend/src/main/java/dev/tripdraw/dto/trip/TripSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.trip; +package dev.tripdraw.trip.dto; -import dev.tripdraw.domain.trip.Trip; +import dev.tripdraw.trip.domain.Trip; import io.swagger.v3.oas.annotations.media.Schema; import java.util.Objects; diff --git a/backend/src/main/java/dev/tripdraw/dto/trip/TripUpdateRequest.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripUpdateRequest.java similarity index 81% rename from backend/src/main/java/dev/tripdraw/dto/trip/TripUpdateRequest.java rename to backend/src/main/java/dev/tripdraw/trip/dto/TripUpdateRequest.java index 5e662f6f8..ae57a20df 100644 --- a/backend/src/main/java/dev/tripdraw/dto/trip/TripUpdateRequest.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripUpdateRequest.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.trip; +package dev.tripdraw.trip.dto; -import dev.tripdraw.domain.trip.TripStatus; +import dev.tripdraw.trip.domain.TripStatus; import io.swagger.v3.oas.annotations.media.Schema; public record TripUpdateRequest( diff --git a/backend/src/main/java/dev/tripdraw/dto/trip/TripsSearchResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java similarity index 88% rename from backend/src/main/java/dev/tripdraw/dto/trip/TripsSearchResponse.java rename to backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java index 4d17bf4bc..31107cac0 100644 --- a/backend/src/main/java/dev/tripdraw/dto/trip/TripsSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java @@ -1,8 +1,8 @@ -package dev.tripdraw.dto.trip; +package dev.tripdraw.trip.dto; import static java.util.stream.Collectors.collectingAndThen; -import dev.tripdraw.domain.trip.Trip; +import dev.tripdraw.trip.domain.Trip; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; import java.util.stream.Collectors; diff --git a/backend/src/main/java/dev/tripdraw/exception/trip/TripException.java b/backend/src/main/java/dev/tripdraw/trip/exception/TripException.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/exception/trip/TripException.java rename to backend/src/main/java/dev/tripdraw/trip/exception/TripException.java index 71555d645..592f778d7 100644 --- a/backend/src/main/java/dev/tripdraw/exception/trip/TripException.java +++ b/backend/src/main/java/dev/tripdraw/trip/exception/TripException.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.trip; +package dev.tripdraw.trip.exception; import dev.tripdraw.exception.common.BaseException; import dev.tripdraw.exception.common.ExceptionType; diff --git a/backend/src/main/java/dev/tripdraw/exception/trip/TripExceptionType.java b/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java similarity index 97% rename from backend/src/main/java/dev/tripdraw/exception/trip/TripExceptionType.java rename to backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java index d1984eb32..cc8e93bc2 100644 --- a/backend/src/main/java/dev/tripdraw/exception/trip/TripExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.trip; +package dev.tripdraw.trip.exception; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CONFLICT; diff --git a/backend/src/main/java/dev/tripdraw/presentation/controller/TripController.java b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java similarity index 92% rename from backend/src/main/java/dev/tripdraw/presentation/controller/TripController.java rename to backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java index 2941132d7..ad7718fff 100644 --- a/backend/src/main/java/dev/tripdraw/presentation/controller/TripController.java +++ b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java @@ -1,18 +1,18 @@ -package dev.tripdraw.presentation.controller; +package dev.tripdraw.trip.presentation; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; -import dev.tripdraw.application.TripService; +import dev.tripdraw.trip.application.TripService; import dev.tripdraw.config.swagger.SwaggerAuthorizationRequired; import dev.tripdraw.dto.auth.LoginUser; -import dev.tripdraw.dto.trip.PointCreateRequest; -import dev.tripdraw.dto.trip.PointCreateResponse; -import dev.tripdraw.dto.trip.PointResponse; -import dev.tripdraw.dto.trip.TripCreateResponse; -import dev.tripdraw.dto.trip.TripResponse; -import dev.tripdraw.dto.trip.TripUpdateRequest; -import dev.tripdraw.dto.trip.TripsSearchResponse; +import dev.tripdraw.trip.dto.PointCreateRequest; +import dev.tripdraw.trip.dto.PointCreateResponse; +import dev.tripdraw.trip.dto.PointResponse; +import dev.tripdraw.trip.dto.TripCreateResponse; +import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripUpdateRequest; +import dev.tripdraw.trip.dto.TripsSearchResponse; import dev.tripdraw.presentation.member.Auth; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; diff --git a/backend/src/test/java/dev/tripdraw/application/MemberServiceTest.java b/backend/src/test/java/dev/tripdraw/application/MemberServiceTest.java index 27f8481a9..c3d08d491 100644 --- a/backend/src/test/java/dev/tripdraw/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/application/MemberServiceTest.java @@ -12,10 +12,10 @@ import dev.tripdraw.domain.member.MemberRepository; import dev.tripdraw.domain.post.Post; import dev.tripdraw.domain.post.PostRepository; -import dev.tripdraw.domain.trip.Point; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripName; -import dev.tripdraw.domain.trip.TripRepository; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripName; +import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.dto.member.MemberSearchResponse; import dev.tripdraw.exception.member.MemberException; import java.time.LocalDateTime; diff --git a/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java index ffacfd083..053c83f59 100644 --- a/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java @@ -4,9 +4,9 @@ import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.exception.post.PostExceptionType.NOT_AUTHORIZED_TO_POST; import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUND; -import static dev.tripdraw.exception.trip.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_NOT_FOUND; -import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; +import static dev.tripdraw.trip.exception.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; +import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -17,9 +17,9 @@ import dev.tripdraw.application.draw.RouteImageGenerator; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; -import dev.tripdraw.domain.trip.Point; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripRepository; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.dto.auth.LoginUser; import dev.tripdraw.dto.post.PostAndPointCreateRequest; import dev.tripdraw.dto.post.PostCreateResponse; @@ -29,7 +29,7 @@ import dev.tripdraw.dto.post.PostsResponse; import dev.tripdraw.exception.member.MemberException; import dev.tripdraw.exception.post.PostException; -import dev.tripdraw.exception.trip.TripException; +import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.BeforeEach; diff --git a/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerIntegrationTest.java b/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerIntegrationTest.java index 6757d4db5..7431258f4 100644 --- a/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerIntegrationTest.java +++ b/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerIntegrationTest.java @@ -9,7 +9,7 @@ import dev.tripdraw.domain.post.PostCreateEvent; import dev.tripdraw.domain.post.PostRepository; -import dev.tripdraw.domain.trip.TripRepository; +import dev.tripdraw.trip.domain.TripRepository; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerTest.java index ed538f9bc..dde08ac70 100644 --- a/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerTest.java @@ -9,7 +9,7 @@ import dev.tripdraw.domain.post.PostCreateEvent; import dev.tripdraw.domain.post.PostRepository; -import dev.tripdraw.domain.trip.TripRepository; +import dev.tripdraw.trip.domain.TripRepository; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerIntegrationTest.java b/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerIntegrationTest.java index 654db3b93..625e4a6e1 100644 --- a/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerIntegrationTest.java +++ b/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerIntegrationTest.java @@ -6,8 +6,8 @@ import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.timeout; -import dev.tripdraw.domain.trip.TripRepository; -import dev.tripdraw.domain.trip.TripUpdateEvent; +import dev.tripdraw.trip.domain.TripRepository; +import dev.tripdraw.trip.domain.TripUpdateEvent; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerTest.java index e0d6e6c0e..e58be2b55 100644 --- a/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerTest.java @@ -6,8 +6,8 @@ import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; -import dev.tripdraw.domain.trip.TripRepository; -import dev.tripdraw.domain.trip.TripUpdateEvent; +import dev.tripdraw.trip.domain.TripRepository; +import dev.tripdraw.trip.domain.TripUpdateEvent; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -26,7 +26,7 @@ class TripUpdateEventHandlerTest { @Mock private TripRepository tripRepository; - + @InjectMocks private TripUpdateEventHandler tripUpdateEventHandler; diff --git a/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java index 3f8c3b7fd..ab9a9350a 100644 --- a/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java @@ -8,10 +8,10 @@ import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; -import dev.tripdraw.domain.trip.Point; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripName; -import dev.tripdraw.domain.trip.TripRepository; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripName; +import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.exception.post.PostException; import java.time.LocalDateTime; import java.util.List; diff --git a/backend/src/test/java/dev/tripdraw/domain/post/PostTest.java b/backend/src/test/java/dev/tripdraw/domain/post/PostTest.java index fc478c1c3..d9b75c44c 100644 --- a/backend/src/test/java/dev/tripdraw/domain/post/PostTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/post/PostTest.java @@ -2,15 +2,15 @@ import static dev.tripdraw.domain.oauth.OauthType.KAKAO; import static dev.tripdraw.exception.post.PostExceptionType.NOT_AUTHORIZED_TO_POST; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_ALREADY_HAS_POST; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_HAS_POST; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.trip.Point; +import dev.tripdraw.trip.domain.Point; import dev.tripdraw.exception.post.PostException; -import dev.tripdraw.exception.trip.TripException; +import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/dto/post/PostResponseAndPointCreateRequestTest.java b/backend/src/test/java/dev/tripdraw/dto/post/PostResponseAndPointCreateRequestTest.java index 5273a6d79..13fefc5e2 100644 --- a/backend/src/test/java/dev/tripdraw/dto/post/PostResponseAndPointCreateRequestTest.java +++ b/backend/src/test/java/dev/tripdraw/dto/post/PostResponseAndPointCreateRequestTest.java @@ -2,7 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import dev.tripdraw.domain.trip.Point; +import dev.tripdraw.trip.domain.Point; import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/presentation/controller/AuthControllerTest.java b/backend/src/test/java/dev/tripdraw/presentation/controller/AuthControllerTest.java index 0f4de118e..a3f5d380c 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/controller/AuthControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/presentation/controller/AuthControllerTest.java @@ -16,6 +16,7 @@ import dev.tripdraw.dto.auth.OauthRequest; import dev.tripdraw.dto.auth.OauthResponse; import dev.tripdraw.dto.auth.RegisterRequest; +import dev.tripdraw.test.ControllerTest; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; @@ -42,7 +43,7 @@ class AuthControllerTest extends ControllerTest { MemberRepository memberRepository; @BeforeEach - void setUp() { + public void setUp() { RestAssured.port = port; when(oauthClientProvider.provide(KAKAO)) diff --git a/backend/src/test/java/dev/tripdraw/presentation/controller/MemberControllerTest.java b/backend/src/test/java/dev/tripdraw/presentation/controller/MemberControllerTest.java index 44a69bec6..908d0105b 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/controller/MemberControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/presentation/controller/MemberControllerTest.java @@ -13,11 +13,12 @@ import dev.tripdraw.domain.member.MemberRepository; import dev.tripdraw.domain.post.Post; import dev.tripdraw.domain.post.PostRepository; -import dev.tripdraw.domain.trip.Point; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripName; -import dev.tripdraw.domain.trip.TripRepository; import dev.tripdraw.dto.member.MemberSearchResponse; +import dev.tripdraw.test.ControllerTest; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripName; +import dev.tripdraw.trip.domain.TripRepository; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; @@ -49,7 +50,7 @@ class MemberControllerTest extends ControllerTest { AuthTokenManager authTokenManager; @BeforeEach - void setUp() { + public void setUp() { RestAssured.port = port; } diff --git a/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java index 6e490e2a3..422d234ad 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java @@ -15,16 +15,17 @@ import dev.tripdraw.application.oauth.AuthTokenManager; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripRepository; import dev.tripdraw.dto.post.PostAndPointCreateRequest; import dev.tripdraw.dto.post.PostCreateResponse; import dev.tripdraw.dto.post.PostRequest; import dev.tripdraw.dto.post.PostResponse; import dev.tripdraw.dto.post.PostUpdateRequest; import dev.tripdraw.dto.post.PostsResponse; -import dev.tripdraw.dto.trip.PointCreateRequest; -import dev.tripdraw.dto.trip.PointResponse; +import dev.tripdraw.test.ControllerTest; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; +import dev.tripdraw.trip.dto.PointCreateRequest; +import dev.tripdraw.trip.dto.PointResponse; import io.restassured.RestAssured; import io.restassured.builder.MultiPartSpecBuilder; import io.restassured.response.ExtractableResponse; @@ -59,7 +60,7 @@ class PostControllerTest extends ControllerTest { private String huchuToken; @BeforeEach - void setUp() { + public void setUp() { super.setUp(); Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); diff --git a/backend/src/test/java/dev/tripdraw/presentation/controller/ControllerTest.java b/backend/src/test/java/dev/tripdraw/test/ControllerTest.java similarity index 91% rename from backend/src/test/java/dev/tripdraw/presentation/controller/ControllerTest.java rename to backend/src/test/java/dev/tripdraw/test/ControllerTest.java index 328983b8b..49dba79f2 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/controller/ControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/test/ControllerTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.presentation.controller; +package dev.tripdraw.test; import io.restassured.RestAssured; import org.junit.jupiter.api.BeforeEach; @@ -16,7 +16,7 @@ public abstract class ControllerTest { private int port; @BeforeEach - void setUp() { + public void setUp() { RestAssured.port = port; } } diff --git a/backend/src/test/java/dev/tripdraw/test/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/TestFixture.java index 6c9f9dcca..2d346957d 100644 --- a/backend/src/test/java/dev/tripdraw/test/TestFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/TestFixture.java @@ -3,10 +3,10 @@ import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.oauth.OauthType; import dev.tripdraw.domain.post.Post; -import dev.tripdraw.domain.trip.Point; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripName; -import dev.tripdraw.domain.trip.TripStatus; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripName; +import dev.tripdraw.trip.domain.TripStatus; import java.time.LocalDateTime; @SuppressWarnings("NonAsciiCharacters") diff --git a/backend/src/test/java/dev/tripdraw/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java similarity index 89% rename from backend/src/test/java/dev/tripdraw/application/TripServiceTest.java rename to backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index 2a656cfc8..478ef32b2 100644 --- a/backend/src/test/java/dev/tripdraw/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -1,32 +1,33 @@ -package dev.tripdraw.application; +package dev.tripdraw.trip.application; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.domain.trip.TripStatus.FINISHED; import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_ALREADY_DELETED; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_NOT_IN_TRIP; -import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; +import static dev.tripdraw.trip.domain.TripStatus.FINISHED; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_IN_TRIP; +import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; +import dev.tripdraw.application.ServiceTest; import dev.tripdraw.application.draw.RouteImageGenerator; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; -import dev.tripdraw.domain.trip.Point; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripRepository; import dev.tripdraw.dto.auth.LoginUser; -import dev.tripdraw.dto.trip.PointCreateRequest; -import dev.tripdraw.dto.trip.PointCreateResponse; -import dev.tripdraw.dto.trip.PointResponse; -import dev.tripdraw.dto.trip.TripCreateResponse; -import dev.tripdraw.dto.trip.TripResponse; -import dev.tripdraw.dto.trip.TripSearchResponse; -import dev.tripdraw.dto.trip.TripUpdateRequest; -import dev.tripdraw.dto.trip.TripsSearchResponse; import dev.tripdraw.exception.member.MemberException; -import dev.tripdraw.exception.trip.TripException; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; +import dev.tripdraw.trip.dto.PointCreateRequest; +import dev.tripdraw.trip.dto.PointCreateResponse; +import dev.tripdraw.trip.dto.PointResponse; +import dev.tripdraw.trip.dto.TripCreateResponse; +import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchResponse; +import dev.tripdraw.trip.dto.TripUpdateRequest; +import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; import java.util.Objects; diff --git a/backend/src/test/java/dev/tripdraw/domain/trip/PointTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java similarity index 88% rename from backend/src/test/java/dev/tripdraw/domain/trip/PointTest.java rename to backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java index 9b2d613c6..15dc18035 100644 --- a/backend/src/test/java/dev/tripdraw/domain/trip/PointTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java @@ -1,11 +1,11 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_ALREADY_DELETED; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_ALREADY_HAS_POST; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_HAS_POST; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import dev.tripdraw.exception.trip.TripException; +import dev.tripdraw.trip.exception.TripException; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/dev/tripdraw/domain/trip/RouteTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/RouteTest.java similarity index 91% rename from backend/src/test/java/dev/tripdraw/domain/trip/RouteTest.java rename to backend/src/test/java/dev/tripdraw/trip/domain/RouteTest.java index ba252bc65..ba405c3f9 100644 --- a/backend/src/test/java/dev/tripdraw/domain/trip/RouteTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/RouteTest.java @@ -1,12 +1,12 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_ALREADY_DELETED; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_NOT_FOUND; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_NOT_IN_TRIP; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_IN_TRIP; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import dev.tripdraw.exception.trip.TripException; +import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; diff --git a/backend/src/test/java/dev/tripdraw/domain/trip/TripNameTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripNameTest.java similarity index 93% rename from backend/src/test/java/dev/tripdraw/domain/trip/TripNameTest.java rename to backend/src/test/java/dev/tripdraw/trip/domain/TripNameTest.java index f1eca3f27..d4d68a0a7 100644 --- a/backend/src/test/java/dev/tripdraw/domain/trip/TripNameTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripNameTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +17,7 @@ class TripNameTest { // when tripName.change("제주도 여행"); - + // then assertThat(tripName.name()).isEqualTo("제주도 여행"); } diff --git a/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java similarity index 96% rename from backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java rename to backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index 25d282fc0..e5abcd4b8 100644 --- a/backend/src/test/java/dev/tripdraw/domain/trip/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -1,7 +1,7 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; +import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -9,7 +9,7 @@ import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; -import dev.tripdraw.exception.trip.TripException; +import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.BeforeEach; diff --git a/backend/src/test/java/dev/tripdraw/domain/trip/TripTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java similarity index 96% rename from backend/src/test/java/dev/tripdraw/domain/trip/TripTest.java rename to backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java index a6e623bcb..9ecbd83d9 100644 --- a/backend/src/test/java/dev/tripdraw/domain/trip/TripTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java @@ -1,16 +1,16 @@ -package dev.tripdraw.domain.trip; +package dev.tripdraw.trip.domain; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.exception.trip.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_ALREADY_DELETED; -import static dev.tripdraw.exception.trip.TripExceptionType.POINT_NOT_IN_TRIP; -import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_INVALID_STATUS; +import static dev.tripdraw.trip.exception.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_IN_TRIP; +import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_INVALID_STATUS; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.domain.member.Member; -import dev.tripdraw.exception.trip.TripException; +import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/dto/trip/PointCreateRequestTest.java b/backend/src/test/java/dev/tripdraw/trip/dto/PointCreateRequestTest.java similarity index 92% rename from backend/src/test/java/dev/tripdraw/dto/trip/PointCreateRequestTest.java rename to backend/src/test/java/dev/tripdraw/trip/dto/PointCreateRequestTest.java index a180db669..02525c70d 100644 --- a/backend/src/test/java/dev/tripdraw/dto/trip/PointCreateRequestTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/dto/PointCreateRequestTest.java @@ -1,8 +1,8 @@ -package dev.tripdraw.dto.trip; +package dev.tripdraw.trip.dto; import static org.assertj.core.api.Assertions.assertThat; -import dev.tripdraw.domain.trip.Point; +import dev.tripdraw.trip.domain.Point; import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/dto/trip/TripSearchResponseTest.java b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java similarity index 86% rename from backend/src/test/java/dev/tripdraw/dto/trip/TripSearchResponseTest.java rename to backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java index bf5575170..93ab96a7a 100644 --- a/backend/src/test/java/dev/tripdraw/dto/trip/TripSearchResponseTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java @@ -1,12 +1,12 @@ -package dev.tripdraw.dto.trip; +package dev.tripdraw.trip.dto; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.domain.trip.TripStatus.ONGOING; +import static dev.tripdraw.trip.domain.TripStatus.ONGOING; import static org.assertj.core.api.Assertions.assertThat; import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripName; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripName; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/dev/tripdraw/presentation/controller/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java similarity index 95% rename from backend/src/test/java/dev/tripdraw/presentation/controller/TripControllerTest.java rename to backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index 294291a4d..34e676067 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/controller/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -1,7 +1,7 @@ -package dev.tripdraw.presentation.controller; +package dev.tripdraw.trip.presentation; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.domain.trip.TripStatus.FINISHED; +import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.CREATED; @@ -15,16 +15,17 @@ import dev.tripdraw.application.oauth.AuthTokenManager; import dev.tripdraw.domain.member.Member; import dev.tripdraw.domain.member.MemberRepository; -import dev.tripdraw.domain.trip.Trip; -import dev.tripdraw.domain.trip.TripRepository; -import dev.tripdraw.dto.trip.PointCreateRequest; -import dev.tripdraw.dto.trip.PointCreateResponse; -import dev.tripdraw.dto.trip.PointResponse; -import dev.tripdraw.dto.trip.TripCreateResponse; -import dev.tripdraw.dto.trip.TripResponse; -import dev.tripdraw.dto.trip.TripSearchResponse; -import dev.tripdraw.dto.trip.TripUpdateRequest; -import dev.tripdraw.dto.trip.TripsSearchResponse; +import dev.tripdraw.test.ControllerTest; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; +import dev.tripdraw.trip.dto.PointCreateRequest; +import dev.tripdraw.trip.dto.PointCreateResponse; +import dev.tripdraw.trip.dto.PointResponse; +import dev.tripdraw.trip.dto.TripCreateResponse; +import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchResponse; +import dev.tripdraw.trip.dto.TripUpdateRequest; +import dev.tripdraw.trip.dto.TripsSearchResponse; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; @@ -59,7 +60,7 @@ class TripControllerTest extends ControllerTest { private String huchuToken; @BeforeEach - void setUp() { + public void setUp() { super.setUp(); Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); From 8ebc89e7442d78eafe450815b829e08f857136ff Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 31 Aug 2023 17:05:30 +0900 Subject: [PATCH 012/119] =?UTF-8?q?[refactor]=20member=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?(#223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Combi153 Co-authored-by: Jaeyoung22 --- .../java/dev/tripdraw/application/AuthService.java | 10 +++++----- .../java/dev/tripdraw/application/PostService.java | 4 ++-- .../main/java/dev/tripdraw/domain/post/Post.java | 2 +- .../dto/post/PostAndPointCreateRequest.java | 2 +- .../java/dev/tripdraw/dto/post/PostRequest.java | 2 +- .../{ => member}/application/MemberService.java | 8 ++++---- .../{domain/member => member/domain}/Member.java | 2 +- .../member => member/domain}/MemberRepository.java | 6 +++--- .../dto}/MemberSearchResponse.java | 4 ++-- .../exception}/MemberException.java | 2 +- .../exception}/MemberExceptionType.java | 2 +- .../presentation}/MemberController.java | 6 +++--- .../presentation/member/AuthInterceptor.java | 2 +- .../dev/tripdraw/trip/application/TripService.java | 4 ++-- .../main/java/dev/tripdraw/trip/domain/Trip.java | 2 +- .../dev/tripdraw/application/AuthServiceTest.java | 10 +++++----- .../dev/tripdraw/application/PostServiceTest.java | 8 ++++---- .../tripdraw/domain/post/PostRepositoryTest.java | 4 ++-- .../java/dev/tripdraw/domain/post/PostTest.java | 2 +- .../application/MemberServiceTest.java | 14 ++++++++------ .../domain}/MemberRepositoryTest.java | 8 +++++--- .../member => member/domain}/MemberTest.java | 3 ++- .../presentation}/MemberControllerTest.java | 8 ++++---- .../controller/AuthControllerTest.java | 4 ++-- .../controller/PostControllerTest.java | 4 ++-- .../test/java/dev/tripdraw/test/TestFixture.java | 2 +- .../tripdraw/trip/application/TripServiceTest.java | 8 ++++---- .../tripdraw/trip/domain/TripRepositoryTest.java | 4 ++-- .../java/dev/tripdraw/trip/domain/TripTest.java | 2 +- .../tripdraw/trip/dto/TripSearchResponseTest.java | 2 +- .../trip/presentation/TripControllerTest.java | 4 ++-- 31 files changed, 75 insertions(+), 70 deletions(-) rename backend/src/main/java/dev/tripdraw/{ => member}/application/MemberService.java (87%) rename backend/src/main/java/dev/tripdraw/{domain/member => member/domain}/Member.java (97%) rename backend/src/main/java/dev/tripdraw/{domain/member => member/domain}/MemberRepository.java (78%) rename backend/src/main/java/dev/tripdraw/{dto/member => member/dto}/MemberSearchResponse.java (87%) rename backend/src/main/java/dev/tripdraw/{exception/member => member/exception}/MemberException.java (86%) rename backend/src/main/java/dev/tripdraw/{exception/member => member/exception}/MemberExceptionType.java (95%) rename backend/src/main/java/dev/tripdraw/{presentation/controller => member/presentation}/MemberController.java (91%) rename backend/src/test/java/dev/tripdraw/{ => member}/application/MemberServiceTest.java (89%) rename backend/src/test/java/dev/tripdraw/{domain/member => member/domain}/MemberRepositoryTest.java (89%) rename backend/src/test/java/dev/tripdraw/{domain/member => member/domain}/MemberTest.java (89%) rename backend/src/test/java/dev/tripdraw/{presentation/controller => member/presentation}/MemberControllerTest.java (96%) diff --git a/backend/src/main/java/dev/tripdraw/application/AuthService.java b/backend/src/main/java/dev/tripdraw/application/AuthService.java index 07106d356..01a053da6 100644 --- a/backend/src/main/java/dev/tripdraw/application/AuthService.java +++ b/backend/src/main/java/dev/tripdraw/application/AuthService.java @@ -1,18 +1,18 @@ package dev.tripdraw.application; -import static dev.tripdraw.exception.member.MemberExceptionType.DUPLICATE_NICKNAME; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; +import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; +import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import dev.tripdraw.application.oauth.AuthTokenManager; import dev.tripdraw.application.oauth.OauthClient; import dev.tripdraw.application.oauth.OauthClientProvider; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.dto.auth.OauthInfo; import dev.tripdraw.dto.auth.OauthRequest; import dev.tripdraw.dto.auth.OauthResponse; import dev.tripdraw.dto.auth.RegisterRequest; -import dev.tripdraw.exception.member.MemberException; +import dev.tripdraw.member.exception.MemberException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/backend/src/main/java/dev/tripdraw/application/PostService.java b/backend/src/main/java/dev/tripdraw/application/PostService.java index db96b7107..fa6090030 100644 --- a/backend/src/main/java/dev/tripdraw/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/application/PostService.java @@ -4,8 +4,8 @@ import dev.tripdraw.application.file.FileUploader; import dev.tripdraw.domain.file.FileType; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.domain.post.Post; import dev.tripdraw.domain.post.PostCreateEvent; import dev.tripdraw.domain.post.PostRepository; diff --git a/backend/src/main/java/dev/tripdraw/domain/post/Post.java b/backend/src/main/java/dev/tripdraw/domain/post/Post.java index be2ec0a4c..0b6e1e316 100644 --- a/backend/src/main/java/dev/tripdraw/domain/post/Post.java +++ b/backend/src/main/java/dev/tripdraw/domain/post/Post.java @@ -6,7 +6,7 @@ import static lombok.AccessLevel.PROTECTED; import dev.tripdraw.domain.common.BaseEntity; -import dev.tripdraw.domain.member.Member; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.exception.post.PostException; import jakarta.persistence.Column; diff --git a/backend/src/main/java/dev/tripdraw/dto/post/PostAndPointCreateRequest.java b/backend/src/main/java/dev/tripdraw/dto/post/PostAndPointCreateRequest.java index 3c43edbb9..de4de2217 100644 --- a/backend/src/main/java/dev/tripdraw/dto/post/PostAndPointCreateRequest.java +++ b/backend/src/main/java/dev/tripdraw/dto/post/PostAndPointCreateRequest.java @@ -3,7 +3,7 @@ import static com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING; import com.fasterxml.jackson.annotation.JsonFormat; -import dev.tripdraw.domain.member.Member; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.domain.post.Post; import dev.tripdraw.trip.domain.Point; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/backend/src/main/java/dev/tripdraw/dto/post/PostRequest.java b/backend/src/main/java/dev/tripdraw/dto/post/PostRequest.java index 0bd95d11a..0bdd792d0 100644 --- a/backend/src/main/java/dev/tripdraw/dto/post/PostRequest.java +++ b/backend/src/main/java/dev/tripdraw/dto/post/PostRequest.java @@ -1,6 +1,6 @@ package dev.tripdraw.dto.post; -import dev.tripdraw.domain.member.Member; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.domain.post.Post; import dev.tripdraw.trip.domain.Point; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/backend/src/main/java/dev/tripdraw/application/MemberService.java b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/application/MemberService.java rename to backend/src/main/java/dev/tripdraw/member/application/MemberService.java index 669bc4e0e..995a87e48 100644 --- a/backend/src/main/java/dev/tripdraw/application/MemberService.java +++ b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java @@ -1,11 +1,11 @@ -package dev.tripdraw.application; +package dev.tripdraw.member.application; import dev.tripdraw.application.oauth.AuthTokenManager; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.domain.post.PostRepository; import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.dto.member.MemberSearchResponse; +import dev.tripdraw.member.dto.MemberSearchResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/backend/src/main/java/dev/tripdraw/domain/member/Member.java b/backend/src/main/java/dev/tripdraw/member/domain/Member.java similarity index 97% rename from backend/src/main/java/dev/tripdraw/domain/member/Member.java rename to backend/src/main/java/dev/tripdraw/member/domain/Member.java index f68766575..a5abcab53 100644 --- a/backend/src/main/java/dev/tripdraw/domain/member/Member.java +++ b/backend/src/main/java/dev/tripdraw/member/domain/Member.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.member; +package dev.tripdraw.member.domain; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; diff --git a/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java b/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java similarity index 78% rename from backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java rename to backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java index 307ce6321..3052b2a54 100644 --- a/backend/src/main/java/dev/tripdraw/domain/member/MemberRepository.java +++ b/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java @@ -1,9 +1,9 @@ -package dev.tripdraw.domain.member; +package dev.tripdraw.member.domain; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; +import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import dev.tripdraw.domain.oauth.OauthType; -import dev.tripdraw.exception.member.MemberException; +import dev.tripdraw.member.exception.MemberException; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.lang.NonNull; diff --git a/backend/src/main/java/dev/tripdraw/dto/member/MemberSearchResponse.java b/backend/src/main/java/dev/tripdraw/member/dto/MemberSearchResponse.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/dto/member/MemberSearchResponse.java rename to backend/src/main/java/dev/tripdraw/member/dto/MemberSearchResponse.java index e84b5929d..7d6e4b949 100644 --- a/backend/src/main/java/dev/tripdraw/dto/member/MemberSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/member/dto/MemberSearchResponse.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.member; +package dev.tripdraw.member.dto; -import dev.tripdraw.domain.member.Member; +import dev.tripdraw.member.domain.Member; import io.swagger.v3.oas.annotations.media.Schema; import java.util.Objects; diff --git a/backend/src/main/java/dev/tripdraw/exception/member/MemberException.java b/backend/src/main/java/dev/tripdraw/member/exception/MemberException.java similarity index 86% rename from backend/src/main/java/dev/tripdraw/exception/member/MemberException.java rename to backend/src/main/java/dev/tripdraw/member/exception/MemberException.java index cd4ccb936..716fb953b 100644 --- a/backend/src/main/java/dev/tripdraw/exception/member/MemberException.java +++ b/backend/src/main/java/dev/tripdraw/member/exception/MemberException.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.member; +package dev.tripdraw.member.exception; import dev.tripdraw.exception.common.BaseException; import dev.tripdraw.exception.common.ExceptionType; diff --git a/backend/src/main/java/dev/tripdraw/exception/member/MemberExceptionType.java b/backend/src/main/java/dev/tripdraw/member/exception/MemberExceptionType.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/exception/member/MemberExceptionType.java rename to backend/src/main/java/dev/tripdraw/member/exception/MemberExceptionType.java index 645c593d3..48c10159d 100644 --- a/backend/src/main/java/dev/tripdraw/exception/member/MemberExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/member/exception/MemberExceptionType.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.member; +package dev.tripdraw.member.exception; import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.NOT_FOUND; diff --git a/backend/src/main/java/dev/tripdraw/presentation/controller/MemberController.java b/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java similarity index 91% rename from backend/src/main/java/dev/tripdraw/presentation/controller/MemberController.java rename to backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java index 1720a1229..a88e8fbc6 100644 --- a/backend/src/main/java/dev/tripdraw/presentation/controller/MemberController.java +++ b/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java @@ -1,7 +1,7 @@ -package dev.tripdraw.presentation.controller; +package dev.tripdraw.member.presentation; -import dev.tripdraw.application.MemberService; -import dev.tripdraw.dto.member.MemberSearchResponse; +import dev.tripdraw.member.application.MemberService; +import dev.tripdraw.member.dto.MemberSearchResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/backend/src/main/java/dev/tripdraw/presentation/member/AuthInterceptor.java b/backend/src/main/java/dev/tripdraw/presentation/member/AuthInterceptor.java index 9c7cbac55..d0b48e7d5 100644 --- a/backend/src/main/java/dev/tripdraw/presentation/member/AuthInterceptor.java +++ b/backend/src/main/java/dev/tripdraw/presentation/member/AuthInterceptor.java @@ -2,7 +2,7 @@ import static dev.tripdraw.exception.auth.AuthExceptionType.AUTH_FAIL; -import dev.tripdraw.application.MemberService; +import dev.tripdraw.member.application.MemberService; import dev.tripdraw.dto.auth.LoginUser; import dev.tripdraw.exception.auth.AuthException; import jakarta.servlet.http.HttpServletRequest; diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index d86f833c9..1a91e5c0e 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -1,7 +1,7 @@ package dev.tripdraw.trip.application; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java b/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java index 2ed6e9a0c..923a28105 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java @@ -8,7 +8,7 @@ import static lombok.AccessLevel.PROTECTED; import dev.tripdraw.domain.common.BaseEntity; -import dev.tripdraw.domain.member.Member; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.trip.exception.TripException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; diff --git a/backend/src/test/java/dev/tripdraw/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/application/AuthServiceTest.java index 54e63b0f4..e24f9c6cc 100644 --- a/backend/src/test/java/dev/tripdraw/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/application/AuthServiceTest.java @@ -1,20 +1,20 @@ package dev.tripdraw.application; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.exception.member.MemberExceptionType.DUPLICATE_NICKNAME; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; +import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; +import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.when; import dev.tripdraw.application.oauth.OauthClientProvider; import dev.tripdraw.common.TestKakaoApiClient; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.dto.auth.OauthRequest; import dev.tripdraw.dto.auth.OauthResponse; import dev.tripdraw.dto.auth.RegisterRequest; -import dev.tripdraw.exception.member.MemberException; +import dev.tripdraw.member.exception.MemberException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java index 053c83f59..205973dcd 100644 --- a/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java @@ -1,7 +1,7 @@ package dev.tripdraw.application; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; +import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.exception.post.PostExceptionType.NOT_AUTHORIZED_TO_POST; import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUND; import static dev.tripdraw.trip.exception.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; @@ -15,8 +15,8 @@ import static org.mockito.ArgumentMatchers.any; import dev.tripdraw.application.draw.RouteImageGenerator; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; @@ -27,7 +27,7 @@ import dev.tripdraw.dto.post.PostResponse; import dev.tripdraw.dto.post.PostUpdateRequest; import dev.tripdraw.dto.post.PostsResponse; -import dev.tripdraw.exception.member.MemberException; +import dev.tripdraw.member.exception.MemberException; import dev.tripdraw.exception.post.PostException; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; diff --git a/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java index ab9a9350a..ee4164429 100644 --- a/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java @@ -6,8 +6,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; diff --git a/backend/src/test/java/dev/tripdraw/domain/post/PostTest.java b/backend/src/test/java/dev/tripdraw/domain/post/PostTest.java index d9b75c44c..7e213fb21 100644 --- a/backend/src/test/java/dev/tripdraw/domain/post/PostTest.java +++ b/backend/src/test/java/dev/tripdraw/domain/post/PostTest.java @@ -7,7 +7,7 @@ import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import dev.tripdraw.domain.member.Member; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.exception.post.PostException; import dev.tripdraw.trip.exception.TripException; diff --git a/backend/src/test/java/dev/tripdraw/application/MemberServiceTest.java b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java similarity index 89% rename from backend/src/test/java/dev/tripdraw/application/MemberServiceTest.java rename to backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java index c3d08d491..91a4a65f9 100644 --- a/backend/src/test/java/dev/tripdraw/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java @@ -1,23 +1,25 @@ -package dev.tripdraw.application; +package dev.tripdraw.member.application; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; +import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; +import dev.tripdraw.application.ServiceTest; import dev.tripdraw.application.oauth.AuthTokenManager; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.application.MemberService; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.domain.post.Post; import dev.tripdraw.domain.post.PostRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.dto.member.MemberSearchResponse; -import dev.tripdraw.exception.member.MemberException; +import dev.tripdraw.member.dto.MemberSearchResponse; +import dev.tripdraw.member.exception.MemberException; import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java similarity index 89% rename from backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java rename to backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java index 21122b7a3..4f5344eb3 100644 --- a/backend/src/test/java/dev/tripdraw/domain/member/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java @@ -1,12 +1,14 @@ -package dev.tripdraw.domain.member; +package dev.tripdraw.member.domain; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; +import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import dev.tripdraw.exception.member.MemberException; +import dev.tripdraw.member.exception.MemberException; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import java.util.Optional; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/domain/member/MemberTest.java b/backend/src/test/java/dev/tripdraw/member/domain/MemberTest.java similarity index 89% rename from backend/src/test/java/dev/tripdraw/domain/member/MemberTest.java rename to backend/src/test/java/dev/tripdraw/member/domain/MemberTest.java index f3b3d14ba..fb9097747 100644 --- a/backend/src/test/java/dev/tripdraw/domain/member/MemberTest.java +++ b/backend/src/test/java/dev/tripdraw/member/domain/MemberTest.java @@ -1,8 +1,9 @@ -package dev.tripdraw.domain.member; +package dev.tripdraw.member.domain; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; import static org.assertj.core.api.Assertions.assertThat; +import dev.tripdraw.member.domain.Member; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/dev/tripdraw/presentation/controller/MemberControllerTest.java b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java similarity index 96% rename from backend/src/test/java/dev/tripdraw/presentation/controller/MemberControllerTest.java rename to backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java index 908d0105b..67c648a1c 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/controller/MemberControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.presentation.controller; +package dev.tripdraw.member.presentation; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; import static java.lang.Long.MIN_VALUE; @@ -9,11 +9,11 @@ import static org.springframework.http.HttpStatus.OK; import dev.tripdraw.application.oauth.AuthTokenManager; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.domain.post.Post; import dev.tripdraw.domain.post.PostRepository; -import dev.tripdraw.dto.member.MemberSearchResponse; +import dev.tripdraw.member.dto.MemberSearchResponse; import dev.tripdraw.test.ControllerTest; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; diff --git a/backend/src/test/java/dev/tripdraw/presentation/controller/AuthControllerTest.java b/backend/src/test/java/dev/tripdraw/presentation/controller/AuthControllerTest.java index a3f5d380c..ac0f13b10 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/controller/AuthControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/presentation/controller/AuthControllerTest.java @@ -11,8 +11,8 @@ import dev.tripdraw.application.oauth.OauthClientProvider; import dev.tripdraw.common.TestKakaoApiClient; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.dto.auth.OauthRequest; import dev.tripdraw.dto.auth.OauthResponse; import dev.tripdraw.dto.auth.RegisterRequest; diff --git a/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java index 422d234ad..d4566a080 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java @@ -13,8 +13,8 @@ import dev.tripdraw.application.draw.RouteImageGenerator; import dev.tripdraw.application.oauth.AuthTokenManager; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.dto.post.PostAndPointCreateRequest; import dev.tripdraw.dto.post.PostCreateResponse; import dev.tripdraw.dto.post.PostRequest; diff --git a/backend/src/test/java/dev/tripdraw/test/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/TestFixture.java index 2d346957d..0543998ac 100644 --- a/backend/src/test/java/dev/tripdraw/test/TestFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/TestFixture.java @@ -1,6 +1,6 @@ package dev.tripdraw.test; -import dev.tripdraw.domain.member.Member; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.domain.oauth.OauthType; import dev.tripdraw.domain.post.Post; import dev.tripdraw.trip.domain.Point; diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index 478ef32b2..5b2fa4876 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -1,7 +1,7 @@ package dev.tripdraw.trip.application; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; +import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_IN_TRIP; @@ -12,10 +12,10 @@ import dev.tripdraw.application.ServiceTest; import dev.tripdraw.application.draw.RouteImageGenerator; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.dto.auth.LoginUser; -import dev.tripdraw.exception.member.MemberException; +import dev.tripdraw.member.exception.MemberException; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index e5abcd4b8..399d98421 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -7,8 +7,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java index 9ecbd83d9..c84c6f970 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java @@ -9,7 +9,7 @@ import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import dev.tripdraw.domain.member.Member; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; diff --git a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java index 93ab96a7a..e3b8fc7c5 100644 --- a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java @@ -4,7 +4,7 @@ import static dev.tripdraw.trip.domain.TripStatus.ONGOING; import static org.assertj.core.api.Assertions.assertThat; -import dev.tripdraw.domain.member.Member; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index 34e676067..3d7967b1c 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -13,8 +13,8 @@ import dev.tripdraw.application.draw.RouteImageGenerator; import dev.tripdraw.application.oauth.AuthTokenManager; -import dev.tripdraw.domain.member.Member; -import dev.tripdraw.domain.member.MemberRepository; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.test.ControllerTest; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; From 7e8a1e151ad618ce1752a0edb75cf4fbc1c45377 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 31 Aug 2023 17:10:41 +0900 Subject: [PATCH 013/119] =?UTF-8?q?[refactor]=20draw=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20(#223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Combi153 Co-authored-by: Jaeyoung22 --- .../application}/PostCreateEventHandler.java | 2 +- .../draw => draw/application}/RouteImageGenerator.java | 8 ++++---- .../draw => draw/application}/RouteImageUploader.java | 6 +++--- .../application}/TripUpdateEventHandler.java | 2 +- .../{domain/draw => draw/domain}/Coordinate.java | 2 +- .../{domain/draw => draw/domain}/Coordinates.java | 6 +++--- .../tripdraw/{domain/draw => draw/domain}/Position.java | 2 +- .../tripdraw/{domain/draw => draw/domain}/Positions.java | 2 +- .../{domain/draw => draw/domain}/RouteImageDrawer.java | 2 +- .../draw => draw/exception}/DrawException.java | 2 +- .../draw => draw/exception}/DrawExceptionType.java | 2 +- .../java/dev/tripdraw/application/PostServiceTest.java | 2 +- .../PostCreateEventHandlerIntegrationTest.java | 3 ++- .../application}/PostCreateEventHandlerTest.java | 4 +++- .../application}/RouteImageGeneratorTest.java | 4 +++- .../application}/RouteImageUploaderTest.java | 5 +++-- .../TripUpdateEventHandlerIntegrationTest.java | 3 ++- .../application}/TripUpdateEventHandlerTest.java | 4 +++- .../{domain/draw => draw/domain}/CoordinatesTest.java | 9 ++++++--- .../{domain/draw => draw/domain}/PositionsTest.java | 4 +++- .../draw => draw/domain}/RouteImageDrawerTest.java | 5 ++++- .../presentation/controller/PostControllerTest.java | 2 +- .../dev/tripdraw/trip/application/TripServiceTest.java | 2 +- .../tripdraw/trip/presentation/TripControllerTest.java | 2 +- 24 files changed, 51 insertions(+), 34 deletions(-) rename backend/src/main/java/dev/tripdraw/{application/draw => draw/application}/PostCreateEventHandler.java (97%) rename backend/src/main/java/dev/tripdraw/{application/draw => draw/application}/RouteImageGenerator.java (89%) rename backend/src/main/java/dev/tripdraw/{application/draw => draw/application}/RouteImageUploader.java (89%) rename backend/src/main/java/dev/tripdraw/{application/draw => draw/application}/TripUpdateEventHandler.java (97%) rename backend/src/main/java/dev/tripdraw/{domain/draw => draw/domain}/Coordinate.java (59%) rename backend/src/main/java/dev/tripdraw/{domain/draw => draw/domain}/Coordinates.java (95%) rename backend/src/main/java/dev/tripdraw/{domain/draw => draw/domain}/Position.java (59%) rename backend/src/main/java/dev/tripdraw/{domain/draw => draw/domain}/Positions.java (98%) rename backend/src/main/java/dev/tripdraw/{domain/draw => draw/domain}/RouteImageDrawer.java (99%) rename backend/src/main/java/dev/tripdraw/{exception/draw => draw/exception}/DrawException.java (87%) rename backend/src/main/java/dev/tripdraw/{exception/draw => draw/exception}/DrawExceptionType.java (95%) rename backend/src/test/java/dev/tripdraw/{application/draw => draw/application}/PostCreateEventHandlerIntegrationTest.java (95%) rename backend/src/test/java/dev/tripdraw/{application/draw => draw/application}/PostCreateEventHandlerTest.java (91%) rename backend/src/test/java/dev/tripdraw/{application/draw => draw/application}/RouteImageGeneratorTest.java (91%) rename backend/src/test/java/dev/tripdraw/{application/draw => draw/application}/RouteImageUploaderTest.java (95%) rename backend/src/test/java/dev/tripdraw/{application/draw => draw/application}/TripUpdateEventHandlerIntegrationTest.java (94%) rename backend/src/test/java/dev/tripdraw/{application/draw => draw/application}/TripUpdateEventHandlerTest.java (90%) rename backend/src/test/java/dev/tripdraw/{domain/draw => draw/domain}/CoordinatesTest.java (92%) rename backend/src/test/java/dev/tripdraw/{domain/draw => draw/domain}/PositionsTest.java (95%) rename backend/src/test/java/dev/tripdraw/{domain/draw => draw/domain}/RouteImageDrawerTest.java (94%) diff --git a/backend/src/main/java/dev/tripdraw/application/draw/PostCreateEventHandler.java b/backend/src/main/java/dev/tripdraw/draw/application/PostCreateEventHandler.java similarity index 97% rename from backend/src/main/java/dev/tripdraw/application/draw/PostCreateEventHandler.java rename to backend/src/main/java/dev/tripdraw/draw/application/PostCreateEventHandler.java index ee8bbbbf7..c64e0b054 100644 --- a/backend/src/main/java/dev/tripdraw/application/draw/PostCreateEventHandler.java +++ b/backend/src/main/java/dev/tripdraw/draw/application/PostCreateEventHandler.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application.draw; +package dev.tripdraw.draw.application; import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; diff --git a/backend/src/main/java/dev/tripdraw/application/draw/RouteImageGenerator.java b/backend/src/main/java/dev/tripdraw/draw/application/RouteImageGenerator.java similarity index 89% rename from backend/src/main/java/dev/tripdraw/application/draw/RouteImageGenerator.java rename to backend/src/main/java/dev/tripdraw/draw/application/RouteImageGenerator.java index 1873f2f41..81c4812f6 100644 --- a/backend/src/main/java/dev/tripdraw/application/draw/RouteImageGenerator.java +++ b/backend/src/main/java/dev/tripdraw/draw/application/RouteImageGenerator.java @@ -1,8 +1,8 @@ -package dev.tripdraw.application.draw; +package dev.tripdraw.draw.application; -import dev.tripdraw.domain.draw.Coordinates; -import dev.tripdraw.domain.draw.Positions; -import dev.tripdraw.domain.draw.RouteImageDrawer; +import dev.tripdraw.draw.domain.Coordinates; +import dev.tripdraw.draw.domain.Positions; +import dev.tripdraw.draw.domain.RouteImageDrawer; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; diff --git a/backend/src/main/java/dev/tripdraw/application/draw/RouteImageUploader.java b/backend/src/main/java/dev/tripdraw/draw/application/RouteImageUploader.java similarity index 89% rename from backend/src/main/java/dev/tripdraw/application/draw/RouteImageUploader.java rename to backend/src/main/java/dev/tripdraw/draw/application/RouteImageUploader.java index 57d7ab84a..c2066aaa1 100644 --- a/backend/src/main/java/dev/tripdraw/application/draw/RouteImageUploader.java +++ b/backend/src/main/java/dev/tripdraw/draw/application/RouteImageUploader.java @@ -1,8 +1,8 @@ -package dev.tripdraw.application.draw; +package dev.tripdraw.draw.application; -import static dev.tripdraw.exception.draw.DrawExceptionType.IMAGE_SAVE_FAIL; +import static dev.tripdraw.draw.exception.DrawExceptionType.IMAGE_SAVE_FAIL; -import dev.tripdraw.exception.draw.DrawException; +import dev.tripdraw.draw.exception.DrawException; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; diff --git a/backend/src/main/java/dev/tripdraw/application/draw/TripUpdateEventHandler.java b/backend/src/main/java/dev/tripdraw/draw/application/TripUpdateEventHandler.java similarity index 97% rename from backend/src/main/java/dev/tripdraw/application/draw/TripUpdateEventHandler.java rename to backend/src/main/java/dev/tripdraw/draw/application/TripUpdateEventHandler.java index c0a49d2d1..318e78468 100644 --- a/backend/src/main/java/dev/tripdraw/application/draw/TripUpdateEventHandler.java +++ b/backend/src/main/java/dev/tripdraw/draw/application/TripUpdateEventHandler.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application.draw; +package dev.tripdraw.draw.application; import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; diff --git a/backend/src/main/java/dev/tripdraw/domain/draw/Coordinate.java b/backend/src/main/java/dev/tripdraw/draw/domain/Coordinate.java similarity index 59% rename from backend/src/main/java/dev/tripdraw/domain/draw/Coordinate.java rename to backend/src/main/java/dev/tripdraw/draw/domain/Coordinate.java index 3e6e84156..09407c8b8 100644 --- a/backend/src/main/java/dev/tripdraw/domain/draw/Coordinate.java +++ b/backend/src/main/java/dev/tripdraw/draw/domain/Coordinate.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.draw; +package dev.tripdraw.draw.domain; public record Coordinate(Double x, Double y) { } diff --git a/backend/src/main/java/dev/tripdraw/domain/draw/Coordinates.java b/backend/src/main/java/dev/tripdraw/draw/domain/Coordinates.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/domain/draw/Coordinates.java rename to backend/src/main/java/dev/tripdraw/draw/domain/Coordinates.java index b71b3c92e..90a52675e 100644 --- a/backend/src/main/java/dev/tripdraw/domain/draw/Coordinates.java +++ b/backend/src/main/java/dev/tripdraw/draw/domain/Coordinates.java @@ -1,10 +1,10 @@ -package dev.tripdraw.domain.draw; +package dev.tripdraw.draw.domain; -import static dev.tripdraw.exception.draw.DrawExceptionType.INVALID_COORDINATES; +import static dev.tripdraw.draw.exception.DrawExceptionType.INVALID_COORDINATES; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; -import dev.tripdraw.exception.draw.DrawException; +import dev.tripdraw.draw.exception.DrawException; import java.util.ArrayList; import java.util.Collections; import java.util.List; diff --git a/backend/src/main/java/dev/tripdraw/domain/draw/Position.java b/backend/src/main/java/dev/tripdraw/draw/domain/Position.java similarity index 59% rename from backend/src/main/java/dev/tripdraw/domain/draw/Position.java rename to backend/src/main/java/dev/tripdraw/draw/domain/Position.java index 0ddb5c173..6a5b346f5 100644 --- a/backend/src/main/java/dev/tripdraw/domain/draw/Position.java +++ b/backend/src/main/java/dev/tripdraw/draw/domain/Position.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.draw; +package dev.tripdraw.draw.domain; public record Position(Integer x, Integer y) { } diff --git a/backend/src/main/java/dev/tripdraw/domain/draw/Positions.java b/backend/src/main/java/dev/tripdraw/draw/domain/Positions.java similarity index 98% rename from backend/src/main/java/dev/tripdraw/domain/draw/Positions.java rename to backend/src/main/java/dev/tripdraw/draw/domain/Positions.java index 5d5765853..cf30b6f43 100644 --- a/backend/src/main/java/dev/tripdraw/domain/draw/Positions.java +++ b/backend/src/main/java/dev/tripdraw/draw/domain/Positions.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.draw; +package dev.tripdraw.draw.domain; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; diff --git a/backend/src/main/java/dev/tripdraw/domain/draw/RouteImageDrawer.java b/backend/src/main/java/dev/tripdraw/draw/domain/RouteImageDrawer.java similarity index 99% rename from backend/src/main/java/dev/tripdraw/domain/draw/RouteImageDrawer.java rename to backend/src/main/java/dev/tripdraw/draw/domain/RouteImageDrawer.java index 687dc50d9..bca7afd6e 100644 --- a/backend/src/main/java/dev/tripdraw/domain/draw/RouteImageDrawer.java +++ b/backend/src/main/java/dev/tripdraw/draw/domain/RouteImageDrawer.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.draw; +package dev.tripdraw.draw.domain; import static java.awt.BasicStroke.CAP_ROUND; import static java.awt.BasicStroke.JOIN_ROUND; diff --git a/backend/src/main/java/dev/tripdraw/exception/draw/DrawException.java b/backend/src/main/java/dev/tripdraw/draw/exception/DrawException.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/exception/draw/DrawException.java rename to backend/src/main/java/dev/tripdraw/draw/exception/DrawException.java index 1e76b37c5..f295cd472 100644 --- a/backend/src/main/java/dev/tripdraw/exception/draw/DrawException.java +++ b/backend/src/main/java/dev/tripdraw/draw/exception/DrawException.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.draw; +package dev.tripdraw.draw.exception; import dev.tripdraw.exception.common.BaseException; import dev.tripdraw.exception.common.ExceptionType; diff --git a/backend/src/main/java/dev/tripdraw/exception/draw/DrawExceptionType.java b/backend/src/main/java/dev/tripdraw/draw/exception/DrawExceptionType.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/exception/draw/DrawExceptionType.java rename to backend/src/main/java/dev/tripdraw/draw/exception/DrawExceptionType.java index bf4fde93a..9bda91bf1 100644 --- a/backend/src/main/java/dev/tripdraw/exception/draw/DrawExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/draw/exception/DrawExceptionType.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.draw; +package dev.tripdraw.draw.exception; import static org.springframework.http.HttpStatus.BAD_REQUEST; diff --git a/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java index 205973dcd..360dc97f4 100644 --- a/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java @@ -14,7 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; -import dev.tripdraw.application.draw.RouteImageGenerator; +import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.domain.Point; diff --git a/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerIntegrationTest.java b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java similarity index 95% rename from backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerIntegrationTest.java rename to backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java index 7431258f4..7bd0edc2d 100644 --- a/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerIntegrationTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application.draw; +package dev.tripdraw.draw.application; import static dev.tripdraw.test.TestFixture.감상; import static dev.tripdraw.test.TestFixture.여행; @@ -9,6 +9,7 @@ import dev.tripdraw.domain.post.PostCreateEvent; import dev.tripdraw.domain.post.PostRepository; +import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.trip.domain.TripRepository; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java similarity index 91% rename from backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerTest.java rename to backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java index dde08ac70..9b80124a0 100644 --- a/backend/src/test/java/dev/tripdraw/application/draw/PostCreateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application.draw; +package dev.tripdraw.draw.application; import static dev.tripdraw.test.TestFixture.감상; import static dev.tripdraw.test.TestFixture.여행; @@ -9,6 +9,8 @@ import dev.tripdraw.domain.post.PostCreateEvent; import dev.tripdraw.domain.post.PostRepository; +import dev.tripdraw.draw.application.PostCreateEventHandler; +import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.trip.domain.TripRepository; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/application/draw/RouteImageGeneratorTest.java b/backend/src/test/java/dev/tripdraw/draw/application/RouteImageGeneratorTest.java similarity index 91% rename from backend/src/test/java/dev/tripdraw/application/draw/RouteImageGeneratorTest.java rename to backend/src/test/java/dev/tripdraw/draw/application/RouteImageGeneratorTest.java index 559315b7c..a9fddf78b 100644 --- a/backend/src/test/java/dev/tripdraw/application/draw/RouteImageGeneratorTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/RouteImageGeneratorTest.java @@ -1,10 +1,12 @@ -package dev.tripdraw.application.draw; +package dev.tripdraw.draw.application; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import dev.tripdraw.draw.application.RouteImageGenerator; +import dev.tripdraw.draw.application.RouteImageUploader; import java.awt.image.BufferedImage; import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/application/draw/RouteImageUploaderTest.java b/backend/src/test/java/dev/tripdraw/draw/application/RouteImageUploaderTest.java similarity index 95% rename from backend/src/test/java/dev/tripdraw/application/draw/RouteImageUploaderTest.java rename to backend/src/test/java/dev/tripdraw/draw/application/RouteImageUploaderTest.java index 4886cdf86..109eab90b 100644 --- a/backend/src/test/java/dev/tripdraw/application/draw/RouteImageUploaderTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/RouteImageUploaderTest.java @@ -1,9 +1,10 @@ -package dev.tripdraw.application.draw; +package dev.tripdraw.draw.application; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; +import dev.tripdraw.draw.application.RouteImageUploader; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; @@ -29,7 +30,7 @@ class RouteImageUploaderTest { // expect try (MockedStatic imageIO = Mockito.mockStatic(ImageIO.class)) { String imageUrl = routeImageUploader.upload(bufferedImage); - + imageIO.verify( () -> ImageIO.write(any(BufferedImage.class), any(String.class), any(File.class)), times(1) diff --git a/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerIntegrationTest.java b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerIntegrationTest.java similarity index 94% rename from backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerIntegrationTest.java rename to backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerIntegrationTest.java index 625e4a6e1..dbbd7cae9 100644 --- a/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerIntegrationTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerIntegrationTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application.draw; +package dev.tripdraw.draw.application; import static dev.tripdraw.test.TestFixture.여행; import static org.mockito.ArgumentMatchers.any; @@ -6,6 +6,7 @@ import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.timeout; +import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java similarity index 90% rename from backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerTest.java rename to backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java index e58be2b55..6f4d8b140 100644 --- a/backend/src/test/java/dev/tripdraw/application/draw/TripUpdateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application.draw; +package dev.tripdraw.draw.application; import static dev.tripdraw.test.TestFixture.여행; import static org.mockito.ArgumentMatchers.any; @@ -6,6 +6,8 @@ import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; +import dev.tripdraw.draw.application.RouteImageGenerator; +import dev.tripdraw.draw.application.TripUpdateEventHandler; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/domain/draw/CoordinatesTest.java b/backend/src/test/java/dev/tripdraw/draw/domain/CoordinatesTest.java similarity index 92% rename from backend/src/test/java/dev/tripdraw/domain/draw/CoordinatesTest.java rename to backend/src/test/java/dev/tripdraw/draw/domain/CoordinatesTest.java index e0e2bbe99..c738758dc 100644 --- a/backend/src/test/java/dev/tripdraw/domain/draw/CoordinatesTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/domain/CoordinatesTest.java @@ -1,11 +1,14 @@ -package dev.tripdraw.domain.draw; +package dev.tripdraw.draw.domain; -import static dev.tripdraw.exception.draw.DrawExceptionType.INVALID_COORDINATES; +import static dev.tripdraw.draw.exception.DrawExceptionType.INVALID_COORDINATES; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import dev.tripdraw.exception.draw.DrawException; +import dev.tripdraw.draw.domain.Coordinates; +import dev.tripdraw.draw.domain.Position; +import dev.tripdraw.draw.domain.Positions; +import dev.tripdraw.draw.exception.DrawException; import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/domain/draw/PositionsTest.java b/backend/src/test/java/dev/tripdraw/draw/domain/PositionsTest.java similarity index 95% rename from backend/src/test/java/dev/tripdraw/domain/draw/PositionsTest.java rename to backend/src/test/java/dev/tripdraw/draw/domain/PositionsTest.java index 78530b470..1feb7ce7a 100644 --- a/backend/src/test/java/dev/tripdraw/domain/draw/PositionsTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/domain/PositionsTest.java @@ -1,7 +1,9 @@ -package dev.tripdraw.domain.draw; +package dev.tripdraw.draw.domain; import static org.assertj.core.api.Assertions.assertThat; +import dev.tripdraw.draw.domain.Position; +import dev.tripdraw.draw.domain.Positions; import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/domain/draw/RouteImageDrawerTest.java b/backend/src/test/java/dev/tripdraw/draw/domain/RouteImageDrawerTest.java similarity index 94% rename from backend/src/test/java/dev/tripdraw/domain/draw/RouteImageDrawerTest.java rename to backend/src/test/java/dev/tripdraw/draw/domain/RouteImageDrawerTest.java index 8ef373c04..636fb2305 100644 --- a/backend/src/test/java/dev/tripdraw/domain/draw/RouteImageDrawerTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/domain/RouteImageDrawerTest.java @@ -1,9 +1,12 @@ -package dev.tripdraw.domain.draw; +package dev.tripdraw.draw.domain; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; +import dev.tripdraw.draw.domain.Position; +import dev.tripdraw.draw.domain.Positions; +import dev.tripdraw.draw.domain.RouteImageDrawer; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; diff --git a/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java index d4566a080..bdab01348 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java @@ -11,7 +11,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; -import dev.tripdraw.application.draw.RouteImageGenerator; +import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.application.oauth.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index 5b2fa4876..b541892c5 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -11,7 +11,7 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import dev.tripdraw.application.ServiceTest; -import dev.tripdraw.application.draw.RouteImageGenerator; +import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.dto.auth.LoginUser; diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index 3d7967b1c..a49e88801 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -11,7 +11,7 @@ import static org.springframework.http.HttpStatus.UNAUTHORIZED; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import dev.tripdraw.application.draw.RouteImageGenerator; +import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.application.oauth.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; From dbe6c9dc81a18426ccb004bd4b0210d465d69323 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 31 Aug 2023 17:13:07 +0900 Subject: [PATCH 014/119] =?UTF-8?q?[refactor]=20post=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20(#223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Combi153 Co-authored-by: Jaeyoung22 --- .../application/PostCreateEventHandler.java | 6 ++--- .../member/application/MemberService.java | 2 +- .../{ => post}/application/PostService.java | 20 ++++++++--------- .../{domain/post => post/domain}/Post.java | 6 ++--- .../post => post/domain}/PostCreateEvent.java | 2 +- .../post => post/domain}/PostRepository.java | 6 ++--- .../dto}/PostAndPointCreateRequest.java | 4 ++-- .../post => post/dto}/PostCreateResponse.java | 4 ++-- .../{dto/post => post/dto}/PostRequest.java | 4 ++-- .../{dto/post => post/dto}/PostResponse.java | 4 ++-- .../post => post/dto}/PostUpdateRequest.java | 2 +- .../{dto/post => post/dto}/PostsResponse.java | 4 ++-- .../exception}/PostException.java | 2 +- .../exception}/PostExceptionType.java | 2 +- .../presentation}/PostController.java | 16 +++++++------- ...PostCreateEventHandlerIntegrationTest.java | 5 ++--- .../PostCreateEventHandlerTest.java | 6 ++--- .../member/application/MemberServiceTest.java | 5 ++--- .../presentation/MemberControllerTest.java | 4 ++-- .../application/PostServiceTest.java | 22 ++++++++++--------- .../domain}/PostRepositoryTest.java | 8 ++++--- .../post => post/domain}/PostTest.java | 7 +++--- ...PostResponseAndPointCreateRequestTest.java | 3 ++- .../presentation}/PostControllerTest.java | 14 ++++++------ .../java/dev/tripdraw/test/TestFixture.java | 2 +- 25 files changed, 81 insertions(+), 79 deletions(-) rename backend/src/main/java/dev/tripdraw/{ => post}/application/PostService.java (91%) rename backend/src/main/java/dev/tripdraw/{domain/post => post/domain}/Post.java (94%) rename backend/src/main/java/dev/tripdraw/{domain/post => post/domain}/PostCreateEvent.java (64%) rename backend/src/main/java/dev/tripdraw/{domain/post => post/domain}/PostRepository.java (73%) rename backend/src/main/java/dev/tripdraw/{dto/post => post/dto}/PostAndPointCreateRequest.java (96%) rename backend/src/main/java/dev/tripdraw/{dto/post => post/dto}/PostCreateResponse.java (80%) rename backend/src/main/java/dev/tripdraw/{dto/post => post/dto}/PostRequest.java (94%) rename backend/src/main/java/dev/tripdraw/{dto/post => post/dto}/PostResponse.java (95%) rename backend/src/main/java/dev/tripdraw/{dto/post => post/dto}/PostUpdateRequest.java (94%) rename backend/src/main/java/dev/tripdraw/{dto/post => post/dto}/PostsResponse.java (84%) rename backend/src/main/java/dev/tripdraw/{exception/post => post/exception}/PostException.java (87%) rename backend/src/main/java/dev/tripdraw/{exception/post => post/exception}/PostExceptionType.java (95%) rename backend/src/main/java/dev/tripdraw/{presentation/controller => post/presentation}/PostController.java (94%) rename backend/src/test/java/dev/tripdraw/{ => post}/application/PostServiceTest.java (96%) rename backend/src/test/java/dev/tripdraw/{domain/post => post/domain}/PostRepositoryTest.java (92%) rename backend/src/test/java/dev/tripdraw/{domain/post => post/domain}/PostTest.java (97%) rename backend/src/test/java/dev/tripdraw/{dto/post => post/dto}/PostResponseAndPointCreateRequestTest.java (92%) rename backend/src/test/java/dev/tripdraw/{presentation/controller => post/presentation}/PostControllerTest.java (98%) diff --git a/backend/src/main/java/dev/tripdraw/draw/application/PostCreateEventHandler.java b/backend/src/main/java/dev/tripdraw/draw/application/PostCreateEventHandler.java index c64e0b054..a7b7a4354 100644 --- a/backend/src/main/java/dev/tripdraw/draw/application/PostCreateEventHandler.java +++ b/backend/src/main/java/dev/tripdraw/draw/application/PostCreateEventHandler.java @@ -2,9 +2,9 @@ import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; -import dev.tripdraw.domain.post.Post; -import dev.tripdraw.domain.post.PostCreateEvent; -import dev.tripdraw.domain.post.PostRepository; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.domain.PostCreateEvent; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import java.util.List; diff --git a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java index 995a87e48..b89ee846b 100644 --- a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java +++ b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java @@ -3,7 +3,7 @@ import dev.tripdraw.application.oauth.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.domain.post.PostRepository; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.member.dto.MemberSearchResponse; import lombok.RequiredArgsConstructor; diff --git a/backend/src/main/java/dev/tripdraw/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java similarity index 91% rename from backend/src/main/java/dev/tripdraw/application/PostService.java rename to backend/src/main/java/dev/tripdraw/post/application/PostService.java index fa6090030..821e79697 100644 --- a/backend/src/main/java/dev/tripdraw/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application; +package dev.tripdraw.post.application; import static dev.tripdraw.domain.file.FileType.POST_IMAGE; @@ -6,19 +6,19 @@ import dev.tripdraw.domain.file.FileType; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.domain.post.Post; -import dev.tripdraw.domain.post.PostCreateEvent; -import dev.tripdraw.domain.post.PostRepository; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.domain.PostCreateEvent; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.dto.auth.LoginUser; -import dev.tripdraw.dto.post.PostAndPointCreateRequest; -import dev.tripdraw.dto.post.PostCreateResponse; -import dev.tripdraw.dto.post.PostRequest; -import dev.tripdraw.dto.post.PostResponse; -import dev.tripdraw.dto.post.PostUpdateRequest; -import dev.tripdraw.dto.post.PostsResponse; +import dev.tripdraw.post.dto.PostAndPointCreateRequest; +import dev.tripdraw.post.dto.PostCreateResponse; +import dev.tripdraw.post.dto.PostRequest; +import dev.tripdraw.post.dto.PostResponse; +import dev.tripdraw.post.dto.PostUpdateRequest; +import dev.tripdraw.post.dto.PostsResponse; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; diff --git a/backend/src/main/java/dev/tripdraw/domain/post/Post.java b/backend/src/main/java/dev/tripdraw/post/domain/Post.java similarity index 94% rename from backend/src/main/java/dev/tripdraw/domain/post/Post.java rename to backend/src/main/java/dev/tripdraw/post/domain/Post.java index 0b6e1e316..9d715d05f 100644 --- a/backend/src/main/java/dev/tripdraw/domain/post/Post.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/Post.java @@ -1,6 +1,6 @@ -package dev.tripdraw.domain.post; +package dev.tripdraw.post.domain; -import static dev.tripdraw.exception.post.PostExceptionType.NOT_AUTHORIZED_TO_POST; +import static dev.tripdraw.post.exception.PostExceptionType.NOT_AUTHORIZED_TO_POST; import static jakarta.persistence.FetchType.LAZY; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; @@ -8,7 +8,7 @@ import dev.tripdraw.domain.common.BaseEntity; import dev.tripdraw.member.domain.Member; import dev.tripdraw.trip.domain.Point; -import dev.tripdraw.exception.post.PostException; +import dev.tripdraw.post.exception.PostException; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; diff --git a/backend/src/main/java/dev/tripdraw/domain/post/PostCreateEvent.java b/backend/src/main/java/dev/tripdraw/post/domain/PostCreateEvent.java similarity index 64% rename from backend/src/main/java/dev/tripdraw/domain/post/PostCreateEvent.java rename to backend/src/main/java/dev/tripdraw/post/domain/PostCreateEvent.java index 3f3d777d8..1f90b1c39 100644 --- a/backend/src/main/java/dev/tripdraw/domain/post/PostCreateEvent.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostCreateEvent.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.post; +package dev.tripdraw.post.domain; public record PostCreateEvent(Long postId, Long tripId) { } diff --git a/backend/src/main/java/dev/tripdraw/domain/post/PostRepository.java b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java similarity index 73% rename from backend/src/main/java/dev/tripdraw/domain/post/PostRepository.java rename to backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java index 038e08aa6..09ad39711 100644 --- a/backend/src/main/java/dev/tripdraw/domain/post/PostRepository.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java @@ -1,8 +1,8 @@ -package dev.tripdraw.domain.post; +package dev.tripdraw.post.domain; -import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUND; +import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; -import dev.tripdraw.exception.post.PostException; +import dev.tripdraw.post.exception.PostException; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/backend/src/main/java/dev/tripdraw/dto/post/PostAndPointCreateRequest.java b/backend/src/main/java/dev/tripdraw/post/dto/PostAndPointCreateRequest.java similarity index 96% rename from backend/src/main/java/dev/tripdraw/dto/post/PostAndPointCreateRequest.java rename to backend/src/main/java/dev/tripdraw/post/dto/PostAndPointCreateRequest.java index de4de2217..6b4edac8a 100644 --- a/backend/src/main/java/dev/tripdraw/dto/post/PostAndPointCreateRequest.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostAndPointCreateRequest.java @@ -1,10 +1,10 @@ -package dev.tripdraw.dto.post; +package dev.tripdraw.post.dto; import static com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING; import com.fasterxml.jackson.annotation.JsonFormat; import dev.tripdraw.member.domain.Member; -import dev.tripdraw.domain.post.Post; +import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.domain.Point; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; diff --git a/backend/src/main/java/dev/tripdraw/dto/post/PostCreateResponse.java b/backend/src/main/java/dev/tripdraw/post/dto/PostCreateResponse.java similarity index 80% rename from backend/src/main/java/dev/tripdraw/dto/post/PostCreateResponse.java rename to backend/src/main/java/dev/tripdraw/post/dto/PostCreateResponse.java index d971d6bfe..22ee61dc9 100644 --- a/backend/src/main/java/dev/tripdraw/dto/post/PostCreateResponse.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostCreateResponse.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.post; +package dev.tripdraw.post.dto; -import dev.tripdraw.domain.post.Post; +import dev.tripdraw.post.domain.Post; import io.swagger.v3.oas.annotations.media.Schema; public record PostCreateResponse( diff --git a/backend/src/main/java/dev/tripdraw/dto/post/PostRequest.java b/backend/src/main/java/dev/tripdraw/post/dto/PostRequest.java similarity index 94% rename from backend/src/main/java/dev/tripdraw/dto/post/PostRequest.java rename to backend/src/main/java/dev/tripdraw/post/dto/PostRequest.java index 0bdd792d0..e09e8a430 100644 --- a/backend/src/main/java/dev/tripdraw/dto/post/PostRequest.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostRequest.java @@ -1,7 +1,7 @@ -package dev.tripdraw.dto.post; +package dev.tripdraw.post.dto; import dev.tripdraw.member.domain.Member; -import dev.tripdraw.domain.post.Post; +import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.domain.Point; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; diff --git a/backend/src/main/java/dev/tripdraw/dto/post/PostResponse.java b/backend/src/main/java/dev/tripdraw/post/dto/PostResponse.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/dto/post/PostResponse.java rename to backend/src/main/java/dev/tripdraw/post/dto/PostResponse.java index cc70ca5a9..20b0ee460 100644 --- a/backend/src/main/java/dev/tripdraw/dto/post/PostResponse.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostResponse.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.post; +package dev.tripdraw.post.dto; -import dev.tripdraw.domain.post.Post; +import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.dto.PointResponse; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/backend/src/main/java/dev/tripdraw/dto/post/PostUpdateRequest.java b/backend/src/main/java/dev/tripdraw/post/dto/PostUpdateRequest.java similarity index 94% rename from backend/src/main/java/dev/tripdraw/dto/post/PostUpdateRequest.java rename to backend/src/main/java/dev/tripdraw/post/dto/PostUpdateRequest.java index bacbf4ad9..9eb63b08c 100644 --- a/backend/src/main/java/dev/tripdraw/dto/post/PostUpdateRequest.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostUpdateRequest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.dto.post; +package dev.tripdraw.post.dto; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; diff --git a/backend/src/main/java/dev/tripdraw/dto/post/PostsResponse.java b/backend/src/main/java/dev/tripdraw/post/dto/PostsResponse.java similarity index 84% rename from backend/src/main/java/dev/tripdraw/dto/post/PostsResponse.java rename to backend/src/main/java/dev/tripdraw/post/dto/PostsResponse.java index 5fec95c23..02d9d255c 100644 --- a/backend/src/main/java/dev/tripdraw/dto/post/PostsResponse.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostsResponse.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.post; +package dev.tripdraw.post.dto; -import dev.tripdraw.domain.post.Post; +import dev.tripdraw.post.domain.Post; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; diff --git a/backend/src/main/java/dev/tripdraw/exception/post/PostException.java b/backend/src/main/java/dev/tripdraw/post/exception/PostException.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/exception/post/PostException.java rename to backend/src/main/java/dev/tripdraw/post/exception/PostException.java index bf32472c8..8c9511c60 100644 --- a/backend/src/main/java/dev/tripdraw/exception/post/PostException.java +++ b/backend/src/main/java/dev/tripdraw/post/exception/PostException.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.post; +package dev.tripdraw.post.exception; import dev.tripdraw.exception.common.BaseException; import dev.tripdraw.exception.common.ExceptionType; diff --git a/backend/src/main/java/dev/tripdraw/exception/post/PostExceptionType.java b/backend/src/main/java/dev/tripdraw/post/exception/PostExceptionType.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/exception/post/PostExceptionType.java rename to backend/src/main/java/dev/tripdraw/post/exception/PostExceptionType.java index 98e274864..6b6974e46 100644 --- a/backend/src/main/java/dev/tripdraw/exception/post/PostExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/post/exception/PostExceptionType.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.post; +package dev.tripdraw.post.exception; import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.NOT_FOUND; diff --git a/backend/src/main/java/dev/tripdraw/presentation/controller/PostController.java b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java similarity index 94% rename from backend/src/main/java/dev/tripdraw/presentation/controller/PostController.java rename to backend/src/main/java/dev/tripdraw/post/presentation/PostController.java index e663859b7..a2ac5802e 100644 --- a/backend/src/main/java/dev/tripdraw/presentation/controller/PostController.java +++ b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java @@ -1,19 +1,19 @@ -package dev.tripdraw.presentation.controller; +package dev.tripdraw.post.presentation; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; -import dev.tripdraw.application.PostService; +import dev.tripdraw.post.application.PostService; import dev.tripdraw.config.swagger.SwaggerAuthorizationRequired; import dev.tripdraw.dto.auth.LoginUser; -import dev.tripdraw.dto.post.PostAndPointCreateRequest; -import dev.tripdraw.dto.post.PostCreateResponse; -import dev.tripdraw.dto.post.PostRequest; -import dev.tripdraw.dto.post.PostResponse; -import dev.tripdraw.dto.post.PostUpdateRequest; -import dev.tripdraw.dto.post.PostsResponse; +import dev.tripdraw.post.dto.PostAndPointCreateRequest; +import dev.tripdraw.post.dto.PostCreateResponse; +import dev.tripdraw.post.dto.PostRequest; +import dev.tripdraw.post.dto.PostResponse; +import dev.tripdraw.post.dto.PostUpdateRequest; +import dev.tripdraw.post.dto.PostsResponse; import dev.tripdraw.presentation.member.Auth; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; diff --git a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java index 7bd0edc2d..6d8590913 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java @@ -7,9 +7,8 @@ import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.timeout; -import dev.tripdraw.domain.post.PostCreateEvent; -import dev.tripdraw.domain.post.PostRepository; -import dev.tripdraw.draw.application.RouteImageGenerator; +import dev.tripdraw.post.domain.PostCreateEvent; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.domain.TripRepository; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java index 9b80124a0..8d818d527 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java @@ -7,10 +7,8 @@ import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; -import dev.tripdraw.domain.post.PostCreateEvent; -import dev.tripdraw.domain.post.PostRepository; -import dev.tripdraw.draw.application.PostCreateEventHandler; -import dev.tripdraw.draw.application.RouteImageGenerator; +import dev.tripdraw.post.domain.PostCreateEvent; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.domain.TripRepository; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java index 91a4a65f9..96325a673 100644 --- a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java @@ -9,11 +9,10 @@ import dev.tripdraw.application.ServiceTest; import dev.tripdraw.application.oauth.AuthTokenManager; -import dev.tripdraw.member.application.MemberService; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.domain.post.Post; -import dev.tripdraw.domain.post.PostRepository; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; diff --git a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java index 67c648a1c..8e444e76a 100644 --- a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java @@ -11,8 +11,8 @@ import dev.tripdraw.application.oauth.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.domain.post.Post; -import dev.tripdraw.domain.post.PostRepository; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.member.dto.MemberSearchResponse; import dev.tripdraw.test.ControllerTest; import dev.tripdraw.trip.domain.Point; diff --git a/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java similarity index 96% rename from backend/src/test/java/dev/tripdraw/application/PostServiceTest.java rename to backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index 360dc97f4..a1d4b8e12 100644 --- a/backend/src/test/java/dev/tripdraw/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -1,9 +1,9 @@ -package dev.tripdraw.application; +package dev.tripdraw.post.application; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import static dev.tripdraw.exception.post.PostExceptionType.NOT_AUTHORIZED_TO_POST; -import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUND; +import static dev.tripdraw.post.exception.PostExceptionType.NOT_AUTHORIZED_TO_POST; +import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; import static dev.tripdraw.trip.exception.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; @@ -14,21 +14,23 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; +import dev.tripdraw.application.ServiceTest; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.post.application.PostService; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.dto.auth.LoginUser; -import dev.tripdraw.dto.post.PostAndPointCreateRequest; -import dev.tripdraw.dto.post.PostCreateResponse; -import dev.tripdraw.dto.post.PostRequest; -import dev.tripdraw.dto.post.PostResponse; -import dev.tripdraw.dto.post.PostUpdateRequest; -import dev.tripdraw.dto.post.PostsResponse; +import dev.tripdraw.post.dto.PostAndPointCreateRequest; +import dev.tripdraw.post.dto.PostCreateResponse; +import dev.tripdraw.post.dto.PostRequest; +import dev.tripdraw.post.dto.PostResponse; +import dev.tripdraw.post.dto.PostUpdateRequest; +import dev.tripdraw.post.dto.PostsResponse; import dev.tripdraw.member.exception.MemberException; -import dev.tripdraw.exception.post.PostException; +import dev.tripdraw.post.exception.PostException; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; diff --git a/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java similarity index 92% rename from backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java rename to backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java index ee4164429..e95d1f492 100644 --- a/backend/src/test/java/dev/tripdraw/domain/post/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java @@ -1,18 +1,20 @@ -package dev.tripdraw.domain.post; +package dev.tripdraw.post.domain; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.exception.post.PostExceptionType.POST_NOT_FOUND; +import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.exception.post.PostException; +import dev.tripdraw.post.exception.PostException; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.BeforeEach; diff --git a/backend/src/test/java/dev/tripdraw/domain/post/PostTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java similarity index 97% rename from backend/src/test/java/dev/tripdraw/domain/post/PostTest.java rename to backend/src/test/java/dev/tripdraw/post/domain/PostTest.java index 7e213fb21..11ca876a8 100644 --- a/backend/src/test/java/dev/tripdraw/domain/post/PostTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java @@ -1,15 +1,16 @@ -package dev.tripdraw.domain.post; +package dev.tripdraw.post.domain; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; -import static dev.tripdraw.exception.post.PostExceptionType.NOT_AUTHORIZED_TO_POST; +import static dev.tripdraw.post.exception.PostExceptionType.NOT_AUTHORIZED_TO_POST; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_HAS_POST; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.member.domain.Member; +import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.domain.Point; -import dev.tripdraw.exception.post.PostException; +import dev.tripdraw.post.exception.PostException; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/dto/post/PostResponseAndPointCreateRequestTest.java b/backend/src/test/java/dev/tripdraw/post/dto/PostResponseAndPointCreateRequestTest.java similarity index 92% rename from backend/src/test/java/dev/tripdraw/dto/post/PostResponseAndPointCreateRequestTest.java rename to backend/src/test/java/dev/tripdraw/post/dto/PostResponseAndPointCreateRequestTest.java index 13fefc5e2..5ed47f316 100644 --- a/backend/src/test/java/dev/tripdraw/dto/post/PostResponseAndPointCreateRequestTest.java +++ b/backend/src/test/java/dev/tripdraw/post/dto/PostResponseAndPointCreateRequestTest.java @@ -1,7 +1,8 @@ -package dev.tripdraw.dto.post; +package dev.tripdraw.post.dto; import static org.assertj.core.api.Assertions.assertThat; +import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.trip.domain.Point; import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java similarity index 98% rename from backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java rename to backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index bdab01348..34eb3aa1d 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/controller/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.presentation.controller; +package dev.tripdraw.post.presentation; import static dev.tripdraw.domain.oauth.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -15,12 +15,12 @@ import dev.tripdraw.application.oauth.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.dto.post.PostAndPointCreateRequest; -import dev.tripdraw.dto.post.PostCreateResponse; -import dev.tripdraw.dto.post.PostRequest; -import dev.tripdraw.dto.post.PostResponse; -import dev.tripdraw.dto.post.PostUpdateRequest; -import dev.tripdraw.dto.post.PostsResponse; +import dev.tripdraw.post.dto.PostAndPointCreateRequest; +import dev.tripdraw.post.dto.PostCreateResponse; +import dev.tripdraw.post.dto.PostRequest; +import dev.tripdraw.post.dto.PostResponse; +import dev.tripdraw.post.dto.PostUpdateRequest; +import dev.tripdraw.post.dto.PostsResponse; import dev.tripdraw.test.ControllerTest; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; diff --git a/backend/src/test/java/dev/tripdraw/test/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/TestFixture.java index 0543998ac..7a91ee91f 100644 --- a/backend/src/test/java/dev/tripdraw/test/TestFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/TestFixture.java @@ -2,7 +2,7 @@ import dev.tripdraw.member.domain.Member; import dev.tripdraw.domain.oauth.OauthType; -import dev.tripdraw.domain.post.Post; +import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; From 40ec6d448b32cdbf6cd52fa4e6addb6078d56d43 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 31 Aug 2023 17:22:40 +0900 Subject: [PATCH 015/119] =?UTF-8?q?[refactor]=20auth=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20(#223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Combi153 Co-authored-by: Jaeyoung22 --- .../tripdraw/application/oauth/OauthClient.java | 11 ----------- .../application}/AuthExtractor.java | 10 +++++----- .../{ => auth}/application/AuthService.java | 15 +++++++-------- .../application}/AuthTokenManager.java | 2 +- .../application}/JwtTokenProvider.java | 8 ++++---- .../{domain/oauth => auth/domain}/OauthType.java | 2 +- .../{dto/auth => auth/dto}/KakaoInfoResponse.java | 4 ++-- .../{dto/auth => auth/dto}/LoginUser.java | 2 +- .../java/dev/tripdraw/auth/dto/OauthInfo.java | 6 ++++++ .../{dto/auth => auth/dto}/OauthRequest.java | 4 ++-- .../{dto/auth => auth/dto}/OauthResponse.java | 2 +- .../{dto/auth => auth/dto}/RegisterRequest.java | 4 ++-- .../auth => auth/exception}/AuthException.java | 2 +- .../exception}/AuthExceptionType.java | 2 +- .../oauth/KakaoApiClient.java | 10 +++++----- .../java/dev/tripdraw/auth/oauth/OauthClient.java | 11 +++++++++++ .../oauth/OauthClientProvider.java | 4 ++-- .../member => auth/presentation}/Auth.java | 2 +- .../presentation}/AuthArgumentResolver.java | 3 ++- .../presentation}/AuthController.java | 10 +++++----- .../presentation}/AuthInterceptor.java | 9 +++++---- .../main/java/dev/tripdraw/config/AuthConfig.java | 6 +++--- .../java/dev/tripdraw/dto/auth/OauthInfo.java | 6 ------ .../member/application/MemberService.java | 2 +- .../java/dev/tripdraw/member/domain/Member.java | 2 +- .../tripdraw/member/domain/MemberRepository.java | 2 +- .../tripdraw/post/application/PostService.java | 2 +- .../post/presentation/PostController.java | 4 ++-- .../tripdraw/trip/application/TripService.java | 2 +- .../trip/presentation/TripController.java | 4 ++-- .../application}/AuthExtractorTest.java | 12 +++++------- .../{ => auth}/application/AuthServiceTest.java | 13 +++++++------ .../application/AuthTokenManagerTest.java | 4 +--- .../application/JwtTokenProviderTest.java | 9 ++++----- .../auth => auth/dto}/KakaoInfoResponseTest.java | 4 ++-- .../oauth/KakaoApiClientTest.java | 10 +++++----- .../oauth/OauthClientProviderTest.java | 7 ++----- .../presentation}/AuthControllerTest.java | 12 ++++++------ .../dev/tripdraw/common/TestKakaoApiClient.java | 8 ++++---- .../member/application/MemberServiceTest.java | 4 ++-- .../member/domain/MemberRepositoryTest.java | 4 +--- .../dev/tripdraw/member/domain/MemberTest.java | 3 +-- .../member/presentation/MemberControllerTest.java | 4 ++-- .../post/application/PostServiceTest.java | 5 ++--- .../tripdraw/post/domain/PostRepositoryTest.java | 4 +--- .../java/dev/tripdraw/post/domain/PostTest.java | 3 +-- .../post/presentation/PostControllerTest.java | 4 ++-- .../test/java/dev/tripdraw/test/TestFixture.java | 2 +- .../trip/application/TripServiceTest.java | 4 ++-- .../tripdraw/trip/domain/TripRepositoryTest.java | 2 +- .../java/dev/tripdraw/trip/domain/TripTest.java | 2 +- .../tripdraw/trip/dto/TripSearchResponseTest.java | 2 +- .../trip/presentation/TripControllerTest.java | 4 ++-- 53 files changed, 133 insertions(+), 146 deletions(-) delete mode 100644 backend/src/main/java/dev/tripdraw/application/oauth/OauthClient.java rename backend/src/main/java/dev/tripdraw/{presentation/member => auth/application}/AuthExtractor.java (83%) rename backend/src/main/java/dev/tripdraw/{ => auth}/application/AuthService.java (86%) rename backend/src/main/java/dev/tripdraw/{application/oauth => auth/application}/AuthTokenManager.java (95%) rename backend/src/main/java/dev/tripdraw/{application/oauth => auth/application}/JwtTokenProvider.java (87%) rename backend/src/main/java/dev/tripdraw/{domain/oauth => auth/domain}/OauthType.java (55%) rename backend/src/main/java/dev/tripdraw/{dto/auth => auth/dto}/KakaoInfoResponse.java (94%) rename backend/src/main/java/dev/tripdraw/{dto/auth => auth/dto}/LoginUser.java (75%) create mode 100644 backend/src/main/java/dev/tripdraw/auth/dto/OauthInfo.java rename backend/src/main/java/dev/tripdraw/{dto/auth => auth/dto}/OauthRequest.java (86%) rename backend/src/main/java/dev/tripdraw/{dto/auth => auth/dto}/OauthResponse.java (92%) rename backend/src/main/java/dev/tripdraw/{dto/auth => auth/dto}/RegisterRequest.java (89%) rename backend/src/main/java/dev/tripdraw/{exception/auth => auth/exception}/AuthException.java (87%) rename backend/src/main/java/dev/tripdraw/{exception/auth => auth/exception}/AuthExceptionType.java (96%) rename backend/src/main/java/dev/tripdraw/{application => auth}/oauth/KakaoApiClient.java (88%) create mode 100644 backend/src/main/java/dev/tripdraw/auth/oauth/OauthClient.java rename backend/src/main/java/dev/tripdraw/{application => auth}/oauth/OauthClientProvider.java (87%) rename backend/src/main/java/dev/tripdraw/{presentation/member => auth/presentation}/Auth.java (86%) rename backend/src/main/java/dev/tripdraw/{presentation/member => auth/presentation}/AuthArgumentResolver.java (92%) rename backend/src/main/java/dev/tripdraw/{presentation/controller => auth/presentation}/AuthController.java (87%) rename backend/src/main/java/dev/tripdraw/{presentation/member => auth/presentation}/AuthInterceptor.java (78%) delete mode 100644 backend/src/main/java/dev/tripdraw/dto/auth/OauthInfo.java rename backend/src/test/java/dev/tripdraw/{presentation/member => auth/application}/AuthExtractorTest.java (90%) rename backend/src/test/java/dev/tripdraw/{ => auth}/application/AuthServiceTest.java (91%) rename backend/src/test/java/dev/tripdraw/{ => auth}/application/AuthTokenManagerTest.java (90%) rename backend/src/test/java/dev/tripdraw/{ => auth}/application/JwtTokenProviderTest.java (90%) rename backend/src/test/java/dev/tripdraw/{dto/auth => auth/dto}/KakaoInfoResponseTest.java (89%) rename backend/src/test/java/dev/tripdraw/{domain => auth}/oauth/KakaoApiClientTest.java (88%) rename backend/src/test/java/dev/tripdraw/{domain => auth}/oauth/OauthClientProviderTest.java (78%) rename backend/src/test/java/dev/tripdraw/{presentation/controller => auth/presentation}/AuthControllerTest.java (95%) diff --git a/backend/src/main/java/dev/tripdraw/application/oauth/OauthClient.java b/backend/src/main/java/dev/tripdraw/application/oauth/OauthClient.java deleted file mode 100644 index 3fba7c0d7..000000000 --- a/backend/src/main/java/dev/tripdraw/application/oauth/OauthClient.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.tripdraw.application.oauth; - -import dev.tripdraw.domain.oauth.OauthType; -import dev.tripdraw.dto.auth.OauthInfo; - -public interface OauthClient { - - OauthType oauthType(); - - OauthInfo requestOauthInfo(String accessToken); -} diff --git a/backend/src/main/java/dev/tripdraw/presentation/member/AuthExtractor.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java similarity index 83% rename from backend/src/main/java/dev/tripdraw/presentation/member/AuthExtractor.java rename to backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java index 0c340e1c0..84ccdb353 100644 --- a/backend/src/main/java/dev/tripdraw/presentation/member/AuthExtractor.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java @@ -1,12 +1,12 @@ -package dev.tripdraw.presentation.member; +package dev.tripdraw.auth.application; -import static dev.tripdraw.exception.auth.AuthExceptionType.INVALID_AUTH_HEADER; +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_AUTH_HEADER; import static org.springframework.http.HttpHeaders.AUTHORIZATION; import static org.springframework.util.StringUtils.hasText; -import dev.tripdraw.application.oauth.AuthTokenManager; -import dev.tripdraw.dto.auth.LoginUser; -import dev.tripdraw.exception.auth.AuthException; +import dev.tripdraw.auth.application.AuthTokenManager; +import dev.tripdraw.auth.dto.LoginUser; +import dev.tripdraw.auth.exception.AuthException; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; diff --git a/backend/src/main/java/dev/tripdraw/application/AuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java similarity index 86% rename from backend/src/main/java/dev/tripdraw/application/AuthService.java rename to backend/src/main/java/dev/tripdraw/auth/application/AuthService.java index 01a053da6..76a4822b8 100644 --- a/backend/src/main/java/dev/tripdraw/application/AuthService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java @@ -1,17 +1,16 @@ -package dev.tripdraw.application; +package dev.tripdraw.auth.application; import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import dev.tripdraw.application.oauth.AuthTokenManager; -import dev.tripdraw.application.oauth.OauthClient; -import dev.tripdraw.application.oauth.OauthClientProvider; +import dev.tripdraw.auth.oauth.OauthClient; +import dev.tripdraw.auth.oauth.OauthClientProvider; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.dto.auth.OauthInfo; -import dev.tripdraw.dto.auth.OauthRequest; -import dev.tripdraw.dto.auth.OauthResponse; -import dev.tripdraw.dto.auth.RegisterRequest; +import dev.tripdraw.auth.dto.OauthInfo; +import dev.tripdraw.auth.dto.OauthRequest; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.dto.RegisterRequest; import dev.tripdraw.member.exception.MemberException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/backend/src/main/java/dev/tripdraw/application/oauth/AuthTokenManager.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/application/oauth/AuthTokenManager.java rename to backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java index d041aa90b..42ca1ad1c 100644 --- a/backend/src/main/java/dev/tripdraw/application/oauth/AuthTokenManager.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application.oauth; +package dev.tripdraw.auth.application; import java.util.Date; import org.springframework.beans.factory.annotation.Value; diff --git a/backend/src/main/java/dev/tripdraw/application/oauth/JwtTokenProvider.java b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/application/oauth/JwtTokenProvider.java rename to backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java index 8750c7cf3..d5c3238aa 100644 --- a/backend/src/main/java/dev/tripdraw/application/oauth/JwtTokenProvider.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java @@ -1,9 +1,9 @@ -package dev.tripdraw.application.oauth; +package dev.tripdraw.auth.application; -import static dev.tripdraw.exception.auth.AuthExceptionType.EXPIRED_TOKEN; -import static dev.tripdraw.exception.auth.AuthExceptionType.INVALID_TOKEN; +import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_TOKEN; +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; -import dev.tripdraw.exception.auth.AuthException; +import dev.tripdraw.auth.exception.AuthException; import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.JwtException; diff --git a/backend/src/main/java/dev/tripdraw/domain/oauth/OauthType.java b/backend/src/main/java/dev/tripdraw/auth/domain/OauthType.java similarity index 55% rename from backend/src/main/java/dev/tripdraw/domain/oauth/OauthType.java rename to backend/src/main/java/dev/tripdraw/auth/domain/OauthType.java index eed4dd1b0..32afd531a 100644 --- a/backend/src/main/java/dev/tripdraw/domain/oauth/OauthType.java +++ b/backend/src/main/java/dev/tripdraw/auth/domain/OauthType.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.oauth; +package dev.tripdraw.auth.domain; public enum OauthType { KAKAO, diff --git a/backend/src/main/java/dev/tripdraw/dto/auth/KakaoInfoResponse.java b/backend/src/main/java/dev/tripdraw/auth/dto/KakaoInfoResponse.java similarity index 94% rename from backend/src/main/java/dev/tripdraw/dto/auth/KakaoInfoResponse.java rename to backend/src/main/java/dev/tripdraw/auth/dto/KakaoInfoResponse.java index c15541d54..ef2b19352 100644 --- a/backend/src/main/java/dev/tripdraw/dto/auth/KakaoInfoResponse.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/KakaoInfoResponse.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.auth; +package dev.tripdraw.auth.dto; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/backend/src/main/java/dev/tripdraw/dto/auth/LoginUser.java b/backend/src/main/java/dev/tripdraw/auth/dto/LoginUser.java similarity index 75% rename from backend/src/main/java/dev/tripdraw/dto/auth/LoginUser.java rename to backend/src/main/java/dev/tripdraw/auth/dto/LoginUser.java index 68110ee5d..e9669fcb0 100644 --- a/backend/src/main/java/dev/tripdraw/dto/auth/LoginUser.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/LoginUser.java @@ -1,4 +1,4 @@ -package dev.tripdraw.dto.auth; +package dev.tripdraw.auth.dto; import io.swagger.v3.oas.annotations.Hidden; diff --git a/backend/src/main/java/dev/tripdraw/auth/dto/OauthInfo.java b/backend/src/main/java/dev/tripdraw/auth/dto/OauthInfo.java new file mode 100644 index 000000000..d99689448 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/dto/OauthInfo.java @@ -0,0 +1,6 @@ +package dev.tripdraw.auth.dto; + +import dev.tripdraw.auth.domain.OauthType; + +public record OauthInfo(String oauthId, OauthType oauthType) { +} diff --git a/backend/src/main/java/dev/tripdraw/dto/auth/OauthRequest.java b/backend/src/main/java/dev/tripdraw/auth/dto/OauthRequest.java similarity index 86% rename from backend/src/main/java/dev/tripdraw/dto/auth/OauthRequest.java rename to backend/src/main/java/dev/tripdraw/auth/dto/OauthRequest.java index 010015716..8f0fb7ad5 100644 --- a/backend/src/main/java/dev/tripdraw/dto/auth/OauthRequest.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/OauthRequest.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.auth; +package dev.tripdraw.auth.dto; -import dev.tripdraw.domain.oauth.OauthType; +import dev.tripdraw.auth.domain.OauthType; import io.swagger.v3.oas.annotations.media.Schema; public record OauthRequest( diff --git a/backend/src/main/java/dev/tripdraw/dto/auth/OauthResponse.java b/backend/src/main/java/dev/tripdraw/auth/dto/OauthResponse.java similarity index 92% rename from backend/src/main/java/dev/tripdraw/dto/auth/OauthResponse.java rename to backend/src/main/java/dev/tripdraw/auth/dto/OauthResponse.java index 345be6832..fa4a6bd69 100644 --- a/backend/src/main/java/dev/tripdraw/dto/auth/OauthResponse.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/OauthResponse.java @@ -1,4 +1,4 @@ -package dev.tripdraw.dto.auth; +package dev.tripdraw.auth.dto; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/backend/src/main/java/dev/tripdraw/dto/auth/RegisterRequest.java b/backend/src/main/java/dev/tripdraw/auth/dto/RegisterRequest.java similarity index 89% rename from backend/src/main/java/dev/tripdraw/dto/auth/RegisterRequest.java rename to backend/src/main/java/dev/tripdraw/auth/dto/RegisterRequest.java index 9594a7210..b6b922cec 100644 --- a/backend/src/main/java/dev/tripdraw/dto/auth/RegisterRequest.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/RegisterRequest.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.auth; +package dev.tripdraw.auth.dto; -import dev.tripdraw.domain.oauth.OauthType; +import dev.tripdraw.auth.domain.OauthType; import dev.tripdraw.dto.validation.NoWhiteSpace; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/backend/src/main/java/dev/tripdraw/exception/auth/AuthException.java b/backend/src/main/java/dev/tripdraw/auth/exception/AuthException.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/exception/auth/AuthException.java rename to backend/src/main/java/dev/tripdraw/auth/exception/AuthException.java index b92c11a02..8ce153e3b 100644 --- a/backend/src/main/java/dev/tripdraw/exception/auth/AuthException.java +++ b/backend/src/main/java/dev/tripdraw/auth/exception/AuthException.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.auth; +package dev.tripdraw.auth.exception; import dev.tripdraw.exception.common.BaseException; import dev.tripdraw.exception.common.ExceptionType; diff --git a/backend/src/main/java/dev/tripdraw/exception/auth/AuthExceptionType.java b/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java similarity index 96% rename from backend/src/main/java/dev/tripdraw/exception/auth/AuthExceptionType.java rename to backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java index 0ffda0bc3..ff453dcf9 100644 --- a/backend/src/main/java/dev/tripdraw/exception/auth/AuthExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.auth; +package dev.tripdraw.auth.exception; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.FORBIDDEN; diff --git a/backend/src/main/java/dev/tripdraw/application/oauth/KakaoApiClient.java b/backend/src/main/java/dev/tripdraw/auth/oauth/KakaoApiClient.java similarity index 88% rename from backend/src/main/java/dev/tripdraw/application/oauth/KakaoApiClient.java rename to backend/src/main/java/dev/tripdraw/auth/oauth/KakaoApiClient.java index 68e1678cb..865a6b071 100644 --- a/backend/src/main/java/dev/tripdraw/application/oauth/KakaoApiClient.java +++ b/backend/src/main/java/dev/tripdraw/auth/oauth/KakaoApiClient.java @@ -1,11 +1,11 @@ -package dev.tripdraw.application.oauth; +package dev.tripdraw.auth.oauth; import static org.springframework.http.HttpHeaders.AUTHORIZATION; import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED; -import dev.tripdraw.domain.oauth.OauthType; -import dev.tripdraw.dto.auth.KakaoInfoResponse; -import dev.tripdraw.dto.auth.OauthInfo; +import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.auth.dto.KakaoInfoResponse; +import dev.tripdraw.auth.dto.OauthInfo; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -16,7 +16,7 @@ public class KakaoApiClient implements OauthClient { private static final String BEARER = "Bearer "; - + private final String kakaoInfoUrl; private final RestTemplate restTemplate; diff --git a/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClient.java b/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClient.java new file mode 100644 index 000000000..879a341df --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClient.java @@ -0,0 +1,11 @@ +package dev.tripdraw.auth.oauth; + +import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.auth.dto.OauthInfo; + +public interface OauthClient { + + OauthType oauthType(); + + OauthInfo requestOauthInfo(String accessToken); +} diff --git a/backend/src/main/java/dev/tripdraw/application/oauth/OauthClientProvider.java b/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClientProvider.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/application/oauth/OauthClientProvider.java rename to backend/src/main/java/dev/tripdraw/auth/oauth/OauthClientProvider.java index bc9421ab2..0e9d60709 100644 --- a/backend/src/main/java/dev/tripdraw/application/oauth/OauthClientProvider.java +++ b/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClientProvider.java @@ -1,9 +1,9 @@ -package dev.tripdraw.application.oauth; +package dev.tripdraw.auth.oauth; import static java.util.function.Function.identity; import static java.util.stream.Collectors.toMap; -import dev.tripdraw.domain.oauth.OauthType; +import dev.tripdraw.auth.domain.OauthType; import java.util.Map; import java.util.Set; import org.springframework.stereotype.Component; diff --git a/backend/src/main/java/dev/tripdraw/presentation/member/Auth.java b/backend/src/main/java/dev/tripdraw/auth/presentation/Auth.java similarity index 86% rename from backend/src/main/java/dev/tripdraw/presentation/member/Auth.java rename to backend/src/main/java/dev/tripdraw/auth/presentation/Auth.java index e78ec36e4..827e6215e 100644 --- a/backend/src/main/java/dev/tripdraw/presentation/member/Auth.java +++ b/backend/src/main/java/dev/tripdraw/auth/presentation/Auth.java @@ -1,4 +1,4 @@ -package dev.tripdraw.presentation.member; +package dev.tripdraw.auth.presentation; import static java.lang.annotation.ElementType.PARAMETER; import static java.lang.annotation.RetentionPolicy.RUNTIME; diff --git a/backend/src/main/java/dev/tripdraw/presentation/member/AuthArgumentResolver.java b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthArgumentResolver.java similarity index 92% rename from backend/src/main/java/dev/tripdraw/presentation/member/AuthArgumentResolver.java rename to backend/src/main/java/dev/tripdraw/auth/presentation/AuthArgumentResolver.java index b95d42285..712f6ff16 100644 --- a/backend/src/main/java/dev/tripdraw/presentation/member/AuthArgumentResolver.java +++ b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthArgumentResolver.java @@ -1,5 +1,6 @@ -package dev.tripdraw.presentation.member; +package dev.tripdraw.auth.presentation; +import dev.tripdraw.auth.application.AuthExtractor; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.core.MethodParameter; diff --git a/backend/src/main/java/dev/tripdraw/presentation/controller/AuthController.java b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/presentation/controller/AuthController.java rename to backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java index 676ea5be1..9b285b36c 100644 --- a/backend/src/main/java/dev/tripdraw/presentation/controller/AuthController.java +++ b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java @@ -1,9 +1,9 @@ -package dev.tripdraw.presentation.controller; +package dev.tripdraw.auth.presentation; -import dev.tripdraw.application.AuthService; -import dev.tripdraw.dto.auth.OauthRequest; -import dev.tripdraw.dto.auth.OauthResponse; -import dev.tripdraw.dto.auth.RegisterRequest; +import dev.tripdraw.auth.application.AuthService; +import dev.tripdraw.auth.dto.OauthRequest; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.dto.RegisterRequest; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/backend/src/main/java/dev/tripdraw/presentation/member/AuthInterceptor.java b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthInterceptor.java similarity index 78% rename from backend/src/main/java/dev/tripdraw/presentation/member/AuthInterceptor.java rename to backend/src/main/java/dev/tripdraw/auth/presentation/AuthInterceptor.java index d0b48e7d5..de9834f30 100644 --- a/backend/src/main/java/dev/tripdraw/presentation/member/AuthInterceptor.java +++ b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthInterceptor.java @@ -1,10 +1,11 @@ -package dev.tripdraw.presentation.member; +package dev.tripdraw.auth.presentation; -import static dev.tripdraw.exception.auth.AuthExceptionType.AUTH_FAIL; +import static dev.tripdraw.auth.exception.AuthExceptionType.AUTH_FAIL; +import dev.tripdraw.auth.application.AuthExtractor; import dev.tripdraw.member.application.MemberService; -import dev.tripdraw.dto.auth.LoginUser; -import dev.tripdraw.exception.auth.AuthException; +import dev.tripdraw.auth.dto.LoginUser; +import dev.tripdraw.auth.exception.AuthException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; diff --git a/backend/src/main/java/dev/tripdraw/config/AuthConfig.java b/backend/src/main/java/dev/tripdraw/config/AuthConfig.java index f039ff7dc..d4a501e5d 100644 --- a/backend/src/main/java/dev/tripdraw/config/AuthConfig.java +++ b/backend/src/main/java/dev/tripdraw/config/AuthConfig.java @@ -1,8 +1,8 @@ package dev.tripdraw.config; -import dev.tripdraw.presentation.member.AuthArgumentResolver; -import dev.tripdraw.presentation.member.AuthExtractor; -import dev.tripdraw.presentation.member.AuthInterceptor; +import dev.tripdraw.auth.presentation.AuthArgumentResolver; +import dev.tripdraw.auth.application.AuthExtractor; +import dev.tripdraw.auth.presentation.AuthInterceptor; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; diff --git a/backend/src/main/java/dev/tripdraw/dto/auth/OauthInfo.java b/backend/src/main/java/dev/tripdraw/dto/auth/OauthInfo.java deleted file mode 100644 index e1b35720c..000000000 --- a/backend/src/main/java/dev/tripdraw/dto/auth/OauthInfo.java +++ /dev/null @@ -1,6 +0,0 @@ -package dev.tripdraw.dto.auth; - -import dev.tripdraw.domain.oauth.OauthType; - -public record OauthInfo(String oauthId, OauthType oauthType) { -} diff --git a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java index b89ee846b..38ea16263 100644 --- a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java +++ b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java @@ -1,6 +1,6 @@ package dev.tripdraw.member.application; -import dev.tripdraw.application.oauth.AuthTokenManager; +import dev.tripdraw.auth.application.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.domain.PostRepository; diff --git a/backend/src/main/java/dev/tripdraw/member/domain/Member.java b/backend/src/main/java/dev/tripdraw/member/domain/Member.java index a5abcab53..e51d7fb8d 100644 --- a/backend/src/main/java/dev/tripdraw/member/domain/Member.java +++ b/backend/src/main/java/dev/tripdraw/member/domain/Member.java @@ -4,7 +4,7 @@ import static lombok.AccessLevel.PROTECTED; import dev.tripdraw.domain.common.BaseEntity; -import dev.tripdraw.domain.oauth.OauthType; +import dev.tripdraw.auth.domain.OauthType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; diff --git a/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java b/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java index 3052b2a54..7c73673a1 100644 --- a/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java +++ b/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java @@ -2,7 +2,7 @@ import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import dev.tripdraw.domain.oauth.OauthType; +import dev.tripdraw.auth.domain.OauthType; import dev.tripdraw.member.exception.MemberException; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index 821e79697..ad6e1446d 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -12,7 +12,7 @@ import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.dto.auth.LoginUser; +import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; diff --git a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java index a2ac5802e..ae07c3e37 100644 --- a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java +++ b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java @@ -7,14 +7,14 @@ import dev.tripdraw.post.application.PostService; import dev.tripdraw.config.swagger.SwaggerAuthorizationRequired; -import dev.tripdraw.dto.auth.LoginUser; +import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; -import dev.tripdraw.presentation.member.Auth; +import dev.tripdraw.auth.presentation.Auth; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index 1a91e5c0e..504c03d0d 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -6,7 +6,7 @@ import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; -import dev.tripdraw.dto.auth.LoginUser; +import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.trip.dto.PointCreateRequest; import dev.tripdraw.trip.dto.PointCreateResponse; import dev.tripdraw.trip.dto.PointResponse; diff --git a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java index ad7718fff..579ec0fe7 100644 --- a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java +++ b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java @@ -5,7 +5,7 @@ import dev.tripdraw.trip.application.TripService; import dev.tripdraw.config.swagger.SwaggerAuthorizationRequired; -import dev.tripdraw.dto.auth.LoginUser; +import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.trip.dto.PointCreateRequest; import dev.tripdraw.trip.dto.PointCreateResponse; import dev.tripdraw.trip.dto.PointResponse; @@ -13,7 +13,7 @@ import dev.tripdraw.trip.dto.TripResponse; import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; -import dev.tripdraw.presentation.member.Auth; +import dev.tripdraw.auth.presentation.Auth; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/backend/src/test/java/dev/tripdraw/presentation/member/AuthExtractorTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java similarity index 90% rename from backend/src/test/java/dev/tripdraw/presentation/member/AuthExtractorTest.java rename to backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java index d72f2f68f..d8a61e2f0 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/member/AuthExtractorTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java @@ -1,17 +1,15 @@ -package dev.tripdraw.presentation.member; +package dev.tripdraw.auth.application; -import static dev.tripdraw.exception.auth.AuthExceptionType.INVALID_AUTH_HEADER; -import static dev.tripdraw.exception.auth.AuthExceptionType.INVALID_TOKEN; +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_AUTH_HEADER; +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.springframework.http.HttpHeaders.AUTHORIZATION; -import dev.tripdraw.application.oauth.AuthTokenManager; -import dev.tripdraw.application.oauth.JwtTokenProvider; -import dev.tripdraw.dto.auth.LoginUser; -import dev.tripdraw.exception.auth.AuthException; +import dev.tripdraw.auth.dto.LoginUser; +import dev.tripdraw.auth.exception.AuthException; import jakarta.servlet.http.HttpServletRequest; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; diff --git a/backend/src/test/java/dev/tripdraw/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java similarity index 91% rename from backend/src/test/java/dev/tripdraw/application/AuthServiceTest.java rename to backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index e24f9c6cc..9a98962c0 100644 --- a/backend/src/test/java/dev/tripdraw/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -1,19 +1,20 @@ -package dev.tripdraw.application; +package dev.tripdraw.auth.application; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.when; -import dev.tripdraw.application.oauth.OauthClientProvider; +import dev.tripdraw.application.ServiceTest; +import dev.tripdraw.auth.dto.OauthRequest; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.dto.RegisterRequest; +import dev.tripdraw.auth.oauth.OauthClientProvider; import dev.tripdraw.common.TestKakaoApiClient; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.dto.auth.OauthRequest; -import dev.tripdraw.dto.auth.OauthResponse; -import dev.tripdraw.dto.auth.RegisterRequest; import dev.tripdraw.member.exception.MemberException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/dev/tripdraw/application/AuthTokenManagerTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthTokenManagerTest.java similarity index 90% rename from backend/src/test/java/dev/tripdraw/application/AuthTokenManagerTest.java rename to backend/src/test/java/dev/tripdraw/auth/application/AuthTokenManagerTest.java index 9f99127a0..66ad3a8f8 100644 --- a/backend/src/test/java/dev/tripdraw/application/AuthTokenManagerTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthTokenManagerTest.java @@ -1,9 +1,7 @@ -package dev.tripdraw.application; +package dev.tripdraw.auth.application; import static org.assertj.core.api.Assertions.assertThat; -import dev.tripdraw.application.oauth.AuthTokenManager; -import dev.tripdraw.application.oauth.JwtTokenProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/application/JwtTokenProviderTest.java b/backend/src/test/java/dev/tripdraw/auth/application/JwtTokenProviderTest.java similarity index 90% rename from backend/src/test/java/dev/tripdraw/application/JwtTokenProviderTest.java rename to backend/src/test/java/dev/tripdraw/auth/application/JwtTokenProviderTest.java index 011dbe67c..b4bca1396 100644 --- a/backend/src/test/java/dev/tripdraw/application/JwtTokenProviderTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/JwtTokenProviderTest.java @@ -1,12 +1,11 @@ -package dev.tripdraw.application; +package dev.tripdraw.auth.application; -import static dev.tripdraw.exception.auth.AuthExceptionType.EXPIRED_TOKEN; -import static dev.tripdraw.exception.auth.AuthExceptionType.INVALID_TOKEN; +import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_TOKEN; +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import dev.tripdraw.application.oauth.JwtTokenProvider; -import dev.tripdraw.exception.auth.AuthException; +import dev.tripdraw.auth.exception.AuthException; import java.time.Instant; import java.util.Date; import org.junit.jupiter.api.BeforeEach; diff --git a/backend/src/test/java/dev/tripdraw/dto/auth/KakaoInfoResponseTest.java b/backend/src/test/java/dev/tripdraw/auth/dto/KakaoInfoResponseTest.java similarity index 89% rename from backend/src/test/java/dev/tripdraw/dto/auth/KakaoInfoResponseTest.java rename to backend/src/test/java/dev/tripdraw/auth/dto/KakaoInfoResponseTest.java index 9716ee778..e009b55eb 100644 --- a/backend/src/test/java/dev/tripdraw/dto/auth/KakaoInfoResponseTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/dto/KakaoInfoResponseTest.java @@ -1,6 +1,6 @@ -package dev.tripdraw.dto.auth; +package dev.tripdraw.auth.dto; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; import java.time.LocalDateTime; diff --git a/backend/src/test/java/dev/tripdraw/domain/oauth/KakaoApiClientTest.java b/backend/src/test/java/dev/tripdraw/auth/oauth/KakaoApiClientTest.java similarity index 88% rename from backend/src/test/java/dev/tripdraw/domain/oauth/KakaoApiClientTest.java rename to backend/src/test/java/dev/tripdraw/auth/oauth/KakaoApiClientTest.java index 4bd407c18..e7ed83b1f 100644 --- a/backend/src/test/java/dev/tripdraw/domain/oauth/KakaoApiClientTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/oauth/KakaoApiClientTest.java @@ -1,14 +1,14 @@ -package dev.tripdraw.domain.oauth; +package dev.tripdraw.auth.oauth; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import dev.tripdraw.application.oauth.KakaoApiClient; -import dev.tripdraw.dto.auth.KakaoInfoResponse; -import dev.tripdraw.dto.auth.OauthInfo; +import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.auth.dto.KakaoInfoResponse; +import dev.tripdraw.auth.dto.OauthInfo; import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/domain/oauth/OauthClientProviderTest.java b/backend/src/test/java/dev/tripdraw/auth/oauth/OauthClientProviderTest.java similarity index 78% rename from backend/src/test/java/dev/tripdraw/domain/oauth/OauthClientProviderTest.java rename to backend/src/test/java/dev/tripdraw/auth/oauth/OauthClientProviderTest.java index 55eb3f031..411479c54 100644 --- a/backend/src/test/java/dev/tripdraw/domain/oauth/OauthClientProviderTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/oauth/OauthClientProviderTest.java @@ -1,11 +1,8 @@ -package dev.tripdraw.domain.oauth; +package dev.tripdraw.auth.oauth; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static org.assertj.core.api.Assertions.assertThat; -import dev.tripdraw.application.oauth.KakaoApiClient; -import dev.tripdraw.application.oauth.OauthClient; -import dev.tripdraw.application.oauth.OauthClientProvider; import java.util.Set; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/presentation/controller/AuthControllerTest.java b/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java similarity index 95% rename from backend/src/test/java/dev/tripdraw/presentation/controller/AuthControllerTest.java rename to backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java index ac0f13b10..a41d7adee 100644 --- a/backend/src/test/java/dev/tripdraw/presentation/controller/AuthControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java @@ -1,6 +1,6 @@ -package dev.tripdraw.presentation.controller; +package dev.tripdraw.auth.presentation; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.Mockito.when; import static org.springframework.http.HttpStatus.BAD_REQUEST; @@ -9,13 +9,13 @@ import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import dev.tripdraw.application.oauth.OauthClientProvider; +import dev.tripdraw.auth.dto.OauthRequest; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.dto.RegisterRequest; +import dev.tripdraw.auth.oauth.OauthClientProvider; import dev.tripdraw.common.TestKakaoApiClient; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.dto.auth.OauthRequest; -import dev.tripdraw.dto.auth.OauthResponse; -import dev.tripdraw.dto.auth.RegisterRequest; import dev.tripdraw.test.ControllerTest; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; diff --git a/backend/src/test/java/dev/tripdraw/common/TestKakaoApiClient.java b/backend/src/test/java/dev/tripdraw/common/TestKakaoApiClient.java index 8ad6c65de..2796f55bd 100644 --- a/backend/src/test/java/dev/tripdraw/common/TestKakaoApiClient.java +++ b/backend/src/test/java/dev/tripdraw/common/TestKakaoApiClient.java @@ -1,10 +1,10 @@ package dev.tripdraw.common; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; -import dev.tripdraw.application.oauth.OauthClient; -import dev.tripdraw.domain.oauth.OauthType; -import dev.tripdraw.dto.auth.OauthInfo; +import dev.tripdraw.auth.oauth.OauthClient; +import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.auth.dto.OauthInfo; public class TestKakaoApiClient implements OauthClient { diff --git a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java index 96325a673..efa9a90df 100644 --- a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.member.application; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; @@ -8,7 +8,7 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import dev.tripdraw.application.ServiceTest; -import dev.tripdraw.application.oauth.AuthTokenManager; +import dev.tripdraw.auth.application.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.domain.Post; diff --git a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java index 4f5344eb3..123c7335e 100644 --- a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java @@ -1,14 +1,12 @@ package dev.tripdraw.member.domain; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.member.exception.MemberException; -import dev.tripdraw.member.domain.Member; -import dev.tripdraw.member.domain.MemberRepository; import java.util.Optional; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/dev/tripdraw/member/domain/MemberTest.java b/backend/src/test/java/dev/tripdraw/member/domain/MemberTest.java index fb9097747..4b988b0bb 100644 --- a/backend/src/test/java/dev/tripdraw/member/domain/MemberTest.java +++ b/backend/src/test/java/dev/tripdraw/member/domain/MemberTest.java @@ -1,9 +1,8 @@ package dev.tripdraw.member.domain; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static org.assertj.core.api.Assertions.assertThat; -import dev.tripdraw.member.domain.Member; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java index 8e444e76a..c6508bd7e 100644 --- a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.member.presentation; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.springframework.http.HttpStatus.FORBIDDEN; @@ -8,7 +8,7 @@ import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; -import dev.tripdraw.application.oauth.AuthTokenManager; +import dev.tripdraw.auth.application.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.domain.Post; diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index a1d4b8e12..d49582150 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.post.application; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.post.exception.PostExceptionType.NOT_AUTHORIZED_TO_POST; import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; @@ -18,11 +18,10 @@ import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.post.application.PostService; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.dto.auth.LoginUser; +import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java index e95d1f492..7a869f796 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.post.domain; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; @@ -8,8 +8,6 @@ import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.post.domain.Post; -import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java index 11ca876a8..5ab76bcfe 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.post.domain; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.post.exception.PostExceptionType.NOT_AUTHORIZED_TO_POST; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_HAS_POST; import static org.assertj.core.api.Assertions.assertThat; @@ -8,7 +8,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.member.domain.Member; -import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.post.exception.PostException; import dev.tripdraw.trip.exception.TripException; diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index 34eb3aa1d..be4dd6a39 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.post.presentation; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CREATED; @@ -12,7 +12,7 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; import dev.tripdraw.draw.application.RouteImageGenerator; -import dev.tripdraw.application.oauth.AuthTokenManager; +import dev.tripdraw.auth.application.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.dto.PostAndPointCreateRequest; diff --git a/backend/src/test/java/dev/tripdraw/test/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/TestFixture.java index 7a91ee91f..519872111 100644 --- a/backend/src/test/java/dev/tripdraw/test/TestFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/TestFixture.java @@ -1,7 +1,7 @@ package dev.tripdraw.test; import dev.tripdraw.member.domain.Member; -import dev.tripdraw.domain.oauth.OauthType; +import dev.tripdraw.auth.domain.OauthType; import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index b541892c5..0c5792a33 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.application; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; @@ -14,7 +14,7 @@ import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.dto.auth.LoginUser; +import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.member.exception.MemberException; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index 399d98421..55aa014a2 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.domain; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java index c84c6f970..908fbd12e 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.domain; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.trip.exception.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_IN_TRIP; diff --git a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java index e3b8fc7c5..46cd6186b 100644 --- a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.dto; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.trip.domain.TripStatus.ONGOING; import static org.assertj.core.api.Assertions.assertThat; diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index a49e88801..4f998d75c 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.presentation; -import static dev.tripdraw.domain.oauth.OauthType.KAKAO; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.springframework.http.HttpStatus.CONFLICT; @@ -12,7 +12,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import dev.tripdraw.draw.application.RouteImageGenerator; -import dev.tripdraw.application.oauth.AuthTokenManager; +import dev.tripdraw.auth.application.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.test.ControllerTest; From b340926878fd8057cddca7224cba9096bdbc89eb Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 31 Aug 2023 17:23:33 +0900 Subject: [PATCH 016/119] =?UTF-8?q?[refactor]=20file=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20(#223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Combi153 Co-authored-by: Jaeyoung22 --- .../main/java/dev/tripdraw/domain/file/FileType.java | 4 ++-- .../file => file/application}/FilePath.java | 4 ++-- .../file => file/application}/FileUploader.java | 6 +++--- .../file => file/application}/FileUrlMaker.java | 2 +- .../file => file/exception}/FileIOException.java | 2 +- .../file => file/exception}/FileIOExceptionType.java | 2 +- .../dev/tripdraw/post/application/PostService.java | 10 +++++----- .../tripdraw/auth/application/AuthServiceTest.java | 2 +- .../file => file/application}/FileUploaderTest.java | 4 ++-- .../file => file/application}/FileUrlMakerTest.java | 2 +- .../member/application/MemberServiceTest.java | 6 +++--- .../tripdraw/post/application/PostServiceTest.java | 12 ++++++------ .../tripdraw/{application => test}/ServiceTest.java | 2 +- .../tripdraw/trip/application/TripServiceTest.java | 4 ++-- 14 files changed, 31 insertions(+), 31 deletions(-) rename backend/src/main/java/dev/tripdraw/{application/file => file/application}/FilePath.java (95%) rename backend/src/main/java/dev/tripdraw/{application/file => file/application}/FileUploader.java (87%) rename backend/src/main/java/dev/tripdraw/{application/file => file/application}/FileUrlMaker.java (90%) rename backend/src/main/java/dev/tripdraw/{exception/file => file/exception}/FileIOException.java (87%) rename backend/src/main/java/dev/tripdraw/{exception/file => file/exception}/FileIOExceptionType.java (95%) rename backend/src/test/java/dev/tripdraw/{application/file => file/application}/FileUploaderTest.java (96%) rename backend/src/test/java/dev/tripdraw/{application/file => file/application}/FileUrlMakerTest.java (94%) rename backend/src/test/java/dev/tripdraw/{application => test}/ServiceTest.java (94%) diff --git a/backend/src/main/java/dev/tripdraw/domain/file/FileType.java b/backend/src/main/java/dev/tripdraw/domain/file/FileType.java index 8188d8549..190692eba 100644 --- a/backend/src/main/java/dev/tripdraw/domain/file/FileType.java +++ b/backend/src/main/java/dev/tripdraw/domain/file/FileType.java @@ -1,9 +1,9 @@ package dev.tripdraw.domain.file; -import static dev.tripdraw.exception.file.FileIOExceptionType.INVALID_CONTENT_TYPE; +import static dev.tripdraw.file.exception.FileIOExceptionType.INVALID_CONTENT_TYPE; import static org.springframework.http.MediaType.IMAGE_JPEG_VALUE; -import dev.tripdraw.exception.file.FileIOException; +import dev.tripdraw.file.exception.FileIOException; import java.util.Arrays; import java.util.Objects; import lombok.Getter; diff --git a/backend/src/main/java/dev/tripdraw/application/file/FilePath.java b/backend/src/main/java/dev/tripdraw/file/application/FilePath.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/application/file/FilePath.java rename to backend/src/main/java/dev/tripdraw/file/application/FilePath.java index 23de87062..6aeae9f85 100644 --- a/backend/src/main/java/dev/tripdraw/application/file/FilePath.java +++ b/backend/src/main/java/dev/tripdraw/file/application/FilePath.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application.file; +package dev.tripdraw.file.application; import static dev.tripdraw.domain.file.FileType.POST_IMAGE; @@ -9,7 +9,7 @@ @Component public class FilePath { - + private final String base; private final String postImagePath; diff --git a/backend/src/main/java/dev/tripdraw/application/file/FileUploader.java b/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/application/file/FileUploader.java rename to backend/src/main/java/dev/tripdraw/file/application/FileUploader.java index df7360e8a..042787990 100644 --- a/backend/src/main/java/dev/tripdraw/application/file/FileUploader.java +++ b/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java @@ -1,9 +1,9 @@ -package dev.tripdraw.application.file; +package dev.tripdraw.file.application; -import static dev.tripdraw.exception.file.FileIOExceptionType.FILE_SAVE_FAIL; +import static dev.tripdraw.file.exception.FileIOExceptionType.FILE_SAVE_FAIL; import dev.tripdraw.domain.file.FileType; -import dev.tripdraw.exception.file.FileIOException; +import dev.tripdraw.file.exception.FileIOException; import java.io.File; import java.io.IOException; import java.util.UUID; diff --git a/backend/src/main/java/dev/tripdraw/application/file/FileUrlMaker.java b/backend/src/main/java/dev/tripdraw/file/application/FileUrlMaker.java similarity index 90% rename from backend/src/main/java/dev/tripdraw/application/file/FileUrlMaker.java rename to backend/src/main/java/dev/tripdraw/file/application/FileUrlMaker.java index fd66c9286..3a40be4da 100644 --- a/backend/src/main/java/dev/tripdraw/application/file/FileUrlMaker.java +++ b/backend/src/main/java/dev/tripdraw/file/application/FileUrlMaker.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application.file; +package dev.tripdraw.file.application; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/backend/src/main/java/dev/tripdraw/exception/file/FileIOException.java b/backend/src/main/java/dev/tripdraw/file/exception/FileIOException.java similarity index 87% rename from backend/src/main/java/dev/tripdraw/exception/file/FileIOException.java rename to backend/src/main/java/dev/tripdraw/file/exception/FileIOException.java index 6a417302b..7461a5580 100644 --- a/backend/src/main/java/dev/tripdraw/exception/file/FileIOException.java +++ b/backend/src/main/java/dev/tripdraw/file/exception/FileIOException.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.file; +package dev.tripdraw.file.exception; import dev.tripdraw.exception.common.BaseException; import dev.tripdraw.exception.common.ExceptionType; diff --git a/backend/src/main/java/dev/tripdraw/exception/file/FileIOExceptionType.java b/backend/src/main/java/dev/tripdraw/file/exception/FileIOExceptionType.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/exception/file/FileIOExceptionType.java rename to backend/src/main/java/dev/tripdraw/file/exception/FileIOExceptionType.java index 186c74b63..c81fc0ead 100644 --- a/backend/src/main/java/dev/tripdraw/exception/file/FileIOExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/file/exception/FileIOExceptionType.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.file; +package dev.tripdraw.file.exception; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index ad6e1446d..b931af4c0 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -2,23 +2,23 @@ import static dev.tripdraw.domain.file.FileType.POST_IMAGE; -import dev.tripdraw.application.file.FileUploader; +import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.domain.file.FileType; +import dev.tripdraw.file.application.FileUploader; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.domain.Post; import dev.tripdraw.post.domain.PostCreateEvent; import dev.tripdraw.post.domain.PostRepository; -import dev.tripdraw.trip.domain.Point; -import dev.tripdraw.trip.domain.Trip; -import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index 9a98962c0..fbcb12c14 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -7,7 +7,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.when; -import dev.tripdraw.application.ServiceTest; import dev.tripdraw.auth.dto.OauthRequest; import dev.tripdraw.auth.dto.OauthResponse; import dev.tripdraw.auth.dto.RegisterRequest; @@ -16,6 +15,7 @@ import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; +import dev.tripdraw.test.ServiceTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/backend/src/test/java/dev/tripdraw/application/file/FileUploaderTest.java b/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java similarity index 96% rename from backend/src/test/java/dev/tripdraw/application/file/FileUploaderTest.java rename to backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java index 454cde4f4..0708ec03a 100644 --- a/backend/src/test/java/dev/tripdraw/application/file/FileUploaderTest.java +++ b/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application.file; +package dev.tripdraw.file.application; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -9,7 +9,7 @@ import static org.mockito.Mockito.when; import dev.tripdraw.domain.file.FileType; -import dev.tripdraw.exception.file.FileIOException; +import dev.tripdraw.file.exception.FileIOException; import java.io.File; import java.io.IOException; import java.util.UUID; diff --git a/backend/src/test/java/dev/tripdraw/application/file/FileUrlMakerTest.java b/backend/src/test/java/dev/tripdraw/file/application/FileUrlMakerTest.java similarity index 94% rename from backend/src/test/java/dev/tripdraw/application/file/FileUrlMakerTest.java rename to backend/src/test/java/dev/tripdraw/file/application/FileUrlMakerTest.java index 92e9e7fc4..8a45d5265 100644 --- a/backend/src/test/java/dev/tripdraw/application/file/FileUrlMakerTest.java +++ b/backend/src/test/java/dev/tripdraw/file/application/FileUrlMakerTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application.file; +package dev.tripdraw.file.application; import static org.assertj.core.api.Assertions.assertThat; diff --git a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java index efa9a90df..d88aa874f 100644 --- a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java @@ -7,18 +7,18 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import dev.tripdraw.application.ServiceTest; import dev.tripdraw.auth.application.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.member.dto.MemberSearchResponse; +import dev.tripdraw.member.exception.MemberException; import dev.tripdraw.post.domain.Post; import dev.tripdraw.post.domain.PostRepository; +import dev.tripdraw.test.ServiceTest; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.member.dto.MemberSearchResponse; -import dev.tripdraw.member.exception.MemberException; import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index d49582150..a2a5cc508 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -14,22 +14,22 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; -import dev.tripdraw.application.ServiceTest; +import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.trip.domain.Point; -import dev.tripdraw.trip.domain.Trip; -import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.auth.dto.LoginUser; +import dev.tripdraw.member.exception.MemberException; import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; -import dev.tripdraw.member.exception.MemberException; import dev.tripdraw.post.exception.PostException; +import dev.tripdraw.test.ServiceTest; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; diff --git a/backend/src/test/java/dev/tripdraw/application/ServiceTest.java b/backend/src/test/java/dev/tripdraw/test/ServiceTest.java similarity index 94% rename from backend/src/test/java/dev/tripdraw/application/ServiceTest.java rename to backend/src/test/java/dev/tripdraw/test/ServiceTest.java index 331e05767..a616a43b3 100644 --- a/backend/src/test/java/dev/tripdraw/application/ServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/test/ServiceTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.application; +package dev.tripdraw.test; import jakarta.transaction.Transactional; import java.lang.annotation.ElementType; diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index 0c5792a33..231081447 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -10,12 +10,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import dev.tripdraw.application.ServiceTest; +import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.member.exception.MemberException; +import dev.tripdraw.test.ServiceTest; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; From 930ad24494f8618535aebdd51857fb15916ca000 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 31 Aug 2023 17:37:05 +0900 Subject: [PATCH 017/119] =?UTF-8?q?[refactor]=20common=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?(#223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Combi153 Co-authored-by: Jaeyoung22 --- backend/build.gradle | 11 +++++++++++ .../dev/tripdraw/auth/application/AuthExtractor.java | 1 - .../java/dev/tripdraw/auth/dto/RegisterRequest.java | 2 +- .../dev/tripdraw/auth/exception/AuthException.java | 4 ++-- .../tripdraw/auth/exception/AuthExceptionType.java | 2 +- .../dev/tripdraw/{ => common}/config/AsyncConfig.java | 2 +- .../dev/tripdraw/{ => common}/config/AuthConfig.java | 2 +- .../tripdraw/{ => common}/config/ClientConfig.java | 2 +- .../tripdraw/{ => common}/config/FilterConfig.java | 8 ++++---- .../tripdraw/{ => common}/config/HibernateConfig.java | 4 ++-- .../dev/tripdraw/{ => common}/config/JpaConfig.java | 2 +- .../tripdraw/{ => common}/config/MultipartConfig.java | 2 +- .../{domain/common => common/entity}/BaseEntity.java | 2 +- .../common => common/exception}/BaseException.java | 2 +- .../exception}/ExceptionResponse.java | 2 +- .../common => common/exception}/ExceptionType.java | 2 +- .../exception}/GlobalExceptionHandler.java | 4 ++-- .../exception}/ValidationException.java | 2 +- .../java/dev/tripdraw/common/{ => log}/LogFilter.java | 5 ++--- .../java/dev/tripdraw/common/{ => log}/MdcFilter.java | 5 ++--- .../java/dev/tripdraw/common/{ => log}/MdcToken.java | 2 +- .../dev/tripdraw/common/{ => log}/QueryCounter.java | 2 +- .../dev/tripdraw/common/{ => log}/QueryInspector.java | 2 +- .../MultipartJackson2HttpMessageConverter.java | 2 +- .../swagger/SwaggerAuthorizationRequired.java | 4 ++-- .../{config => common}/swagger/SwaggerConfig.java | 2 +- .../{dto => common}/validation/NoWhiteSpace.java | 2 +- .../validation/NoWhiteSpaceValidator.java | 2 +- .../dev/tripdraw/draw/exception/DrawException.java | 4 ++-- .../tripdraw/draw/exception/DrawExceptionType.java | 2 +- .../java/dev/tripdraw/file/application/FilePath.java | 4 ++-- .../dev/tripdraw/file/application/FileUploader.java | 2 +- .../{domain/file => file/domain}/FileType.java | 2 +- .../dev/tripdraw/file/exception/FileIOException.java | 4 ++-- .../tripdraw/file/exception/FileIOExceptionType.java | 2 +- .../main/java/dev/tripdraw/member/domain/Member.java | 2 +- .../tripdraw/member/exception/MemberException.java | 4 ++-- .../member/exception/MemberExceptionType.java | 2 +- .../dev/tripdraw/post/application/PostService.java | 4 ++-- .../src/main/java/dev/tripdraw/post/domain/Post.java | 4 ++-- .../dev/tripdraw/post/exception/PostException.java | 4 ++-- .../tripdraw/post/exception/PostExceptionType.java | 2 +- .../tripdraw/post/presentation/PostController.java | 2 +- .../src/main/java/dev/tripdraw/trip/domain/Point.java | 2 +- .../src/main/java/dev/tripdraw/trip/domain/Trip.java | 2 +- .../dev/tripdraw/trip/exception/TripException.java | 4 ++-- .../tripdraw/trip/exception/TripExceptionType.java | 2 +- .../tripdraw/trip/presentation/TripController.java | 2 +- backend/src/main/resources/application-local.yml | 9 --------- .../tripdraw/auth/application/AuthServiceTest.java | 2 +- .../auth/presentation/AuthControllerTest.java | 2 +- .../tripdraw/common/{ => log}/QueryCounterTest.java | 4 ++-- .../tripdraw/file/application/FileUploaderTest.java | 2 +- .../tripdraw/{common => test}/TestKakaoApiClient.java | 4 ++-- 54 files changed, 81 insertions(+), 82 deletions(-) rename backend/src/main/java/dev/tripdraw/{ => common}/config/AsyncConfig.java (83%) rename backend/src/main/java/dev/tripdraw/{ => common}/config/AuthConfig.java (97%) rename backend/src/main/java/dev/tripdraw/{ => common}/config/ClientConfig.java (89%) rename backend/src/main/java/dev/tripdraw/{ => common}/config/FilterConfig.java (86%) rename backend/src/main/java/dev/tripdraw/{ => common}/config/HibernateConfig.java (88%) rename backend/src/main/java/dev/tripdraw/{ => common}/config/JpaConfig.java (84%) rename backend/src/main/java/dev/tripdraw/{ => common}/config/MultipartConfig.java (96%) rename backend/src/main/java/dev/tripdraw/{domain/common => common/entity}/BaseEntity.java (94%) rename backend/src/main/java/dev/tripdraw/{exception/common => common/exception}/BaseException.java (90%) rename backend/src/main/java/dev/tripdraw/{exception/common => common/exception}/ExceptionResponse.java (93%) rename backend/src/main/java/dev/tripdraw/{exception/common => common/exception}/ExceptionType.java (79%) rename backend/src/main/java/dev/tripdraw/{exception/common => common/exception}/GlobalExceptionHandler.java (96%) rename backend/src/main/java/dev/tripdraw/{exception/common => common/exception}/ValidationException.java (88%) rename backend/src/main/java/dev/tripdraw/common/{ => log}/LogFilter.java (94%) rename backend/src/main/java/dev/tripdraw/common/{ => log}/MdcFilter.java (86%) rename backend/src/main/java/dev/tripdraw/common/{ => log}/MdcToken.java (88%) rename backend/src/main/java/dev/tripdraw/common/{ => log}/QueryCounter.java (95%) rename backend/src/main/java/dev/tripdraw/common/{ => log}/QueryInspector.java (95%) rename backend/src/main/java/dev/tripdraw/{config => common}/swagger/MultipartJackson2HttpMessageConverter.java (96%) rename backend/src/main/java/dev/tripdraw/{config => common}/swagger/SwaggerAuthorizationRequired.java (81%) rename backend/src/main/java/dev/tripdraw/{config => common}/swagger/SwaggerConfig.java (97%) rename backend/src/main/java/dev/tripdraw/{dto => common}/validation/NoWhiteSpace.java (93%) rename backend/src/main/java/dev/tripdraw/{dto => common}/validation/NoWhiteSpaceValidator.java (90%) rename backend/src/main/java/dev/tripdraw/{domain/file => file/domain}/FileType.java (96%) rename backend/src/test/java/dev/tripdraw/common/{ => log}/QueryCounterTest.java (97%) rename backend/src/test/java/dev/tripdraw/{common => test}/TestKakaoApiClient.java (93%) diff --git a/backend/build.gradle b/backend/build.gradle index ba8e44d63..8c08b0114 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -21,23 +21,34 @@ repositories { } dependencies { + // spring implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' + + // jwt implementation 'io.jsonwebtoken:jjwt-api:0.11.5' implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' + // h2 runtimeOnly 'com.h2database:h2' + + // mysql runtimeOnly 'com.mysql:mysql-connector-j' + + // swagger implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' + // test testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'io.rest-assured:rest-assured:5.3.0' + // flyway implementation 'org.flywaydb:flyway-core' implementation 'org.flywaydb:flyway-mysql' + // lombok compileOnly 'org.projectlombok:lombok:1.18.28' annotationProcessor 'org.projectlombok:lombok:1.18.28' } diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java index 84ccdb353..ff29b4bc2 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java @@ -4,7 +4,6 @@ import static org.springframework.http.HttpHeaders.AUTHORIZATION; import static org.springframework.util.StringUtils.hasText; -import dev.tripdraw.auth.application.AuthTokenManager; import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.auth.exception.AuthException; import jakarta.servlet.http.HttpServletRequest; diff --git a/backend/src/main/java/dev/tripdraw/auth/dto/RegisterRequest.java b/backend/src/main/java/dev/tripdraw/auth/dto/RegisterRequest.java index b6b922cec..daad6cfa0 100644 --- a/backend/src/main/java/dev/tripdraw/auth/dto/RegisterRequest.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/RegisterRequest.java @@ -1,7 +1,7 @@ package dev.tripdraw.auth.dto; import dev.tripdraw.auth.domain.OauthType; -import dev.tripdraw.dto.validation.NoWhiteSpace; +import dev.tripdraw.common.validation.NoWhiteSpace; import io.swagger.v3.oas.annotations.media.Schema; public record RegisterRequest( diff --git a/backend/src/main/java/dev/tripdraw/auth/exception/AuthException.java b/backend/src/main/java/dev/tripdraw/auth/exception/AuthException.java index 8ce153e3b..e5839e24d 100644 --- a/backend/src/main/java/dev/tripdraw/auth/exception/AuthException.java +++ b/backend/src/main/java/dev/tripdraw/auth/exception/AuthException.java @@ -1,7 +1,7 @@ package dev.tripdraw.auth.exception; -import dev.tripdraw.exception.common.BaseException; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.BaseException; +import dev.tripdraw.common.exception.ExceptionType; public class AuthException extends BaseException { diff --git a/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java b/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java index ff453dcf9..f713fc95b 100644 --- a/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java @@ -4,7 +4,7 @@ import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.UNAUTHORIZED; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.ExceptionType; import org.springframework.http.HttpStatus; public enum AuthExceptionType implements ExceptionType { diff --git a/backend/src/main/java/dev/tripdraw/config/AsyncConfig.java b/backend/src/main/java/dev/tripdraw/common/config/AsyncConfig.java similarity index 83% rename from backend/src/main/java/dev/tripdraw/config/AsyncConfig.java rename to backend/src/main/java/dev/tripdraw/common/config/AsyncConfig.java index 6bfe04d56..ec9efdbb3 100644 --- a/backend/src/main/java/dev/tripdraw/config/AsyncConfig.java +++ b/backend/src/main/java/dev/tripdraw/common/config/AsyncConfig.java @@ -1,4 +1,4 @@ -package dev.tripdraw.config; +package dev.tripdraw.common.config; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableAsync; diff --git a/backend/src/main/java/dev/tripdraw/config/AuthConfig.java b/backend/src/main/java/dev/tripdraw/common/config/AuthConfig.java similarity index 97% rename from backend/src/main/java/dev/tripdraw/config/AuthConfig.java rename to backend/src/main/java/dev/tripdraw/common/config/AuthConfig.java index d4a501e5d..7a98c5fd7 100644 --- a/backend/src/main/java/dev/tripdraw/config/AuthConfig.java +++ b/backend/src/main/java/dev/tripdraw/common/config/AuthConfig.java @@ -1,4 +1,4 @@ -package dev.tripdraw.config; +package dev.tripdraw.common.config; import dev.tripdraw.auth.presentation.AuthArgumentResolver; import dev.tripdraw.auth.application.AuthExtractor; diff --git a/backend/src/main/java/dev/tripdraw/config/ClientConfig.java b/backend/src/main/java/dev/tripdraw/common/config/ClientConfig.java similarity index 89% rename from backend/src/main/java/dev/tripdraw/config/ClientConfig.java rename to backend/src/main/java/dev/tripdraw/common/config/ClientConfig.java index 0b224145f..d02add7da 100644 --- a/backend/src/main/java/dev/tripdraw/config/ClientConfig.java +++ b/backend/src/main/java/dev/tripdraw/common/config/ClientConfig.java @@ -1,4 +1,4 @@ -package dev.tripdraw.config; +package dev.tripdraw.common.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/backend/src/main/java/dev/tripdraw/config/FilterConfig.java b/backend/src/main/java/dev/tripdraw/common/config/FilterConfig.java similarity index 86% rename from backend/src/main/java/dev/tripdraw/config/FilterConfig.java rename to backend/src/main/java/dev/tripdraw/common/config/FilterConfig.java index 04e1eb5c0..6ada66ec8 100644 --- a/backend/src/main/java/dev/tripdraw/config/FilterConfig.java +++ b/backend/src/main/java/dev/tripdraw/common/config/FilterConfig.java @@ -1,8 +1,8 @@ -package dev.tripdraw.config; +package dev.tripdraw.common.config; -import dev.tripdraw.common.LogFilter; -import dev.tripdraw.common.MdcFilter; -import dev.tripdraw.common.QueryCounter; +import dev.tripdraw.common.log.LogFilter; +import dev.tripdraw.common.log.MdcFilter; +import dev.tripdraw.common.log.QueryCounter; import lombok.RequiredArgsConstructor; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; diff --git a/backend/src/main/java/dev/tripdraw/config/HibernateConfig.java b/backend/src/main/java/dev/tripdraw/common/config/HibernateConfig.java similarity index 88% rename from backend/src/main/java/dev/tripdraw/config/HibernateConfig.java rename to backend/src/main/java/dev/tripdraw/common/config/HibernateConfig.java index 6614ec4de..371708a24 100644 --- a/backend/src/main/java/dev/tripdraw/config/HibernateConfig.java +++ b/backend/src/main/java/dev/tripdraw/common/config/HibernateConfig.java @@ -1,8 +1,8 @@ -package dev.tripdraw.config; +package dev.tripdraw.common.config; import static org.hibernate.cfg.AvailableSettings.STATEMENT_INSPECTOR; -import dev.tripdraw.common.QueryInspector; +import dev.tripdraw.common.log.QueryInspector; import lombok.RequiredArgsConstructor; import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer; import org.springframework.context.annotation.Bean; diff --git a/backend/src/main/java/dev/tripdraw/config/JpaConfig.java b/backend/src/main/java/dev/tripdraw/common/config/JpaConfig.java similarity index 84% rename from backend/src/main/java/dev/tripdraw/config/JpaConfig.java rename to backend/src/main/java/dev/tripdraw/common/config/JpaConfig.java index 4a30c6f60..029d5edb8 100644 --- a/backend/src/main/java/dev/tripdraw/config/JpaConfig.java +++ b/backend/src/main/java/dev/tripdraw/common/config/JpaConfig.java @@ -1,4 +1,4 @@ -package dev.tripdraw.config; +package dev.tripdraw.common.config; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; diff --git a/backend/src/main/java/dev/tripdraw/config/MultipartConfig.java b/backend/src/main/java/dev/tripdraw/common/config/MultipartConfig.java similarity index 96% rename from backend/src/main/java/dev/tripdraw/config/MultipartConfig.java rename to backend/src/main/java/dev/tripdraw/common/config/MultipartConfig.java index 1f0945cb6..969e4503d 100644 --- a/backend/src/main/java/dev/tripdraw/config/MultipartConfig.java +++ b/backend/src/main/java/dev/tripdraw/common/config/MultipartConfig.java @@ -1,4 +1,4 @@ -package dev.tripdraw.config; +package dev.tripdraw.common.config; import static org.springframework.util.unit.DataUnit.MEGABYTES; diff --git a/backend/src/main/java/dev/tripdraw/domain/common/BaseEntity.java b/backend/src/main/java/dev/tripdraw/common/entity/BaseEntity.java similarity index 94% rename from backend/src/main/java/dev/tripdraw/domain/common/BaseEntity.java rename to backend/src/main/java/dev/tripdraw/common/entity/BaseEntity.java index 7b1ab624b..e41183d78 100644 --- a/backend/src/main/java/dev/tripdraw/domain/common/BaseEntity.java +++ b/backend/src/main/java/dev/tripdraw/common/entity/BaseEntity.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.common; +package dev.tripdraw.common.entity; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; diff --git a/backend/src/main/java/dev/tripdraw/exception/common/BaseException.java b/backend/src/main/java/dev/tripdraw/common/exception/BaseException.java similarity index 90% rename from backend/src/main/java/dev/tripdraw/exception/common/BaseException.java rename to backend/src/main/java/dev/tripdraw/common/exception/BaseException.java index ea8ffbeb1..6a406449d 100644 --- a/backend/src/main/java/dev/tripdraw/exception/common/BaseException.java +++ b/backend/src/main/java/dev/tripdraw/common/exception/BaseException.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.common; +package dev.tripdraw.common.exception; public class BaseException extends RuntimeException { diff --git a/backend/src/main/java/dev/tripdraw/exception/common/ExceptionResponse.java b/backend/src/main/java/dev/tripdraw/common/exception/ExceptionResponse.java similarity index 93% rename from backend/src/main/java/dev/tripdraw/exception/common/ExceptionResponse.java rename to backend/src/main/java/dev/tripdraw/common/exception/ExceptionResponse.java index 397623952..784b7b09c 100644 --- a/backend/src/main/java/dev/tripdraw/exception/common/ExceptionResponse.java +++ b/backend/src/main/java/dev/tripdraw/common/exception/ExceptionResponse.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.common; +package dev.tripdraw.common.exception; import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY; diff --git a/backend/src/main/java/dev/tripdraw/exception/common/ExceptionType.java b/backend/src/main/java/dev/tripdraw/common/exception/ExceptionType.java similarity index 79% rename from backend/src/main/java/dev/tripdraw/exception/common/ExceptionType.java rename to backend/src/main/java/dev/tripdraw/common/exception/ExceptionType.java index a9517065b..1e96dd306 100644 --- a/backend/src/main/java/dev/tripdraw/exception/common/ExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/common/exception/ExceptionType.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.common; +package dev.tripdraw.common.exception; import org.springframework.http.HttpStatus; diff --git a/backend/src/main/java/dev/tripdraw/exception/common/GlobalExceptionHandler.java b/backend/src/main/java/dev/tripdraw/common/exception/GlobalExceptionHandler.java similarity index 96% rename from backend/src/main/java/dev/tripdraw/exception/common/GlobalExceptionHandler.java rename to backend/src/main/java/dev/tripdraw/common/exception/GlobalExceptionHandler.java index a4314c372..f4ce42272 100644 --- a/backend/src/main/java/dev/tripdraw/exception/common/GlobalExceptionHandler.java +++ b/backend/src/main/java/dev/tripdraw/common/exception/GlobalExceptionHandler.java @@ -1,6 +1,6 @@ -package dev.tripdraw.exception.common; +package dev.tripdraw.common.exception; -import static dev.tripdraw.common.MdcToken.REQUEST_ID; +import static dev.tripdraw.common.log.MdcToken.REQUEST_ID; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; diff --git a/backend/src/main/java/dev/tripdraw/exception/common/ValidationException.java b/backend/src/main/java/dev/tripdraw/common/exception/ValidationException.java similarity index 88% rename from backend/src/main/java/dev/tripdraw/exception/common/ValidationException.java rename to backend/src/main/java/dev/tripdraw/common/exception/ValidationException.java index cb8e025bc..1d305a5c4 100644 --- a/backend/src/main/java/dev/tripdraw/exception/common/ValidationException.java +++ b/backend/src/main/java/dev/tripdraw/common/exception/ValidationException.java @@ -1,4 +1,4 @@ -package dev.tripdraw.exception.common; +package dev.tripdraw.common.exception; import org.springframework.validation.FieldError; diff --git a/backend/src/main/java/dev/tripdraw/common/LogFilter.java b/backend/src/main/java/dev/tripdraw/common/log/LogFilter.java similarity index 94% rename from backend/src/main/java/dev/tripdraw/common/LogFilter.java rename to backend/src/main/java/dev/tripdraw/common/log/LogFilter.java index bf3b758b0..7bebfda9c 100644 --- a/backend/src/main/java/dev/tripdraw/common/LogFilter.java +++ b/backend/src/main/java/dev/tripdraw/common/log/LogFilter.java @@ -1,6 +1,6 @@ -package dev.tripdraw.common; +package dev.tripdraw.common.log; -import static dev.tripdraw.common.MdcToken.REQUEST_ID; +import static dev.tripdraw.common.log.MdcToken.REQUEST_ID; import jakarta.servlet.Filter; import jakarta.servlet.FilterChain; @@ -34,7 +34,6 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha long end = System.currentTimeMillis(); log(httpServletRequest.getRequestURI(), httpServletRequest.getMethod(), end - start); queryCounter.close(); - } private void log(String uri, String method, long time) { diff --git a/backend/src/main/java/dev/tripdraw/common/MdcFilter.java b/backend/src/main/java/dev/tripdraw/common/log/MdcFilter.java similarity index 86% rename from backend/src/main/java/dev/tripdraw/common/MdcFilter.java rename to backend/src/main/java/dev/tripdraw/common/log/MdcFilter.java index ecd9caa81..9fd46b285 100644 --- a/backend/src/main/java/dev/tripdraw/common/MdcFilter.java +++ b/backend/src/main/java/dev/tripdraw/common/log/MdcFilter.java @@ -1,6 +1,6 @@ -package dev.tripdraw.common; +package dev.tripdraw.common.log; -import static dev.tripdraw.common.MdcToken.REQUEST_ID; +import static dev.tripdraw.common.log.MdcToken.REQUEST_ID; import jakarta.servlet.Filter; import jakarta.servlet.FilterChain; @@ -18,6 +18,5 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha throws IOException, ServletException { MDC.put(REQUEST_ID.key(), UUID.randomUUID().toString()); chain.doFilter(request, response); - } } diff --git a/backend/src/main/java/dev/tripdraw/common/MdcToken.java b/backend/src/main/java/dev/tripdraw/common/log/MdcToken.java similarity index 88% rename from backend/src/main/java/dev/tripdraw/common/MdcToken.java rename to backend/src/main/java/dev/tripdraw/common/log/MdcToken.java index dd400de53..f88ea2416 100644 --- a/backend/src/main/java/dev/tripdraw/common/MdcToken.java +++ b/backend/src/main/java/dev/tripdraw/common/log/MdcToken.java @@ -1,4 +1,4 @@ -package dev.tripdraw.common; +package dev.tripdraw.common.log; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/backend/src/main/java/dev/tripdraw/common/QueryCounter.java b/backend/src/main/java/dev/tripdraw/common/log/QueryCounter.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/common/QueryCounter.java rename to backend/src/main/java/dev/tripdraw/common/log/QueryCounter.java index 633ffc711..2788c9b6b 100644 --- a/backend/src/main/java/dev/tripdraw/common/QueryCounter.java +++ b/backend/src/main/java/dev/tripdraw/common/log/QueryCounter.java @@ -1,4 +1,4 @@ -package dev.tripdraw.common; +package dev.tripdraw.common.log; import org.springframework.stereotype.Component; diff --git a/backend/src/main/java/dev/tripdraw/common/QueryInspector.java b/backend/src/main/java/dev/tripdraw/common/log/QueryInspector.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/common/QueryInspector.java rename to backend/src/main/java/dev/tripdraw/common/log/QueryInspector.java index e858c645f..da07a70fa 100644 --- a/backend/src/main/java/dev/tripdraw/common/QueryInspector.java +++ b/backend/src/main/java/dev/tripdraw/common/log/QueryInspector.java @@ -1,4 +1,4 @@ -package dev.tripdraw.common; +package dev.tripdraw.common.log; import java.util.Objects; import lombok.RequiredArgsConstructor; diff --git a/backend/src/main/java/dev/tripdraw/config/swagger/MultipartJackson2HttpMessageConverter.java b/backend/src/main/java/dev/tripdraw/common/swagger/MultipartJackson2HttpMessageConverter.java similarity index 96% rename from backend/src/main/java/dev/tripdraw/config/swagger/MultipartJackson2HttpMessageConverter.java rename to backend/src/main/java/dev/tripdraw/common/swagger/MultipartJackson2HttpMessageConverter.java index 2372aa17e..56868f2c6 100644 --- a/backend/src/main/java/dev/tripdraw/config/swagger/MultipartJackson2HttpMessageConverter.java +++ b/backend/src/main/java/dev/tripdraw/common/swagger/MultipartJackson2HttpMessageConverter.java @@ -1,4 +1,4 @@ -package dev.tripdraw.config.swagger; +package dev.tripdraw.common.swagger; import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM; diff --git a/backend/src/main/java/dev/tripdraw/config/swagger/SwaggerAuthorizationRequired.java b/backend/src/main/java/dev/tripdraw/common/swagger/SwaggerAuthorizationRequired.java similarity index 81% rename from backend/src/main/java/dev/tripdraw/config/swagger/SwaggerAuthorizationRequired.java rename to backend/src/main/java/dev/tripdraw/common/swagger/SwaggerAuthorizationRequired.java index a63dec77a..e85cf85fd 100644 --- a/backend/src/main/java/dev/tripdraw/config/swagger/SwaggerAuthorizationRequired.java +++ b/backend/src/main/java/dev/tripdraw/common/swagger/SwaggerAuthorizationRequired.java @@ -1,6 +1,6 @@ -package dev.tripdraw.config.swagger; +package dev.tripdraw.common.swagger; -import static dev.tripdraw.config.swagger.SwaggerConfig.BEARER_SECURITY_SCHEME_KEY; +import static dev.tripdraw.common.swagger.SwaggerConfig.BEARER_SECURITY_SCHEME_KEY; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import java.lang.annotation.ElementType; diff --git a/backend/src/main/java/dev/tripdraw/config/swagger/SwaggerConfig.java b/backend/src/main/java/dev/tripdraw/common/swagger/SwaggerConfig.java similarity index 97% rename from backend/src/main/java/dev/tripdraw/config/swagger/SwaggerConfig.java rename to backend/src/main/java/dev/tripdraw/common/swagger/SwaggerConfig.java index fe4d1293a..a2b75c085 100644 --- a/backend/src/main/java/dev/tripdraw/config/swagger/SwaggerConfig.java +++ b/backend/src/main/java/dev/tripdraw/common/swagger/SwaggerConfig.java @@ -1,4 +1,4 @@ -package dev.tripdraw.config.swagger; +package dev.tripdraw.common.swagger; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; diff --git a/backend/src/main/java/dev/tripdraw/dto/validation/NoWhiteSpace.java b/backend/src/main/java/dev/tripdraw/common/validation/NoWhiteSpace.java similarity index 93% rename from backend/src/main/java/dev/tripdraw/dto/validation/NoWhiteSpace.java rename to backend/src/main/java/dev/tripdraw/common/validation/NoWhiteSpace.java index c2a866aed..24d260593 100644 --- a/backend/src/main/java/dev/tripdraw/dto/validation/NoWhiteSpace.java +++ b/backend/src/main/java/dev/tripdraw/common/validation/NoWhiteSpace.java @@ -1,4 +1,4 @@ -package dev.tripdraw.dto.validation; +package dev.tripdraw.common.validation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.RetentionPolicy.RUNTIME; diff --git a/backend/src/main/java/dev/tripdraw/dto/validation/NoWhiteSpaceValidator.java b/backend/src/main/java/dev/tripdraw/common/validation/NoWhiteSpaceValidator.java similarity index 90% rename from backend/src/main/java/dev/tripdraw/dto/validation/NoWhiteSpaceValidator.java rename to backend/src/main/java/dev/tripdraw/common/validation/NoWhiteSpaceValidator.java index f86e4bd9a..1d2a089a9 100644 --- a/backend/src/main/java/dev/tripdraw/dto/validation/NoWhiteSpaceValidator.java +++ b/backend/src/main/java/dev/tripdraw/common/validation/NoWhiteSpaceValidator.java @@ -1,4 +1,4 @@ -package dev.tripdraw.dto.validation; +package dev.tripdraw.common.validation; import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; diff --git a/backend/src/main/java/dev/tripdraw/draw/exception/DrawException.java b/backend/src/main/java/dev/tripdraw/draw/exception/DrawException.java index f295cd472..58230d228 100644 --- a/backend/src/main/java/dev/tripdraw/draw/exception/DrawException.java +++ b/backend/src/main/java/dev/tripdraw/draw/exception/DrawException.java @@ -1,7 +1,7 @@ package dev.tripdraw.draw.exception; -import dev.tripdraw.exception.common.BaseException; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.BaseException; +import dev.tripdraw.common.exception.ExceptionType; public class DrawException extends BaseException { diff --git a/backend/src/main/java/dev/tripdraw/draw/exception/DrawExceptionType.java b/backend/src/main/java/dev/tripdraw/draw/exception/DrawExceptionType.java index 9bda91bf1..d5a176bef 100644 --- a/backend/src/main/java/dev/tripdraw/draw/exception/DrawExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/draw/exception/DrawExceptionType.java @@ -2,7 +2,7 @@ import static org.springframework.http.HttpStatus.BAD_REQUEST; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.ExceptionType; import org.springframework.http.HttpStatus; public enum DrawExceptionType implements ExceptionType { diff --git a/backend/src/main/java/dev/tripdraw/file/application/FilePath.java b/backend/src/main/java/dev/tripdraw/file/application/FilePath.java index 6aeae9f85..7f92c5a82 100644 --- a/backend/src/main/java/dev/tripdraw/file/application/FilePath.java +++ b/backend/src/main/java/dev/tripdraw/file/application/FilePath.java @@ -1,8 +1,8 @@ package dev.tripdraw.file.application; -import static dev.tripdraw.domain.file.FileType.POST_IMAGE; +import static dev.tripdraw.file.domain.FileType.POST_IMAGE; -import dev.tripdraw.domain.file.FileType; +import dev.tripdraw.file.domain.FileType; import java.util.Map; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java b/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java index 042787990..70de7ba22 100644 --- a/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java +++ b/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java @@ -2,7 +2,7 @@ import static dev.tripdraw.file.exception.FileIOExceptionType.FILE_SAVE_FAIL; -import dev.tripdraw.domain.file.FileType; +import dev.tripdraw.file.domain.FileType; import dev.tripdraw.file.exception.FileIOException; import java.io.File; import java.io.IOException; diff --git a/backend/src/main/java/dev/tripdraw/domain/file/FileType.java b/backend/src/main/java/dev/tripdraw/file/domain/FileType.java similarity index 96% rename from backend/src/main/java/dev/tripdraw/domain/file/FileType.java rename to backend/src/main/java/dev/tripdraw/file/domain/FileType.java index 190692eba..42a0efd45 100644 --- a/backend/src/main/java/dev/tripdraw/domain/file/FileType.java +++ b/backend/src/main/java/dev/tripdraw/file/domain/FileType.java @@ -1,4 +1,4 @@ -package dev.tripdraw.domain.file; +package dev.tripdraw.file.domain; import static dev.tripdraw.file.exception.FileIOExceptionType.INVALID_CONTENT_TYPE; import static org.springframework.http.MediaType.IMAGE_JPEG_VALUE; diff --git a/backend/src/main/java/dev/tripdraw/file/exception/FileIOException.java b/backend/src/main/java/dev/tripdraw/file/exception/FileIOException.java index 7461a5580..f86004141 100644 --- a/backend/src/main/java/dev/tripdraw/file/exception/FileIOException.java +++ b/backend/src/main/java/dev/tripdraw/file/exception/FileIOException.java @@ -1,7 +1,7 @@ package dev.tripdraw.file.exception; -import dev.tripdraw.exception.common.BaseException; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.BaseException; +import dev.tripdraw.common.exception.ExceptionType; public class FileIOException extends BaseException { diff --git a/backend/src/main/java/dev/tripdraw/file/exception/FileIOExceptionType.java b/backend/src/main/java/dev/tripdraw/file/exception/FileIOExceptionType.java index c81fc0ead..d54f97fe3 100644 --- a/backend/src/main/java/dev/tripdraw/file/exception/FileIOExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/file/exception/FileIOExceptionType.java @@ -3,7 +3,7 @@ import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.ExceptionType; import org.springframework.http.HttpStatus; public enum FileIOExceptionType implements ExceptionType { diff --git a/backend/src/main/java/dev/tripdraw/member/domain/Member.java b/backend/src/main/java/dev/tripdraw/member/domain/Member.java index e51d7fb8d..871463cea 100644 --- a/backend/src/main/java/dev/tripdraw/member/domain/Member.java +++ b/backend/src/main/java/dev/tripdraw/member/domain/Member.java @@ -3,8 +3,8 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; -import dev.tripdraw.domain.common.BaseEntity; import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.common.entity.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; diff --git a/backend/src/main/java/dev/tripdraw/member/exception/MemberException.java b/backend/src/main/java/dev/tripdraw/member/exception/MemberException.java index 716fb953b..89c47d17e 100644 --- a/backend/src/main/java/dev/tripdraw/member/exception/MemberException.java +++ b/backend/src/main/java/dev/tripdraw/member/exception/MemberException.java @@ -1,7 +1,7 @@ package dev.tripdraw.member.exception; -import dev.tripdraw.exception.common.BaseException; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.BaseException; +import dev.tripdraw.common.exception.ExceptionType; public class MemberException extends BaseException { diff --git a/backend/src/main/java/dev/tripdraw/member/exception/MemberExceptionType.java b/backend/src/main/java/dev/tripdraw/member/exception/MemberExceptionType.java index 48c10159d..e6a7b31f8 100644 --- a/backend/src/main/java/dev/tripdraw/member/exception/MemberExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/member/exception/MemberExceptionType.java @@ -3,7 +3,7 @@ import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.NOT_FOUND; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.ExceptionType; import org.springframework.http.HttpStatus; public enum MemberExceptionType implements ExceptionType { diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index b931af4c0..88301d92b 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -1,10 +1,10 @@ package dev.tripdraw.post.application; -import static dev.tripdraw.domain.file.FileType.POST_IMAGE; +import static dev.tripdraw.file.domain.FileType.POST_IMAGE; import dev.tripdraw.auth.dto.LoginUser; -import dev.tripdraw.domain.file.FileType; import dev.tripdraw.file.application.FileUploader; +import dev.tripdraw.file.domain.FileType; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.domain.Post; diff --git a/backend/src/main/java/dev/tripdraw/post/domain/Post.java b/backend/src/main/java/dev/tripdraw/post/domain/Post.java index 9d715d05f..da6cead66 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/Post.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/Post.java @@ -5,10 +5,10 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; -import dev.tripdraw.domain.common.BaseEntity; +import dev.tripdraw.common.entity.BaseEntity; import dev.tripdraw.member.domain.Member; -import dev.tripdraw.trip.domain.Point; import dev.tripdraw.post.exception.PostException; +import dev.tripdraw.trip.domain.Point; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; diff --git a/backend/src/main/java/dev/tripdraw/post/exception/PostException.java b/backend/src/main/java/dev/tripdraw/post/exception/PostException.java index 8c9511c60..e8a3eceb2 100644 --- a/backend/src/main/java/dev/tripdraw/post/exception/PostException.java +++ b/backend/src/main/java/dev/tripdraw/post/exception/PostException.java @@ -1,7 +1,7 @@ package dev.tripdraw.post.exception; -import dev.tripdraw.exception.common.BaseException; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.BaseException; +import dev.tripdraw.common.exception.ExceptionType; public class PostException extends BaseException { diff --git a/backend/src/main/java/dev/tripdraw/post/exception/PostExceptionType.java b/backend/src/main/java/dev/tripdraw/post/exception/PostExceptionType.java index 6b6974e46..036c00137 100644 --- a/backend/src/main/java/dev/tripdraw/post/exception/PostExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/post/exception/PostExceptionType.java @@ -3,7 +3,7 @@ import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.NOT_FOUND; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.ExceptionType; import org.springframework.http.HttpStatus; public enum PostExceptionType implements ExceptionType { diff --git a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java index ae07c3e37..8128deb44 100644 --- a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java +++ b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java @@ -6,7 +6,7 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; import dev.tripdraw.post.application.PostService; -import dev.tripdraw.config.swagger.SwaggerAuthorizationRequired; +import dev.tripdraw.common.swagger.SwaggerAuthorizationRequired; import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.post.dto.PostCreateResponse; diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/Point.java b/backend/src/main/java/dev/tripdraw/trip/domain/Point.java index ab1eec951..fb2edb96b 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/Point.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Point.java @@ -5,7 +5,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; -import dev.tripdraw.domain.common.BaseEntity; +import dev.tripdraw.common.entity.BaseEntity; import dev.tripdraw.trip.exception.TripException; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java b/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java index 923a28105..1468decbf 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java @@ -7,7 +7,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; -import dev.tripdraw.domain.common.BaseEntity; +import dev.tripdraw.common.entity.BaseEntity; import dev.tripdraw.member.domain.Member; import dev.tripdraw.trip.exception.TripException; import jakarta.persistence.Column; diff --git a/backend/src/main/java/dev/tripdraw/trip/exception/TripException.java b/backend/src/main/java/dev/tripdraw/trip/exception/TripException.java index 592f778d7..fb0c73832 100644 --- a/backend/src/main/java/dev/tripdraw/trip/exception/TripException.java +++ b/backend/src/main/java/dev/tripdraw/trip/exception/TripException.java @@ -1,7 +1,7 @@ package dev.tripdraw.trip.exception; -import dev.tripdraw.exception.common.BaseException; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.BaseException; +import dev.tripdraw.common.exception.ExceptionType; public class TripException extends BaseException { diff --git a/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java b/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java index cc8e93bc2..5d2578e10 100644 --- a/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java @@ -5,7 +5,7 @@ import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.NOT_FOUND; -import dev.tripdraw.exception.common.ExceptionType; +import dev.tripdraw.common.exception.ExceptionType; import org.springframework.http.HttpStatus; public enum TripExceptionType implements ExceptionType { diff --git a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java index 579ec0fe7..6ec5c3f56 100644 --- a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java +++ b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java @@ -4,7 +4,7 @@ import static org.springframework.http.HttpStatus.NO_CONTENT; import dev.tripdraw.trip.application.TripService; -import dev.tripdraw.config.swagger.SwaggerAuthorizationRequired; +import dev.tripdraw.common.swagger.SwaggerAuthorizationRequired; import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.trip.dto.PointCreateRequest; import dev.tripdraw.trip.dto.PointCreateResponse; diff --git a/backend/src/main/resources/application-local.yml b/backend/src/main/resources/application-local.yml index 89403e743..e6eb5a412 100644 --- a/backend/src/main/resources/application-local.yml +++ b/backend/src/main/resources/application-local.yml @@ -54,15 +54,6 @@ jwt: secret-key: ItIsALocalKeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee2222222222222222222222222222222222eeeeeeeeeeyXD expiration-time: 172800000 # 48시간 millisecond -management: - endpoint: - health: - enabled: true - endpoints: - web: - exposure: - include: prometheus - oauth: kakao: info-url: https://kapi.kakao.com/v2/user/me diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index fbcb12c14..781690813 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -11,11 +11,11 @@ import dev.tripdraw.auth.dto.OauthResponse; import dev.tripdraw.auth.dto.RegisterRequest; import dev.tripdraw.auth.oauth.OauthClientProvider; -import dev.tripdraw.common.TestKakaoApiClient; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; import dev.tripdraw.test.ServiceTest; +import dev.tripdraw.test.TestKakaoApiClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java b/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java index a41d7adee..31cf58d41 100644 --- a/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java @@ -13,10 +13,10 @@ import dev.tripdraw.auth.dto.OauthResponse; import dev.tripdraw.auth.dto.RegisterRequest; import dev.tripdraw.auth.oauth.OauthClientProvider; -import dev.tripdraw.common.TestKakaoApiClient; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.test.ControllerTest; +import dev.tripdraw.test.TestKakaoApiClient; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; diff --git a/backend/src/test/java/dev/tripdraw/common/QueryCounterTest.java b/backend/src/test/java/dev/tripdraw/common/log/QueryCounterTest.java similarity index 97% rename from backend/src/test/java/dev/tripdraw/common/QueryCounterTest.java rename to backend/src/test/java/dev/tripdraw/common/log/QueryCounterTest.java index 2d15ea388..f2411eafc 100644 --- a/backend/src/test/java/dev/tripdraw/common/QueryCounterTest.java +++ b/backend/src/test/java/dev/tripdraw/common/log/QueryCounterTest.java @@ -1,4 +1,4 @@ -package dev.tripdraw.common; +package dev.tripdraw.common.log; import static org.assertj.core.api.Assertions.assertThat; @@ -11,7 +11,7 @@ @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class QueryCounterTest { - + @Test void 쿼리_개수를_하나_증가시킨다() { // given diff --git a/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java b/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java index 0708ec03a..2a0b151fb 100644 --- a/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java +++ b/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java @@ -8,7 +8,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import dev.tripdraw.domain.file.FileType; +import dev.tripdraw.file.domain.FileType; import dev.tripdraw.file.exception.FileIOException; import java.io.File; import java.io.IOException; diff --git a/backend/src/test/java/dev/tripdraw/common/TestKakaoApiClient.java b/backend/src/test/java/dev/tripdraw/test/TestKakaoApiClient.java similarity index 93% rename from backend/src/test/java/dev/tripdraw/common/TestKakaoApiClient.java rename to backend/src/test/java/dev/tripdraw/test/TestKakaoApiClient.java index 2796f55bd..003438871 100644 --- a/backend/src/test/java/dev/tripdraw/common/TestKakaoApiClient.java +++ b/backend/src/test/java/dev/tripdraw/test/TestKakaoApiClient.java @@ -1,10 +1,10 @@ -package dev.tripdraw.common; +package dev.tripdraw.test; import static dev.tripdraw.auth.domain.OauthType.KAKAO; -import dev.tripdraw.auth.oauth.OauthClient; import dev.tripdraw.auth.domain.OauthType; import dev.tripdraw.auth.dto.OauthInfo; +import dev.tripdraw.auth.oauth.OauthClient; public class TestKakaoApiClient implements OauthClient { From d0051e66afc9b85d051b5d8ddf150ea5e6a87b34 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Fri, 1 Sep 2023 12:49:45 +0900 Subject: [PATCH 018/119] =?UTF-8?q?[feat]=20PointRepository=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#276)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/trip/domain/PointRepository.java | 14 ++++ .../trip/domain/PointRepositoryTest.java | 67 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 backend/src/main/java/dev/tripdraw/trip/domain/PointRepository.java create mode 100644 backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/PointRepository.java b/backend/src/main/java/dev/tripdraw/trip/domain/PointRepository.java new file mode 100644 index 000000000..a3a94f04c --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/domain/PointRepository.java @@ -0,0 +1,14 @@ +package dev.tripdraw.trip.domain; + +import dev.tripdraw.trip.exception.TripException; +import org.springframework.data.jpa.repository.JpaRepository; + +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; + +public interface PointRepository extends JpaRepository { + + default Point getById(Long id) { + return findById(id) + .orElseThrow(() -> new TripException(POINT_NOT_FOUND)); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java new file mode 100644 index 000000000..ec7000529 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java @@ -0,0 +1,67 @@ +package dev.tripdraw.trip.domain; + +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.trip.exception.TripException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +import java.time.LocalDateTime; + +import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; +import static java.lang.Long.MIN_VALUE; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@DataJpaTest +class PointRepositoryTest { + + @Autowired + private PointRepository pointRepository; + + @Autowired + private TripRepository tripRepository; + + @Autowired + private MemberRepository memberRepository; + + private Trip trip; + + @BeforeEach + void setUp() { + Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + trip = tripRepository.save(Trip.from(member)); + } + + @Test + void 위치정보_ID로_위치정보를_조회한다() { + // given + Point point = new Point(3.14, 5.25, LocalDateTime.now()); + point.setTrip(trip); + pointRepository.save(point); + + // when + Point foundPoint = pointRepository.getById(point.id()); + + // then + assertThat(foundPoint).isEqualTo(point); + } + + @Test + void 위치정보_ID로_위치정보를_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { + // given + Long wrongId = MIN_VALUE; + + // expect + assertThatThrownBy(() -> pointRepository.getById(wrongId)) + .isInstanceOf(TripException.class) + .hasMessage(POINT_NOT_FOUND.message()); + } +} From a058925512dd7117e9c8004f223e051a07c116e2 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Fri, 1 Sep 2023 12:54:22 +0900 Subject: [PATCH 019/119] =?UTF-8?q?[refactor]=20@NonNull=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=82=AD=EC=A0=9C=20(#2?= =?UTF-8?q?76)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/member/domain/MemberRepository.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java b/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java index 7c73673a1..49a35b7b7 100644 --- a/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java +++ b/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java @@ -6,7 +6,6 @@ import dev.tripdraw.member.exception.MemberException; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.lang.NonNull; public interface MemberRepository extends JpaRepository { @@ -14,8 +13,7 @@ public interface MemberRepository extends JpaRepository { boolean existsByNickname(String nickname); - @NonNull - default Member getById(@NonNull Long id) { + default Member getById(Long id) { return findById(id) .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); } From 0733103621c99c8fcd1d9008f2e2f7fff5537a7d Mon Sep 17 00:00:00 2001 From: Combi153 Date: Fri, 1 Sep 2023 13:02:00 +0900 Subject: [PATCH 020/119] =?UTF-8?q?[style]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=8A=A4=ED=83=80=EC=9D=BC=20=EB=B3=80=EA=B2=BD=20(#276)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/member/presentation/MemberControllerTest.java | 2 +- .../java/dev/tripdraw/post/domain/PostRepositoryTest.java | 2 +- backend/src/test/java/dev/tripdraw/post/domain/PostTest.java | 2 +- backend/src/test/java/dev/tripdraw/test/TestFixture.java | 4 ++-- .../java/dev/tripdraw/trip/domain/TripRepositoryTest.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java index c6508bd7e..7b501f97b 100644 --- a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java @@ -11,9 +11,9 @@ import dev.tripdraw.auth.application.AuthTokenManager; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.member.dto.MemberSearchResponse; import dev.tripdraw.post.domain.Post; import dev.tripdraw.post.domain.PostRepository; -import dev.tripdraw.member.dto.MemberSearchResponse; import dev.tripdraw.test.ControllerTest; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java index 7a869f796..1e8ae0ffb 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java @@ -8,11 +8,11 @@ import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.post.exception.PostException; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.post.exception.PostException; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.BeforeEach; diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java index 5ab76bcfe..611dab92d 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java @@ -8,8 +8,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.member.domain.Member; -import dev.tripdraw.trip.domain.Point; import dev.tripdraw.post.exception.PostException; +import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/test/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/TestFixture.java index 519872111..50d0f0b89 100644 --- a/backend/src/test/java/dev/tripdraw/test/TestFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/TestFixture.java @@ -1,7 +1,7 @@ package dev.tripdraw.test; -import dev.tripdraw.member.domain.Member; import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; @@ -17,7 +17,7 @@ public class TestFixture { } public static Point 위치정보() { - return new Point(1L, 1.1, 2.2, false, LocalDateTime.now()); + return new Point(1L, 1.1, 2.2, false, LocalDateTime.now(), 여행()); } public static Trip 여행() { diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index 55aa014a2..71e6b9711 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -59,7 +59,7 @@ void setUp() { List trips = tripRepository.findAllByMemberId(member.id()); // then - assertThat(trips).hasSize(0); + assertThat(trips).isEmpty(); } @Test From 68759a530b61e9413c79e6a47e87e81e7a32ecae Mon Sep 17 00:00:00 2001 From: Combi153 Date: Fri, 1 Sep 2023 13:08:02 +0900 Subject: [PATCH 021/119] =?UTF-8?q?[refactor]=20Point,=20Trip=20=EB=8B=A4?= =?UTF-8?q?=EB=8C=80=EC=9D=BC=20=EC=96=91=EB=B0=A9=ED=96=A5=20=EB=A7=A4?= =?UTF-8?q?=ED=95=91=20(#276)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/application/PostService.java | 15 ++- .../trip/application/TripService.java | 16 +-- .../java/dev/tripdraw/trip/domain/Point.java | 22 +++- .../java/dev/tripdraw/trip/domain/Route.java | 23 +--- .../java/dev/tripdraw/trip/domain/Trip.java | 15 ++- .../trip/exception/TripExceptionType.java | 1 - .../post/application/PostServiceTest.java | 9 +- .../trip/application/TripServiceTest.java | 43 +------- .../dev/tripdraw/trip/domain/PointTest.java | 21 ++++ .../dev/tripdraw/trip/domain/RouteTest.java | 103 +++++------------- .../dev/tripdraw/trip/domain/TripTest.java | 96 +++++++--------- .../trip/presentation/TripControllerTest.java | 76 +------------ 12 files changed, 143 insertions(+), 297 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index 88301d92b..829cc51f1 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -17,10 +17,10 @@ import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.PointRepository; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import java.util.Comparator; -import java.util.List; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; @@ -35,6 +35,7 @@ public class PostService { private final PostRepository postRepository; private final TripRepository tripRepository; + private final PointRepository pointRepository; private final MemberRepository memberRepository; private final FileUploader fileUploader; private final ApplicationEventPublisher applicationEventPublisher; @@ -48,8 +49,8 @@ public PostCreateResponse addAtCurrentPoint( Trip trip = findValidatedTripById(postAndPointCreateRequest.tripId(), member); Point point = postAndPointCreateRequest.toPoint(); - trip.add(point); - tripRepository.flush(); + point.setTrip(trip); + pointRepository.save(point); Post post = postAndPointCreateRequest.toPost(member, point); Post savedPost = postRepository.save(registerFileToPost(file, post)); @@ -66,8 +67,7 @@ public PostCreateResponse addAtExistingLocation( ) { Member member = memberRepository.getById(loginUser.memberId()); Trip trip = findValidatedTripById(postRequest.tripId(), member); - - Point point = trip.findPointById(postRequest.pointId()); + Point point = pointRepository.getById(postRequest.pointId()); Post post = postRequest.toPost(member, point); Post savedPost = postRepository.save(registerFileToPost(file, post)); @@ -88,10 +88,9 @@ public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { Member member = memberRepository.getById(loginUser.memberId()); findValidatedTripById(tripId, member); - List posts = postRepository.findAllByTripId(tripId).stream() + return postRepository.findAllByTripId(tripId).stream() .sorted(Comparator.comparing(Post::pointRecordedAt).reversed()) - .collect(Collectors.toList()); - return PostsResponse.from(posts); + .collect(Collectors.collectingAndThen(Collectors.toList(), PostsResponse::from)); } public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdateRequest, MultipartFile file) { diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index 504c03d0d..5b53091ae 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -1,12 +1,13 @@ package dev.tripdraw.trip.application; +import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.PointRepository; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; -import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.trip.dto.PointCreateRequest; import dev.tripdraw.trip.dto.PointCreateResponse; import dev.tripdraw.trip.dto.PointResponse; @@ -26,6 +27,7 @@ public class TripService { private final TripRepository tripRepository; + private final PointRepository pointRepository; private final MemberRepository memberRepository; private final ApplicationEventPublisher applicationEventPublisher; @@ -39,22 +41,22 @@ public TripCreateResponse create(LoginUser loginUser) { public PointCreateResponse addPoint(LoginUser loginUser, PointCreateRequest pointCreateRequest) { Member member = memberRepository.getById(loginUser.memberId()); Trip trip = tripRepository.getById(pointCreateRequest.tripId()); + trip.validateAuthorization(member); Point point = pointCreateRequest.toPoint(); - trip.validateAuthorization(member); - trip.add(point); + point.setTrip(trip); + pointRepository.save(point); - tripRepository.flush(); return PointCreateResponse.from(point); } public void deletePoint(LoginUser loginUser, Long pointId, Long tripId) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); - trip.deletePointById(pointId); + Point point = pointRepository.getById(pointId); + pointRepository.delete(point); } @Transactional(readOnly = true) @@ -89,7 +91,7 @@ public PointResponse readPointByTripAndPointId(LoginUser loginUser, Long tripId, Trip trip = tripRepository.getById(tripId); trip.validateAuthorization(member); - Point point = trip.findPointById(pointId); + Point point = pointRepository.getById(pointId); return PointResponse.from(point); } diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/Point.java b/backend/src/main/java/dev/tripdraw/trip/domain/Point.java index fb2edb96b..341cd92b8 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/Point.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Point.java @@ -11,6 +11,8 @@ import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import java.time.LocalDateTime; import lombok.Getter; import lombok.NoArgsConstructor; @@ -39,23 +41,35 @@ public class Point extends BaseEntity { @Column(nullable = false) private LocalDateTime recordedAt; + @JoinColumn(name = "trip_id") + @ManyToOne + private Trip trip; + @Column(nullable = false) private Boolean isDeleted = false; public Point(Double latitude, Double longitude, LocalDateTime recordedAt) { - this(null, latitude, longitude, false, recordedAt); + this(null, latitude, longitude, false, recordedAt, null); + } + + public Point(Double latitude, Double longitude, boolean hasPost, LocalDateTime recordedAt) { + this(null, latitude, longitude, hasPost, recordedAt, null); } - public Point(Long id, Double latitude, Double longitude, boolean hasPost, LocalDateTime recordedAt) { + public Point(Long id, Double latitude, Double longitude, boolean hasPost, LocalDateTime recordedAt, Trip trip) { this.id = id; this.latitude = latitude; this.longitude = longitude; this.hasPost = hasPost; this.recordedAt = recordedAt; + this.trip = trip; } - public Long id() { - return id; + public void setTrip(Trip trip) { + this.trip = trip; + if (!trip.contains(this)) { + trip.add(this); + } } public void registerPost() { diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/Route.java b/backend/src/main/java/dev/tripdraw/trip/domain/Route.java index 49428d735..f5be835dd 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/Route.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Route.java @@ -1,19 +1,14 @@ package dev.tripdraw.trip.domain; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_IN_TRIP; import static jakarta.persistence.CascadeType.PERSIST; import static jakarta.persistence.CascadeType.REMOVE; import static jakarta.persistence.FetchType.LAZY; import static lombok.AccessLevel.PROTECTED; -import dev.tripdraw.trip.exception.TripException; import jakarta.persistence.Embeddable; -import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; @@ -24,27 +19,15 @@ @Embeddable public class Route { - @OneToMany(fetch = LAZY, cascade = {PERSIST, REMOVE}) - @JoinColumn(name = "trip_id", updatable = false, nullable = false) + @OneToMany(mappedBy = "trip", fetch = LAZY, cascade = {PERSIST, REMOVE}) private List points = new ArrayList<>(); public void add(Point point) { points.add(point); } - public Point findPointById(Long pointIdToFind) { + public boolean contains(Point point) { return points.stream() - .filter(point -> Objects.equals(point.id(), pointIdToFind)) - .findAny() - .orElseThrow(() -> new TripException(POINT_NOT_FOUND)); - } - - public void deletePointById(Long pointId) { - Point pointToDelete = points.stream() - .filter(point -> Objects.equals(point.id(), pointId)) - .findFirst() - .orElseThrow(() -> new TripException(POINT_NOT_IN_TRIP)); - - pointToDelete.delete(); + .anyMatch(it -> it == point); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java b/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java index 1468decbf..cdcfaf40a 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java @@ -72,6 +72,13 @@ public static Trip from(Member member) { public void add(Point point) { route.add(point); + if (point.trip() != this) { + point.setTrip(this); + } + } + + public boolean contains(Point point) { + return route.contains(point); } public void validateAuthorization(Member member) { @@ -95,10 +102,6 @@ public void changeName(String name) { this.name.change(name); } - public Point findPointById(Long pointId) { - return route.findPointById(pointId); - } - public void changeImageUrl(String imageUrl) { this.imageUrl = imageUrl; } @@ -133,10 +136,6 @@ public List getPointedLongitudes() { .toList(); } - public void deletePointById(Long pointId) { - route.deletePointById(pointId); - } - public List points() { return route.points().stream() .filter(point -> !point.isDeleted()) diff --git a/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java b/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java index 5d2578e10..d4b03778d 100644 --- a/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java @@ -11,7 +11,6 @@ public enum TripExceptionType implements ExceptionType { TRIP_NOT_FOUND(NOT_FOUND, "존재하지 않는 여행입니다."), NOT_AUTHORIZED_TO_TRIP(FORBIDDEN, "해당 여행에 대한 접근 권한이 없습니다."), - POINT_NOT_IN_TRIP(NOT_FOUND, "해당 여행에 존재하지 않는 위치정보입니다."), POINT_ALREADY_DELETED(CONFLICT, "이미 삭제된 위치정보입니다."), POINT_NOT_FOUND(NOT_FOUND, "존재하지 않는 위치입니다."), TRIP_INVALID_STATUS(BAD_REQUEST, "잘못된 여행 상태입니다."), diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index a2a5cc508..2eca06b50 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -28,6 +28,7 @@ import dev.tripdraw.post.exception.PostException; import dev.tripdraw.test.ServiceTest; import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.PointRepository; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.exception.TripException; @@ -48,6 +49,10 @@ class PostServiceTest { @Autowired private TripRepository tripRepository; + @Autowired + private PointRepository pointRepository; + + @Autowired private MemberRepository memberRepository; @@ -65,8 +70,8 @@ void setUp() { Member otherMember = memberRepository.save(new Member("순후추", "kakaoId", KAKAO)); trip = tripRepository.save(Trip.from(member)); point = new Point(1.1, 2.1, LocalDateTime.now()); - trip.add(point); - tripRepository.flush(); + point.setTrip(trip); + pointRepository.save(point); loginUser = new LoginUser(member.id()); otherUser = new LoginUser(otherMember.id()); } diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index 231081447..c6a219723 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -3,9 +3,8 @@ import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_IN_TRIP; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; +import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -16,7 +15,6 @@ import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; import dev.tripdraw.test.ServiceTest; -import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.dto.PointCreateRequest; @@ -85,7 +83,7 @@ void setUp() { @Test void 여행에_위치정보를_추가할_때_해당_여행이_존재하지_않으면_예외를_발생시킨다() { // given - Long nonExistentId = Long.MIN_VALUE; + Long nonExistentId = MIN_VALUE; PointCreateRequest pointCreateRequest = new PointCreateRequest(nonExistentId, 1.1, 2.2, LocalDateTime.now()); // expect @@ -118,13 +116,11 @@ void setUp() { tripService.deletePoint(loginUser, response.pointId(), trip.id()); // then - Point deletedPoint = trip.route().points() + boolean expected = trip.route().points() .stream() - .filter(point -> Objects.equals(point.id(), response.pointId())) - .findFirst() - .get(); + .anyMatch(point -> Objects.equals(point.id(), response.pointId())); - assertThat(deletedPoint.isDeleted()).isTrue(); + assertThat(expected).isTrue(); } @Test @@ -132,7 +128,7 @@ void setUp() { // given PointCreateRequest pointCreateRequest = new PointCreateRequest(trip.id(), 1.1, 2.2, LocalDateTime.now()); PointCreateResponse response = tripService.addPoint(loginUser, pointCreateRequest); - LoginUser otherUser = new LoginUser(Long.MIN_VALUE); + LoginUser otherUser = new LoginUser(MIN_VALUE); // expect assertThatThrownBy(() -> tripService.deletePoint(otherUser, response.pointId(), trip.id())) @@ -140,33 +136,6 @@ void setUp() { .hasMessage(MEMBER_NOT_FOUND.message()); } - @Test - void 여행에서_위치정보를_삭제시_여행에_해당_위치정보가_존재하지_않으면_예외를_발생시킨다() { - // given - PointCreateRequest pointCreateRequest = new PointCreateRequest(trip.id(), 1.1, 2.2, LocalDateTime.now()); - tripService.addPoint(loginUser, pointCreateRequest); - - Point inExistentPoint = new Point(Long.MAX_VALUE, 1.1, 2.2, false, LocalDateTime.now()); - - // expect - assertThatThrownBy(() -> tripService.deletePoint(loginUser, inExistentPoint.id(), trip.id())) - .isInstanceOf(TripException.class) - .hasMessage(POINT_NOT_IN_TRIP.message()); - } - - @Test - void 여행에서_위치정보를_삭제시_이미_삭제된_위치정보면_예외를_발생시킨다() { - // given - PointCreateRequest pointCreateRequest = new PointCreateRequest(trip.id(), 1.1, 2.2, LocalDateTime.now()); - PointCreateResponse response = tripService.addPoint(loginUser, pointCreateRequest); - tripService.deletePoint(loginUser, response.pointId(), trip.id()); - - // expect - assertThatThrownBy(() -> tripService.deletePoint(loginUser, response.pointId(), trip.id())) - .isInstanceOf(TripException.class) - .hasMessage(POINT_ALREADY_DELETED.message()); - } - @Test void 전체_여행을_조회한다() { // given & when diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java index 15dc18035..a087085d8 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java @@ -1,11 +1,15 @@ package dev.tripdraw.trip.domain; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_HAS_POST; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.trip.exception.TripException; +import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -61,4 +65,21 @@ class PointTest { .isInstanceOf(TripException.class) .hasMessage(POINT_ALREADY_HAS_POST.message()); } + + @Test + void 여행을_등록한다() { + // given + Point point = new Point(3.14, 5.25, LocalDateTime.now()); + Member member = new Member("통후추", "kakaoId", KAKAO); + Trip trip = Trip.from(member); + + // when + point.setTrip(trip); + + // then + assertSoftly(softly -> { + softly.assertThat(point.trip()).isEqualTo(trip); + softly.assertThat(trip.route().points()).contains(point); + }); + } } diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/RouteTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/RouteTest.java index ba405c3f9..3504b57de 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/RouteTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/RouteTest.java @@ -1,15 +1,11 @@ package dev.tripdraw.trip.domain; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_IN_TRIP; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @SuppressWarnings("NonAsciiCharacters") @@ -17,7 +13,7 @@ class RouteTest { @Test - void 경로에_좌표를_추가한다() { + void 경로에_위치정보를_추가한다() { // given Route route = new Route(); Point point = new Point(1.1, 2.2, LocalDateTime.now()); @@ -29,78 +25,29 @@ class RouteTest { assertThat(route.points()).hasSize(1); } - @Test - void 경로에서_위치정보를_삭제한다() { - // given - Route route = new Route(); - Point point = new Point(1L, 1.1, 2.2, false, LocalDateTime.now()); - route.add(point); - Long id = point.id(); - - // when - route.deletePointById(id); - - // then - assertThat(point.isDeleted()).isTrue(); - } - - @Test - void 경로에_존재하지_않는_위치정보를_삭제하면_예외를_발생시킨다() { - // given - Route route = new Route(); - Point point = new Point(1L, 1.1, 2.2, false, LocalDateTime.now()); - Point inexistentPoint = new Point(2L, 1.1, 2.2, false, LocalDateTime.now()); - - route.add(point); - - // expect - assertThatThrownBy(() -> route.deletePointById(inexistentPoint.id())) - .isInstanceOf(TripException.class) - .hasMessage(POINT_NOT_IN_TRIP.message()); - } - - @Test - void 이미_삭제된_위치정보를_삭제하면_예외를_발생시킨다() { - // given - Route route = new Route(); - Point point = new Point(1L, 1.1, 2.2, false, LocalDateTime.now()); - - route.add(point); - route.deletePointById(point.id()); - - // expect - assertThatThrownBy(() -> route.deletePointById(point.id())) - .isInstanceOf(TripException.class) - .hasMessage(POINT_ALREADY_DELETED.message()); - } - - @Test - void 위치를_ID로_조회한다() { - // given - Route route = new Route(); - Point point1 = new Point(1L, 1.1, 2.1, false, LocalDateTime.now()); - Point point2 = new Point(2L, 1.2, 2.2, false, LocalDateTime.now()); - route.add(point1); - route.add(point2); - - // when - Point foundPoint = route.findPointById(1L); - - // then - assertThat(foundPoint).isEqualTo(point1); - } - - @Test - void 위치를_존재하지_않는_ID로_조회하면_예외가_발생한다() { - // given - Route route = new Route(); - Point point = new Point(1L, 1.1, 2.1, false, LocalDateTime.now()); - route.add(point); - - // expect - assertThatThrownBy(() -> route.findPointById(2L)) - .isInstanceOf(TripException.class) - .hasMessage(POINT_NOT_FOUND.message()); + @Nested + class 위치정보_포함_여부를_확인할_때 { + + @Test + void 위치정보_포함하면_참값을_반환한다() { + // given + Route route = new Route(); + Point point = new Point(1.1, 2.2, LocalDateTime.now()); + route.add(point); + + // expect + assertThat(route.contains(point)).isTrue(); + } + + @Test + void 위치정보를_포함하지_않으면_참값을_반환하지_않는다() { + // given + Route route = new Route(); + Point point = new Point(1.1, 2.2, LocalDateTime.now()); + + // expect + assertThat(route.contains(point)).isFalse(); + } } } diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java index 908fbd12e..e0b2f681a 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java @@ -2,12 +2,11 @@ import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.trip.exception.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_IN_TRIP; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_INVALID_STATUS; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.SoftAssertions.assertSoftly; import dev.tripdraw.member.domain.Member; import dev.tripdraw.trip.exception.TripException; @@ -15,6 +14,7 @@ import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -35,7 +35,37 @@ class TripTest { // then Route route = trip.route(); - assertThat(route.points()).hasSize(1); + assertSoftly(softly -> { + softly.assertThat(route.points()).hasSize(1); + softly.assertThat(point.trip()).isEqualTo(trip); + }); + } + + @Nested + class 위치정보_포함_여부를_확인할_때 { + + @Test + void 위치정보를_포함하는_여행이면_참값을_반환한다() { + // given + Member member = new Member("통후추", "kakaoId", KAKAO); + Trip trip = Trip.from(member); + Point point = new Point(1.1, 2.2, LocalDateTime.now()); + trip.add(point); + + // expect + assertThat(trip.contains(point)).isTrue(); + } + + @Test + void 위치정보를_포함하지_않는_여행이면_참값을_반환하지_않는다() { + // given + Member member = new Member("통후추", "kakaoId", KAKAO); + Trip trip = Trip.from(member); + Point point = new Point(1.1, 2.2, LocalDateTime.now()); + + // expect + assertThat(trip.contains(point)).isFalse(); + } } @Test @@ -126,54 +156,6 @@ class TripTest { .hasMessage(TRIP_INVALID_STATUS.message()); } - @Test - void 여행에_존재하는_위치정보를_삭제한다() { - // given - Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); - Point point1 = new Point(1.1, 2.2, LocalDateTime.now()); - Point point2 = new Point(3.3, 4.4, LocalDateTime.now()); - trip.add(point1); - trip.add(point2); - Long point1Id = point1.id(); - - // when - trip.deletePointById(point1Id); - - // then - assertThat(point1.isDeleted()).isTrue(); - } - - @Test - void 삭제된_위치정보를_삭제하면_예외를_발생시킨다() { - // given - Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); - Point point1 = new Point(1L, 1.1, 2.2, false, LocalDateTime.now()); - trip.add(point1); - trip.deletePointById(point1.id()); - - // expect - assertThatThrownBy(() -> trip.deletePointById(point1.id())) - .isInstanceOf(TripException.class) - .hasMessage(POINT_ALREADY_DELETED.message()); - } - - @Test - void 여행에_존재하지_않는_위치정보를_삭제하면_예외를_발생시킨다() { - // given - Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); - Point point1 = new Point(1L, 1.1, 2.2, false, LocalDateTime.now()); - Point point2 = new Point(2L, 3.3, 4.4, false, LocalDateTime.now()); - trip.add(point1); - - // expect - assertThatThrownBy(() -> trip.deletePointById(point2.id())) - .isInstanceOf(TripException.class) - .hasMessage(POINT_NOT_IN_TRIP.message()); - } - @Test void 감상_사진_URL을_변경한다() { // given @@ -237,9 +219,9 @@ class TripTest { // given Member member = new Member("통후추", "kakaoId", KAKAO); Trip trip = Trip.from(member); - trip.add(new Point(1L, 1.1, 2.2, true, LocalDateTime.now())); - trip.add(new Point(2L, 3.3, 4.4, false, LocalDateTime.now())); - trip.add(new Point(3L, 5.5, 6.6, true, LocalDateTime.now())); + trip.add(new Point(1.1, 2.2, true, LocalDateTime.now())); + trip.add(new Point(3.3, 4.4, false, LocalDateTime.now())); + trip.add(new Point(5.5, 6.6, true, LocalDateTime.now())); // when List pointedLatitudes = trip.getPointedLatitudes(); @@ -253,9 +235,9 @@ class TripTest { // given Member member = new Member("통후추", "kakaoId", KAKAO); Trip trip = Trip.from(member); - trip.add(new Point(1L, 1.1, 2.2, true, LocalDateTime.now())); - trip.add(new Point(2L, 3.3, 4.4, false, LocalDateTime.now())); - trip.add(new Point(3L, 5.5, 6.6, true, LocalDateTime.now())); + trip.add(new Point(1.1, 2.2, true, LocalDateTime.now())); + trip.add(new Point(3.3, 4.4, false, LocalDateTime.now())); + trip.add(new Point(5.5, 6.6, true, LocalDateTime.now())); // when List pointedLongitudes = trip.getPointedLongitudes(); diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index 4f998d75c..e5344221a 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -3,16 +3,14 @@ import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.UNAUTHORIZED; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.auth.application.AuthTokenManager; +import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.test.ControllerTest; @@ -225,78 +223,6 @@ public void setUp() { .statusCode(UNAUTHORIZED.value()); } - @Test - void 특정_위치정보_삭제시_해당_여행에_존재하는_위치정보가_아니면_예외를_발생시킨다() { - // given - - PointCreateRequest pointCreateRequest = new PointCreateRequest( - trip.id(), - 1.1, - 2.2, - LocalDateTime.of(2023, 7, 18, 20, 24) - ); - - PointResponse pointResponse = RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) - .auth().preemptive().oauth2(huchuToken) - .body(pointCreateRequest) - .when().post("/points") - .then().log().all() - .extract() - .as(PointResponse.class); - - TripResponse tripResponse = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .when().post("/trips") - .then().log().all() - .extract() - .as(TripResponse.class); - - // expect - RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) - .auth().preemptive().oauth2(huchuToken) - .param("tripId", tripResponse.tripId()) - .when().delete("/points/{pointId}", pointResponse.pointId()) - .then().log().all() - .statusCode(NOT_FOUND.value()); - } - - @Test - void 삭제된_위치정보를_삭제시_예외를_발생시킨다() { - // given - PointCreateRequest pointCreateRequest = new PointCreateRequest( - trip.id(), - 1.1, - 2.2, - LocalDateTime.of(2023, 7, 18, 20, 24) - ); - - ExtractableResponse response = RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) - .auth().preemptive().oauth2(huchuToken) - .body(pointCreateRequest) - .when().post("/points") - .then().log().all() - .extract(); - - PointResponse pointResponse = response.as(PointResponse.class); - - RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .param("tripId", trip.id()) - .when().delete("/points/{pointId}", pointResponse.pointId()) - .then().log().all(); - - // expect - RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .param("tripId", trip.id()) - .when().delete("/points/{pointId}", pointResponse.pointId()) - .then().log().all() - .statusCode(CONFLICT.value()); - } - @Test void 전체_여행을_조회한다() { // given From 79bda0698de35b35d25e25dad2d98b31fc5c8292 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Fri, 1 Sep 2023 13:12:29 +0900 Subject: [PATCH 022/119] =?UTF-8?q?[style]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=8A=A4=ED=83=80=EC=9D=BC=20=EB=B3=80=EA=B2=BD=20(#276)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/dev/tripdraw/trip/domain/PointRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/PointRepository.java b/backend/src/main/java/dev/tripdraw/trip/domain/PointRepository.java index a3a94f04c..ac4e94e36 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/PointRepository.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/PointRepository.java @@ -1,10 +1,10 @@ package dev.tripdraw.trip.domain; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; + import dev.tripdraw.trip.exception.TripException; import org.springframework.data.jpa.repository.JpaRepository; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; - public interface PointRepository extends JpaRepository { default Point getById(Long id) { From 49acf107bcceff47e7d9616e93a20b88648ecfa8 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Fri, 1 Sep 2023 13:21:16 +0900 Subject: [PATCH 023/119] =?UTF-8?q?[refactor]=20Point=20hard=20delete?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20(#276)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/trip/domain/Point.java | 16 ----------- .../java/dev/tripdraw/trip/domain/Trip.java | 4 +-- .../db/migration/h2/V7__modifyPoint.sql | 1 + .../db/migration/mysql/V7__modifyPoint.sql | 1 + .../dev/tripdraw/trip/domain/PointTest.java | 27 +------------------ .../dev/tripdraw/trip/domain/TripTest.java | 15 ----------- 6 files changed, 4 insertions(+), 60 deletions(-) create mode 100644 backend/src/main/resources/db/migration/h2/V7__modifyPoint.sql create mode 100644 backend/src/main/resources/db/migration/mysql/V7__modifyPoint.sql diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/Point.java b/backend/src/main/java/dev/tripdraw/trip/domain/Point.java index 341cd92b8..f18491ace 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/Point.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Point.java @@ -1,6 +1,5 @@ package dev.tripdraw.trip.domain; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_HAS_POST; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; @@ -45,9 +44,6 @@ public class Point extends BaseEntity { @ManyToOne private Trip trip; - @Column(nullable = false) - private Boolean isDeleted = false; - public Point(Double latitude, Double longitude, LocalDateTime recordedAt) { this(null, latitude, longitude, false, recordedAt, null); } @@ -82,16 +78,4 @@ private void validateNotPosted() { throw new TripException(POINT_ALREADY_HAS_POST); } } - - public void delete() { - validateNotDeleted(); - - isDeleted = true; - } - - private void validateNotDeleted() { - if (isDeleted) { - throw new TripException(POINT_ALREADY_DELETED); - } - } } diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java b/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java index cdcfaf40a..44b49fd9c 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java @@ -137,9 +137,7 @@ public List getPointedLongitudes() { } public List points() { - return route.points().stream() - .filter(point -> !point.isDeleted()) - .toList(); + return route.points(); } public String nameValue() { diff --git a/backend/src/main/resources/db/migration/h2/V7__modifyPoint.sql b/backend/src/main/resources/db/migration/h2/V7__modifyPoint.sql new file mode 100644 index 000000000..d4d093cde --- /dev/null +++ b/backend/src/main/resources/db/migration/h2/V7__modifyPoint.sql @@ -0,0 +1 @@ +alter table point drop column is_deleted; diff --git a/backend/src/main/resources/db/migration/mysql/V7__modifyPoint.sql b/backend/src/main/resources/db/migration/mysql/V7__modifyPoint.sql new file mode 100644 index 000000000..d4d093cde --- /dev/null +++ b/backend/src/main/resources/db/migration/mysql/V7__modifyPoint.sql @@ -0,0 +1 @@ +alter table point drop column is_deleted; diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java index a087085d8..514bdd12a 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java @@ -1,7 +1,6 @@ package dev.tripdraw.trip.domain; import static dev.tripdraw.auth.domain.OauthType.KAKAO; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_DELETED; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_HAS_POST; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -18,30 +17,6 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class PointTest { - @Test - void 위치정보를_삭제한다() { - // given - Point point = new Point(); - - // when - point.delete(); - - // then - assertThat(point.isDeleted()).isTrue(); - } - - @Test - void 이미_삭제된_위치정보를_삭제하면_예외를_발생시킨다() { - // given - Point point = new Point(); - point.delete(); - - // expect - assertThatThrownBy(point::delete) - .isInstanceOf(TripException.class) - .hasMessage(POINT_ALREADY_DELETED.message()); - } - @Test void 위치에_감상을_등록한다() { // given @@ -65,7 +40,7 @@ class PointTest { .isInstanceOf(TripException.class) .hasMessage(POINT_ALREADY_HAS_POST.message()); } - + @Test void 여행을_등록한다() { // given diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java index e0b2f681a..84abb4b09 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java @@ -245,19 +245,4 @@ class 위치정보_포함_여부를_확인할_때 { // then assertThat(pointedLongitudes).containsExactly(2.2, 6.6); } - - @Test - void 여행의_위치정보_중_삭제되지_않은_위치정보를_반환한다() { - // given - Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); - Point point1 = new Point(1.1, 2.2, LocalDateTime.now()); - Point point2 = new Point(3.3, 4.4, LocalDateTime.now()); - trip.add(point1); - trip.add(point2); - point2.delete(); - - // expect - assertThat(trip.points()).containsExactly(point1); - } } From 54c2c76503eb2b361036a63f5f284fa612ad09dc Mon Sep 17 00:00:00 2001 From: Combi153 Date: Fri, 1 Sep 2023 17:36:08 +0900 Subject: [PATCH 024/119] =?UTF-8?q?[style]=20static=20import=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=20(#276)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/dev/tripdraw/post/application/PostService.java | 5 +++-- .../main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index 829cc51f1..ac07b9993 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -1,6 +1,8 @@ package dev.tripdraw.post.application; import static dev.tripdraw.file.domain.FileType.POST_IMAGE; +import static java.util.stream.Collectors.collectingAndThen; +import static java.util.stream.Collectors.toList; import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.file.application.FileUploader; @@ -21,7 +23,6 @@ import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import java.util.Comparator; -import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; @@ -90,7 +91,7 @@ public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { return postRepository.findAllByTripId(tripId).stream() .sorted(Comparator.comparing(Post::pointRecordedAt).reversed()) - .collect(Collectors.collectingAndThen(Collectors.toList(), PostsResponse::from)); + .collect(collectingAndThen(toList(), PostsResponse::from)); } public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdateRequest, MultipartFile file) { diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java index 31107cac0..5d7e375e0 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java @@ -1,11 +1,11 @@ package dev.tripdraw.trip.dto; import static java.util.stream.Collectors.collectingAndThen; +import static java.util.stream.Collectors.toList; import dev.tripdraw.trip.domain.Trip; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; -import java.util.stream.Collectors; public record TripsSearchResponse( @Schema(description = "여행 목록") @@ -15,6 +15,6 @@ public record TripsSearchResponse( public static TripsSearchResponse from(List trips) { return trips.stream() .map(TripSearchResponse::from) - .collect(collectingAndThen(Collectors.toList(), TripsSearchResponse::new)); + .collect(collectingAndThen(toList(), TripsSearchResponse::new)); } } From 4b5fa6cbfb2e841e8ff3b1aa1be973d8a4ef9dc2 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Fri, 1 Sep 2023 17:38:01 +0900 Subject: [PATCH 025/119] =?UTF-8?q?[refactor]=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=20(#276)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/dev/tripdraw/trip/domain/Route.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/Route.java b/backend/src/main/java/dev/tripdraw/trip/domain/Route.java index f5be835dd..0fa735423 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/Route.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Route.java @@ -27,7 +27,6 @@ public void add(Point point) { } public boolean contains(Point point) { - return points.stream() - .anyMatch(it -> it == point); + return points.contains(point); } } From 996d6438c4777c0081a8843efbe9b2599de03d1a Mon Sep 17 00:00:00 2001 From: Combi153 Date: Fri, 1 Sep 2023 17:44:21 +0900 Subject: [PATCH 026/119] =?UTF-8?q?[style]=20static=20import=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD,=20=EA=B0=9C=ED=96=89=20=EC=82=AD=EC=A0=9C=20(#276)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/application/MemberServiceTest.java | 3 +- .../member/domain/MemberRepositoryTest.java | 3 +- .../presentation/MemberControllerTest.java | 3 +- .../post/application/PostServiceTest.java | 28 +++++++++---------- .../post/domain/PostRepositoryTest.java | 3 +- .../trip/application/TripServiceTest.java | 5 ++-- .../trip/domain/PointRepositoryTest.java | 16 +++++------ .../trip/domain/TripRepositoryTest.java | 3 +- 8 files changed, 27 insertions(+), 37 deletions(-) diff --git a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java index d88aa874f..7aac73271 100644 --- a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java @@ -2,7 +2,6 @@ import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -92,7 +91,7 @@ void setUp() { @Test void code를_입력_받아_사용자를_조회할_때_존재하지_않는_사용자라면_예외를_발생시킨다() { - String nonExistentCode = authTokenManager.generate(MIN_VALUE); + String nonExistentCode = authTokenManager.generate(Long.MIN_VALUE); // expect assertThatThrownBy(() -> memberService.findByCode(nonExistentCode)) diff --git a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java index 123c7335e..0c9f20fab 100644 --- a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java @@ -2,7 +2,6 @@ import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -59,7 +58,7 @@ class MemberRepositoryTest { @Test void 회원_ID로_회원을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { // given - Long wrongId = MIN_VALUE; + Long wrongId = Long.MIN_VALUE; // expect assertThatThrownBy(() -> memberRepository.getById(wrongId)) diff --git a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java index 7b501f97b..62f63cf49 100644 --- a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java @@ -1,7 +1,6 @@ package dev.tripdraw.member.presentation; import static dev.tripdraw.auth.domain.OauthType.KAKAO; -import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.NOT_FOUND; @@ -81,7 +80,7 @@ public void setUp() { @Test void code를_입력_받아_사용자를_조회할_때_존재하지_않는_사용자라면_예외가_발생한다() { // given - String code = authTokenManager.generate(MIN_VALUE); + String code = authTokenManager.generate(Long.MIN_VALUE); // expect RestAssured.given().log().all() diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index 2eca06b50..943021185 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -7,7 +7,6 @@ import static dev.tripdraw.trip.exception.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; -import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -52,7 +51,6 @@ class PostServiceTest { @Autowired private PointRepository pointRepository; - @Autowired private MemberRepository memberRepository; @@ -100,7 +98,7 @@ void setUp() { @Test void 현재_위치에_대한_감상을_생성할_때_존재하지_않는_사용자_닉네임이면_예외를_발생시킨다() { // given - LoginUser wrongUser = new LoginUser(MIN_VALUE); + LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( trip.id(), "우도의 바닷가", @@ -121,7 +119,7 @@ void setUp() { void 현재_위치에_대한_감상을_생성할_때_존재하지_않는_여행의_ID이면_예외를_발생시킨다() { // given PostAndPointCreateRequest requestOfNotExistedTripId = new PostAndPointCreateRequest( - MIN_VALUE, + Long.MIN_VALUE, "우도의 바닷가", "제주특별자치도 제주시 애월읍 소길리", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", @@ -158,7 +156,7 @@ void setUp() { @Test void 사용자가_선택한_위치에_대한_감상을_생성할_때_존재하지_않는_사용자_닉네임이면_예외를_발생시킨다() { // given - LoginUser wrongUser = new LoginUser(MIN_VALUE); + LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); PostRequest postRequest = new PostRequest( trip.id(), point.id(), @@ -177,7 +175,7 @@ void setUp() { void 사용자가_선택한_위치에_대한_감상을_생성할_때_존재하지_않는_여행의_ID이면_예외를_발생시킨다() { // given PostRequest requestOfNotExistedTripId = new PostRequest( - MIN_VALUE, + Long.MIN_VALUE, point.id(), "우도의 바닷가", "제주특별자치도 제주시 애월읍 소길리", @@ -195,7 +193,7 @@ void setUp() { // given PostRequest requestOfNotExistedPointId = new PostRequest( trip.id(), - MIN_VALUE, + Long.MIN_VALUE, "우도의 바닷가", "제주특별자치도 제주시 애월읍 소길리", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다." @@ -226,7 +224,7 @@ void setUp() { @Test void 특정_감상을_조회할_때_존재하지_않는_감상_ID이면_예외를_발생시킨다() { // given & expect - assertThatThrownBy(() -> postService.read(loginUser, MIN_VALUE)) + assertThatThrownBy(() -> postService.read(loginUser, Long.MIN_VALUE)) .isInstanceOf(PostException.class) .hasMessage(POST_NOT_FOUND.message()); } @@ -235,7 +233,7 @@ void setUp() { void 특정_감상을_조회할_때_존재하지_않는_사용자_닉네임이면_예외를_발생시킨다() { // given PostCreateResponse postCreateResponse = createPost(); - LoginUser wrongUser = new LoginUser(MIN_VALUE); + LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); // expect assertThatThrownBy(() -> postService.read(wrongUser, postCreateResponse.postId())) @@ -278,7 +276,7 @@ void setUp() { @Test void 특정_여행의_모든_감상을_조회할_때_존재하지_않는_사용자_닉네임이면_예외를_발생시킨다() { // given - LoginUser wrongUser = new LoginUser(MIN_VALUE); + LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); // expect assertThatThrownBy(() -> postService.readAllByTripId(wrongUser, trip.id())) @@ -289,7 +287,7 @@ void setUp() { @Test void 특정_여행의_모든_감상을_조회할_때_존재하지_않는_여행_ID이면_예외가_발생한다() { // given & expect - assertThatThrownBy(() -> postService.readAllByTripId(loginUser, MIN_VALUE)) + assertThatThrownBy(() -> postService.readAllByTripId(loginUser, Long.MIN_VALUE)) .isInstanceOf(TripException.class) .hasMessage(TRIP_NOT_FOUND.message()); } @@ -334,7 +332,7 @@ void setUp() { ); // expect - assertThatThrownBy(() -> postService.update(loginUser, MIN_VALUE, postUpdateRequest, null)) + assertThatThrownBy(() -> postService.update(loginUser, Long.MIN_VALUE, postUpdateRequest, null)) .isInstanceOf(PostException.class) .hasMessage(POST_NOT_FOUND.message()); } @@ -347,7 +345,7 @@ void setUp() { "우도의 땅콩 아이스크림", "수정한 내용입니다." ); - LoginUser wrongUser = new LoginUser(MIN_VALUE); + LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); // expect assertThatThrownBy(() -> postService.update(wrongUser, postCreateResponse.postId(), postUpdateRequest, null)) @@ -386,7 +384,7 @@ void setUp() { @Test void 감상을_삭제할_때_존재하지_않는_감상_ID이면_예외를_발생시킨다() { // given & expect - assertThatThrownBy(() -> postService.delete(loginUser, MIN_VALUE)) + assertThatThrownBy(() -> postService.delete(loginUser, Long.MIN_VALUE)) .isInstanceOf(PostException.class) .hasMessage(POST_NOT_FOUND.message()); } @@ -395,7 +393,7 @@ void setUp() { void 감상을_삭제할_때_존재하지_않는_사용자_닉네임이면_예외를_발생시킨다() { // given PostCreateResponse postCreateResponse = createPost(); - LoginUser wrongUser = new LoginUser(MIN_VALUE); + LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); // expect assertThatThrownBy(() -> postService.delete(wrongUser, postCreateResponse.postId())) diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java index 1e8ae0ffb..cd94d408a 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java @@ -2,7 +2,6 @@ import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; -import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -89,7 +88,7 @@ void setUp() { @Test void 감상_ID로_감상을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { // given - Long wrongId = MIN_VALUE; + Long wrongId = Long.MIN_VALUE; // expect assertThatThrownBy(() -> postRepository.getById(wrongId)) diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index c6a219723..55fd85393 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -4,7 +4,6 @@ import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; -import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -83,7 +82,7 @@ void setUp() { @Test void 여행에_위치정보를_추가할_때_해당_여행이_존재하지_않으면_예외를_발생시킨다() { // given - Long nonExistentId = MIN_VALUE; + Long nonExistentId = Long.MIN_VALUE; PointCreateRequest pointCreateRequest = new PointCreateRequest(nonExistentId, 1.1, 2.2, LocalDateTime.now()); // expect @@ -128,7 +127,7 @@ void setUp() { // given PointCreateRequest pointCreateRequest = new PointCreateRequest(trip.id(), 1.1, 2.2, LocalDateTime.now()); PointCreateResponse response = tripService.addPoint(loginUser, pointCreateRequest); - LoginUser otherUser = new LoginUser(MIN_VALUE); + LoginUser otherUser = new LoginUser(Long.MIN_VALUE); // expect assertThatThrownBy(() -> tripService.deletePoint(otherUser, response.pointId(), trip.id())) diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java index ec7000529..65bbc43e0 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java @@ -1,8 +1,14 @@ package dev.tripdraw.trip.domain; +import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.exception.TripException; +import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -10,14 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import java.time.LocalDateTime; - -import static dev.tripdraw.auth.domain.OauthType.KAKAO; -import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; -import static java.lang.Long.MIN_VALUE; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @DataJpaTest @@ -57,7 +55,7 @@ void setUp() { @Test void 위치정보_ID로_위치정보를_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { // given - Long wrongId = MIN_VALUE; + Long wrongId = Long.MIN_VALUE; // expect assertThatThrownBy(() -> pointRepository.getById(wrongId)) diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index 71e6b9711..90ba4de79 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -2,7 +2,6 @@ import static dev.tripdraw.auth.domain.OauthType.KAKAO; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; -import static java.lang.Long.MIN_VALUE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -110,7 +109,7 @@ void setUp() { @Test void 여행_ID로_여행을_조회할_때_존재하지_않는_경우_예외를_발생시킨다() { // given - Long wrongId = MIN_VALUE; + Long wrongId = Long.MIN_VALUE; // expect assertThatThrownBy(() -> tripRepository.getById(wrongId)) From 2361b366d69eb507dd9a7d570e739ca9ca857bf8 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 3 Sep 2023 22:43:17 +0900 Subject: [PATCH 027/119] =?UTF-8?q?[refactor]=20JwtTokenProvider=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/auth/application/AuthExtractor.java | 2 +- .../main/java/dev/tripdraw/auth/dto/KakaoInfoResponse.java | 2 +- backend/src/main/java/dev/tripdraw/auth/dto/OauthInfo.java | 2 +- .../src/main/java/dev/tripdraw/auth/dto/OauthRequest.java | 2 +- .../main/java/dev/tripdraw/auth/dto/RegisterRequest.java | 2 +- .../main/java/dev/tripdraw/auth/oauth/KakaoApiClient.java | 2 +- .../src/main/java/dev/tripdraw/auth/oauth/OauthClient.java | 2 +- .../java/dev/tripdraw/auth/oauth/OauthClientProvider.java | 2 +- .../tripdraw/auth/presentation/AuthArgumentResolver.java | 1 + .../dev/tripdraw/auth/presentation/AuthInterceptor.java | 4 ++-- .../tripdraw/{auth/presentation => common/auth}/Auth.java | 2 +- .../dev/tripdraw/{auth/dto => common/auth}/LoginUser.java | 2 +- .../tripdraw/{auth/domain => common/auth}/OauthType.java | 2 +- .../src/main/java/dev/tripdraw/member/domain/Member.java | 2 +- .../java/dev/tripdraw/member/domain/MemberRepository.java | 2 +- .../java/dev/tripdraw/post/application/PostService.java | 2 +- .../java/dev/tripdraw/post/presentation/PostController.java | 6 +++--- .../java/dev/tripdraw/trip/application/TripService.java | 2 +- .../java/dev/tripdraw/trip/presentation/TripController.java | 6 +++--- .../dev/tripdraw/auth/application/AuthExtractorTest.java | 2 +- .../java/dev/tripdraw/auth/application/AuthServiceTest.java | 2 +- .../java/dev/tripdraw/auth/dto/KakaoInfoResponseTest.java | 2 +- .../java/dev/tripdraw/auth/oauth/KakaoApiClientTest.java | 4 ++-- .../dev/tripdraw/auth/oauth/OauthClientProviderTest.java | 2 +- .../dev/tripdraw/auth/presentation/AuthControllerTest.java | 2 +- .../dev/tripdraw/member/application/MemberServiceTest.java | 2 +- .../dev/tripdraw/member/domain/MemberRepositoryTest.java | 2 +- .../test/java/dev/tripdraw/member/domain/MemberTest.java | 2 +- .../tripdraw/member/presentation/MemberControllerTest.java | 2 +- .../java/dev/tripdraw/post/application/PostServiceTest.java | 4 ++-- .../java/dev/tripdraw/post/domain/PostRepositoryTest.java | 2 +- .../src/test/java/dev/tripdraw/post/domain/PostTest.java | 2 +- .../dev/tripdraw/post/presentation/PostControllerTest.java | 4 ++-- backend/src/test/java/dev/tripdraw/test/TestFixture.java | 2 +- .../src/test/java/dev/tripdraw/test/TestKakaoApiClient.java | 4 ++-- .../java/dev/tripdraw/trip/application/TripServiceTest.java | 4 ++-- .../java/dev/tripdraw/trip/domain/TripRepositoryTest.java | 2 +- .../src/test/java/dev/tripdraw/trip/domain/TripTest.java | 2 +- .../java/dev/tripdraw/trip/dto/TripSearchResponseTest.java | 2 +- .../dev/tripdraw/trip/presentation/TripControllerTest.java | 2 +- sub-2023-trip-draw | 2 +- 41 files changed, 51 insertions(+), 50 deletions(-) rename backend/src/main/java/dev/tripdraw/{auth/presentation => common/auth}/Auth.java (86%) rename backend/src/main/java/dev/tripdraw/{auth/dto => common/auth}/LoginUser.java (74%) rename backend/src/main/java/dev/tripdraw/{auth/domain => common/auth}/OauthType.java (56%) diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java index ff29b4bc2..4f5345dc9 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java @@ -4,8 +4,8 @@ import static org.springframework.http.HttpHeaders.AUTHORIZATION; import static org.springframework.util.StringUtils.hasText; -import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.auth.exception.AuthException; +import dev.tripdraw.common.auth.LoginUser; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; diff --git a/backend/src/main/java/dev/tripdraw/auth/dto/KakaoInfoResponse.java b/backend/src/main/java/dev/tripdraw/auth/dto/KakaoInfoResponse.java index ef2b19352..ef99336de 100644 --- a/backend/src/main/java/dev/tripdraw/auth/dto/KakaoInfoResponse.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/KakaoInfoResponse.java @@ -1,6 +1,6 @@ package dev.tripdraw.auth.dto; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/backend/src/main/java/dev/tripdraw/auth/dto/OauthInfo.java b/backend/src/main/java/dev/tripdraw/auth/dto/OauthInfo.java index d99689448..78135316c 100644 --- a/backend/src/main/java/dev/tripdraw/auth/dto/OauthInfo.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/OauthInfo.java @@ -1,6 +1,6 @@ package dev.tripdraw.auth.dto; -import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.common.auth.OauthType; public record OauthInfo(String oauthId, OauthType oauthType) { } diff --git a/backend/src/main/java/dev/tripdraw/auth/dto/OauthRequest.java b/backend/src/main/java/dev/tripdraw/auth/dto/OauthRequest.java index 8f0fb7ad5..c11eb0151 100644 --- a/backend/src/main/java/dev/tripdraw/auth/dto/OauthRequest.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/OauthRequest.java @@ -1,6 +1,6 @@ package dev.tripdraw.auth.dto; -import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.common.auth.OauthType; import io.swagger.v3.oas.annotations.media.Schema; public record OauthRequest( diff --git a/backend/src/main/java/dev/tripdraw/auth/dto/RegisterRequest.java b/backend/src/main/java/dev/tripdraw/auth/dto/RegisterRequest.java index daad6cfa0..4d94c2330 100644 --- a/backend/src/main/java/dev/tripdraw/auth/dto/RegisterRequest.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/RegisterRequest.java @@ -1,6 +1,6 @@ package dev.tripdraw.auth.dto; -import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.common.auth.OauthType; import dev.tripdraw.common.validation.NoWhiteSpace; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/backend/src/main/java/dev/tripdraw/auth/oauth/KakaoApiClient.java b/backend/src/main/java/dev/tripdraw/auth/oauth/KakaoApiClient.java index 865a6b071..88e4358b5 100644 --- a/backend/src/main/java/dev/tripdraw/auth/oauth/KakaoApiClient.java +++ b/backend/src/main/java/dev/tripdraw/auth/oauth/KakaoApiClient.java @@ -3,9 +3,9 @@ import static org.springframework.http.HttpHeaders.AUTHORIZATION; import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED; -import dev.tripdraw.auth.domain.OauthType; import dev.tripdraw.auth.dto.KakaoInfoResponse; import dev.tripdraw.auth.dto.OauthInfo; +import dev.tripdraw.common.auth.OauthType; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; diff --git a/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClient.java b/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClient.java index 879a341df..0792963cf 100644 --- a/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClient.java +++ b/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClient.java @@ -1,7 +1,7 @@ package dev.tripdraw.auth.oauth; -import dev.tripdraw.auth.domain.OauthType; import dev.tripdraw.auth.dto.OauthInfo; +import dev.tripdraw.common.auth.OauthType; public interface OauthClient { diff --git a/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClientProvider.java b/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClientProvider.java index 0e9d60709..877d52df1 100644 --- a/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClientProvider.java +++ b/backend/src/main/java/dev/tripdraw/auth/oauth/OauthClientProvider.java @@ -3,7 +3,7 @@ import static java.util.function.Function.identity; import static java.util.stream.Collectors.toMap; -import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.common.auth.OauthType; import java.util.Map; import java.util.Set; import org.springframework.stereotype.Component; diff --git a/backend/src/main/java/dev/tripdraw/auth/presentation/AuthArgumentResolver.java b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthArgumentResolver.java index 712f6ff16..03e48e7e7 100644 --- a/backend/src/main/java/dev/tripdraw/auth/presentation/AuthArgumentResolver.java +++ b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthArgumentResolver.java @@ -1,6 +1,7 @@ package dev.tripdraw.auth.presentation; import dev.tripdraw.auth.application.AuthExtractor; +import dev.tripdraw.common.auth.Auth; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.core.MethodParameter; diff --git a/backend/src/main/java/dev/tripdraw/auth/presentation/AuthInterceptor.java b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthInterceptor.java index de9834f30..dded01696 100644 --- a/backend/src/main/java/dev/tripdraw/auth/presentation/AuthInterceptor.java +++ b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthInterceptor.java @@ -3,9 +3,9 @@ import static dev.tripdraw.auth.exception.AuthExceptionType.AUTH_FAIL; import dev.tripdraw.auth.application.AuthExtractor; -import dev.tripdraw.member.application.MemberService; -import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.auth.exception.AuthException; +import dev.tripdraw.common.auth.LoginUser; +import dev.tripdraw.member.application.MemberService; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; diff --git a/backend/src/main/java/dev/tripdraw/auth/presentation/Auth.java b/backend/src/main/java/dev/tripdraw/common/auth/Auth.java similarity index 86% rename from backend/src/main/java/dev/tripdraw/auth/presentation/Auth.java rename to backend/src/main/java/dev/tripdraw/common/auth/Auth.java index 827e6215e..89a02d0ee 100644 --- a/backend/src/main/java/dev/tripdraw/auth/presentation/Auth.java +++ b/backend/src/main/java/dev/tripdraw/common/auth/Auth.java @@ -1,4 +1,4 @@ -package dev.tripdraw.auth.presentation; +package dev.tripdraw.common.auth; import static java.lang.annotation.ElementType.PARAMETER; import static java.lang.annotation.RetentionPolicy.RUNTIME; diff --git a/backend/src/main/java/dev/tripdraw/auth/dto/LoginUser.java b/backend/src/main/java/dev/tripdraw/common/auth/LoginUser.java similarity index 74% rename from backend/src/main/java/dev/tripdraw/auth/dto/LoginUser.java rename to backend/src/main/java/dev/tripdraw/common/auth/LoginUser.java index e9669fcb0..442e7cc3c 100644 --- a/backend/src/main/java/dev/tripdraw/auth/dto/LoginUser.java +++ b/backend/src/main/java/dev/tripdraw/common/auth/LoginUser.java @@ -1,4 +1,4 @@ -package dev.tripdraw.auth.dto; +package dev.tripdraw.common.auth; import io.swagger.v3.oas.annotations.Hidden; diff --git a/backend/src/main/java/dev/tripdraw/auth/domain/OauthType.java b/backend/src/main/java/dev/tripdraw/common/auth/OauthType.java similarity index 56% rename from backend/src/main/java/dev/tripdraw/auth/domain/OauthType.java rename to backend/src/main/java/dev/tripdraw/common/auth/OauthType.java index 32afd531a..5def98842 100644 --- a/backend/src/main/java/dev/tripdraw/auth/domain/OauthType.java +++ b/backend/src/main/java/dev/tripdraw/common/auth/OauthType.java @@ -1,4 +1,4 @@ -package dev.tripdraw.auth.domain; +package dev.tripdraw.common.auth; public enum OauthType { KAKAO, diff --git a/backend/src/main/java/dev/tripdraw/member/domain/Member.java b/backend/src/main/java/dev/tripdraw/member/domain/Member.java index 871463cea..bdfb4251e 100644 --- a/backend/src/main/java/dev/tripdraw/member/domain/Member.java +++ b/backend/src/main/java/dev/tripdraw/member/domain/Member.java @@ -3,7 +3,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; -import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.common.auth.OauthType; import dev.tripdraw.common.entity.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java b/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java index 49a35b7b7..7828bd7c1 100644 --- a/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java +++ b/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java @@ -2,7 +2,7 @@ import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.common.auth.OauthType; import dev.tripdraw.member.exception.MemberException; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index ac07b9993..ba6f96a96 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -4,7 +4,7 @@ import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; -import dev.tripdraw.auth.dto.LoginUser; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.file.application.FileUploader; import dev.tripdraw.file.domain.FileType; import dev.tripdraw.member.domain.Member; diff --git a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java index 8128deb44..fe0cffd08 100644 --- a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java +++ b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java @@ -5,16 +5,16 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; -import dev.tripdraw.post.application.PostService; +import dev.tripdraw.common.auth.Auth; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.common.swagger.SwaggerAuthorizationRequired; -import dev.tripdraw.auth.dto.LoginUser; +import dev.tripdraw.post.application.PostService; import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; -import dev.tripdraw.auth.presentation.Auth; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index 5b53091ae..284fef946 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.application; -import dev.tripdraw.auth.dto.LoginUser; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.domain.Point; diff --git a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java index 6ec5c3f56..66fe49b84 100644 --- a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java +++ b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java @@ -3,9 +3,10 @@ import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; -import dev.tripdraw.trip.application.TripService; +import dev.tripdraw.common.auth.Auth; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.common.swagger.SwaggerAuthorizationRequired; -import dev.tripdraw.auth.dto.LoginUser; +import dev.tripdraw.trip.application.TripService; import dev.tripdraw.trip.dto.PointCreateRequest; import dev.tripdraw.trip.dto.PointCreateResponse; import dev.tripdraw.trip.dto.PointResponse; @@ -13,7 +14,6 @@ import dev.tripdraw.trip.dto.TripResponse; import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; -import dev.tripdraw.auth.presentation.Auth; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java index d8a61e2f0..6633edd7c 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java @@ -8,8 +8,8 @@ import static org.mockito.Mockito.when; import static org.springframework.http.HttpHeaders.AUTHORIZATION; -import dev.tripdraw.auth.dto.LoginUser; import dev.tripdraw.auth.exception.AuthException; +import dev.tripdraw.common.auth.LoginUser; import jakarta.servlet.http.HttpServletRequest; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index 781690813..e11340ef7 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.auth.application; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; diff --git a/backend/src/test/java/dev/tripdraw/auth/dto/KakaoInfoResponseTest.java b/backend/src/test/java/dev/tripdraw/auth/dto/KakaoInfoResponseTest.java index e009b55eb..75900eec8 100644 --- a/backend/src/test/java/dev/tripdraw/auth/dto/KakaoInfoResponseTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/dto/KakaoInfoResponseTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.auth.dto; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; import java.time.LocalDateTime; diff --git a/backend/src/test/java/dev/tripdraw/auth/oauth/KakaoApiClientTest.java b/backend/src/test/java/dev/tripdraw/auth/oauth/KakaoApiClientTest.java index e7ed83b1f..b33dd79bf 100644 --- a/backend/src/test/java/dev/tripdraw/auth/oauth/KakaoApiClientTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/oauth/KakaoApiClientTest.java @@ -1,14 +1,14 @@ package dev.tripdraw.auth.oauth; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import dev.tripdraw.auth.domain.OauthType; import dev.tripdraw.auth.dto.KakaoInfoResponse; import dev.tripdraw.auth.dto.OauthInfo; +import dev.tripdraw.common.auth.OauthType; import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/auth/oauth/OauthClientProviderTest.java b/backend/src/test/java/dev/tripdraw/auth/oauth/OauthClientProviderTest.java index 411479c54..3f325536b 100644 --- a/backend/src/test/java/dev/tripdraw/auth/oauth/OauthClientProviderTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/oauth/OauthClientProviderTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.auth.oauth; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static org.assertj.core.api.Assertions.assertThat; import java.util.Set; diff --git a/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java b/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java index 31cf58d41..1ffa77988 100644 --- a/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.auth.presentation; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.Mockito.when; import static org.springframework.http.HttpStatus.BAD_REQUEST; diff --git a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java index 7aac73271..3e7669d02 100644 --- a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.member.application; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java index 0c9f20fab..2a96e2981 100644 --- a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.member.domain; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/backend/src/test/java/dev/tripdraw/member/domain/MemberTest.java b/backend/src/test/java/dev/tripdraw/member/domain/MemberTest.java index 4b988b0bb..083c3f6c2 100644 --- a/backend/src/test/java/dev/tripdraw/member/domain/MemberTest.java +++ b/backend/src/test/java/dev/tripdraw/member/domain/MemberTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.member.domain; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java index 62f63cf49..e458ffa10 100644 --- a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.member.presentation; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.NOT_FOUND; diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index 943021185..0f0d28c50 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.post.application; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.post.exception.PostExceptionType.NOT_AUTHORIZED_TO_POST; import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; @@ -13,7 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; -import dev.tripdraw.auth.dto.LoginUser; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java index cd94d408a..2029a0f18 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.post.domain; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java index 611dab92d..5e8f673a0 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.post.domain; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.post.exception.PostExceptionType.NOT_AUTHORIZED_TO_POST; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_HAS_POST; import static org.assertj.core.api.Assertions.assertThat; diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index be4dd6a39..f2b1909f2 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.post.presentation; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CREATED; @@ -11,8 +11,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; -import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.auth.application.AuthTokenManager; +import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.dto.PostAndPointCreateRequest; diff --git a/backend/src/test/java/dev/tripdraw/test/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/TestFixture.java index 50d0f0b89..924049ed2 100644 --- a/backend/src/test/java/dev/tripdraw/test/TestFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/TestFixture.java @@ -1,6 +1,6 @@ package dev.tripdraw.test; -import dev.tripdraw.auth.domain.OauthType; +import dev.tripdraw.common.auth.OauthType; import dev.tripdraw.member.domain.Member; import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.domain.Point; diff --git a/backend/src/test/java/dev/tripdraw/test/TestKakaoApiClient.java b/backend/src/test/java/dev/tripdraw/test/TestKakaoApiClient.java index 003438871..e83a45038 100644 --- a/backend/src/test/java/dev/tripdraw/test/TestKakaoApiClient.java +++ b/backend/src/test/java/dev/tripdraw/test/TestKakaoApiClient.java @@ -1,10 +1,10 @@ package dev.tripdraw.test; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; -import dev.tripdraw.auth.domain.OauthType; import dev.tripdraw.auth.dto.OauthInfo; import dev.tripdraw.auth.oauth.OauthClient; +import dev.tripdraw.common.auth.OauthType; public class TestKakaoApiClient implements OauthClient { diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index 55fd85393..2fa177ebd 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.application; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; @@ -8,7 +8,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import dev.tripdraw.auth.dto.LoginUser; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index 90ba4de79..b448e684e 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.domain; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java index 84abb4b09..5bfa29998 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.domain; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.trip.exception.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_INVALID_STATUS; import static org.assertj.core.api.Assertions.assertThat; diff --git a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java index 46cd6186b..0009c1499 100644 --- a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.dto; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.trip.domain.TripStatus.ONGOING; import static org.assertj.core.api.Assertions.assertThat; diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index e5344221a..7890e5aa9 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.presentation; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.springframework.http.HttpStatus.CREATED; diff --git a/sub-2023-trip-draw b/sub-2023-trip-draw index 792706acf..c98599a51 160000 --- a/sub-2023-trip-draw +++ b/sub-2023-trip-draw @@ -1 +1 @@ -Subproject commit 792706acf760803367ee7dc21d1f2b4b5bfd4c2e +Subproject commit c98599a5179689f84b5b494365ff464ddacc0069 From 757335e242248268ec337af4abe817583847904e Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 3 Sep 2023 16:49:37 +0900 Subject: [PATCH 028/119] =?UTF-8?q?[feat]=20configuration=20processor=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 8 ++++++++ .../src/main/java/dev/tripdraw/BackendApplication.java | 2 ++ 2 files changed, 10 insertions(+) diff --git a/backend/build.gradle b/backend/build.gradle index 8c08b0114..cb1b4be1c 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -26,6 +26,9 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' + // configuration processor + annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" + // jwt implementation 'io.jsonwebtoken:jjwt-api:0.11.5' implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' @@ -63,3 +66,8 @@ tasks.register('copySecret', Copy) { tasks.named('test') { useJUnitPlatform() } + +// configuration processor +tasks.named('compileJava') { + inputs.files(tasks.named('processResources')) +} diff --git a/backend/src/main/java/dev/tripdraw/BackendApplication.java b/backend/src/main/java/dev/tripdraw/BackendApplication.java index 6be14c569..85f79ef5e 100644 --- a/backend/src/main/java/dev/tripdraw/BackendApplication.java +++ b/backend/src/main/java/dev/tripdraw/BackendApplication.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; +@ConfigurationPropertiesScan @SpringBootApplication public class BackendApplication { From aa5674d9269fe2bfb304ee7b1318a0a01bb6bb24 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 3 Sep 2023 16:53:56 +0900 Subject: [PATCH 029/119] =?UTF-8?q?[feat]=20refresh=20=ED=86=A0=ED=81=B0?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthTokenManager.java | 3 +- .../auth/application/JwtTokenProvider.java | 2 +- .../auth/config/AccessTokenConfig.java | 10 +++++++ .../auth/config/RefreshTokenConfig.java | 10 +++++++ .../tripdraw/auth/domain/RefreshToken.java | 29 +++++++++++++++++++ .../src/main/resources/application-local.yml | 8 +++-- .../migration/h2/V7__addRefreshTokenTable.sql | 11 +++++++ .../mysql/V7__addRefreshTokenTable.sql | 11 +++++++ 8 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/auth/config/AccessTokenConfig.java create mode 100644 backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java create mode 100644 backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java create mode 100644 backend/src/main/resources/db/migration/h2/V7__addRefreshTokenTable.sql create mode 100644 backend/src/main/resources/db/migration/mysql/V7__addRefreshTokenTable.sql diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java index 42ca1ad1c..4edea872d 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java @@ -10,7 +10,8 @@ public class AuthTokenManager { private final JwtTokenProvider jwtTokenProvider; private final Long expirationTime; - public AuthTokenManager(JwtTokenProvider jwtTokenProvider, @Value("${jwt.expiration-time}") Long expirationTime) { + public AuthTokenManager(JwtTokenProvider jwtTokenProvider, + @Value("${jwt.access.expiration-time}") Long expirationTime) { this.jwtTokenProvider = jwtTokenProvider; this.expirationTime = expirationTime; } diff --git a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java index d5c3238aa..729b00257 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java @@ -21,7 +21,7 @@ public class JwtTokenProvider { private final Key key; - public JwtTokenProvider(@Value("${jwt.secret-key}") String secretKey) { + public JwtTokenProvider(@Value("${jwt.access.secret-key}") String secretKey) { byte[] keyBytes = Decoders.BASE64.decode(secretKey); this.key = Keys.hmacShaKeyFor(keyBytes); } diff --git a/backend/src/main/java/dev/tripdraw/auth/config/AccessTokenConfig.java b/backend/src/main/java/dev/tripdraw/auth/config/AccessTokenConfig.java new file mode 100644 index 000000000..fe4dc8d1c --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/config/AccessTokenConfig.java @@ -0,0 +1,10 @@ +package dev.tripdraw.auth.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "jwt.access") +public record AccessTokenConfig( + String secretKey, + Long expirationTime +) { +} diff --git a/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java new file mode 100644 index 000000000..98dc19286 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java @@ -0,0 +1,10 @@ +package dev.tripdraw.auth.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "jwt.access") +public record RefreshTokenConfig( + String secretKey, + Long expirationTime +) { +} diff --git a/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java new file mode 100644 index 000000000..f7e3fe9f0 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java @@ -0,0 +1,29 @@ +package dev.tripdraw.auth.domain; + +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import dev.tripdraw.common.entity.BaseEntity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Accessors(fluent = true) +@Getter +@NoArgsConstructor(access = PROTECTED) +@Entity +public class RefreshToken extends BaseEntity { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "refresh_token_id") + private Long id; + + private Long memberId; + + private String token; +} diff --git a/backend/src/main/resources/application-local.yml b/backend/src/main/resources/application-local.yml index e6eb5a412..6d470d991 100644 --- a/backend/src/main/resources/application-local.yml +++ b/backend/src/main/resources/application-local.yml @@ -51,8 +51,12 @@ trip: route: jwt: - secret-key: ItIsALocalKeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee2222222222222222222222222222222222eeeeeeeeeeyXD - expiration-time: 172800000 # 48시간 millisecond + access: + secret-key: ACCESSTOKENACCESSTOKENACCESSTOKENACCESSTOKENACCESSTOKENACCESSTOKENACCESSTOKENACCESSTOKEN + expiration-time: 1800000 # 30 minutes + refresh: + secret-key: REFRESHTOKENREFRESHTOKENREFRESHTOKENREFRESHTOKENREFRESHTOKENREFRESHTOKENREFRESHTOKENREFR + expiration-time: 1209600000 # 14 days oauth: kakao: diff --git a/backend/src/main/resources/db/migration/h2/V7__addRefreshTokenTable.sql b/backend/src/main/resources/db/migration/h2/V7__addRefreshTokenTable.sql new file mode 100644 index 000000000..a33f20f7a --- /dev/null +++ b/backend/src/main/resources/db/migration/h2/V7__addRefreshTokenTable.sql @@ -0,0 +1,11 @@ +CREATE TABLE `refresh_token` +( + `refresh_token_id` BIGINT, + `member_id` BIGINT, + `token` TEXT, + `created_at` TIMESTAMP, + `updated_at` TIMESTAMP +); + +ALTER TABLE `refresh_token` + ADD FOREIGN KEY (`member_id`) REFERENCES `member` (`member_id`); diff --git a/backend/src/main/resources/db/migration/mysql/V7__addRefreshTokenTable.sql b/backend/src/main/resources/db/migration/mysql/V7__addRefreshTokenTable.sql new file mode 100644 index 000000000..a33f20f7a --- /dev/null +++ b/backend/src/main/resources/db/migration/mysql/V7__addRefreshTokenTable.sql @@ -0,0 +1,11 @@ +CREATE TABLE `refresh_token` +( + `refresh_token_id` BIGINT, + `member_id` BIGINT, + `token` TEXT, + `created_at` TIMESTAMP, + `updated_at` TIMESTAMP +); + +ALTER TABLE `refresh_token` + ADD FOREIGN KEY (`member_id`) REFERENCES `member` (`member_id`); From 63d180a8a937e026f162bccf46c62da66d8164fd Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 3 Sep 2023 22:44:23 +0900 Subject: [PATCH 030/119] =?UTF-8?q?[refactor]=20JwtTokenProvider=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthTokenManager.java | 9 ++---- .../auth/application/JwtTokenProvider.java | 28 +++++++++-------- .../auth/application/AuthExtractorTest.java | 9 ++++-- .../application/AuthTokenManagerTest.java | 4 ++- .../application/JwtTokenProviderTest.java | 30 +++++++------------ .../tripdraw/test/fixture/AuthFixture.java | 30 +++++++++++++++++++ 6 files changed, 67 insertions(+), 43 deletions(-) create mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/AuthFixture.java diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java index 4edea872d..31d08c0ff 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java @@ -1,6 +1,5 @@ package dev.tripdraw.auth.application; -import java.util.Date; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -17,15 +16,11 @@ public AuthTokenManager(JwtTokenProvider jwtTokenProvider, } public String generate(Long memberId) { - long now = (new Date()).getTime(); - Date accessTokenExpiredAt = new Date(now + expirationTime); - String subject = memberId.toString(); - - return jwtTokenProvider.generate(subject, accessTokenExpiredAt); + return jwtTokenProvider.generateAccessToken(subject); } public Long extractMemberId(String accessToken) { - return Long.valueOf(jwtTokenProvider.extractSubject(accessToken)); + return Long.valueOf(jwtTokenProvider.extractAccessToken(accessToken)); } } diff --git a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java index 729b00257..ff46694f5 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java @@ -3,6 +3,7 @@ import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_TOKEN; import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; +import dev.tripdraw.auth.config.AccessTokenConfig; import dev.tripdraw.auth.exception.AuthException; import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; @@ -13,38 +14,41 @@ import io.jsonwebtoken.security.Keys; import java.security.Key; import java.util.Date; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class JwtTokenProvider { - private final Key key; + private final Key accessKey; + private final Long accessTokenExpirationTime; - public JwtTokenProvider(@Value("${jwt.access.secret-key}") String secretKey) { - byte[] keyBytes = Decoders.BASE64.decode(secretKey); - this.key = Keys.hmacShaKeyFor(keyBytes); + public JwtTokenProvider(AccessTokenConfig accessTokenConfig) { + byte[] keyBytes = Decoders.BASE64.decode(accessTokenConfig.secretKey()); + this.accessKey = Keys.hmacShaKeyFor(keyBytes); + this.accessTokenExpirationTime = accessTokenConfig.expirationTime(); } - public String generate(String subject, Date expiredAt) { + public String generateAccessToken(String subject) { + final Date now = new Date(); return Jwts.builder() .setSubject(subject) - .setExpiration(expiredAt) - .signWith(key, SignatureAlgorithm.HS512) + .setIssuedAt(now) + .setExpiration(new Date(now.getTime() + accessTokenExpirationTime)) + .signWith(accessKey, SignatureAlgorithm.HS512) .compact(); } - public String extractSubject(String accessToken) { - Claims claims = parseClaims(accessToken); + public String extractAccessToken(String accessToken) { + Claims claims = parseClaims(accessToken, accessKey); return claims.getSubject(); } - private Claims parseClaims(String accessToken) { + private Claims parseClaims(String token, Key key) { try { return Jwts.parserBuilder() .setSigningKey(key) .build() - .parseClaimsJws(accessToken) + .parseClaimsJws(token) .getBody(); } catch (ExpiredJwtException e) { throw new AuthException(EXPIRED_TOKEN); diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java index 6633edd7c..1eef50ede 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java @@ -8,6 +8,7 @@ import static org.mockito.Mockito.when; import static org.springframework.http.HttpHeaders.AUTHORIZATION; +import dev.tripdraw.auth.config.AccessTokenConfig; import dev.tripdraw.auth.exception.AuthException; import dev.tripdraw.common.auth.LoginUser; import jakarta.servlet.http.HttpServletRequest; @@ -25,10 +26,12 @@ class AuthExtractorTest { private static final long ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 30; private AuthTokenManager authTokenManager; + private AccessTokenConfig accessTokenConfig; @BeforeEach void setUp() { - authTokenManager = new AuthTokenManager(new JwtTokenProvider(TEST_SECRET_KEY), ACCESS_TOKEN_EXPIRE_TIME); + accessTokenConfig = new AccessTokenConfig(TEST_SECRET_KEY, ACCESS_TOKEN_EXPIRE_TIME); + authTokenManager = new AuthTokenManager(new JwtTokenProvider(accessTokenConfig), ACCESS_TOKEN_EXPIRE_TIME); } @Test @@ -51,7 +54,7 @@ void setUp() { void 요청_헤더에_Bearer_형식이_아닌_다른_인증정보를_사용하는_경우_예외가_발생한다() { // given AuthExtractor authExtractor = new AuthExtractor( - new AuthTokenManager(new JwtTokenProvider(TEST_SECRET_KEY), ACCESS_TOKEN_EXPIRE_TIME) + new AuthTokenManager(new JwtTokenProvider(accessTokenConfig), ACCESS_TOKEN_EXPIRE_TIME) ); HttpServletRequest request = mock(HttpServletRequest.class); String encoded = "Basic eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiZXhwIjoxNjkxNTE1Mzk2fQ.WEDBjEXfIAd4MaUTK29ElnnGYmYNCKSHLGVPJHlyf2DNECDX8QDqvigUCBzO4ULmpnxr4GiZZqdQyeH1BgU0Ag"; @@ -67,7 +70,7 @@ void setUp() { void 요청_헤더에_인증_정보가_없을_경우_예외를_발생시킨다() { // given AuthExtractor authExtractor = new AuthExtractor( - new AuthTokenManager(new JwtTokenProvider(TEST_SECRET_KEY), ACCESS_TOKEN_EXPIRE_TIME) + new AuthTokenManager(new JwtTokenProvider(accessTokenConfig), ACCESS_TOKEN_EXPIRE_TIME) ); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getHeader(AUTHORIZATION)).thenReturn(null); diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthTokenManagerTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthTokenManagerTest.java index 66ad3a8f8..7c8485852 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthTokenManagerTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthTokenManagerTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import dev.tripdraw.auth.config.AccessTokenConfig; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -16,8 +17,9 @@ class AuthTokenManagerTest { @BeforeEach void setUp() { + String key = "test2222222222eeeeeeeeeeee222222222asdfasdfasdfasdfasdssssssssssaaaaaaaaaavvvvvvvfsdfsf2eeeeeeeeeeeee"; jwtTokenProvider = new JwtTokenProvider( - "test2222222222eeeeeeeeeeee222222222asdfasdfasdfasdfasdssssssssssaaaaaaaaaavvvvvvvfsdfsf2eeeeeeeeeeeee" + new AccessTokenConfig(key, ACCESS_TOKEN_EXPIRE_TIME) ); } diff --git a/backend/src/test/java/dev/tripdraw/auth/application/JwtTokenProviderTest.java b/backend/src/test/java/dev/tripdraw/auth/application/JwtTokenProviderTest.java index b4bca1396..02d41ed5e 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/JwtTokenProviderTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/JwtTokenProviderTest.java @@ -2,13 +2,12 @@ import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_TOKEN; import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; +import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_ACCESS_TOKEN_설정; +import static dev.tripdraw.test.fixture.AuthFixture.테스트_ACCESS_TOKEN_설정; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.auth.exception.AuthException; -import java.time.Instant; -import java.util.Date; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -17,24 +16,15 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class JwtTokenProviderTest { - private static final long ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 30; - private static final Date EXPIRED_AT = new Date(new Date().getTime() + ACCESS_TOKEN_EXPIRE_TIME); - - private JwtTokenProvider jwtTokenProvider; - - @BeforeEach - void setUp() { - String secretKey = "test2222222222eeeeeeeeeeee222222222asdfasdfasdfasdfasdssssssssssaaaaaaaaaavvvvvvvfsdfsf2eeeeeeeeeeeee"; - jwtTokenProvider = new JwtTokenProvider(secretKey); - } + private final JwtTokenProvider jwtTokenProvider = new JwtTokenProvider(테스트_ACCESS_TOKEN_설정()); @Test void 토큰_정보를_추출한다() { // given - String accessToken = jwtTokenProvider.generate("memberId", EXPIRED_AT); + String accessToken = jwtTokenProvider.generateAccessToken("memberId"); // when - String subject = jwtTokenProvider.extractSubject(accessToken); + String subject = jwtTokenProvider.extractAccessToken(accessToken); // then assertThat(subject).isEqualTo("memberId"); @@ -46,7 +36,7 @@ void setUp() { String subject = "memberId"; // when - String accessToken = jwtTokenProvider.generate(subject, EXPIRED_AT); + String accessToken = jwtTokenProvider.generateAccessToken(subject); // then assertThat(accessToken).isNotEmpty(); @@ -58,7 +48,7 @@ void setUp() { String invalidToken = "Invalid.Token.XD"; // expect - assertThatThrownBy(() -> jwtTokenProvider.extractSubject(invalidToken)) + assertThatThrownBy(() -> jwtTokenProvider.extractAccessToken(invalidToken)) .isInstanceOf(AuthException.class) .hasMessage(INVALID_TOKEN.message()); } @@ -66,11 +56,11 @@ void setUp() { @Test void 만료된_토큰의_정보를_추출할_때_예외를_발생시킨다() { // given - Date expiredDate = Date.from(Instant.now().minusSeconds(1)); - String expiredToken = jwtTokenProvider.generate("memberId", expiredDate); + JwtTokenProvider expiredTokenProvider = new JwtTokenProvider(만료된_토큰_생성용_ACCESS_TOKEN_설정()); + String expiredToken = expiredTokenProvider.generateAccessToken("memberId"); // expect - assertThatThrownBy(() -> jwtTokenProvider.extractSubject(expiredToken)) + assertThatThrownBy(() -> jwtTokenProvider.extractAccessToken(expiredToken)) .isInstanceOf(AuthException.class) .hasMessage(EXPIRED_TOKEN.message()); } diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/AuthFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/AuthFixture.java new file mode 100644 index 000000000..bd3012836 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/fixture/AuthFixture.java @@ -0,0 +1,30 @@ +package dev.tripdraw.test.fixture; + +import dev.tripdraw.auth.config.AccessTokenConfig; +import dev.tripdraw.auth.config.RefreshTokenConfig; + +public class AuthFixture { + + public static final String 유효하지_않은_토큰 = "Invalid.Token.XD"; + private static final long INVALID_TOKEN_EXPIRE_TIME = -180000L; + private static final long ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 30; + private static final long REFRESH_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 14; + private static final String TOKEN = + "TOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKEN"; + + public static AccessTokenConfig 테스트_ACCESS_TOKEN_설정() { + return new AccessTokenConfig(TOKEN, ACCESS_TOKEN_EXPIRE_TIME); + } + + public static AccessTokenConfig 만료된_토큰_생성용_ACCESS_TOKEN_설정() { + return new AccessTokenConfig(TOKEN, INVALID_TOKEN_EXPIRE_TIME); + } + + public static RefreshTokenConfig 테스트_REFRESH_TOKEN_설정() { + return new RefreshTokenConfig(TOKEN, REFRESH_TOKEN_EXPIRE_TIME); + } + + public static RefreshTokenConfig 만료된_토큰_생성용_REFRESH_TOKEN_설정() { + return new RefreshTokenConfig(TOKEN, INVALID_TOKEN_EXPIRE_TIME); + } +} From bec4b9ced75cf9ae2d366b2bc1581c5288836f87 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 3 Sep 2023 22:46:28 +0900 Subject: [PATCH 031/119] =?UTF-8?q?[refactor]=20JwtTokenProvider=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthExtractor.java | 4 +- .../auth/application/AuthService.java | 14 +++--- .../auth/application/AuthTokenManager.java | 26 ---------- .../member/application/MemberService.java | 10 ++-- .../auth/application/AuthExtractorTest.java | 28 ++--------- .../application/AuthTokenManagerTest.java | 50 ------------------- .../member/application/MemberServiceTest.java | 10 ++-- .../presentation/MemberControllerTest.java | 12 ++--- .../post/presentation/PostControllerTest.java | 6 +-- .../trip/presentation/TripControllerTest.java | 6 +-- 10 files changed, 36 insertions(+), 130 deletions(-) delete mode 100644 backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java delete mode 100644 backend/src/test/java/dev/tripdraw/auth/application/AuthTokenManagerTest.java diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java index 4f5345dc9..fb3273b8c 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthExtractor.java @@ -17,7 +17,7 @@ public class AuthExtractor { private static final String AUTHORIZATION_PREFIX = "Bearer "; private static final String EMPTY = ""; - private final AuthTokenManager authTokenManager; + private final JwtTokenProvider jwtTokenProvider; public LoginUser extract(HttpServletRequest request) { Long memberId = parse(request); @@ -38,6 +38,6 @@ private static void validate(String header) { private Long parseCredential(String header) { String credential = header.replace(AUTHORIZATION_PREFIX, EMPTY); - return authTokenManager.extractMemberId(credential); + return Long.valueOf(jwtTokenProvider.extractAccessToken(credential)); } } diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java index 76a4822b8..2e5cbe7a7 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java @@ -3,14 +3,14 @@ import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import dev.tripdraw.auth.oauth.OauthClient; -import dev.tripdraw.auth.oauth.OauthClientProvider; -import dev.tripdraw.member.domain.Member; -import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.auth.dto.OauthInfo; import dev.tripdraw.auth.dto.OauthRequest; import dev.tripdraw.auth.dto.OauthResponse; import dev.tripdraw.auth.dto.RegisterRequest; +import dev.tripdraw.auth.oauth.OauthClient; +import dev.tripdraw.auth.oauth.OauthClientProvider; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -25,14 +25,14 @@ public class AuthService { private final MemberRepository memberRepository; private final OauthClientProvider oauthClientProvider; - private final AuthTokenManager authTokenManager; + private final JwtTokenProvider jwtTokenProvider; public OauthResponse login(OauthRequest oauthRequest) { OauthClient oauthClient = oauthClientProvider.provide(oauthRequest.oauthType()); OauthInfo oauthInfo = oauthClient.requestOauthInfo(oauthRequest.oauthToken()); String accessToken = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) - .map(member -> authTokenManager.generate(member.id())) + .map(member -> jwtTokenProvider.generateAccessToken(member.id().toString())) .orElse(EMPTY_TOKEN); if (accessToken.isEmpty()) { @@ -53,7 +53,7 @@ public OauthResponse register(RegisterRequest registerRequest) { validateDuplicateNickname(nickname); member.changeNickname(nickname); - String accessToken = authTokenManager.generate(member.id()); + String accessToken = jwtTokenProvider.generateAccessToken(member.id().toString()); return new OauthResponse(accessToken); } diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java deleted file mode 100644 index 31d08c0ff..000000000 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthTokenManager.java +++ /dev/null @@ -1,26 +0,0 @@ -package dev.tripdraw.auth.application; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class AuthTokenManager { - - private final JwtTokenProvider jwtTokenProvider; - private final Long expirationTime; - - public AuthTokenManager(JwtTokenProvider jwtTokenProvider, - @Value("${jwt.access.expiration-time}") Long expirationTime) { - this.jwtTokenProvider = jwtTokenProvider; - this.expirationTime = expirationTime; - } - - public String generate(Long memberId) { - String subject = memberId.toString(); - return jwtTokenProvider.generateAccessToken(subject); - } - - public Long extractMemberId(String accessToken) { - return Long.valueOf(jwtTokenProvider.extractAccessToken(accessToken)); - } -} diff --git a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java index 38ea16263..52593a4b8 100644 --- a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java +++ b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java @@ -1,11 +1,11 @@ package dev.tripdraw.member.application; -import dev.tripdraw.auth.application.AuthTokenManager; +import dev.tripdraw.auth.application.JwtTokenProvider; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.member.dto.MemberSearchResponse; import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.member.dto.MemberSearchResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -18,7 +18,7 @@ public class MemberService { private final MemberRepository memberRepository; private final TripRepository tripRepository; private final PostRepository postRepository; - private final AuthTokenManager authTokenManager; + private final JwtTokenProvider jwtTokenProvider; @Transactional(readOnly = true) public boolean existsById(Long memberId) { @@ -27,13 +27,13 @@ public boolean existsById(Long memberId) { @Transactional(readOnly = true) public MemberSearchResponse findByCode(String code) { - Long memberId = authTokenManager.extractMemberId(code); + Long memberId = Long.valueOf(jwtTokenProvider.extractAccessToken(code)); Member member = memberRepository.getById(memberId); return MemberSearchResponse.from(member); } public void deleteByCode(String code) { - Long memberId = authTokenManager.extractMemberId(code); + Long memberId = Long.valueOf(jwtTokenProvider.extractAccessToken(code)); postRepository.deleteByMemberId(memberId); tripRepository.deleteByMemberId(memberId); memberRepository.deleteById(memberId); diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java index 1eef50ede..8fa1e33d2 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java @@ -2,18 +2,17 @@ import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_AUTH_HEADER; import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; +import static dev.tripdraw.test.fixture.AuthFixture.테스트_ACCESS_TOKEN_설정; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.springframework.http.HttpHeaders.AUTHORIZATION; -import dev.tripdraw.auth.config.AccessTokenConfig; import dev.tripdraw.auth.exception.AuthException; import dev.tripdraw.common.auth.LoginUser; import jakarta.servlet.http.HttpServletRequest; import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -22,23 +21,13 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class AuthExtractorTest { - private static final String TEST_SECRET_KEY = "ItIsALocalKeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee2222222222222222222222222222222222eeeeeeeeeeyXD"; - private static final long ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 30; - - private AuthTokenManager authTokenManager; - private AccessTokenConfig accessTokenConfig; - - @BeforeEach - void setUp() { - accessTokenConfig = new AccessTokenConfig(TEST_SECRET_KEY, ACCESS_TOKEN_EXPIRE_TIME); - authTokenManager = new AuthTokenManager(new JwtTokenProvider(accessTokenConfig), ACCESS_TOKEN_EXPIRE_TIME); - } + private final JwtTokenProvider jwtTokenProvider = new JwtTokenProvider(테스트_ACCESS_TOKEN_설정()); + private final AuthExtractor authExtractor = new AuthExtractor(jwtTokenProvider); @Test void 요청_헤더에서_LoginUser를_추출한다() { // given - AuthExtractor authExtractor = new AuthExtractor(authTokenManager); - String accessToken = authTokenManager.generate(1L); + String accessToken = jwtTokenProvider.generateAccessToken("1"); HttpServletRequest request = mock(HttpServletRequest.class); String encoded = "Bearer " + accessToken; when(request.getHeader(AUTHORIZATION)).thenReturn(encoded); @@ -53,11 +42,8 @@ void setUp() { @Test void 요청_헤더에_Bearer_형식이_아닌_다른_인증정보를_사용하는_경우_예외가_발생한다() { // given - AuthExtractor authExtractor = new AuthExtractor( - new AuthTokenManager(new JwtTokenProvider(accessTokenConfig), ACCESS_TOKEN_EXPIRE_TIME) - ); HttpServletRequest request = mock(HttpServletRequest.class); - String encoded = "Basic eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiZXhwIjoxNjkxNTE1Mzk2fQ.WEDBjEXfIAd4MaUTK29ElnnGYmYNCKSHLGVPJHlyf2DNECDX8QDqvigUCBzO4ULmpnxr4GiZZqdQyeH1BgU0Ag"; + String encoded = "Basic aGVsbG86d29ybGQ="; when(request.getHeader(AUTHORIZATION)).thenReturn(encoded); // expect @@ -69,9 +55,6 @@ void setUp() { @Test void 요청_헤더에_인증_정보가_없을_경우_예외를_발생시킨다() { // given - AuthExtractor authExtractor = new AuthExtractor( - new AuthTokenManager(new JwtTokenProvider(accessTokenConfig), ACCESS_TOKEN_EXPIRE_TIME) - ); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getHeader(AUTHORIZATION)).thenReturn(null); @@ -84,7 +67,6 @@ void setUp() { @Test void 헤더의_담긴_토큰이_유효하지_않으면_예외를_발생시킨다() { // given - AuthExtractor authExtractor = new AuthExtractor(authTokenManager); HttpServletRequest request = mock(HttpServletRequest.class); String notEncoded = "Bearer wrong.long.token"; when(request.getHeader(AUTHORIZATION)).thenReturn(notEncoded); diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthTokenManagerTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthTokenManagerTest.java deleted file mode 100644 index 7c8485852..000000000 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthTokenManagerTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package dev.tripdraw.auth.application; - -import static org.assertj.core.api.Assertions.assertThat; - -import dev.tripdraw.auth.config.AccessTokenConfig; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Test; - -@SuppressWarnings("NonAsciiCharacters") -@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class AuthTokenManagerTest { - - private static final long ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 30; - private JwtTokenProvider jwtTokenProvider; - - @BeforeEach - void setUp() { - String key = "test2222222222eeeeeeeeeeee222222222asdfasdfasdfasdfasdssssssssssaaaaaaaaaavvvvvvvfsdfsf2eeeeeeeeeeeee"; - jwtTokenProvider = new JwtTokenProvider( - new AccessTokenConfig(key, ACCESS_TOKEN_EXPIRE_TIME) - ); - } - - @Test - void 회원_ID를_입력_받아_토큰을_생성한다() { - // given - AuthTokenManager authTokenManager = new AuthTokenManager(jwtTokenProvider, ACCESS_TOKEN_EXPIRE_TIME); - - // when - String accessToken = authTokenManager.generate(1L); - - // then - assertThat(accessToken).isNotEmpty(); - } - - @Test - void 토큰에서_회원_ID를_추출한다() { - // given - AuthTokenManager authTokenManager = new AuthTokenManager(jwtTokenProvider, ACCESS_TOKEN_EXPIRE_TIME); - String accessToken = authTokenManager.generate(1L); - - // when - Long memberId = authTokenManager.extractMemberId(accessToken); - - // then - assertThat(memberId).isEqualTo(1L); - } -} diff --git a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java index 3e7669d02..3aac554fc 100644 --- a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java @@ -6,7 +6,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import dev.tripdraw.auth.application.AuthTokenManager; +import dev.tripdraw.auth.application.JwtTokenProvider; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.dto.MemberSearchResponse; @@ -33,7 +33,7 @@ class MemberServiceTest { private MemberRepository memberRepository; @Autowired - private AuthTokenManager authTokenManager; + private JwtTokenProvider jwtTokenProvider; @Autowired private TripRepository tripRepository; @@ -49,7 +49,7 @@ class MemberServiceTest { @BeforeEach void setUp() { member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - code = authTokenManager.generate(member.id()); + code = jwtTokenProvider.generateAccessToken(member.id().toString()); trip = tripRepository.save(new Trip(TripName.from("통후추의 여행"), member)); Point point = new Point(3.14, 5.25, LocalDateTime.now()); @@ -79,7 +79,7 @@ void setUp() { void code를_입력_받아_사용자를_조회할_때_이미_삭제된_사용자라면_예외를_발생시킨다() { // given Member member = memberRepository.save(new Member("순후추", "kakaoId", KAKAO)); - String code = authTokenManager.generate(member.id()); + String code = jwtTokenProvider.generateAccessToken(member.id().toString()); memberRepository.deleteById(member.id()); @@ -91,7 +91,7 @@ void setUp() { @Test void code를_입력_받아_사용자를_조회할_때_존재하지_않는_사용자라면_예외를_발생시킨다() { - String nonExistentCode = authTokenManager.generate(Long.MIN_VALUE); + String nonExistentCode = jwtTokenProvider.generateAccessToken("-1"); // expect assertThatThrownBy(() -> memberService.findByCode(nonExistentCode)) diff --git a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java index e458ffa10..3c00128fe 100644 --- a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java @@ -7,7 +7,7 @@ import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; -import dev.tripdraw.auth.application.AuthTokenManager; +import dev.tripdraw.auth.application.JwtTokenProvider; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.dto.MemberSearchResponse; @@ -46,7 +46,7 @@ class MemberControllerTest extends ControllerTest { PostRepository postRepository; @Autowired - AuthTokenManager authTokenManager; + JwtTokenProvider jwtTokenProvider; @BeforeEach public void setUp() { @@ -57,7 +57,7 @@ public void setUp() { void code를_입력_받아_사용자를_조회한다() { // given Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - String code = authTokenManager.generate(member.id()); + String code = jwtTokenProvider.generateAccessToken(member.id().toString()); // when ExtractableResponse response = RestAssured.given().log().all() @@ -80,7 +80,7 @@ public void setUp() { @Test void code를_입력_받아_사용자를_조회할_때_존재하지_않는_사용자라면_예외가_발생한다() { // given - String code = authTokenManager.generate(Long.MIN_VALUE); + String code = jwtTokenProvider.generateAccessToken("-1"); // expect RestAssured.given().log().all() @@ -94,7 +94,7 @@ public void setUp() { void code를_입력_받아_사용자를_조회할_때_이미_삭제된_사용자라면_예외가_발생한다() { // given Member member = memberRepository.save(new Member("순후추", "kakaoId", KAKAO)); - String code = authTokenManager.generate(member.id()); + String code = jwtTokenProvider.generateAccessToken(member.id().toString()); memberRepository.delete(member); @@ -110,7 +110,7 @@ public void setUp() { void code를_입력_받아_사용자를_삭제한다() { // given Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - String code = authTokenManager.generate(member.id()); + String code = jwtTokenProvider.generateAccessToken(member.id().toString()); Trip trip = new Trip(TripName.from("통후추의 여행"), member); Point point = new Point(3.14, 5.25, LocalDateTime.now()); diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index f2b1909f2..cbe85dd93 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -11,7 +11,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; -import dev.tripdraw.auth.application.AuthTokenManager; +import dev.tripdraw.auth.application.JwtTokenProvider; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; @@ -51,7 +51,7 @@ class PostControllerTest extends ControllerTest { private MemberRepository memberRepository; @Autowired - private AuthTokenManager authTokenManager; + private JwtTokenProvider jwtTokenProvider; @MockBean private RouteImageGenerator routeImageGenerator; @@ -65,7 +65,7 @@ public void setUp() { Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); trip = tripRepository.save(Trip.from(member)); - huchuToken = authTokenManager.generate(member.id()); + huchuToken = jwtTokenProvider.generateAccessToken(member.id().toString()); } @Test diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index 7890e5aa9..5bf763a3e 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -9,7 +9,7 @@ import static org.springframework.http.HttpStatus.UNAUTHORIZED; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import dev.tripdraw.auth.application.AuthTokenManager; +import dev.tripdraw.auth.application.JwtTokenProvider; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; @@ -49,7 +49,7 @@ class TripControllerTest extends ControllerTest { private MemberRepository memberRepository; @Autowired - private AuthTokenManager authTokenManager; + private JwtTokenProvider jwtTokenProvider; @MockBean private RouteImageGenerator routeImageGenerator; @@ -63,7 +63,7 @@ public void setUp() { Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); trip = tripRepository.save(Trip.from(member)); - huchuToken = authTokenManager.generate(member.id()); + huchuToken = jwtTokenProvider.generateAccessToken(member.id().toString()); } @Test From ec614a071f387659aaba579df83054007f5a031f Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 3 Sep 2023 20:28:37 +0900 Subject: [PATCH 032/119] =?UTF-8?q?[feat]=20RefreshToken=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/JwtTokenProvider.java | 52 ++++++++++++---- .../auth/exception/AuthExceptionType.java | 3 +- .../auth/application/AuthExtractorTest.java | 6 +- .../application/JwtTokenProviderTest.java | 61 ++++++++++++++++--- 4 files changed, 99 insertions(+), 23 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java index ff46694f5..d5ff60abe 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java @@ -1,11 +1,12 @@ package dev.tripdraw.auth.application; -import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_TOKEN; +import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_ACCESS_TOKEN; +import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_REFRESH_TOKEN; import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import dev.tripdraw.auth.config.AccessTokenConfig; +import dev.tripdraw.auth.config.RefreshTokenConfig; import dev.tripdraw.auth.exception.AuthException; -import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.JwtException; import io.jsonwebtoken.Jwts; @@ -21,11 +22,16 @@ public class JwtTokenProvider { private final Key accessKey; private final Long accessTokenExpirationTime; + private final Key refreshKey; + private final Long refreshTokenExpirationTime; - public JwtTokenProvider(AccessTokenConfig accessTokenConfig) { - byte[] keyBytes = Decoders.BASE64.decode(accessTokenConfig.secretKey()); - this.accessKey = Keys.hmacShaKeyFor(keyBytes); + public JwtTokenProvider(AccessTokenConfig accessTokenConfig, RefreshTokenConfig refreshTokenConfig) { + byte[] accessKeyBytes = Decoders.BASE64.decode(accessTokenConfig.secretKey()); + this.accessKey = Keys.hmacShaKeyFor(accessKeyBytes); this.accessTokenExpirationTime = accessTokenConfig.expirationTime(); + byte[] refreshKeyBytes = Decoders.BASE64.decode(refreshTokenConfig.secretKey()); + this.refreshKey = Keys.hmacShaKeyFor(refreshKeyBytes); + this.refreshTokenExpirationTime = refreshTokenConfig.expirationTime(); } public String generateAccessToken(String subject) { @@ -39,19 +45,39 @@ public String generateAccessToken(String subject) { } public String extractAccessToken(String accessToken) { - Claims claims = parseClaims(accessToken, accessKey); - return claims.getSubject(); + try { + return Jwts.parserBuilder() + .setSigningKey(accessKey) + .build() + .parseClaimsJws(accessToken) + .getBody() + .getSubject(); + } catch (ExpiredJwtException e) { + throw new AuthException(EXPIRED_ACCESS_TOKEN); + } catch (JwtException e) { + throw new AuthException(INVALID_TOKEN); + } } - private Claims parseClaims(String token, Key key) { + public String generateRefreshToken() { + final Date now = new Date(); + return Jwts.builder() + .setIssuedAt(now) + .setExpiration(new Date(now.getTime() + refreshTokenExpirationTime)) + .signWith(refreshKey, SignatureAlgorithm.HS512) + .compact(); + } + + public void validateRefreshToken(String refreshToken) { try { - return Jwts.parserBuilder() - .setSigningKey(key) + Jwts.parserBuilder() + .setSigningKey(refreshKey) .build() - .parseClaimsJws(token) - .getBody(); + .parseClaimsJws(refreshToken) + .getBody() + .getSubject(); } catch (ExpiredJwtException e) { - throw new AuthException(EXPIRED_TOKEN); + throw new AuthException(EXPIRED_REFRESH_TOKEN); } catch (JwtException e) { throw new AuthException(INVALID_TOKEN); } diff --git a/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java b/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java index f713fc95b..57fcbb001 100644 --- a/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java @@ -10,7 +10,8 @@ public enum AuthExceptionType implements ExceptionType { INVALID_AUTH_HEADER(BAD_REQUEST, "Authoriztion 헤더가 올바르지 않습니다."), AUTH_FAIL(FORBIDDEN, "접근 권한이 없습니다."), - EXPIRED_TOKEN(UNAUTHORIZED, "만료된 토큰입니다."), + EXPIRED_ACCESS_TOKEN(UNAUTHORIZED, "만료된 인증 토큰입니다."), + EXPIRED_REFRESH_TOKEN(UNAUTHORIZED, "만료된 리프레시 토큰입니다."), INVALID_TOKEN(UNAUTHORIZED, "유효하지 않은 토큰입니다."), ; diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java index 8fa1e33d2..880c8c97b 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthExtractorTest.java @@ -3,6 +3,7 @@ import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_AUTH_HEADER; import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import static dev.tripdraw.test.fixture.AuthFixture.테스트_ACCESS_TOKEN_설정; +import static dev.tripdraw.test.fixture.AuthFixture.테스트_REFRESH_TOKEN_설정; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; @@ -21,7 +22,10 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class AuthExtractorTest { - private final JwtTokenProvider jwtTokenProvider = new JwtTokenProvider(테스트_ACCESS_TOKEN_설정()); + private final JwtTokenProvider jwtTokenProvider = new JwtTokenProvider( + 테스트_ACCESS_TOKEN_설정(), + 테스트_REFRESH_TOKEN_설정() + ); private final AuthExtractor authExtractor = new AuthExtractor(jwtTokenProvider); @Test diff --git a/backend/src/test/java/dev/tripdraw/auth/application/JwtTokenProviderTest.java b/backend/src/test/java/dev/tripdraw/auth/application/JwtTokenProviderTest.java index 02d41ed5e..3a1c4e995 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/JwtTokenProviderTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/JwtTokenProviderTest.java @@ -1,10 +1,14 @@ package dev.tripdraw.auth.application; -import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_TOKEN; +import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_ACCESS_TOKEN; +import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_REFRESH_TOKEN; import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_ACCESS_TOKEN_설정; +import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_REFRESH_TOKEN_설정; import static dev.tripdraw.test.fixture.AuthFixture.테스트_ACCESS_TOKEN_설정; +import static dev.tripdraw.test.fixture.AuthFixture.테스트_REFRESH_TOKEN_설정; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.auth.exception.AuthException; @@ -16,10 +20,13 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class JwtTokenProviderTest { - private final JwtTokenProvider jwtTokenProvider = new JwtTokenProvider(테스트_ACCESS_TOKEN_설정()); + private final JwtTokenProvider jwtTokenProvider = new JwtTokenProvider( + 테스트_ACCESS_TOKEN_설정(), + 테스트_REFRESH_TOKEN_설정() + ); @Test - void 토큰_정보를_추출한다() { + void ACCESS_토큰_정보를_추출한다() { // given String accessToken = jwtTokenProvider.generateAccessToken("memberId"); @@ -31,7 +38,7 @@ class JwtTokenProviderTest { } @Test - void 대상과_만료기한을_입력_받아_토큰을_생성한다() { + void 대상을_입력_받아_ACCESS_토큰을_생성한다() { // given String subject = "memberId"; @@ -43,7 +50,7 @@ class JwtTokenProviderTest { } @Test - void 유효하지_않은_토큰의_정보를_추출할_때_예외를_발생시킨다() { + void 유효하지_않은_ACCESS_토큰의_정보를_추출할_때_예외를_발생시킨다() { // given String invalidToken = "Invalid.Token.XD"; @@ -54,14 +61,52 @@ class JwtTokenProviderTest { } @Test - void 만료된_토큰의_정보를_추출할_때_예외를_발생시킨다() { + void 만료된_ACCESS_토큰의_정보를_추출할_때_예외를_발생시킨다() { // given - JwtTokenProvider expiredTokenProvider = new JwtTokenProvider(만료된_토큰_생성용_ACCESS_TOKEN_설정()); + JwtTokenProvider expiredTokenProvider = new JwtTokenProvider( + 만료된_토큰_생성용_ACCESS_TOKEN_설정(), + 만료된_토큰_생성용_REFRESH_TOKEN_설정() + ); String expiredToken = expiredTokenProvider.generateAccessToken("memberId"); // expect assertThatThrownBy(() -> jwtTokenProvider.extractAccessToken(expiredToken)) .isInstanceOf(AuthException.class) - .hasMessage(EXPIRED_TOKEN.message()); + .hasMessage(EXPIRED_ACCESS_TOKEN.message()); + } + + @Test + void REFRESH_토큰을_생성한다() { + // when + String refreshToken = jwtTokenProvider.generateRefreshToken(); + + // then + assertThatNoException().isThrownBy(() -> jwtTokenProvider.validateRefreshToken(refreshToken)); + } + + @Test + void 유효하지_않은_REFRESH_TOKEN인_경우_예외를_발생시킨다() { + // given + String invalidToken = "Invalid.Token.XD"; + + // expect + assertThatThrownBy(() -> jwtTokenProvider.validateRefreshToken(invalidToken)) + .isInstanceOf(AuthException.class) + .hasMessage(INVALID_TOKEN.message()); + } + + @Test + void 만료된_REFRESH_토큰인_경우_예외를_발생시킨다() { + // given + JwtTokenProvider expiredTokenProvider = new JwtTokenProvider( + 만료된_토큰_생성용_ACCESS_TOKEN_설정(), + 만료된_토큰_생성용_REFRESH_TOKEN_설정() + ); + String expiredToken = expiredTokenProvider.generateRefreshToken(); + + // expect + assertThatThrownBy(() -> jwtTokenProvider.validateRefreshToken(expiredToken)) + .isInstanceOf(AuthException.class) + .hasMessage(EXPIRED_REFRESH_TOKEN.message()); } } From 2a2c17a438ecce96e9e8f670887c19011b5d096c Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 3 Sep 2023 20:37:06 +0900 Subject: [PATCH 033/119] =?UTF-8?q?[feat]=20RefreshTokenRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/auth/domain/RefreshToken.java | 5 +++ .../auth/domain/RefreshTokenRepository.java | 9 ++++++ .../migration/h2/V7__addRefreshTokenTable.sql | 5 +-- .../mysql/V7__addRefreshTokenTable.sql | 5 +-- .../domain/RefreshTokenRepositoryTest.java | 32 +++++++++++++++++++ 5 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/auth/domain/RefreshTokenRepository.java create mode 100644 backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java diff --git a/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java index f7e3fe9f0..66caf2d23 100644 --- a/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java +++ b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java @@ -26,4 +26,9 @@ public class RefreshToken extends BaseEntity { private Long memberId; private String token; + + public RefreshToken(Long memberId, String token) { + this.memberId = memberId; + this.token = token; + } } diff --git a/backend/src/main/java/dev/tripdraw/auth/domain/RefreshTokenRepository.java b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshTokenRepository.java new file mode 100644 index 000000000..006aae89b --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshTokenRepository.java @@ -0,0 +1,9 @@ +package dev.tripdraw.auth.domain; + +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RefreshTokenRepository extends JpaRepository { + + Optional findByToken(String token); +} diff --git a/backend/src/main/resources/db/migration/h2/V7__addRefreshTokenTable.sql b/backend/src/main/resources/db/migration/h2/V7__addRefreshTokenTable.sql index a33f20f7a..3c77cda90 100644 --- a/backend/src/main/resources/db/migration/h2/V7__addRefreshTokenTable.sql +++ b/backend/src/main/resources/db/migration/h2/V7__addRefreshTokenTable.sql @@ -1,11 +1,8 @@ CREATE TABLE `refresh_token` ( - `refresh_token_id` BIGINT, + `refresh_token_id` BIGINT PRIMARY KEY AUTO_INCREMENT, `member_id` BIGINT, `token` TEXT, `created_at` TIMESTAMP, `updated_at` TIMESTAMP ); - -ALTER TABLE `refresh_token` - ADD FOREIGN KEY (`member_id`) REFERENCES `member` (`member_id`); diff --git a/backend/src/main/resources/db/migration/mysql/V7__addRefreshTokenTable.sql b/backend/src/main/resources/db/migration/mysql/V7__addRefreshTokenTable.sql index a33f20f7a..3c77cda90 100644 --- a/backend/src/main/resources/db/migration/mysql/V7__addRefreshTokenTable.sql +++ b/backend/src/main/resources/db/migration/mysql/V7__addRefreshTokenTable.sql @@ -1,11 +1,8 @@ CREATE TABLE `refresh_token` ( - `refresh_token_id` BIGINT, + `refresh_token_id` BIGINT PRIMARY KEY AUTO_INCREMENT, `member_id` BIGINT, `token` TEXT, `created_at` TIMESTAMP, `updated_at` TIMESTAMP ); - -ALTER TABLE `refresh_token` - ADD FOREIGN KEY (`member_id`) REFERENCES `member` (`member_id`); diff --git a/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java new file mode 100644 index 000000000..d46e501ff --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java @@ -0,0 +1,32 @@ +package dev.tripdraw.auth.domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Optional; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@DataJpaTest +class RefreshTokenRepositoryTest { + + @Autowired + private RefreshTokenRepository refreshTokenRepository; + + @Test + void 토큰을_입력받아_refreshToken_객체를_반환한다() { + // given + RefreshToken refreshToken = new RefreshToken(1L, "refreshToken"); + refreshTokenRepository.save(refreshToken); + + // when + Optional findToken = refreshTokenRepository.findByToken(refreshToken.token()); + + // then + assertThat(findToken).isPresent(); + } +} From 3993b5c5c6784dc42196ce3ba15de9d9f30295e1 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 3 Sep 2023 21:06:50 +0900 Subject: [PATCH 034/119] =?UTF-8?q?[feat]=20refreshToken=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=EB=B0=98=ED=99=98=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthService.java | 30 +++++++++++++------ .../auth/domain/RefreshTokenRepository.java | 2 ++ .../dev/tripdraw/auth/dto/OauthResponse.java | 5 +++- .../auth/application/AuthServiceTest.java | 19 ++++++++---- .../domain/RefreshTokenRepositoryTest.java | 13 ++++++++ .../auth/presentation/AuthControllerTest.java | 3 ++ 6 files changed, 57 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java index 2e5cbe7a7..52225e97c 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java @@ -3,6 +3,8 @@ import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; +import dev.tripdraw.auth.domain.RefreshToken; +import dev.tripdraw.auth.domain.RefreshTokenRepository; import dev.tripdraw.auth.dto.OauthInfo; import dev.tripdraw.auth.dto.OauthRequest; import dev.tripdraw.auth.dto.OauthResponse; @@ -12,6 +14,7 @@ import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; +import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,20 +29,31 @@ public class AuthService { private final MemberRepository memberRepository; private final OauthClientProvider oauthClientProvider; private final JwtTokenProvider jwtTokenProvider; + private final RefreshTokenRepository refreshTokenRepository; public OauthResponse login(OauthRequest oauthRequest) { OauthClient oauthClient = oauthClientProvider.provide(oauthRequest.oauthType()); OauthInfo oauthInfo = oauthClient.requestOauthInfo(oauthRequest.oauthToken()); - String accessToken = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) - .map(member -> jwtTokenProvider.generateAccessToken(member.id().toString())) - .orElse(EMPTY_TOKEN); - - if (accessToken.isEmpty()) { + Optional member = memberRepository.findByOauthIdAndOauthType( + oauthInfo.oauthId(), + oauthInfo.oauthType() + ); + if (member.isEmpty()) { memberRepository.save(Member.of(oauthInfo.oauthId(), oauthInfo.oauthType())); + return new OauthResponse(EMPTY_TOKEN, EMPTY_TOKEN); } - return new OauthResponse(accessToken); + Member findMember = member.orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); + return generateToken(findMember); + } + + private OauthResponse generateToken(Member member) { + String accessToken = jwtTokenProvider.generateAccessToken(member.id().toString()); + String refreshToken = jwtTokenProvider.generateRefreshToken(); + refreshTokenRepository.deleteByMemberId(member.id()); + RefreshToken savedRefreshToken = refreshTokenRepository.save(new RefreshToken(member.id(), refreshToken)); + return new OauthResponse(accessToken, savedRefreshToken.token()); } public OauthResponse register(RegisterRequest registerRequest) { @@ -52,9 +66,7 @@ public OauthResponse register(RegisterRequest registerRequest) { String nickname = registerRequest.nickname(); validateDuplicateNickname(nickname); member.changeNickname(nickname); - - String accessToken = jwtTokenProvider.generateAccessToken(member.id().toString()); - return new OauthResponse(accessToken); + return generateToken(member); } private void validateDuplicateNickname(String nickname) { diff --git a/backend/src/main/java/dev/tripdraw/auth/domain/RefreshTokenRepository.java b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshTokenRepository.java index 006aae89b..15fff325c 100644 --- a/backend/src/main/java/dev/tripdraw/auth/domain/RefreshTokenRepository.java +++ b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshTokenRepository.java @@ -6,4 +6,6 @@ public interface RefreshTokenRepository extends JpaRepository { Optional findByToken(String token); + + void deleteByMemberId(Long memberId); } diff --git a/backend/src/main/java/dev/tripdraw/auth/dto/OauthResponse.java b/backend/src/main/java/dev/tripdraw/auth/dto/OauthResponse.java index fa4a6bd69..2f244b2e0 100644 --- a/backend/src/main/java/dev/tripdraw/auth/dto/OauthResponse.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/OauthResponse.java @@ -3,9 +3,12 @@ import io.swagger.v3.oas.annotations.media.Schema; public record OauthResponse( + @Schema(description = "Access Token", example = TOKEN_SAMPLE) + String accessToken, - String accessToken + @Schema(description = "Refresh Token", example = TOKEN_SAMPLE) + String refreshToken ) { private static final String TOKEN_SAMPLE = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzMiLCJleHAiOjE2OTE4OTA0NjZ9.NlzZEEDWdjovafRPCD1ZvddeRUccZfyZpcUWzGPAI4oK-PKyPM64TIMJ3HyOy29vJtg_MET1c4omWUkGOb4qyQ"; } diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index e11340ef7..e0357babe 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -3,8 +3,8 @@ import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.Mockito.when; import dev.tripdraw.auth.dto.OauthRequest; @@ -28,7 +28,7 @@ class AuthServiceTest { private AuthService authService; @MockBean - OauthClientProvider oauthClientProvider; + private OauthClientProvider oauthClientProvider; @Autowired private MemberRepository memberRepository; @@ -48,7 +48,10 @@ void setUp() { OauthResponse response = authService.login(oauthRequest); // then - assertThat(response.accessToken()).isNotEmpty(); + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isNotEmpty(); + softly.assertThat(response.refreshToken()).isNotEmpty(); + }); } @Test @@ -60,7 +63,10 @@ void setUp() { OauthResponse response = authService.login(oauthRequest); // then - assertThat(response.accessToken()).isEmpty(); + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isEmpty(); + softly.assertThat(response.refreshToken()).isEmpty(); + }); } @Test @@ -75,7 +81,10 @@ void setUp() { OauthResponse response = authService.register(registerRequest); // then - assertThat(response.accessToken()).isNotEmpty(); + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isNotEmpty(); + softly.assertThat(response.refreshToken()).isNotEmpty(); + }); } @Test diff --git a/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java index d46e501ff..36e525227 100644 --- a/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java @@ -29,4 +29,17 @@ class RefreshTokenRepositoryTest { // then assertThat(findToken).isPresent(); } + + @Test + void 사용자_아이디를_입력받아_해당되는_모든_RefreshToken을_제거한다() { + // given + refreshTokenRepository.save(new RefreshToken(1L, "refreshToken")); + refreshTokenRepository.save(new RefreshToken(1L, "refreshToken")); + + // when + refreshTokenRepository.deleteByMemberId(1L); + + // then + assertThat(refreshTokenRepository.count()).isZero(); + } } diff --git a/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java b/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java index 1ffa77988..0f5b43736 100644 --- a/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java @@ -73,6 +73,7 @@ class 로그인할_때 { assertSoftly(softly -> { softly.assertThat(response.statusCode()).isEqualTo(OK.value()); softly.assertThat(oauthResponse.accessToken()).isNotNull(); + softly.assertThat(oauthResponse.refreshToken()).isNotNull(); }); } @@ -95,6 +96,7 @@ class 로그인할_때 { assertSoftly(softly -> { softly.assertThat(response.statusCode()).isEqualTo(OK.value()); softly.assertThat(oauthResponse.accessToken()).isEmpty(); + softly.assertThat(oauthResponse.refreshToken()).isEmpty(); }); } } @@ -124,6 +126,7 @@ class 신규_회원의_닉네임을_등록할_때 { assertSoftly(softly -> { softly.assertThat(response.statusCode()).isEqualTo(OK.value()); softly.assertThat(oauthResponse.accessToken()).isNotEmpty(); + softly.assertThat(oauthResponse.refreshToken()).isNotEmpty(); }); } From 3f230daf661d2e80e6814ee072d0c2fc425df200 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 3 Sep 2023 22:28:19 +0900 Subject: [PATCH 035/119] =?UTF-8?q?[feat]=20refreshToken=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20api,=20service=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthService.java | 22 ++++-- .../auth/application/JwtTokenProvider.java | 6 +- .../auth/config/RefreshTokenConfig.java | 2 +- .../dev/tripdraw/auth/dto/OauthRequest.java | 1 - .../auth/dto/TokenRefreshRequest.java | 11 +++ .../auth/presentation/AuthController.java | 12 ++++ .../auth/application/AuthServiceTest.java | 51 ++++++++++++++ .../auth/presentation/AuthControllerTest.java | 70 +++++++++++++++++-- .../tripdraw/test/fixture/AuthFixture.java | 14 ++-- 9 files changed, 168 insertions(+), 21 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/auth/dto/TokenRefreshRequest.java diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java index 52225e97c..dcfddd589 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java @@ -1,5 +1,6 @@ package dev.tripdraw.auth.application; +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; @@ -9,6 +10,8 @@ import dev.tripdraw.auth.dto.OauthRequest; import dev.tripdraw.auth.dto.OauthResponse; import dev.tripdraw.auth.dto.RegisterRequest; +import dev.tripdraw.auth.dto.TokenRefreshRequest; +import dev.tripdraw.auth.exception.AuthException; import dev.tripdraw.auth.oauth.OauthClient; import dev.tripdraw.auth.oauth.OauthClientProvider; import dev.tripdraw.member.domain.Member; @@ -45,14 +48,14 @@ public OauthResponse login(OauthRequest oauthRequest) { } Member findMember = member.orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); - return generateToken(findMember); + return generateToken(findMember.id()); } - private OauthResponse generateToken(Member member) { - String accessToken = jwtTokenProvider.generateAccessToken(member.id().toString()); + private OauthResponse generateToken(Long memberId) { + String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); String refreshToken = jwtTokenProvider.generateRefreshToken(); - refreshTokenRepository.deleteByMemberId(member.id()); - RefreshToken savedRefreshToken = refreshTokenRepository.save(new RefreshToken(member.id(), refreshToken)); + refreshTokenRepository.deleteByMemberId(memberId); + RefreshToken savedRefreshToken = refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); return new OauthResponse(accessToken, savedRefreshToken.token()); } @@ -66,7 +69,7 @@ public OauthResponse register(RegisterRequest registerRequest) { String nickname = registerRequest.nickname(); validateDuplicateNickname(nickname); member.changeNickname(nickname); - return generateToken(member); + return generateToken(member.id()); } private void validateDuplicateNickname(String nickname) { @@ -74,4 +77,11 @@ private void validateDuplicateNickname(String nickname) { throw new MemberException(DUPLICATE_NICKNAME); } } + + public OauthResponse refresh(TokenRefreshRequest tokenRefreshRequest) { + jwtTokenProvider.validateRefreshToken(tokenRefreshRequest.refreshToken()); + RefreshToken refreshToken = refreshTokenRepository.findByToken(tokenRefreshRequest.refreshToken()) + .orElseThrow(() -> new AuthException(INVALID_TOKEN)); + return generateToken(refreshToken.memberId()); + } } diff --git a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java index d5ff60abe..17f4cfa0d 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java @@ -15,6 +15,7 @@ import io.jsonwebtoken.security.Keys; import java.security.Key; import java.util.Date; +import java.util.UUID; import org.springframework.stereotype.Component; @Component @@ -62,6 +63,7 @@ public String extractAccessToken(String accessToken) { public String generateRefreshToken() { final Date now = new Date(); return Jwts.builder() + .setSubject(UUID.randomUUID().toString()) .setIssuedAt(now) .setExpiration(new Date(now.getTime() + refreshTokenExpirationTime)) .signWith(refreshKey, SignatureAlgorithm.HS512) @@ -73,9 +75,7 @@ public void validateRefreshToken(String refreshToken) { Jwts.parserBuilder() .setSigningKey(refreshKey) .build() - .parseClaimsJws(refreshToken) - .getBody() - .getSubject(); + .parseClaimsJws(refreshToken); } catch (ExpiredJwtException e) { throw new AuthException(EXPIRED_REFRESH_TOKEN); } catch (JwtException e) { diff --git a/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java index 98dc19286..c3f05dc88 100644 --- a/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java +++ b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java @@ -2,7 +2,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; -@ConfigurationProperties(prefix = "jwt.access") +@ConfigurationProperties(prefix = "jwt.refresh") public record RefreshTokenConfig( String secretKey, Long expirationTime diff --git a/backend/src/main/java/dev/tripdraw/auth/dto/OauthRequest.java b/backend/src/main/java/dev/tripdraw/auth/dto/OauthRequest.java index c11eb0151..c2d79d4fe 100644 --- a/backend/src/main/java/dev/tripdraw/auth/dto/OauthRequest.java +++ b/backend/src/main/java/dev/tripdraw/auth/dto/OauthRequest.java @@ -11,6 +11,5 @@ public record OauthRequest( @Schema(description = "Access Token", example = TOKEN_SAMPLE) String oauthToken ) { - private static final String TOKEN_SAMPLE = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzMiLCJleHAiOjE2OTE4OTA0NjZ9.NlzZEEDWdjovafRPCD1ZvddeRUccZfyZpcUWzGPAI4oK-PKyPM64TIMJ3HyOy29vJtg_MET1c4omWUkGOb4qyQ"; } diff --git a/backend/src/main/java/dev/tripdraw/auth/dto/TokenRefreshRequest.java b/backend/src/main/java/dev/tripdraw/auth/dto/TokenRefreshRequest.java new file mode 100644 index 000000000..9aedc144e --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/dto/TokenRefreshRequest.java @@ -0,0 +1,11 @@ +package dev.tripdraw.auth.dto; + +import io.swagger.v3.oas.annotations.media.Schema; + +public record TokenRefreshRequest( + + @Schema(description = "Refresh Token", example = TOKEN_SAMPLE) + String refreshToken +) { + private static final String TOKEN_SAMPLE = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzMiLCJleHAiOjE2OTE4OTA0NjZ9.NlzZEEDWdjovafRPCD1ZvddeRUccZfyZpcUWzGPAI4oK-PKyPM64TIMJ3HyOy29vJtg_MET1c4omWUkGOb4qyQ"; +} diff --git a/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java index 9b285b36c..ce2b7b7ce 100644 --- a/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java +++ b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java @@ -4,6 +4,7 @@ import dev.tripdraw.auth.dto.OauthRequest; import dev.tripdraw.auth.dto.OauthResponse; import dev.tripdraw.auth.dto.RegisterRequest; +import dev.tripdraw.auth.dto.TokenRefreshRequest; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; @@ -42,4 +43,15 @@ public ResponseEntity register(@Valid @RequestBody RegisterReques OauthResponse oauthResponse = authService.register(registerRequest); return ResponseEntity.ok(oauthResponse); } + + @Operation(summary = "토큰 재발급 API", description = "리프레쉬 토큰을 이용하여 토큰을 재발급합니다.") + @ApiResponse( + responseCode = "200", + description = "토큰 재발급 성공." + ) + @PostMapping("/oauth/refresh") + public ResponseEntity refresh(@Valid @RequestBody TokenRefreshRequest tokenRefreshRequest) { + OauthResponse oauthResponse = authService.refresh(tokenRefreshRequest); + return ResponseEntity.ok(oauthResponse); + } } diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index e0357babe..dcc32a829 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -1,15 +1,22 @@ package dev.tripdraw.auth.application; +import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_REFRESH_TOKEN; import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; +import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_ACCESS_TOKEN_설정; +import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_REFRESH_TOKEN_설정; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.Mockito.when; +import dev.tripdraw.auth.domain.RefreshToken; +import dev.tripdraw.auth.domain.RefreshTokenRepository; import dev.tripdraw.auth.dto.OauthRequest; import dev.tripdraw.auth.dto.OauthResponse; import dev.tripdraw.auth.dto.RegisterRequest; +import dev.tripdraw.auth.dto.TokenRefreshRequest; +import dev.tripdraw.auth.exception.AuthException; import dev.tripdraw.auth.oauth.OauthClientProvider; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; @@ -33,6 +40,12 @@ class AuthServiceTest { @Autowired private MemberRepository memberRepository; + @Autowired + private RefreshTokenRepository refreshTokenRepository; + + @Autowired + private JwtTokenProvider jwtTokenProvider; + @BeforeEach void setUp() { when(oauthClientProvider.provide(KAKAO)).thenReturn(new TestKakaoApiClient()); @@ -109,4 +122,42 @@ void setUp() { .isInstanceOf(MemberException.class) .hasMessage(DUPLICATE_NICKNAME.message()); } + + @Test + void Refresh_토큰_재발급시_입력받은_토큰이_만료되는_경우_예외가_발생한다() { + // given + Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + JwtTokenProvider expiredTokenProvider = new JwtTokenProvider( + 만료된_토큰_생성용_ACCESS_TOKEN_설정(), + 만료된_토큰_생성용_REFRESH_TOKEN_설정() + ); + String expiredToken = expiredTokenProvider.generateRefreshToken(); + refreshTokenRepository.save(new RefreshToken(member.id(), expiredToken)); + TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(expiredToken); + + // expect + assertThatThrownBy(() -> authService.refresh(tokenRefreshRequest)) + .isInstanceOf(AuthException.class) + .hasMessage(EXPIRED_REFRESH_TOKEN.message()); + } + + @Test + void Refresh_토큰을_입력받아_Access_토큰과_Refresh_토큰을_재발급한다() { + // given + Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + String refreshToken = jwtTokenProvider.generateRefreshToken(); + refreshTokenRepository.save(new RefreshToken(member.id(), refreshToken)); + TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(refreshToken); + + // when + OauthResponse response = authService.refresh(tokenRefreshRequest); + + // then + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isNotEmpty(); + softly.assertThat(response.refreshToken()).isNotEmpty(); + softly.assertThat(refreshTokenRepository.findByToken(refreshToken)).isEmpty(); + softly.assertThat(refreshTokenRepository.findByToken(response.refreshToken())).isPresent(); + }); + } } diff --git a/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java b/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java index 0f5b43736..8e697da22 100644 --- a/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/presentation/AuthControllerTest.java @@ -1,17 +1,24 @@ package dev.tripdraw.auth.presentation; import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_ACCESS_TOKEN_설정; +import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_REFRESH_TOKEN_설정; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.Mockito.when; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.UNAUTHORIZED; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import dev.tripdraw.auth.application.JwtTokenProvider; +import dev.tripdraw.auth.domain.RefreshToken; +import dev.tripdraw.auth.domain.RefreshTokenRepository; import dev.tripdraw.auth.dto.OauthRequest; import dev.tripdraw.auth.dto.OauthResponse; import dev.tripdraw.auth.dto.RegisterRequest; +import dev.tripdraw.auth.dto.TokenRefreshRequest; import dev.tripdraw.auth.oauth.OauthClientProvider; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; @@ -34,18 +41,23 @@ class AuthControllerTest extends ControllerTest { @LocalServerPort - int port; + private int port; @MockBean - OauthClientProvider oauthClientProvider; + private OauthClientProvider oauthClientProvider; @Autowired - MemberRepository memberRepository; + private MemberRepository memberRepository; + + @Autowired + private RefreshTokenRepository refreshTokenRepository; + + @Autowired + private JwtTokenProvider jwtTokenProvider; @BeforeEach public void setUp() { RestAssured.port = port; - when(oauthClientProvider.provide(KAKAO)) .thenReturn(new TestKakaoApiClient()); } @@ -173,4 +185,54 @@ class 신규_회원의_닉네임을_등록할_때 { .statusCode(BAD_REQUEST.value()); } } + + @Nested + class Refresh_토큰_재발급_시 { + + @Test + void 만료기간이_남은_Refresh_토큰이면_Access_토큰과_Refresh_토큰을_재발급한다() { + // given + Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + String refreshToken = jwtTokenProvider.generateRefreshToken(); + refreshTokenRepository.save(new RefreshToken(member.id(), refreshToken)); + TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(refreshToken); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .contentType(APPLICATION_JSON_VALUE) + .body(tokenRefreshRequest) + .when().post("/oauth/refresh") + .then().log().all() + .extract(); + + // then + OauthResponse oauthResponse = response.as(OauthResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(oauthResponse.accessToken()).isNotEmpty(); + softly.assertThat(oauthResponse.refreshToken()).isNotEmpty(); + }); + } + + @Test + void 만료기간이_지난_Refresh_토큰이면_401_예외가_발생한다() { + // given + Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + JwtTokenProvider expiredTokenProvider = new JwtTokenProvider( + 만료된_토큰_생성용_ACCESS_TOKEN_설정(), + 만료된_토큰_생성용_REFRESH_TOKEN_설정() + ); + String expiredToken = expiredTokenProvider.generateRefreshToken(); + refreshTokenRepository.save(new RefreshToken(member.id(), expiredToken)); + TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(expiredToken); + + RestAssured.given().log().all() + .contentType(APPLICATION_JSON_VALUE) + .body(tokenRefreshRequest) + .when().post("/oauth/refresh") + .then().log().all() + .statusCode(UNAUTHORIZED.value()); + } + } } diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/AuthFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/AuthFixture.java index bd3012836..c94b35f3b 100644 --- a/backend/src/test/java/dev/tripdraw/test/fixture/AuthFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/fixture/AuthFixture.java @@ -7,24 +7,26 @@ public class AuthFixture { public static final String 유효하지_않은_토큰 = "Invalid.Token.XD"; private static final long INVALID_TOKEN_EXPIRE_TIME = -180000L; + private static final String ACCESS_TOKEN_KEY = + "ACCESSTOKENACCESSTOKENACCESSTOKENACCESSTOKENACCESSTOKENACCESSTOKENACCESSTOKENACCESSTOKEN"; + private static final String REFRESH_TOKEN_KEY = + "REFRESHTOKENREFRESHTOKENREFRESHTOKENREFRESHTOKENREFRESHTOKENREFRESHTOKENREFRESHTOKENREFR"; private static final long ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 30; private static final long REFRESH_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 14; - private static final String TOKEN = - "TOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKEN"; public static AccessTokenConfig 테스트_ACCESS_TOKEN_설정() { - return new AccessTokenConfig(TOKEN, ACCESS_TOKEN_EXPIRE_TIME); + return new AccessTokenConfig(ACCESS_TOKEN_KEY, ACCESS_TOKEN_EXPIRE_TIME); } public static AccessTokenConfig 만료된_토큰_생성용_ACCESS_TOKEN_설정() { - return new AccessTokenConfig(TOKEN, INVALID_TOKEN_EXPIRE_TIME); + return new AccessTokenConfig(ACCESS_TOKEN_KEY, INVALID_TOKEN_EXPIRE_TIME); } public static RefreshTokenConfig 테스트_REFRESH_TOKEN_설정() { - return new RefreshTokenConfig(TOKEN, REFRESH_TOKEN_EXPIRE_TIME); + return new RefreshTokenConfig(REFRESH_TOKEN_KEY, REFRESH_TOKEN_EXPIRE_TIME); } public static RefreshTokenConfig 만료된_토큰_생성용_REFRESH_TOKEN_설정() { - return new RefreshTokenConfig(TOKEN, INVALID_TOKEN_EXPIRE_TIME); + return new RefreshTokenConfig(REFRESH_TOKEN_KEY, INVALID_TOKEN_EXPIRE_TIME); } } From e51e4681a72a46fd404600ab34dff272e6b92ee9 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 3 Sep 2023 22:32:05 +0900 Subject: [PATCH 036/119] =?UTF-8?q?[refactor]=20JwtTokenProvider=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/JwtTokenProvider.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java index 17f4cfa0d..730a9f90a 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java @@ -36,15 +36,23 @@ public JwtTokenProvider(AccessTokenConfig accessTokenConfig, RefreshTokenConfig } public String generateAccessToken(String subject) { + return generateToken(subject, accessTokenExpirationTime, accessKey); + } + + private String generateToken(String subject, Long expirationTime, Key key) { final Date now = new Date(); return Jwts.builder() .setSubject(subject) .setIssuedAt(now) - .setExpiration(new Date(now.getTime() + accessTokenExpirationTime)) - .signWith(accessKey, SignatureAlgorithm.HS512) + .setExpiration(new Date(now.getTime() + expirationTime)) + .signWith(key, SignatureAlgorithm.HS512) .compact(); } + public String generateRefreshToken() { + return generateToken(UUID.randomUUID().toString(), refreshTokenExpirationTime, refreshKey); + } + public String extractAccessToken(String accessToken) { try { return Jwts.parserBuilder() @@ -60,16 +68,6 @@ public String extractAccessToken(String accessToken) { } } - public String generateRefreshToken() { - final Date now = new Date(); - return Jwts.builder() - .setSubject(UUID.randomUUID().toString()) - .setIssuedAt(now) - .setExpiration(new Date(now.getTime() + refreshTokenExpirationTime)) - .signWith(refreshKey, SignatureAlgorithm.HS512) - .compact(); - } - public void validateRefreshToken(String refreshToken) { try { Jwts.parserBuilder() From e70169249c3e209f371563e2d418686229186c85 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 3 Sep 2023 22:48:25 +0900 Subject: [PATCH 037/119] =?UTF-8?q?[fix]=20rebase=20=EB=AA=BB=ED=95=9C=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...7__addRefreshTokenTable.sql => V8__addRefreshTokenTable.sql} | 0 ...7__addRefreshTokenTable.sql => V8__addRefreshTokenTable.sql} | 0 .../test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java | 2 +- backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename backend/src/main/resources/db/migration/h2/{V7__addRefreshTokenTable.sql => V8__addRefreshTokenTable.sql} (100%) rename backend/src/main/resources/db/migration/mysql/{V7__addRefreshTokenTable.sql => V8__addRefreshTokenTable.sql} (100%) diff --git a/backend/src/main/resources/db/migration/h2/V7__addRefreshTokenTable.sql b/backend/src/main/resources/db/migration/h2/V8__addRefreshTokenTable.sql similarity index 100% rename from backend/src/main/resources/db/migration/h2/V7__addRefreshTokenTable.sql rename to backend/src/main/resources/db/migration/h2/V8__addRefreshTokenTable.sql diff --git a/backend/src/main/resources/db/migration/mysql/V7__addRefreshTokenTable.sql b/backend/src/main/resources/db/migration/mysql/V8__addRefreshTokenTable.sql similarity index 100% rename from backend/src/main/resources/db/migration/mysql/V7__addRefreshTokenTable.sql rename to backend/src/main/resources/db/migration/mysql/V8__addRefreshTokenTable.sql diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java index 65bbc43e0..717a48695 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.domain; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java index 514bdd12a..ac22e44ff 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.trip.domain; -import static dev.tripdraw.auth.domain.OauthType.KAKAO; +import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_ALREADY_HAS_POST; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; From 60c1dfc7d764ead36f617601fcf4b84922cc343e Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 4 Sep 2023 15:15:23 +0900 Subject: [PATCH 038/119] =?UTF-8?q?[refactor]=20JwtTokenProvider=20?= =?UTF-8?q?=ED=82=A4=20=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=EC=A0=9C=EA=B1=B0=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/auth/application/JwtTokenProvider.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java index 730a9f90a..fa7664478 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/JwtTokenProvider.java @@ -27,14 +27,17 @@ public class JwtTokenProvider { private final Long refreshTokenExpirationTime; public JwtTokenProvider(AccessTokenConfig accessTokenConfig, RefreshTokenConfig refreshTokenConfig) { - byte[] accessKeyBytes = Decoders.BASE64.decode(accessTokenConfig.secretKey()); - this.accessKey = Keys.hmacShaKeyFor(accessKeyBytes); + this.accessKey = generateKey(accessTokenConfig.secretKey()); this.accessTokenExpirationTime = accessTokenConfig.expirationTime(); - byte[] refreshKeyBytes = Decoders.BASE64.decode(refreshTokenConfig.secretKey()); - this.refreshKey = Keys.hmacShaKeyFor(refreshKeyBytes); + this.refreshKey = generateKey(refreshTokenConfig.secretKey()); this.refreshTokenExpirationTime = refreshTokenConfig.expirationTime(); } + private Key generateKey(String secret) { + byte[] accessKeyBytes = Decoders.BASE64.decode(secret); + return Keys.hmacShaKeyFor(accessKeyBytes); + } + public String generateAccessToken(String subject) { return generateToken(subject, accessTokenExpirationTime, accessKey); } From 47020227d7ebd0781fafed31901512c9d20ea666 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 4 Sep 2023 15:20:04 +0900 Subject: [PATCH 039/119] =?UTF-8?q?[refactor]=20memberId=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EC=B6=9C=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/domain/RefreshTokenRepositoryTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java index 36e525227..f652fdaa6 100644 --- a/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java @@ -20,7 +20,8 @@ class RefreshTokenRepositoryTest { @Test void 토큰을_입력받아_refreshToken_객체를_반환한다() { // given - RefreshToken refreshToken = new RefreshToken(1L, "refreshToken"); + long memberId = 1L; + RefreshToken refreshToken = new RefreshToken(memberId, "refreshToken"); refreshTokenRepository.save(refreshToken); // when @@ -33,11 +34,12 @@ class RefreshTokenRepositoryTest { @Test void 사용자_아이디를_입력받아_해당되는_모든_RefreshToken을_제거한다() { // given - refreshTokenRepository.save(new RefreshToken(1L, "refreshToken")); - refreshTokenRepository.save(new RefreshToken(1L, "refreshToken")); + long memberId = 1L; + refreshTokenRepository.save(new RefreshToken(memberId, "refreshToken")); + refreshTokenRepository.save(new RefreshToken(memberId, "refreshToken")); // when - refreshTokenRepository.deleteByMemberId(1L); + refreshTokenRepository.deleteByMemberId(memberId); // then assertThat(refreshTokenRepository.count()).isZero(); From b566326f267b3e989b5e4e70fc1ba1ac91fcf30f Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 4 Sep 2023 15:20:27 +0900 Subject: [PATCH 040/119] =?UTF-8?q?[refactor]=20=EB=A7=8C=EB=A3=8C?= =?UTF-8?q?=EB=90=9C=20=EC=9D=B8=EC=A6=9D=20=ED=86=A0=ED=81=B0=20->=20?= =?UTF-8?q?=EB=A7=8C=EB=A3=8C=EB=90=9C=20=EC=97=91=EC=84=B8=EC=8A=A4=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=EC=9C=BC=EB=A1=9C=20=EC=98=88=EC=99=B8=20mes?= =?UTF-8?q?sage=20=EC=88=98=EC=A0=95=20(#337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/auth/exception/AuthExceptionType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java b/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java index 57fcbb001..9e6440d6f 100644 --- a/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/auth/exception/AuthExceptionType.java @@ -10,7 +10,7 @@ public enum AuthExceptionType implements ExceptionType { INVALID_AUTH_HEADER(BAD_REQUEST, "Authoriztion 헤더가 올바르지 않습니다."), AUTH_FAIL(FORBIDDEN, "접근 권한이 없습니다."), - EXPIRED_ACCESS_TOKEN(UNAUTHORIZED, "만료된 인증 토큰입니다."), + EXPIRED_ACCESS_TOKEN(UNAUTHORIZED, "만료된 엑세스 토큰입니다."), EXPIRED_REFRESH_TOKEN(UNAUTHORIZED, "만료된 리프레시 토큰입니다."), INVALID_TOKEN(UNAUTHORIZED, "유효하지 않은 토큰입니다."), ; From c5bc8a322b625b05f7a1987888be5d1837679774 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 7 Sep 2023 15:38:31 +0900 Subject: [PATCH 041/119] =?UTF-8?q?[refactor]=20post=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=EC=97=90=EC=84=9C=20fileType=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=9C=20=EC=9D=98=EC=A1=B4=20=EC=A0=9C=EA=B1=B0=20(#341)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/file/application/FilePath.java | 6 +++--- .../dev/tripdraw/file/application/FileUploader.java | 11 ++++------- .../main/java/dev/tripdraw/file/domain/FileType.java | 2 +- .../dev/tripdraw/post/application/PostService.java | 7 ++----- .../tripdraw/file/application/FileUploaderTest.java | 11 +++++++---- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/file/application/FilePath.java b/backend/src/main/java/dev/tripdraw/file/application/FilePath.java index 7f92c5a82..a87e1b91d 100644 --- a/backend/src/main/java/dev/tripdraw/file/application/FilePath.java +++ b/backend/src/main/java/dev/tripdraw/file/application/FilePath.java @@ -1,6 +1,6 @@ package dev.tripdraw.file.application; -import static dev.tripdraw.file.domain.FileType.POST_IMAGE; +import static dev.tripdraw.file.domain.FileType.IMAGE; import dev.tripdraw.file.domain.FileType; import java.util.Map; @@ -20,7 +20,7 @@ public FilePath(@Value("${trip.base}") String base, @Value("${trip.post}") Strin public String getPath(FileType fileType) { Map typeAndPath = Map.of( - POST_IMAGE, postImagePath + IMAGE, postImagePath ); return typeAndPath.get(fileType); @@ -28,7 +28,7 @@ public String getPath(FileType fileType) { public String getPathWithBase(FileType fileType) { Map typeAndPath = Map.of( - POST_IMAGE, base + postImagePath + IMAGE, base + postImagePath ); return typeAndPath.get(fileType); diff --git a/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java b/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java index 70de7ba22..77c941f21 100644 --- a/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java +++ b/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java @@ -18,16 +18,13 @@ public class FileUploader { private final FilePath filePath; private final FileUrlMaker fileUrlMaker; - public String upload(MultipartFile file, FileType fileType) { - if (file == null || file.isEmpty()) { - return null; - } - + public String upload(MultipartFile file) { + FileType type = FileType.from(file.getContentType()); UUID id = UUID.randomUUID(); - String filePathWithBase = filePath.getPathWithBase(fileType) + id + fileType.extension(); + String filePathWithBase = filePath.getPathWithBase(type) + id + type.extension(); fileUpload(file, filePathWithBase); - return fileUrlMaker.make(filePath.getPath(fileType) + id + fileType.extension()); + return fileUrlMaker.make(filePath.getPath(type) + id + type.extension()); } private void fileUpload(MultipartFile file, String filePathWithBase) { diff --git a/backend/src/main/java/dev/tripdraw/file/domain/FileType.java b/backend/src/main/java/dev/tripdraw/file/domain/FileType.java index 42a0efd45..9a627bd4d 100644 --- a/backend/src/main/java/dev/tripdraw/file/domain/FileType.java +++ b/backend/src/main/java/dev/tripdraw/file/domain/FileType.java @@ -12,7 +12,7 @@ @Accessors(fluent = true) @Getter public enum FileType { - POST_IMAGE(IMAGE_JPEG_VALUE, ".jpg"), + IMAGE(IMAGE_JPEG_VALUE, ".jpg"), ; private final String contentType; diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index ba6f96a96..41287c45e 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -1,12 +1,10 @@ package dev.tripdraw.post.application; -import static dev.tripdraw.file.domain.FileType.POST_IMAGE; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.file.application.FileUploader; -import dev.tripdraw.file.domain.FileType; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.domain.Post; @@ -116,7 +114,7 @@ private void updateFileOfPost(MultipartFile file, Post post) { if (file == null) { return; } - String imageUrl = fileUploader.upload(file, POST_IMAGE); + String imageUrl = fileUploader.upload(file); post.changePostImageUrl(imageUrl); } @@ -130,8 +128,7 @@ private Post registerFileToPost(MultipartFile file, Post post) { if (file == null) { return post; } - FileType type = FileType.from(file.getContentType()); - String fileUrl = fileUploader.upload(file, type); + String fileUrl = fileUploader.upload(file); post.changePostImageUrl(fileUrl); return post; diff --git a/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java b/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java index 2a0b151fb..9ba9b240a 100644 --- a/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java +++ b/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java @@ -1,5 +1,6 @@ package dev.tripdraw.file.application; +import static dev.tripdraw.file.domain.FileType.IMAGE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; @@ -8,7 +9,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import dev.tripdraw.file.domain.FileType; import dev.tripdraw.file.exception.FileIOException; import java.io.File; import java.io.IOException; @@ -44,10 +44,11 @@ class FileUploaderTest { String baseUrl = "https://example.com/files/"; String expectedFileUrl = baseUrl + randomUUID + ".jpg"; MultipartFile multipartFile = Mockito.mock(MultipartFile.class); + when(multipartFile.getContentType()).thenReturn(IMAGE.contentType()); when(fileUrlMaker.make(any())).thenReturn(expectedFileUrl); // when - String url = fileUploader.upload(multipartFile, FileType.POST_IMAGE); + String url = fileUploader.upload(multipartFile); // then assertThat(url).isEqualTo(expectedFileUrl); @@ -57,9 +58,10 @@ class FileUploaderTest { void 파일을_업로드_한다() throws IOException { // given MultipartFile multipartFile = Mockito.mock(MultipartFile.class); + when(multipartFile.getContentType()).thenReturn(IMAGE.contentType()); // when - fileUploader.upload(multipartFile, FileType.POST_IMAGE); + fileUploader.upload(multipartFile); // then verify(multipartFile, times(1)).transferTo(any(File.class)); @@ -69,10 +71,11 @@ class FileUploaderTest { void 파일_저장에_실패할시_예외륿_발생시킨다() throws IOException { // given MultipartFile multipartFile = Mockito.mock(MultipartFile.class); + when(multipartFile.getContentType()).thenReturn(IMAGE.contentType()); doThrow(new IOException()).when(multipartFile).transferTo(any(File.class)); // expect - assertThatThrownBy(() -> fileUploader.upload(multipartFile, FileType.POST_IMAGE)) + assertThatThrownBy(() -> fileUploader.upload(multipartFile)) .isInstanceOf(FileIOException.class); } } From 229feb4938d0afbf65f2de4c30058737c943e693 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 7 Sep 2023 17:16:18 +0900 Subject: [PATCH 042/119] =?UTF-8?q?[refactor]=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20=EC=A0=80=EC=9E=A5=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EB=8C=80=ED=91=9C=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=EB=8F=84=20=EB=B3=80=EA=B2=BD=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20(#341)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/application/FileUploader.java | 3 + .../post/application/PostService.java | 66 ++++++++----------- .../post/dto/PostAndPointCreateRequest.java | 5 ++ .../java/dev/tripdraw/trip/domain/Point.java | 4 ++ .../post/application/PostServiceTest.java | 46 ++++++++++--- 5 files changed, 75 insertions(+), 49 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java b/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java index 77c941f21..b4935282e 100644 --- a/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java +++ b/backend/src/main/java/dev/tripdraw/file/application/FileUploader.java @@ -19,6 +19,9 @@ public class FileUploader { private final FileUrlMaker fileUrlMaker; public String upload(MultipartFile file) { + if (file == null || file.isEmpty()) { + return null; + } FileType type = FileType.from(file.getContentType()); UUID id = UUID.randomUUID(); String filePathWithBase = filePath.getPathWithBase(type) + id + type.extension(); diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index 41287c45e..f1a969d0d 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -1,5 +1,6 @@ package dev.tripdraw.post.application; +import static java.util.Comparator.comparing; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; @@ -20,7 +21,6 @@ import dev.tripdraw.trip.domain.PointRepository; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; -import java.util.Comparator; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; @@ -45,37 +45,46 @@ public PostCreateResponse addAtCurrentPoint( MultipartFile file ) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = findValidatedTripById(postAndPointCreateRequest.tripId(), member); - - Point point = postAndPointCreateRequest.toPoint(); - point.setTrip(trip); - pointRepository.save(point); + Trip trip = tripRepository.getById(postAndPointCreateRequest.tripId()); + trip.validateAuthorization(member); + Point point = pointRepository.save(postAndPointCreateRequest.toPoint(trip)); Post post = postAndPointCreateRequest.toPost(member, point); - Post savedPost = postRepository.save(registerFileToPost(file, post)); + uploadImage(file, post, trip); + Post savedPost = postRepository.save(post); applicationEventPublisher.publishEvent(new PostCreateEvent(post.id(), trip.id())); - return PostCreateResponse.from(savedPost); } + private void uploadImage(MultipartFile file, Post post, Trip trip) { + String filename = fileUploader.upload(file); + if (filename == null) { + return; + } + post.changePostImageUrl(filename); + trip.changeImageUrl(filename); + } + public PostCreateResponse addAtExistingLocation( LoginUser loginUser, PostRequest postRequest, MultipartFile file ) { Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = findValidatedTripById(postRequest.tripId(), member); + Trip trip = tripRepository.getById(postRequest.tripId()); + trip.validateAuthorization(member); Point point = pointRepository.getById(postRequest.pointId()); Post post = postRequest.toPost(member, point); - Post savedPost = postRepository.save(registerFileToPost(file, post)); + uploadImage(file, post, trip); + Post savedPost = postRepository.save(post); applicationEventPublisher.publishEvent(new PostCreateEvent(post.id(), trip.id())); - return PostCreateResponse.from(savedPost); } + @Transactional(readOnly = true) public PostResponse read(LoginUser loginUser, Long postId) { Post post = postRepository.getById(postId); Member member = memberRepository.getById(loginUser.memberId()); @@ -83,12 +92,14 @@ public PostResponse read(LoginUser loginUser, Long postId) { return PostResponse.from(post); } + @Transactional(readOnly = true) public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { Member member = memberRepository.getById(loginUser.memberId()); - findValidatedTripById(tripId, member); + Trip trip = tripRepository.getById(tripId); + trip.validateAuthorization(member); return postRepository.findAllByTripId(tripId).stream() - .sorted(Comparator.comparing(Post::pointRecordedAt).reversed()) + .sorted(comparing(Post::id).reversed()) .collect(collectingAndThen(toList(), PostsResponse::from)); } @@ -96,42 +107,19 @@ public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdat Post post = postRepository.getById(postId); Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); + Trip trip = tripRepository.getById(post.tripId()); + trip.validateAuthorization(member); post.changeTitle(postUpdateRequest.title()); post.changeWriting(postUpdateRequest.writing()); - updateFileOfPost(file, post); + uploadImage(file, post, trip); } public void delete(LoginUser loginUser, Long postId) { Post post = postRepository.getById(postId); Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); - postRepository.deleteById(postId); } - - private void updateFileOfPost(MultipartFile file, Post post) { - if (file == null) { - return; - } - String imageUrl = fileUploader.upload(file); - post.changePostImageUrl(imageUrl); - } - - private Trip findValidatedTripById(Long tripId, Member member) { - Trip trip = tripRepository.getById(tripId); - trip.validateAuthorization(member); - return trip; - } - - private Post registerFileToPost(MultipartFile file, Post post) { - if (file == null) { - return post; - } - String fileUrl = fileUploader.upload(file); - - post.changePostImageUrl(fileUrl); - return post; - } } diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostAndPointCreateRequest.java b/backend/src/main/java/dev/tripdraw/post/dto/PostAndPointCreateRequest.java index 6b4edac8a..1f368b674 100644 --- a/backend/src/main/java/dev/tripdraw/post/dto/PostAndPointCreateRequest.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostAndPointCreateRequest.java @@ -6,6 +6,7 @@ import dev.tripdraw.member.domain.Member; import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; @@ -48,6 +49,10 @@ public Point toPoint() { return new Point(latitude, longitude, recordedAt); } + public Point toPoint(Trip trip) { + return new Point(latitude, longitude, recordedAt, trip); + } + public Post toPost(Member member, Point point) { return new Post(title, point, address, writing, member, tripId); } diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/Point.java b/backend/src/main/java/dev/tripdraw/trip/domain/Point.java index f18491ace..84e916d21 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/Point.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Point.java @@ -48,6 +48,10 @@ public Point(Double latitude, Double longitude, LocalDateTime recordedAt) { this(null, latitude, longitude, false, recordedAt, null); } + public Point(Double latitude, Double longitude, LocalDateTime recordedAt, Trip trip) { + this(null, latitude, longitude, false, recordedAt, trip); + } + public Point(Double latitude, Double longitude, boolean hasPost, LocalDateTime recordedAt) { this(null, latitude, longitude, hasPost, recordedAt, null); } diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index 0f0d28c50..9ea9cb413 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -12,9 +12,12 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.draw.application.RouteImageGenerator; +import dev.tripdraw.file.application.FileUploader; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; @@ -35,9 +38,9 @@ import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.BDDMockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.web.multipart.MultipartFile; @ServiceTest class PostServiceTest { @@ -57,6 +60,9 @@ class PostServiceTest { @MockBean private RouteImageGenerator routeImageGenerator; + @MockBean + private FileUploader fileUploader; + private Trip trip; private LoginUser loginUser; private LoginUser otherUser; @@ -77,7 +83,7 @@ void setUp() { @Test void 현재_위치에_대한_감상을_생성한다() { // given - PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( + PostAndPointCreateRequest request = new PostAndPointCreateRequest( trip.id(), "우도의 바닷가", "제주특별자치도 제주시 애월읍 소길리", @@ -88,8 +94,7 @@ void setUp() { ); // when - PostCreateResponse postCreateResponse = postService.addAtCurrentPoint(loginUser, postAndPointCreateRequest, - null); + PostCreateResponse postCreateResponse = postService.addAtCurrentPoint(loginUser, request, null); // then assertThat(postCreateResponse.postId()).isNotNull(); @@ -144,7 +149,7 @@ void setUp() { "제주특별자치도 제주시 애월읍 소길리", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다." ); - BDDMockito.given(routeImageGenerator.generate(any(), any(), any(), any())).willReturn("hello.png"); + given(routeImageGenerator.generate(any(), any(), any(), any())).willReturn("hello.png"); // when PostCreateResponse postCreateResponse = postService.addAtExistingLocation(loginUser, postRequest, null); @@ -223,7 +228,7 @@ void setUp() { @Test void 특정_감상을_조회할_때_존재하지_않는_감상_ID이면_예외를_발생시킨다() { - // given & expect + // expect assertThatThrownBy(() -> postService.read(loginUser, Long.MIN_VALUE)) .isInstanceOf(PostException.class) .hasMessage(POST_NOT_FOUND.message()); @@ -286,7 +291,7 @@ void setUp() { @Test void 특정_여행의_모든_감상을_조회할_때_존재하지_않는_여행_ID이면_예외가_발생한다() { - // given & expect + // expect assertThatThrownBy(() -> postService.readAllByTripId(loginUser, Long.MIN_VALUE)) .isInstanceOf(TripException.class) .hasMessage(TRIP_NOT_FOUND.message()); @@ -294,7 +299,7 @@ void setUp() { @Test void 특정_여행의_모든_감상을_조회할_때_로그인_한_사용자가_여행의_주인이_아니면_예외가_발생한다() { - // given & expect + // expect assertThatThrownBy(() -> postService.readAllByTripId(otherUser, trip.id())) .isInstanceOf(TripException.class) .hasMessage(NOT_AUTHORIZED_TO_TRIP.message()); @@ -325,7 +330,6 @@ void setUp() { @Test void 감상을_수정할_때_존재하지_않는_감상_ID이면_예외를_발생시킨다() { // given - PostCreateResponse postCreateResponse = createPost(); PostUpdateRequest postUpdateRequest = new PostUpdateRequest( "우도의 땅콩 아이스크림", "수정한 내용입니다." @@ -383,7 +387,7 @@ void setUp() { @Test void 감상을_삭제할_때_존재하지_않는_감상_ID이면_예외를_발생시킨다() { - // given & expect + // expect assertThatThrownBy(() -> postService.delete(loginUser, Long.MIN_VALUE)) .isInstanceOf(PostException.class) .hasMessage(POST_NOT_FOUND.message()); @@ -412,6 +416,28 @@ void setUp() { .hasMessage(NOT_AUTHORIZED_TO_POST.message()); } + @Test + void 이미지를_저장하는_경우_여행의_대표이미지도_변경한다() { + // given + PostAndPointCreateRequest request = new PostAndPointCreateRequest( + trip.id(), + "우도의 바닷가", + "제주특별자치도 제주시 애월읍 소길리", + "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", + 1.1, + 2.2, + LocalDateTime.of(2023, 7, 18, 20, 24) + ); + MultipartFile multipartFile = mock(MultipartFile.class); + given(fileUploader.upload(any())).willReturn("hello.png"); + + // when + postService.addAtCurrentPoint(loginUser, request, multipartFile); + + // then + assertThat(trip.imageUrl()).isEqualTo("hello.png"); + } + private PostCreateResponse createPost() { PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( trip.id(), From ae223b3a8df172b82a2a9c2b7979e07a1c8e0cc8 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 7 Sep 2023 17:50:02 +0900 Subject: [PATCH 043/119] =?UTF-8?q?[refactor]=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20=EB=A1=9C=EC=A7=81=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#341)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/dev/tripdraw/post/application/PostService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index f1a969d0d..3cd1e95bb 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -99,7 +99,7 @@ public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { trip.validateAuthorization(member); return postRepository.findAllByTripId(tripId).stream() - .sorted(comparing(Post::id).reversed()) + .sorted(comparing(Post::pointRecordedAt).reversed()) .collect(collectingAndThen(toList(), PostsResponse::from)); } From a5550c444bb245bfaf89740a2047af3ea9c1a2fb Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 7 Sep 2023 17:56:01 +0900 Subject: [PATCH 044/119] =?UTF-8?q?[test]=20FileUploadTest=20=EC=98=A4?= =?UTF-8?q?=ED=83=80=20=EC=88=98=EC=A0=95=20(#341)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/file/application/FileUploaderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java b/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java index 9ba9b240a..9b64bd814 100644 --- a/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java +++ b/backend/src/test/java/dev/tripdraw/file/application/FileUploaderTest.java @@ -68,7 +68,7 @@ class FileUploaderTest { } @Test - void 파일_저장에_실패할시_예외륿_발생시킨다() throws IOException { + void 파일_저장에_실패할시_예외를_발생시킨다() throws IOException { // given MultipartFile multipartFile = Mockito.mock(MultipartFile.class); when(multipartFile.getContentType()).thenReturn(IMAGE.contentType()); From aa5518ecb3045ea33af155f064a06be0df52a9f9 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 8 Sep 2023 10:20:35 +0900 Subject: [PATCH 045/119] =?UTF-8?q?[fix]=20dto=EC=9D=98=20image=20null?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EB=B9=88=20=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EC=97=B4=EC=9D=84=20=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95=20(#343)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/dev/tripdraw/post/dto/PostResponse.java | 7 +++++-- .../src/main/java/dev/tripdraw/trip/dto/TripResponse.java | 7 +++++-- .../java/dev/tripdraw/trip/dto/TripSearchResponse.java | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostResponse.java b/backend/src/main/java/dev/tripdraw/post/dto/PostResponse.java index 20b0ee460..3dcfdb93f 100644 --- a/backend/src/main/java/dev/tripdraw/post/dto/PostResponse.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostResponse.java @@ -3,6 +3,7 @@ import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.dto.PointResponse; import io.swagger.v3.oas.annotations.media.Schema; +import java.util.Objects; public record PostResponse( @Schema(description = "감상의 Id", example = "1") @@ -30,6 +31,8 @@ public record PostResponse( String routeImageUrl ) { + private static final String EMPTY_IMAGE_URL = ""; + public static PostResponse from(Post post) { return new PostResponse( post.id(), @@ -38,8 +41,8 @@ public static PostResponse from(Post post) { post.address(), post.writing(), PointResponse.from(post.point()), - post.postImageUrl(), - post.routeImageUrl() + Objects.requireNonNullElse(post.postImageUrl(), EMPTY_IMAGE_URL), + Objects.requireNonNullElse(post.routeImageUrl(), EMPTY_IMAGE_URL) ); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripResponse.java index 146fd3c94..51051c363 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripResponse.java @@ -4,6 +4,7 @@ import dev.tripdraw.trip.domain.TripStatus; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; +import java.util.Objects; public record TripResponse( @Schema(description = "여행 Id", example = "1") @@ -25,14 +26,16 @@ public record TripResponse( String routeImageUrl ) { + private static final String EMPTY_IMAGE_URL = ""; + public static TripResponse from(Trip trip) { return new TripResponse( trip.id(), trip.nameValue(), generateRoute(trip), trip.status(), - trip.imageUrl(), - trip.routeImageUrl() + Objects.requireNonNullElse(trip.imageUrl(), EMPTY_IMAGE_URL), + Objects.requireNonNullElse(trip.routeImageUrl(), EMPTY_IMAGE_URL) ); } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java index 105522c2f..c388137f4 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java @@ -25,7 +25,7 @@ public static TripSearchResponse from(Trip trip) { trip.id(), trip.nameValue(), Objects.requireNonNullElse(trip.imageUrl(), EMPTY_IMAGE_URL), - Objects.requireNonNullElse(trip.imageUrl(), EMPTY_IMAGE_URL) + Objects.requireNonNullElse(trip.routeImageUrl(), EMPTY_IMAGE_URL) ); } } From 0e9d8df44c5f5f5993846d1d2043d0f3fe1910f5 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 8 Sep 2023 10:25:02 +0900 Subject: [PATCH 046/119] =?UTF-8?q?[test]=20isNull=EB=A1=9C=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=ED=95=98=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#343)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/post/presentation/PostControllerTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index cbe85dd93..a41a2bda6 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -380,7 +380,8 @@ public void setUp() { softly.assertThat(getResponse.title()).isEqualTo("우도의 바닷가"); softly.assertThat(getResponse.pointResponse().pointId()).isNotNull(); softly.assertThat(getResponse.pointResponse().latitude()).isEqualTo(1.1); - softly.assertThat(getResponse.postImageUrl()).isNull(); + softly.assertThat(getResponse.postImageUrl()).isEmpty(); + softly.assertThat(getResponse.routeImageUrl()).isEmpty(); }); } From 65bc548f77c5557e75e754b75d68a3d4881de358 Mon Sep 17 00:00:00 2001 From: Herb Date: Fri, 8 Sep 2023 10:57:21 +0900 Subject: [PATCH 047/119] =?UTF-8?q?[chore]=20dev=20cd=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index 4c807bee2..1e51c0343 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -7,7 +7,7 @@ on: jobs: deploy: - runs-on: self-hosted + runs-on: backend-dev-cd steps: - name: 배포 스크립트 실행 From 8b8f4e69ebc91cb221cbe30010914784ec46336d Mon Sep 17 00:00:00 2001 From: greeng00se Date: Wed, 13 Sep 2023 15:08:18 +0900 Subject: [PATCH 048/119] =?UTF-8?q?[refactor]=20OAuth=20API=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C=EC=97=90=20=ED=95=B4=EB=8B=B9=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=EC=9D=84=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=EC=97=90=EC=84=9C=20=EC=A0=9C=EC=99=B8=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthService.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java index dcfddd589..5b7b15ea4 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java @@ -20,19 +20,19 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionTemplate; @RequiredArgsConstructor -@Transactional @Service public class AuthService { private static final String EMPTY_TOKEN = ""; + private final TransactionTemplate transactionTemplate; private final MemberRepository memberRepository; + private final RefreshTokenRepository refreshTokenRepository; private final OauthClientProvider oauthClientProvider; private final JwtTokenProvider jwtTokenProvider; - private final RefreshTokenRepository refreshTokenRepository; public OauthResponse login(OauthRequest oauthRequest) { OauthClient oauthClient = oauthClientProvider.provide(oauthRequest.oauthType()); @@ -51,25 +51,28 @@ public OauthResponse login(OauthRequest oauthRequest) { return generateToken(findMember.id()); } - private OauthResponse generateToken(Long memberId) { - String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); - String refreshToken = jwtTokenProvider.generateRefreshToken(); - refreshTokenRepository.deleteByMemberId(memberId); - RefreshToken savedRefreshToken = refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); - return new OauthResponse(accessToken, savedRefreshToken.token()); - } - public OauthResponse register(RegisterRequest registerRequest) { OauthClient oauthClient = oauthClientProvider.provide(registerRequest.oauthType()); OauthInfo oauthInfo = oauthClient.requestOauthInfo(registerRequest.oauthToken()); - Member member = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) - .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); + return transactionTemplate.execute(status -> { + Member member = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) + .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); + validateDuplicateNickname(registerRequest.nickname()); + member.changeNickname(registerRequest.nickname()); + return generateToken(member.id()); + }); + } - String nickname = registerRequest.nickname(); - validateDuplicateNickname(nickname); - member.changeNickname(nickname); - return generateToken(member.id()); + private OauthResponse generateToken(Long memberId) { + String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); + String refreshToken = jwtTokenProvider.generateRefreshToken(); + + RefreshToken savedRefreshToken = transactionTemplate.execute(status -> { + refreshTokenRepository.deleteByMemberId(memberId); + return refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); + }); + return new OauthResponse(accessToken, savedRefreshToken.token()); } private void validateDuplicateNickname(String nickname) { From 9e28c2998628f39c77ad716f8932e7f4619d7b99 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Thu, 14 Sep 2023 16:53:58 +0900 Subject: [PATCH 049/119] =?UTF-8?q?[feat]=20Member=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?Event=20=EA=B5=AC=ED=98=84=20(#346)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/application/MemberService.java | 10 ++--- .../member/domain/MemberDeleteEvent.java | 4 ++ .../application/PostDeleteEventHandler.java | 25 ++++++++++++ .../application/TripDeleteEventHandler.java | 21 ++++++++++ .../member/application/MemberServiceTest.java | 17 ++++++-- .../PostDeleteEventHandlerTest.java | 40 +++++++++++++++++++ .../TripDeleteEventHandlerTest.java | 40 +++++++++++++++++++ .../trip/domain/TripRepositoryTest.java | 14 +++++++ 8 files changed, 161 insertions(+), 10 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/member/domain/MemberDeleteEvent.java create mode 100644 backend/src/main/java/dev/tripdraw/post/application/PostDeleteEventHandler.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/application/TripDeleteEventHandler.java create mode 100644 backend/src/test/java/dev/tripdraw/post/application/PostDeleteEventHandlerTest.java create mode 100644 backend/src/test/java/dev/tripdraw/trip/application/TripDeleteEventHandlerTest.java diff --git a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java index 52593a4b8..2f056fd01 100644 --- a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java +++ b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java @@ -2,11 +2,11 @@ import dev.tripdraw.auth.application.JwtTokenProvider; import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberDeleteEvent; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.dto.MemberSearchResponse; -import dev.tripdraw.post.domain.PostRepository; -import dev.tripdraw.trip.domain.TripRepository; import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,9 +16,8 @@ public class MemberService { private final MemberRepository memberRepository; - private final TripRepository tripRepository; - private final PostRepository postRepository; private final JwtTokenProvider jwtTokenProvider; + private final ApplicationEventPublisher publisher; @Transactional(readOnly = true) public boolean existsById(Long memberId) { @@ -34,8 +33,7 @@ public MemberSearchResponse findByCode(String code) { public void deleteByCode(String code) { Long memberId = Long.valueOf(jwtTokenProvider.extractAccessToken(code)); - postRepository.deleteByMemberId(memberId); - tripRepository.deleteByMemberId(memberId); + publisher.publishEvent(new MemberDeleteEvent(memberId)); memberRepository.deleteById(memberId); } } diff --git a/backend/src/main/java/dev/tripdraw/member/domain/MemberDeleteEvent.java b/backend/src/main/java/dev/tripdraw/member/domain/MemberDeleteEvent.java new file mode 100644 index 000000000..8fe1df59b --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/member/domain/MemberDeleteEvent.java @@ -0,0 +1,4 @@ +package dev.tripdraw.member.domain; + +public record MemberDeleteEvent(Long memberId) { +} diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostDeleteEventHandler.java b/backend/src/main/java/dev/tripdraw/post/application/PostDeleteEventHandler.java new file mode 100644 index 000000000..8be36b7a0 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/application/PostDeleteEventHandler.java @@ -0,0 +1,25 @@ +package dev.tripdraw.post.application; + +import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE; + +import dev.tripdraw.member.domain.MemberDeleteEvent; +import dev.tripdraw.post.domain.PostRepository; +import org.springframework.context.event.EventListener; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +@Component +public class PostDeleteEventHandler { + + private final PostRepository postRepository; + + public PostDeleteEventHandler(PostRepository postRepository) { + this.postRepository = postRepository; + } + + @Order(HIGHEST_PRECEDENCE) + @EventListener + public void deletePostByMemberId(MemberDeleteEvent event) { + postRepository.deleteByMemberId(event.memberId()); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripDeleteEventHandler.java b/backend/src/main/java/dev/tripdraw/trip/application/TripDeleteEventHandler.java new file mode 100644 index 000000000..c23fbdfb3 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripDeleteEventHandler.java @@ -0,0 +1,21 @@ +package dev.tripdraw.trip.application; + +import dev.tripdraw.member.domain.MemberDeleteEvent; +import dev.tripdraw.trip.domain.TripRepository; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +@Component +public class TripDeleteEventHandler { + + private final TripRepository tripRepository; + + public TripDeleteEventHandler(TripRepository tripRepository) { + this.tripRepository = tripRepository; + } + + @EventListener + public void deletePostByMemberId(MemberDeleteEvent event) { + tripRepository.deleteByMemberId(event.memberId()); + } +} diff --git a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java index 3aac554fc..42f7c7200 100644 --- a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java @@ -8,6 +8,7 @@ import dev.tripdraw.auth.application.JwtTokenProvider; import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberDeleteEvent; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.dto.MemberSearchResponse; import dev.tripdraw.member.exception.MemberException; @@ -22,13 +23,19 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.event.ApplicationEvents; +import org.springframework.test.context.event.RecordApplicationEvents; +@RecordApplicationEvents @ServiceTest class MemberServiceTest { @Autowired private MemberService memberService; + @Autowired + private ApplicationEvents applicationEvents; + @Autowired private MemberRepository memberRepository; @@ -44,7 +51,6 @@ class MemberServiceTest { private Member member; private String code; private Trip trip; - private Post post; @BeforeEach void setUp() { @@ -54,7 +60,7 @@ void setUp() { trip = tripRepository.save(new Trip(TripName.from("통후추의 여행"), member)); Point point = new Point(3.14, 5.25, LocalDateTime.now()); trip.add(point); - post = postRepository.save(new Post( + postRepository.save(new Post( "제목", point, "위치", @@ -105,10 +111,13 @@ void setUp() { memberService.deleteByCode(code); // then + long publishedEvents = applicationEvents.stream(MemberDeleteEvent.class) + .filter(event -> event.memberId().equals(member.id())) + .count(); + assertSoftly(softly -> { softly.assertThat(memberRepository.findById(member.id())).isEmpty(); - softly.assertThat(tripRepository.findById(trip.id())).isEmpty(); - softly.assertThat(postRepository.findById(post.id())).isEmpty(); + softly.assertThat(publishedEvents).isOne(); }); } } diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostDeleteEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostDeleteEventHandlerTest.java new file mode 100644 index 000000000..32f3f5e85 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/post/application/PostDeleteEventHandlerTest.java @@ -0,0 +1,40 @@ +package dev.tripdraw.post.application; + +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + +import dev.tripdraw.member.domain.MemberDeleteEvent; +import dev.tripdraw.post.domain.PostRepository; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@ExtendWith(MockitoExtension.class) +class PostDeleteEventHandlerTest { + + @Mock + private PostRepository postRepository; + + @InjectMocks + private PostDeleteEventHandler postDeleteEventHandler; + + @Test + void 회원_삭제_이벤트를_받아_회원의_감상을_삭제한다() { + // given + MemberDeleteEvent memberDeleteEvent = new MemberDeleteEvent(1L); + + // when + postDeleteEventHandler.deletePostByMemberId(memberDeleteEvent); + + // then + then(postRepository) + .should(times(1)) + .deleteByMemberId(1L); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripDeleteEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripDeleteEventHandlerTest.java new file mode 100644 index 000000000..5ac2d23bf --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripDeleteEventHandlerTest.java @@ -0,0 +1,40 @@ +package dev.tripdraw.trip.application; + +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + +import dev.tripdraw.member.domain.MemberDeleteEvent; +import dev.tripdraw.trip.domain.TripRepository; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@ExtendWith(MockitoExtension.class) +class TripDeleteEventHandlerTest { + + @Mock + private TripRepository tripRepository; + + @InjectMocks + private TripDeleteEventHandler tripDeleteEventHandler; + + @Test + void 회원_삭제_이벤트를_받아_회원의_여행을_삭제한다() { + // given + MemberDeleteEvent memberDeleteEvent = new MemberDeleteEvent(1L); + + // when + tripDeleteEventHandler.deletePostByMemberId(memberDeleteEvent); + + // then + then(tripRepository) + .should(times(1)) + .deleteByMemberId(1L); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index b448e684e..2bc7ee8b4 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -94,6 +94,20 @@ void setUp() { assertThat(tripRepository.findById(trip.id())).isEmpty(); } + @Test + void 회원_ID로_모든_여행을_삭제한다() { + // given + Trip trip = new Trip(TripName.from("제주도 여행"), member); + tripRepository.save(trip); + tripRepository.save(new Trip(TripName.from("제주도 여행"), member)); + + // when + tripRepository.deleteByMemberId(member.id()); + + // then + assertThat(tripRepository.findById(trip.id())).isEmpty(); + } + @Test void 여행_ID로_여행을_조회한다() { // given From 36bdcd837514a8b4d14c5c1e94c3a3e7b207ff0a Mon Sep 17 00:00:00 2001 From: Combi153 Date: Thu, 14 Sep 2023 21:17:13 +0900 Subject: [PATCH 050/119] =?UTF-8?q?[build]=20Querydsl=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/backend/build.gradle b/backend/build.gradle index cb1b4be1c..6724178ae 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -54,6 +54,12 @@ dependencies { // lombok compileOnly 'org.projectlombok:lombok:1.18.28' annotationProcessor 'org.projectlombok:lombok:1.18.28' + + // querydsl + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" } processResources.dependsOn('copySecret') @@ -71,3 +77,18 @@ tasks.named('test') { tasks.named('compileJava') { inputs.files(tasks.named('processResources')) } + +// Querydsl +def querydslDir = "$buildDir/generated/querydsl" + +sourceSets { + main.java.srcDirs += [querydslDir] +} + +tasks.withType(JavaCompile).configureEach { + options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir) +} + +clean.doLast { + file(querydslDir).deleteDir() +} From 8684f80da0b0f06130e787c2b7b235b01e1ff774 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 15 Sep 2023 01:29:16 +0900 Subject: [PATCH 051/119] =?UTF-8?q?[feat]=20refreshToken=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EC=B6=94=EA=B0=80=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/auth/config/RefreshTokenConfig.java | 1 + .../src/main/java/dev/tripdraw/auth/domain/RefreshToken.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java index c3f05dc88..a1af2f37c 100644 --- a/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java +++ b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java @@ -7,4 +7,5 @@ public record RefreshTokenConfig( String secretKey, Long expirationTime ) { + } diff --git a/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java index 66caf2d23..7b393e55d 100644 --- a/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java +++ b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java @@ -28,6 +28,11 @@ public class RefreshToken extends BaseEntity { private String token; public RefreshToken(Long memberId, String token) { + this(null, memberId, token); + } + + public RefreshToken(Long id, Long memberId, String token) { + this.id = id; this.memberId = memberId; this.token = token; } From 65fd9e9ea44c05a988a71bb7420f7887b2881766 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 15 Sep 2023 01:29:48 +0900 Subject: [PATCH 052/119] =?UTF-8?q?[refactor]=20Api=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=20OAuthService=EB=A1=9C=20=EB=B6=84=EB=A6=AC=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/OAuthService.java | 20 ++++++++ .../auth/application/OAuthServiceTest.java | 48 +++++++++++++++++++ .../tripdraw/test/fixture/MemberFixture.java | 11 +++++ 3 files changed, 79 insertions(+) create mode 100644 backend/src/main/java/dev/tripdraw/auth/application/OAuthService.java create mode 100644 backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java create mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/MemberFixture.java diff --git a/backend/src/main/java/dev/tripdraw/auth/application/OAuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/OAuthService.java new file mode 100644 index 000000000..3356a2c5e --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/application/OAuthService.java @@ -0,0 +1,20 @@ +package dev.tripdraw.auth.application; + +import dev.tripdraw.auth.dto.OauthInfo; +import dev.tripdraw.auth.oauth.OauthClient; +import dev.tripdraw.auth.oauth.OauthClientProvider; +import dev.tripdraw.common.auth.OauthType; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class OAuthService { + + private final OauthClientProvider oauthClientProvider; + + public OauthInfo request(OauthType oauthType, String oauthToken) { + OauthClient oauthClient = oauthClientProvider.provide(oauthType); + return oauthClient.requestOauthInfo(oauthToken); + } +} diff --git a/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java new file mode 100644 index 000000000..dea6fa39f --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java @@ -0,0 +1,48 @@ +package dev.tripdraw.auth.application; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.Mockito.when; + +import dev.tripdraw.auth.dto.OauthInfo; +import dev.tripdraw.auth.oauth.OauthClientProvider; +import dev.tripdraw.test.TestKakaoApiClient; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@SpringBootTest +class OAuthServiceTest { + + @Autowired + private OAuthService oAuthService; + + @MockBean + private OauthClientProvider oauthClientProvider; + + @BeforeEach + void setUp() { + when(oauthClientProvider.provide(KAKAO)).thenReturn(new TestKakaoApiClient()); + } + + @Test + void Oauth_공통_정보를_반환한다() { + // given + String oauthToken = "oauth.kakao.token"; + + // when + OauthInfo oauthInfo = oAuthService.request(KAKAO, oauthToken); + + // then + assertSoftly(softly -> { + softly.assertThat(oauthInfo.oauthId()).isEqualTo("kakaoId"); + softly.assertThat(oauthInfo.oauthType()).isEqualTo(KAKAO); + }); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/MemberFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/MemberFixture.java new file mode 100644 index 000000000..4b051817e --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/fixture/MemberFixture.java @@ -0,0 +1,11 @@ +package dev.tripdraw.test.fixture; + +import dev.tripdraw.common.auth.OauthType; +import dev.tripdraw.member.domain.Member; + +public class MemberFixture { + + public static Member 사용자() { + return new Member(1L, "통후추", "", OauthType.KAKAO); + } +} From c6b2f6ff67a5f91c91338dabea503d85014852f3 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 15 Sep 2023 01:30:14 +0900 Subject: [PATCH 053/119] =?UTF-8?q?[refactor]=20AuthService=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthFacadeService.java | 31 +++++ .../auth/application/AuthService.java | 77 ++++-------- .../auth/presentation/AuthController.java | 10 +- .../application/AuthFacadeServiceTest.java | 114 +++++++++++++++++ .../auth/application/AuthServiceTest.java | 119 ++++++++---------- 5 files changed, 225 insertions(+), 126 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java create mode 100644 backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java new file mode 100644 index 000000000..f8bfa11b2 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java @@ -0,0 +1,31 @@ +package dev.tripdraw.auth.application; + +import dev.tripdraw.auth.dto.OauthInfo; +import dev.tripdraw.auth.dto.OauthRequest; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.dto.RegisterRequest; +import dev.tripdraw.auth.dto.TokenRefreshRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class AuthFacadeService { + + private final OAuthService oAuthService; + private final AuthService authService; + + public OauthResponse login(OauthRequest oauthRequest) { + OauthInfo oauthInfo = oAuthService.request(oauthRequest.oauthType(), oauthRequest.oauthToken()); + return authService.login(oauthInfo); + } + + public OauthResponse register(RegisterRequest registerRequest) { + OauthInfo oauthInfo = oAuthService.request(registerRequest.oauthType(), registerRequest.oauthToken()); + return authService.register(oauthInfo, registerRequest.nickname()); + } + + public OauthResponse refresh(TokenRefreshRequest tokenRefreshRequest) { + return authService.refresh(tokenRefreshRequest.refreshToken()); + } +} diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java index 5b7b15ea4..b8f25f505 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java @@ -7,84 +7,59 @@ import dev.tripdraw.auth.domain.RefreshToken; import dev.tripdraw.auth.domain.RefreshTokenRepository; import dev.tripdraw.auth.dto.OauthInfo; -import dev.tripdraw.auth.dto.OauthRequest; import dev.tripdraw.auth.dto.OauthResponse; -import dev.tripdraw.auth.dto.RegisterRequest; -import dev.tripdraw.auth.dto.TokenRefreshRequest; import dev.tripdraw.auth.exception.AuthException; -import dev.tripdraw.auth.oauth.OauthClient; -import dev.tripdraw.auth.oauth.OauthClientProvider; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.support.TransactionTemplate; +import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor +@Transactional @Service public class AuthService { - private static final String EMPTY_TOKEN = ""; + private static final OauthResponse EMPTY_TOKEN_RESPONSE = new OauthResponse("", ""); - private final TransactionTemplate transactionTemplate; - private final MemberRepository memberRepository; - private final RefreshTokenRepository refreshTokenRepository; - private final OauthClientProvider oauthClientProvider; private final JwtTokenProvider jwtTokenProvider; + private final RefreshTokenRepository refreshTokenRepository; + private final MemberRepository memberRepository; - public OauthResponse login(OauthRequest oauthRequest) { - OauthClient oauthClient = oauthClientProvider.provide(oauthRequest.oauthType()); - OauthInfo oauthInfo = oauthClient.requestOauthInfo(oauthRequest.oauthToken()); - - Optional member = memberRepository.findByOauthIdAndOauthType( - oauthInfo.oauthId(), - oauthInfo.oauthType() - ); - if (member.isEmpty()) { - memberRepository.save(Member.of(oauthInfo.oauthId(), oauthInfo.oauthType())); - return new OauthResponse(EMPTY_TOKEN, EMPTY_TOKEN); - } - - Member findMember = member.orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); - return generateToken(findMember.id()); - } - - public OauthResponse register(RegisterRequest registerRequest) { - OauthClient oauthClient = oauthClientProvider.provide(registerRequest.oauthType()); - OauthInfo oauthInfo = oauthClient.requestOauthInfo(registerRequest.oauthToken()); - - return transactionTemplate.execute(status -> { - Member member = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) - .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); - validateDuplicateNickname(registerRequest.nickname()); - member.changeNickname(registerRequest.nickname()); - return generateToken(member.id()); - }); + public OauthResponse login(OauthInfo oauthInfo) { + return memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) + .map(member -> generateOAuthResponse(member.id())) + .orElseGet(() -> { + memberRepository.save(Member.of(oauthInfo.oauthId(), oauthInfo.oauthType())); + return EMPTY_TOKEN_RESPONSE; + }); } - private OauthResponse generateToken(Long memberId) { + private OauthResponse generateOAuthResponse(Long memberId) { String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); String refreshToken = jwtTokenProvider.generateRefreshToken(); - RefreshToken savedRefreshToken = transactionTemplate.execute(status -> { - refreshTokenRepository.deleteByMemberId(memberId); - return refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); - }); - return new OauthResponse(accessToken, savedRefreshToken.token()); + refreshTokenRepository.deleteByMemberId(memberId); + refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); + return new OauthResponse(accessToken, refreshToken); } - private void validateDuplicateNickname(String nickname) { + public OauthResponse register(OauthInfo oauthInfo, String nickname) { if (memberRepository.existsByNickname(nickname)) { throw new MemberException(DUPLICATE_NICKNAME); } + + Member member = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) + .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); + member.changeNickname(nickname); + return generateOAuthResponse(member.id()); } - public OauthResponse refresh(TokenRefreshRequest tokenRefreshRequest) { - jwtTokenProvider.validateRefreshToken(tokenRefreshRequest.refreshToken()); - RefreshToken refreshToken = refreshTokenRepository.findByToken(tokenRefreshRequest.refreshToken()) + public OauthResponse refresh(String token) { + jwtTokenProvider.validateRefreshToken(token); + RefreshToken refreshToken = refreshTokenRepository.findByToken(token) .orElseThrow(() -> new AuthException(INVALID_TOKEN)); - return generateToken(refreshToken.memberId()); + return generateOAuthResponse(refreshToken.memberId()); } } diff --git a/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java index ce2b7b7ce..8a6e313f0 100644 --- a/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java +++ b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java @@ -1,6 +1,6 @@ package dev.tripdraw.auth.presentation; -import dev.tripdraw.auth.application.AuthService; +import dev.tripdraw.auth.application.AuthFacadeService; import dev.tripdraw.auth.dto.OauthRequest; import dev.tripdraw.auth.dto.OauthResponse; import dev.tripdraw.auth.dto.RegisterRequest; @@ -20,7 +20,7 @@ @RestController public class AuthController { - private final AuthService authService; + private final AuthFacadeService authFacadeService; @Operation(summary = "소셜 로그인 API", description = "소셜 로그인을 합니다.") @ApiResponse( @@ -29,7 +29,7 @@ public class AuthController { ) @PostMapping("/oauth/login") public ResponseEntity login(@RequestBody OauthRequest oauthRequest) { - OauthResponse oauthResponse = authService.login(oauthRequest); + OauthResponse oauthResponse = authFacadeService.login(oauthRequest); return ResponseEntity.ok(oauthResponse); } @@ -40,7 +40,7 @@ public ResponseEntity login(@RequestBody OauthRequest oauthReques ) @PostMapping("/oauth/register") public ResponseEntity register(@Valid @RequestBody RegisterRequest registerRequest) { - OauthResponse oauthResponse = authService.register(registerRequest); + OauthResponse oauthResponse = authFacadeService.register(registerRequest); return ResponseEntity.ok(oauthResponse); } @@ -51,7 +51,7 @@ public ResponseEntity register(@Valid @RequestBody RegisterReques ) @PostMapping("/oauth/refresh") public ResponseEntity refresh(@Valid @RequestBody TokenRefreshRequest tokenRefreshRequest) { - OauthResponse oauthResponse = authService.refresh(tokenRefreshRequest); + OauthResponse oauthResponse = authFacadeService.refresh(tokenRefreshRequest); return ResponseEntity.ok(oauthResponse); } } diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java new file mode 100644 index 000000000..60eb17e0d --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java @@ -0,0 +1,114 @@ +package dev.tripdraw.auth.application; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.Mockito.when; + +import dev.tripdraw.auth.domain.RefreshToken; +import dev.tripdraw.auth.domain.RefreshTokenRepository; +import dev.tripdraw.auth.dto.OauthRequest; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.dto.RegisterRequest; +import dev.tripdraw.auth.dto.TokenRefreshRequest; +import dev.tripdraw.auth.oauth.OauthClientProvider; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.test.ServiceTest; +import dev.tripdraw.test.TestKakaoApiClient; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; + +@ServiceTest +class AuthFacadeServiceTest { + + @Autowired + private AuthFacadeService authFacadeService; + + @MockBean + private OauthClientProvider oauthClientProvider; + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private RefreshTokenRepository refreshTokenRepository; + + @Autowired + private JwtTokenProvider jwtTokenProvider; + + @BeforeEach + void setUp() { + when(oauthClientProvider.provide(KAKAO)).thenReturn(new TestKakaoApiClient()); + } + + @Test + void 가입된_회원이_카카오_소셜_로그인하면_토큰이_포함된_응답을_반환한다() { + // given + memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + OauthRequest oauthRequest = new OauthRequest(KAKAO, "oauth.kakao.token"); + + // when + OauthResponse response = authFacadeService.login(oauthRequest); + + // then + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isNotEmpty(); + softly.assertThat(response.refreshToken()).isNotEmpty(); + }); + } + + @Test + void 신규_회원이_로그인하면_회원을_저장하고_빈_토큰이_포함된_응답을_반환한다() { + // given + OauthRequest oauthRequest = new OauthRequest(KAKAO, "oauth.kakao.token"); + + // when + OauthResponse response = authFacadeService.login(oauthRequest); + + // then + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isEmpty(); + softly.assertThat(response.refreshToken()).isEmpty(); + }); + } + + @Test + void 신규_회원의_닉네임을_등록하면_토큰이_포함된_응답을_반환한다() { + // given + Member member = Member.of("kakaoId", KAKAO); + memberRepository.save(member); + + RegisterRequest registerRequest = new RegisterRequest("통후추", KAKAO, "oauth.kakao.token"); + + // when + OauthResponse response = authFacadeService.register(registerRequest); + + // then + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isNotEmpty(); + softly.assertThat(response.refreshToken()).isNotEmpty(); + }); + } + + @Test + void Refresh_토큰을_입력받아_Access_토큰과_Refresh_토큰을_재발급한다() { + // given + Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + String refreshToken = jwtTokenProvider.generateRefreshToken(); + refreshTokenRepository.save(new RefreshToken(member.id(), refreshToken)); + TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(refreshToken); + + // when + OauthResponse response = authFacadeService.refresh(tokenRefreshRequest); + + // then + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isNotEmpty(); + softly.assertThat(response.refreshToken()).isNotEmpty(); + softly.assertThat(refreshTokenRepository.findByToken(refreshToken)).isEmpty(); + softly.assertThat(refreshTokenRepository.findByToken(response.refreshToken())).isPresent(); + }); + } +} diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index dcc32a829..262081029 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -1,79 +1,60 @@ package dev.tripdraw.auth.application; import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_REFRESH_TOKEN; +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_ACCESS_TOKEN_설정; import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_REFRESH_TOKEN_설정; +import static dev.tripdraw.test.fixture.MemberFixture.사용자; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.mockito.Mockito.when; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; import dev.tripdraw.auth.domain.RefreshToken; import dev.tripdraw.auth.domain.RefreshTokenRepository; -import dev.tripdraw.auth.dto.OauthRequest; +import dev.tripdraw.auth.dto.OauthInfo; import dev.tripdraw.auth.dto.OauthResponse; -import dev.tripdraw.auth.dto.RegisterRequest; -import dev.tripdraw.auth.dto.TokenRefreshRequest; import dev.tripdraw.auth.exception.AuthException; -import dev.tripdraw.auth.oauth.OauthClientProvider; -import dev.tripdraw.member.domain.Member; +import dev.tripdraw.common.auth.OauthType; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; -import dev.tripdraw.test.ServiceTest; -import dev.tripdraw.test.TestKakaoApiClient; -import org.junit.jupiter.api.BeforeEach; +import java.util.Optional; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; -@ServiceTest +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@SpringBootTest class AuthServiceTest { @Autowired private AuthService authService; - @MockBean - private OauthClientProvider oauthClientProvider; - - @Autowired - private MemberRepository memberRepository; - - @Autowired - private RefreshTokenRepository refreshTokenRepository; - @Autowired private JwtTokenProvider jwtTokenProvider; - @BeforeEach - void setUp() { - when(oauthClientProvider.provide(KAKAO)).thenReturn(new TestKakaoApiClient()); - } - - @Test - void 가입된_회원이_카카오_소셜_로그인하면_토큰이_포함된_응답을_반환한다() { - // given - memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - OauthRequest oauthRequest = new OauthRequest(KAKAO, "oauth.kakao.token"); - - // when - OauthResponse response = authService.login(oauthRequest); + @MockBean + private MemberRepository memberRepository; - // then - assertSoftly(softly -> { - softly.assertThat(response.accessToken()).isNotEmpty(); - softly.assertThat(response.refreshToken()).isNotEmpty(); - }); - } + @MockBean + private RefreshTokenRepository refreshTokenRepository; @Test void 신규_회원이_로그인하면_회원을_저장하고_빈_토큰이_포함된_응답을_반환한다() { // given - OauthRequest oauthRequest = new OauthRequest(KAKAO, "oauth.kakao.token"); + given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) + .willReturn(Optional.empty()); + + OauthInfo oauthInfo = new OauthInfo("id", KAKAO); // when - OauthResponse response = authService.login(oauthRequest); + OauthResponse response = authService.login(oauthInfo); // then assertSoftly(softly -> { @@ -85,13 +66,13 @@ void setUp() { @Test void 신규_회원의_닉네임을_등록하면_토큰이_포함된_응답을_반환한다() { // given - Member member = Member.of("kakaoId", KAKAO); - memberRepository.save(member); + given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) + .willReturn(Optional.of(사용자())); - RegisterRequest registerRequest = new RegisterRequest("통후추", KAKAO, "oauth.kakao.token"); + OauthInfo oauthInfo = new OauthInfo("id", KAKAO); // when - OauthResponse response = authService.register(registerRequest); + OauthResponse response = authService.register(oauthInfo, "통후추"); // then assertSoftly(softly -> { @@ -103,61 +84,59 @@ void setUp() { @Test void 신규_회원의_닉네임을_등록할_때_회원이_존재하지_않으면_예외가_발생한다() { // given - RegisterRequest registerRequest = new RegisterRequest("저장안된후추", KAKAO, "oauth.kakao.token"); - - // expect - assertThatThrownBy(() -> authService.register(registerRequest)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); - } + given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) + .willReturn(Optional.empty()); - @Test - void 신규_회원의_닉네임을_등록할_때_이미_존재하는_닉네임이면_예외가_발생한다() { - // given - memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - RegisterRequest registerRequest = new RegisterRequest("통후추", KAKAO, "oauth.kakao.token"); + OauthInfo unregisteredOauthInfo = new OauthInfo("id", KAKAO); // expect - assertThatThrownBy(() -> authService.register(registerRequest)) + assertThatThrownBy(() -> authService.register(unregisteredOauthInfo, "통후추")) .isInstanceOf(MemberException.class) - .hasMessage(DUPLICATE_NICKNAME.message()); + .hasMessage(MEMBER_NOT_FOUND.message()); } @Test - void Refresh_토큰_재발급시_입력받은_토큰이_만료되는_경우_예외가_발생한다() { + void Refresh_토큰_재발급시_입력받은_Refresh_토큰이_만료된_경우_예외가_발생한다() { // given - Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); JwtTokenProvider expiredTokenProvider = new JwtTokenProvider( 만료된_토큰_생성용_ACCESS_TOKEN_설정(), 만료된_토큰_생성용_REFRESH_TOKEN_설정() ); String expiredToken = expiredTokenProvider.generateRefreshToken(); - refreshTokenRepository.save(new RefreshToken(member.id(), expiredToken)); - TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(expiredToken); // expect - assertThatThrownBy(() -> authService.refresh(tokenRefreshRequest)) + assertThatThrownBy(() -> authService.refresh(expiredToken)) .isInstanceOf(AuthException.class) .hasMessage(EXPIRED_REFRESH_TOKEN.message()); } + @Test + void Refresh_토큰_재발급시_입력받은_Refresh_토큰이_존재하지_않는_토큰인_경우_예외가_발생한다() { + // given + given(refreshTokenRepository.findByToken(any(String.class))).willReturn(Optional.empty()); + String token = jwtTokenProvider.generateRefreshToken(); + + // expect + assertThatThrownBy(() -> authService.refresh(token)) + .isInstanceOf(AuthException.class) + .hasMessage(INVALID_TOKEN.message()); + } + @Test void Refresh_토큰을_입력받아_Access_토큰과_Refresh_토큰을_재발급한다() { // given - Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); String refreshToken = jwtTokenProvider.generateRefreshToken(); - refreshTokenRepository.save(new RefreshToken(member.id(), refreshToken)); - TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(refreshToken); + given(refreshTokenRepository.findByToken(any(String.class))) + .willReturn(Optional.of(new RefreshToken(1L, 1L, refreshToken))); // when - OauthResponse response = authService.refresh(tokenRefreshRequest); + OauthResponse response = authService.refresh(refreshToken); // then assertSoftly(softly -> { softly.assertThat(response.accessToken()).isNotEmpty(); softly.assertThat(response.refreshToken()).isNotEmpty(); - softly.assertThat(refreshTokenRepository.findByToken(refreshToken)).isEmpty(); - softly.assertThat(refreshTokenRepository.findByToken(response.refreshToken())).isPresent(); + softly.assertThat(response.refreshToken()).isNotEqualTo(refreshToken); }); } } From a2fb27a33c6315581b1776b41063b15ddc85c06b Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 16 Sep 2023 15:16:56 +0900 Subject: [PATCH 054/119] =?UTF-8?q?[refactor]=20Token=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=B6=84=EB=A6=AC=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthFacadeService.java | 11 +- .../auth/application/AuthService.java | 37 ++----- .../application/TokenGenerateService.java | 39 +++++++ .../application/AuthFacadeServiceTest.java | 10 +- .../auth/application/AuthServiceTest.java | 101 ++++++------------ .../application/TokenGenerateServiceTest.java | 92 ++++++++++++++++ 6 files changed, 186 insertions(+), 104 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java create mode 100644 backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java index f8bfa11b2..e1d2edace 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java @@ -14,18 +14,23 @@ public class AuthFacadeService { private final OAuthService oAuthService; private final AuthService authService; + private final TokenGenerateService tokenGenerateService; public OauthResponse login(OauthRequest oauthRequest) { OauthInfo oauthInfo = oAuthService.request(oauthRequest.oauthType(), oauthRequest.oauthToken()); - return authService.login(oauthInfo); + return authService.login(oauthInfo) + .map(member -> tokenGenerateService.generate(member.id())) + .orElseGet(tokenGenerateService::generateEmptyToken); } public OauthResponse register(RegisterRequest registerRequest) { OauthInfo oauthInfo = oAuthService.request(registerRequest.oauthType(), registerRequest.oauthToken()); - return authService.register(oauthInfo, registerRequest.nickname()); + return authService.register(oauthInfo, registerRequest.nickname()) + .map(member -> tokenGenerateService.generate(member.id())) + .orElseGet(tokenGenerateService::generateEmptyToken); } public OauthResponse refresh(TokenRefreshRequest tokenRefreshRequest) { - return authService.refresh(tokenRefreshRequest.refreshToken()); + return tokenGenerateService.refresh(tokenRefreshRequest.refreshToken()); } } diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java index b8f25f505..dc75fcbc7 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java @@ -1,17 +1,13 @@ package dev.tripdraw.auth.application; -import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import dev.tripdraw.auth.domain.RefreshToken; -import dev.tripdraw.auth.domain.RefreshTokenRepository; import dev.tripdraw.auth.dto.OauthInfo; -import dev.tripdraw.auth.dto.OauthResponse; -import dev.tripdraw.auth.exception.AuthException; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; +import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,31 +17,17 @@ @Service public class AuthService { - private static final OauthResponse EMPTY_TOKEN_RESPONSE = new OauthResponse("", ""); - - private final JwtTokenProvider jwtTokenProvider; - private final RefreshTokenRepository refreshTokenRepository; private final MemberRepository memberRepository; - public OauthResponse login(OauthInfo oauthInfo) { + public Optional login(OauthInfo oauthInfo) { return memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) - .map(member -> generateOAuthResponse(member.id())) - .orElseGet(() -> { + .or(() -> { memberRepository.save(Member.of(oauthInfo.oauthId(), oauthInfo.oauthType())); - return EMPTY_TOKEN_RESPONSE; + return Optional.empty(); }); } - private OauthResponse generateOAuthResponse(Long memberId) { - String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); - String refreshToken = jwtTokenProvider.generateRefreshToken(); - - refreshTokenRepository.deleteByMemberId(memberId); - refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); - return new OauthResponse(accessToken, refreshToken); - } - - public OauthResponse register(OauthInfo oauthInfo, String nickname) { + public Optional register(OauthInfo oauthInfo, String nickname) { if (memberRepository.existsByNickname(nickname)) { throw new MemberException(DUPLICATE_NICKNAME); } @@ -53,13 +35,6 @@ public OauthResponse register(OauthInfo oauthInfo, String nickname) { Member member = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); member.changeNickname(nickname); - return generateOAuthResponse(member.id()); - } - - public OauthResponse refresh(String token) { - jwtTokenProvider.validateRefreshToken(token); - RefreshToken refreshToken = refreshTokenRepository.findByToken(token) - .orElseThrow(() -> new AuthException(INVALID_TOKEN)); - return generateOAuthResponse(refreshToken.memberId()); + return Optional.of(member); } } diff --git a/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java b/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java new file mode 100644 index 000000000..ea96e6f50 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java @@ -0,0 +1,39 @@ +package dev.tripdraw.auth.application; + +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; + +import dev.tripdraw.auth.domain.RefreshToken; +import dev.tripdraw.auth.domain.RefreshTokenRepository; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.exception.AuthException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Transactional +@Service +public class TokenGenerateService { + + private final JwtTokenProvider jwtTokenProvider; + private final RefreshTokenRepository refreshTokenRepository; + + public OauthResponse refresh(String token) { + jwtTokenProvider.validateRefreshToken(token); + RefreshToken refreshToken = refreshTokenRepository.findByToken(token) + .orElseThrow(() -> new AuthException(INVALID_TOKEN)); + return generate(refreshToken.memberId()); + } + + public OauthResponse generate(Long memberId) { + String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); + String refreshToken = jwtTokenProvider.generateRefreshToken(); + refreshTokenRepository.deleteByMemberId(memberId); + refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); + return new OauthResponse(accessToken, refreshToken); + } + + public OauthResponse generateEmptyToken() { + return new OauthResponse("", ""); + } +} diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java index 60eb17e0d..6231009f4 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java @@ -13,14 +13,20 @@ import dev.tripdraw.auth.oauth.OauthClientProvider; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.test.ServiceTest; import dev.tripdraw.test.TestKakaoApiClient; +import jakarta.transaction.Transactional; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; -@ServiceTest +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@Transactional +@SpringBootTest class AuthFacadeServiceTest { @Autowired diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index 262081029..f68d4fb23 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -1,23 +1,20 @@ package dev.tripdraw.auth.application; -import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_REFRESH_TOKEN; -import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_ACCESS_TOKEN_설정; -import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_REFRESH_TOKEN_설정; import static dev.tripdraw.test.fixture.MemberFixture.사용자; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; -import dev.tripdraw.auth.domain.RefreshToken; -import dev.tripdraw.auth.domain.RefreshTokenRepository; import dev.tripdraw.auth.dto.OauthInfo; -import dev.tripdraw.auth.dto.OauthResponse; -import dev.tripdraw.auth.exception.AuthException; import dev.tripdraw.common.auth.OauthType; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; import java.util.Optional; @@ -36,107 +33,75 @@ class AuthServiceTest { @Autowired private AuthService authService; - @Autowired - private JwtTokenProvider jwtTokenProvider; - @MockBean private MemberRepository memberRepository; - @MockBean - private RefreshTokenRepository refreshTokenRepository; + private final OauthInfo oauthInfo = new OauthInfo("id", KAKAO); @Test - void 신규_회원이_로그인하면_회원을_저장하고_빈_토큰이_포함된_응답을_반환한다() { + void 신규_회원이_로그인하면_회원을_저장_후_빈_회원을_반환한다() { // given given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) .willReturn(Optional.empty()); - OauthInfo oauthInfo = new OauthInfo("id", KAKAO); - // when - OauthResponse response = authService.login(oauthInfo); + Optional member = authService.login(oauthInfo); // then assertSoftly(softly -> { - softly.assertThat(response.accessToken()).isEmpty(); - softly.assertThat(response.refreshToken()).isEmpty(); + softly.assertThat(member).isNotPresent(); + verify(memberRepository, times(1)).save(any(Member.class)); }); } @Test - void 신규_회원의_닉네임을_등록하면_토큰이_포함된_응답을_반환한다() { + void 기존의_회원이_로그인하면_회원_정보를_반환한다() { // given + Member 사용자 = 사용자(); given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) - .willReturn(Optional.of(사용자())); - - OauthInfo oauthInfo = new OauthInfo("id", KAKAO); + .willReturn(Optional.of(사용자)); // when - OauthResponse response = authService.register(oauthInfo, "통후추"); + Optional member = authService.login(oauthInfo); // then - assertSoftly(softly -> { - softly.assertThat(response.accessToken()).isNotEmpty(); - softly.assertThat(response.refreshToken()).isNotEmpty(); - }); + assertThat(member).isPresent(); } @Test - void 신규_회원의_닉네임을_등록할_때_회원이_존재하지_않으면_예외가_발생한다() { + void 신규_회원의_닉네임을_등록_후_회원_정보를_반환한다() { // given given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) - .willReturn(Optional.empty()); + .willReturn(Optional.of(사용자())); - OauthInfo unregisteredOauthInfo = new OauthInfo("id", KAKAO); + // when + Optional member = authService.register(oauthInfo, "통후추"); - // expect - assertThatThrownBy(() -> authService.register(unregisteredOauthInfo, "통후추")) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); + // then + assertThat(member).isPresent(); } @Test - void Refresh_토큰_재발급시_입력받은_Refresh_토큰이_만료된_경우_예외가_발생한다() { + void 신규_회원의_닉네임을_등록할_때_회원이_존재하지_않으면_예외가_발생한다() { // given - JwtTokenProvider expiredTokenProvider = new JwtTokenProvider( - 만료된_토큰_생성용_ACCESS_TOKEN_설정(), - 만료된_토큰_생성용_REFRESH_TOKEN_설정() - ); - String expiredToken = expiredTokenProvider.generateRefreshToken(); + given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) + .willReturn(Optional.empty()); // expect - assertThatThrownBy(() -> authService.refresh(expiredToken)) - .isInstanceOf(AuthException.class) - .hasMessage(EXPIRED_REFRESH_TOKEN.message()); + assertThatThrownBy(() -> authService.register(oauthInfo, "통후추")) + .isInstanceOf(MemberException.class) + .hasMessage(MEMBER_NOT_FOUND.message()); } @Test - void Refresh_토큰_재발급시_입력받은_Refresh_토큰이_존재하지_않는_토큰인_경우_예외가_발생한다() { + void 신규_회원의_닉네임을_등록할_때_이미_존재하는_닉네임이라면_예외가_발생한다() { // given - given(refreshTokenRepository.findByToken(any(String.class))).willReturn(Optional.empty()); - String token = jwtTokenProvider.generateRefreshToken(); + given(memberRepository.existsByNickname(any(String.class))) + .willReturn(true); // expect - assertThatThrownBy(() -> authService.refresh(token)) - .isInstanceOf(AuthException.class) - .hasMessage(INVALID_TOKEN.message()); - } - - @Test - void Refresh_토큰을_입력받아_Access_토큰과_Refresh_토큰을_재발급한다() { - // given - String refreshToken = jwtTokenProvider.generateRefreshToken(); - given(refreshTokenRepository.findByToken(any(String.class))) - .willReturn(Optional.of(new RefreshToken(1L, 1L, refreshToken))); - - // when - OauthResponse response = authService.refresh(refreshToken); - - // then - assertSoftly(softly -> { - softly.assertThat(response.accessToken()).isNotEmpty(); - softly.assertThat(response.refreshToken()).isNotEmpty(); - softly.assertThat(response.refreshToken()).isNotEqualTo(refreshToken); - }); + assertThatThrownBy(() -> authService.register(oauthInfo, "통후추")) + .isInstanceOf(MemberException.class) + .hasMessage(DUPLICATE_NICKNAME.message()); } } diff --git a/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java new file mode 100644 index 000000000..7e262ee32 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java @@ -0,0 +1,92 @@ +package dev.tripdraw.auth.application; + +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import dev.tripdraw.auth.domain.RefreshToken; +import dev.tripdraw.auth.domain.RefreshTokenRepository; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.exception.AuthException; +import java.util.Optional; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@SpringBootTest +class TokenGenerateServiceTest { + + @Autowired + private TokenGenerateService tokenGenerateService; + + @Autowired + private JwtTokenProvider jwtTokenProvider; + + @MockBean + private RefreshTokenRepository refreshTokenRepository; + + @Test + void refreshToken을_발급하여_저장하고_Access_토큰과_Refresh_토큰을_반환한다() { + // given + Long memberId = 1L; + + // when + OauthResponse result = tokenGenerateService.generate(memberId); + + // then + assertSoftly(softly -> { + softly.assertThat(result.accessToken()).isNotEmpty(); + softly.assertThat(result.refreshToken()).isNotEmpty(); + verify(refreshTokenRepository, times(1)).save(any(RefreshToken.class)); + }); + } + + @Test + void Refresh_토큰_재발급시_입력받은_Refresh_토큰이_존재하지_않는_토큰인_경우_예외가_발생한다() { + // given + given(refreshTokenRepository.findByToken(any(String.class))).willReturn(Optional.empty()); + String token = jwtTokenProvider.generateRefreshToken(); + + // expect + assertThatThrownBy(() -> tokenGenerateService.refresh(token)) + .isInstanceOf(AuthException.class) + .hasMessage(INVALID_TOKEN.message()); + } + + @Test + void Refresh_토큰을_입력받아_Access_토큰과_Refresh_토큰을_재발급한다() { + // given + String refreshToken = jwtTokenProvider.generateRefreshToken(); + given(refreshTokenRepository.findByToken(any(String.class))) + .willReturn(Optional.of(new RefreshToken(1L, 1L, refreshToken))); + + // when + OauthResponse result = tokenGenerateService.refresh(refreshToken); + + // then + assertSoftly(softly -> { + softly.assertThat(result.accessToken()).isNotEmpty(); + softly.assertThat(result.refreshToken()).isNotEmpty(); + softly.assertThat(result.refreshToken()).isNotEqualTo(refreshToken); + }); + } + + @Test + void 빈_토큰을_발급한다() { + // given + OauthResponse emptyToken = new OauthResponse("", ""); + + // expect + assertThat(tokenGenerateService.generateEmptyToken()).isEqualTo(emptyToken); + } +} From c24a97efad10f31bee4e9c8c61a115184bbbd11c Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 16 Sep 2023 16:11:11 +0900 Subject: [PATCH 055/119] =?UTF-8?q?[refactor]=20transactionTemplate=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20AuthService=EC=99=80=20T?= =?UTF-8?q?okenGenerateService=20=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98?= =?UTF-8?q?=EC=9D=84=20=EB=AC=B6=EA=B8=B0=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthFacadeService.java | 10 ++++---- .../application/TokenGenerateService.java | 3 ++- .../auth/config/RefreshTokenConfig.java | 1 - .../application/AuthFacadeServiceTest.java | 4 ++-- .../auth/application/AuthServiceTest.java | 13 ++++++----- .../auth/application/OAuthServiceTest.java | 13 ++++++----- .../application/TokenGenerateServiceTest.java | 23 ++++++++++++------- 7 files changed, 39 insertions(+), 28 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java index e1d2edace..30a65a004 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java @@ -7,6 +7,7 @@ import dev.tripdraw.auth.dto.TokenRefreshRequest; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.support.TransactionTemplate; @RequiredArgsConstructor @Service @@ -15,19 +16,20 @@ public class AuthFacadeService { private final OAuthService oAuthService; private final AuthService authService; private final TokenGenerateService tokenGenerateService; + private final TransactionTemplate transactionTemplate; public OauthResponse login(OauthRequest oauthRequest) { OauthInfo oauthInfo = oAuthService.request(oauthRequest.oauthType(), oauthRequest.oauthToken()); - return authService.login(oauthInfo) + return transactionTemplate.execute(status -> authService.login(oauthInfo) .map(member -> tokenGenerateService.generate(member.id())) - .orElseGet(tokenGenerateService::generateEmptyToken); + .orElseGet(tokenGenerateService::generateEmptyToken)); } public OauthResponse register(RegisterRequest registerRequest) { OauthInfo oauthInfo = oAuthService.request(registerRequest.oauthType(), registerRequest.oauthToken()); - return authService.register(oauthInfo, registerRequest.nickname()) + return transactionTemplate.execute(status -> authService.register(oauthInfo, registerRequest.nickname()) .map(member -> tokenGenerateService.generate(member.id())) - .orElseGet(tokenGenerateService::generateEmptyToken); + .orElseGet(tokenGenerateService::generateEmptyToken)); } public OauthResponse refresh(TokenRefreshRequest tokenRefreshRequest) { diff --git a/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java b/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java index ea96e6f50..ff1e088f8 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java @@ -11,13 +11,13 @@ import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor -@Transactional @Service public class TokenGenerateService { private final JwtTokenProvider jwtTokenProvider; private final RefreshTokenRepository refreshTokenRepository; + @Transactional public OauthResponse refresh(String token) { jwtTokenProvider.validateRefreshToken(token); RefreshToken refreshToken = refreshTokenRepository.findByToken(token) @@ -25,6 +25,7 @@ public OauthResponse refresh(String token) { return generate(refreshToken.memberId()); } + @Transactional public OauthResponse generate(Long memberId) { String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); String refreshToken = jwtTokenProvider.generateRefreshToken(); diff --git a/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java index a1af2f37c..c3f05dc88 100644 --- a/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java +++ b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java @@ -7,5 +7,4 @@ public record RefreshTokenConfig( String secretKey, Long expirationTime ) { - } diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java index 6231009f4..92d3f535c 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java @@ -2,7 +2,7 @@ import static dev.tripdraw.common.auth.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; import dev.tripdraw.auth.domain.RefreshToken; import dev.tripdraw.auth.domain.RefreshTokenRepository; @@ -46,7 +46,7 @@ class AuthFacadeServiceTest { @BeforeEach void setUp() { - when(oauthClientProvider.provide(KAKAO)).thenReturn(new TestKakaoApiClient()); + given(oauthClientProvider.provide(KAKAO)).willReturn(new TestKakaoApiClient()); } @Test diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index f68d4fb23..27eefe303 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -21,19 +21,20 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -@SpringBootTest +@ExtendWith(MockitoExtension.class) class AuthServiceTest { - @Autowired + @InjectMocks private AuthService authService; - @MockBean + @Mock private MemberRepository memberRepository; private final OauthInfo oauthInfo = new OauthInfo("id", KAKAO); diff --git a/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java index dea6fa39f..b37f56102 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java @@ -11,19 +11,20 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -@SpringBootTest +@ExtendWith(MockitoExtension.class) class OAuthServiceTest { - @Autowired + @InjectMocks private OAuthService oAuthService; - @MockBean + @Mock private OauthClientProvider oauthClientProvider; @BeforeEach diff --git a/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java index 7e262ee32..a0dc881bc 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java @@ -1,6 +1,8 @@ package dev.tripdraw.auth.application; import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; +import static dev.tripdraw.test.fixture.AuthFixture.테스트_ACCESS_TOKEN_설정; +import static dev.tripdraw.test.fixture.AuthFixture.테스트_REFRESH_TOKEN_설정; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -17,22 +19,27 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -@SpringBootTest +@ExtendWith(MockitoExtension.class) class TokenGenerateServiceTest { - @Autowired + @InjectMocks private TokenGenerateService tokenGenerateService; - @Autowired - private JwtTokenProvider jwtTokenProvider; + @Spy + private JwtTokenProvider jwtTokenProvider = new JwtTokenProvider( + 테스트_ACCESS_TOKEN_설정(), + 테스트_REFRESH_TOKEN_설정() + ); - @MockBean + @Mock private RefreshTokenRepository refreshTokenRepository; @Test From 7f4005a78d38689753c9b856295538c8e8e925f0 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Sat, 16 Sep 2023 18:15:56 +0900 Subject: [PATCH 056/119] =?UTF-8?q?[build]=20Querydsl=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/build.gradle b/backend/build.gradle index 6724178ae..b178d3561 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -57,9 +57,9 @@ dependencies { // querydsl implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' - annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" - annotationProcessor "jakarta.annotation:jakarta.annotation-api" - annotationProcessor "jakarta.persistence:jakarta.persistence-api" + annotationProcessor 'com.querydsl:querydsl-apt:5.0.0:jakarta' + annotationProcessor 'jakarta.annotation:jakarta.annotation-api' + annotationProcessor 'jakarta.persistence:jakarta.persistence-api' } processResources.dependsOn('copySecret') @@ -86,7 +86,7 @@ sourceSets { } tasks.withType(JavaCompile).configureEach { - options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir) + options.compilerArgs += ["-s", querydslDir] } clean.doLast { From 3016f43fa8e5e687c96836423371ec5c0ce674c0 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Sat, 16 Sep 2023 18:20:01 +0900 Subject: [PATCH 057/119] =?UTF-8?q?[feat]=20TripRepository=20=EB=8F=99?= =?UTF-8?q?=EC=A0=81=20=EC=BF=BC=EB=A6=AC=EB=A1=9C=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/config/QueryDslConfig.java | 22 + .../dev/tripdraw/common/domain/Paging.java | 7 + .../trip/domain/SearchConditions.java | 13 + .../trip/domain/TripCustomRepository.java | 9 + .../trip/domain/TripCustomRepositoryImpl.java | 72 ++++ .../tripdraw/trip/domain/TripRepository.java | 2 +- .../domain/RefreshTokenRepositoryTest.java | 3 + .../tripdraw/common/domain/PagingTest.java | 26 ++ .../TripUpdateEventHandlerTest.java | 2 - .../member/domain/MemberRepositoryTest.java | 3 + .../post/domain/PostRepositoryTest.java | 3 + .../test/SearchConditionsTestFixture.java | 85 ++++ .../java/dev/tripdraw/test/TestFixture.java | 4 + .../trip/domain/PointRepositoryTest.java | 3 + .../trip/domain/TripRepositoryTest.java | 390 ++++++++++++++++++ 15 files changed, 641 insertions(+), 3 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java create mode 100644 backend/src/main/java/dev/tripdraw/common/domain/Paging.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java create mode 100644 backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java create mode 100644 backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java diff --git a/backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java b/backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java new file mode 100644 index 000000000..e3e15a840 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java @@ -0,0 +1,22 @@ +package dev.tripdraw.common.config; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class QueryDslConfig { + + @PersistenceContext + private EntityManager entityManager; + + public QueryDslConfig() { + } + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(entityManager); + } +} diff --git a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java b/backend/src/main/java/dev/tripdraw/common/domain/Paging.java new file mode 100644 index 000000000..44873b535 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/common/domain/Paging.java @@ -0,0 +1,7 @@ +package dev.tripdraw.common.domain; + +public record Paging(Long lastViewedId, Integer limit) { + public boolean hasNextPage(int size) { + return size > limit; + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java new file mode 100644 index 000000000..1a47fa905 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java @@ -0,0 +1,13 @@ +package dev.tripdraw.trip.domain; + +import java.util.List; + +public record SearchConditions( + List years, + List months, + List daysOfWeek, + List ageRanges, + List genders, + String address +) { +} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java new file mode 100644 index 000000000..4f99ea52d --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java @@ -0,0 +1,9 @@ +package dev.tripdraw.trip.domain; + +import dev.tripdraw.common.domain.Paging; +import java.util.List; + +public interface TripCustomRepository { + + List findAllByConditions(SearchConditions searchConditions, Paging paging); +} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java new file mode 100644 index 000000000..6d98e01bf --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java @@ -0,0 +1,72 @@ +package dev.tripdraw.trip.domain; + +import static dev.tripdraw.post.domain.QPost.post; +import static dev.tripdraw.trip.domain.QPoint.point; +import static dev.tripdraw.trip.domain.QTrip.trip; + +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; +import dev.tripdraw.common.domain.Paging; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@RequiredArgsConstructor +@Repository +public class TripCustomRepositoryImpl implements TripCustomRepository { + + private final JPAQueryFactory query; + + @Override + public List findAllByConditions(SearchConditions searchConditions, Paging paging) { + return query + .selectFrom(trip) + .join(post).on(trip.id.eq(post.tripId)) + .join(point).on(post.point.id.eq(point.id)) + .where( + tripsBeforeLastViewedId(paging.lastViewedId()), + tripsRecordedAtYears(searchConditions.years()), + tripsRecordedAtMonths(searchConditions.months()), + tripsRecordedAtDaysOfWeek(searchConditions.daysOfWeek()), + tripsAddressed(searchConditions.address()) + ) + .orderBy(trip.id.desc()) + .limit(paging.limit() + 1) + .fetch(); + } + + private BooleanExpression tripsBeforeLastViewedId(Long lastViewedId) { + if (lastViewedId == null) { + return null; + } + return trip.id.lt(lastViewedId); + } + + private BooleanExpression tripsRecordedAtYears(List years) { + if (years.isEmpty()) { + return null; + } + return point.recordedAt.year().in(years); + } + + private BooleanExpression tripsRecordedAtMonths(List months) { + if (months.isEmpty()) { + return null; + } + return point.recordedAt.month().in(months); + } + + private BooleanExpression tripsRecordedAtDaysOfWeek(List daysOfWeek) { + if (daysOfWeek.isEmpty()) { + return null; + } + return point.recordedAt.dayOfWeek().in(daysOfWeek); + } + + private BooleanExpression tripsAddressed(String address) { + if (address.isEmpty()) { + return null; + } + return post.address.contains(address); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java index edb45c393..5dab56ecd 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java @@ -9,7 +9,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -public interface TripRepository extends JpaRepository { +public interface TripRepository extends JpaRepository, TripCustomRepository { List findAllByMemberId(Long memberId); diff --git a/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java index f652fdaa6..dfa7ec889 100644 --- a/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java @@ -2,15 +2,18 @@ import static org.assertj.core.api.Assertions.assertThat; +import dev.tripdraw.common.config.QueryDslConfig; import java.util.Optional; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@Import(QueryDslConfig.class) @DataJpaTest class RefreshTokenRepositoryTest { diff --git a/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java b/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java new file mode 100644 index 000000000..968b0bbc0 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java @@ -0,0 +1,26 @@ +package dev.tripdraw.common.domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +class PagingTest { + + @ParameterizedTest + @CsvSource({"19, false", "20, false", "21, true"}) + void 다음_페이지가_있는지_확인한다(int size, boolean expected) { + // given + Paging paging = new Paging(1L, 20); + + // when + boolean actual = paging.hasNextPage(size); + + // then + assertThat(actual).isEqualTo(expected); + } +} diff --git a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java index 6f4d8b140..c524e59ee 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java @@ -6,8 +6,6 @@ import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; -import dev.tripdraw.draw.application.RouteImageGenerator; -import dev.tripdraw.draw.application.TripUpdateEventHandler; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java index 2a96e2981..c42355852 100644 --- a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import dev.tripdraw.common.config.QueryDslConfig; import dev.tripdraw.member.exception.MemberException; import java.util.Optional; import org.junit.jupiter.api.DisplayNameGeneration; @@ -12,9 +13,11 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@Import(QueryDslConfig.class) @DataJpaTest class MemberRepositoryTest { diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java index 2029a0f18..447fa2ec4 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import dev.tripdraw.common.config.QueryDslConfig; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.exception.PostException; @@ -20,9 +21,11 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@Import(QueryDslConfig.class) @DataJpaTest class PostRepositoryTest { diff --git a/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java b/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java new file mode 100644 index 000000000..61c7b52a7 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java @@ -0,0 +1,85 @@ +package dev.tripdraw.test; + +import dev.tripdraw.trip.domain.SearchConditions; +import java.util.List; + + +public class SearchConditionsTestFixture { + + public static SearchConditions emptySearchConditions() { + return new SearchConditions( + List.of(), + List.of(), + List.of(), + List.of(), + List.of(), + "" + ); + } + + public static SearchConditions yearsSearchConditions(List years) { + return new SearchConditions( + years, + List.of(), + List.of(), + List.of(), + List.of(), + "" + ); + } + + public static SearchConditions monthsSearchConditions(List months) { + return new SearchConditions( + List.of(), + months, + List.of(), + List.of(), + List.of(), + "" + ); + } + + public static SearchConditions daysOfWeekSearchConditions(List daysOfWeek) { + return new SearchConditions( + List.of(), + List.of(), + daysOfWeek, + List.of(), + List.of(), + "" + ); + } + + public static SearchConditions ageRangesSearchConditions(List ageRanges) { + return new SearchConditions( + List.of(), + List.of(), + List.of(), + ageRanges, + List.of(), + "" + ); + } + + public static SearchConditions gendersSearchConditions(List genders) { + return new SearchConditions( + List.of(), + List.of(), + List.of(), + List.of(), + genders, + "" + ); + } + + public static SearchConditions addressSearchConditions(String address) { + return new SearchConditions( + List.of(), + List.of(), + List.of(), + List.of(), + List.of(), + address + ); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/TestFixture.java index 924049ed2..434233c23 100644 --- a/backend/src/test/java/dev/tripdraw/test/TestFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/TestFixture.java @@ -20,6 +20,10 @@ public class TestFixture { return new Point(1L, 1.1, 2.2, false, LocalDateTime.now(), 여행()); } + public static Point 위치정보(int year, int month, int dayOfMonth, int hour, int minute) { + return new Point(1.1, 2.2, LocalDateTime.of(year, month, dayOfMonth, hour, minute)); + } + public static Trip 여행() { return new Trip(1L, TripName.from("통후추"), 사용자(), TripStatus.ONGOING, "", ""); } diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java index 717a48695..f5e715990 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import dev.tripdraw.common.config.QueryDslConfig; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.exception.TripException; @@ -15,9 +16,11 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@Import(QueryDslConfig.class) @DataJpaTest class PointRepositoryTest { diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index b448e684e..2b32c017e 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -1,31 +1,50 @@ package dev.tripdraw.trip.domain; import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.SearchConditionsTestFixture.addressSearchConditions; +import static dev.tripdraw.test.SearchConditionsTestFixture.daysOfWeekSearchConditions; +import static dev.tripdraw.test.SearchConditionsTestFixture.emptySearchConditions; +import static dev.tripdraw.test.SearchConditionsTestFixture.monthsSearchConditions; +import static dev.tripdraw.test.SearchConditionsTestFixture.yearsSearchConditions; +import static dev.tripdraw.test.TestFixture.위치정보; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; +import dev.tripdraw.common.config.JpaConfig; +import dev.tripdraw.common.config.QueryDslConfig; +import dev.tripdraw.common.domain.Paging; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@Import({JpaConfig.class, QueryDslConfig.class}) @DataJpaTest class TripRepositoryTest { @Autowired private TripRepository tripRepository; + @Autowired + private PostRepository postRepository; + @Autowired private MemberRepository memberRepository; @@ -116,4 +135,375 @@ void setUp() { .isInstanceOf(TripException.class) .hasMessage(TRIP_NOT_FOUND.message()); } + + @Nested + class 조건에_따라_여행을_조회할_때 { + + @Nested + class 개수_제한을_입력하면 { + + @ParameterizedTest + @CsvSource({"0, 1", "1, 2", "2, 3"}) + void 개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { + // given + jeju_2023_1_1_Sun(); + jeju_2023_1_1_Sun(); + jeju_2023_1_1_Sun(); + + Paging paging = new Paging(null, limit); + + // when + List trips = tripRepository.findAllByConditions(emptySearchConditions(), paging); + + // then + assertThat(trips).hasSize(expectedSize); + } + } + + @Nested + class 마지막으로_조회한_Id를 { + + @Test + void 입력하지_않으면_가장_최신_여행부터_내림차순으로_반환한다() { + // given + Trip jeju_2023_1_1_sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + Long lastViewedId = null; + + // when + List trips = tripRepository.findAllByConditions(emptySearchConditions(), + new Paging(lastViewedId, 10)); + + // then + assertThat(trips).containsExactly( + jeju2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju_2023_1_1_sun + ); + } + + @Test + void 입력하면_해당_Id_이하의_최신_여행을_내림차순으로_반환한다() { + // given + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + Long lastViewedId = jeju2023_2_1_Wed.id(); + + // when + List trips = tripRepository.findAllByConditions(emptySearchConditions(), + new Paging(lastViewedId, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun); + } + } + + @Nested + class 조건으로_연도를 { + + @Test + void 한_개_설정하면_해당_연도의_여행을_반환한다() { + // given + seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = yearsSearchConditions(List.of(2023)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(jeju2023_2_1_Wed, seoul2023_1_1_Sun, jeju2023_1_1_Sun); + } + + @Test + void 여러_개_설정하면_해당_연도들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = yearsSearchConditions(List.of(2023, 2021)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly( + jeju2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_월을 { + + @Test + void 한_개_설정하면_해당_월의_여행을_반환한다() { + // given + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = monthsSearchConditions(List.of(1)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); + } + + @Test + void 여러_개_설정하면_해당_월들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = monthsSearchConditions(List.of(1, 3)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly( + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_요일을 { + + @Test + void 한_개_설정하면_해당_요일의_여행을_반환한다() { + // given + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = daysOfWeekSearchConditions(List.of(1)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); + } + + @Test + void 여러_개_설정하면_해당_요일들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = daysOfWeekSearchConditions(List.of(1, 3)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly( + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_주소를 { + + @Test + void 시도_시군구_읍면동_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + SearchConditions searchConditions = addressSearchConditions("서울특별시 송파구 신천동"); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon); + } + + @Test + void 시도_시군구_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + SearchConditions searchConditions = addressSearchConditions("서울특별시 송파구"); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); + } + + @Test + void 시도_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + SearchConditions searchConditions = addressSearchConditions("서울특별시"); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); + } + } + + @Nested + class 조건을 { + + @Test + void 여러_개_설정하면_해당하는_여행을_반환한다() { + // given + yangyang_2021_3_2_Tue(); + seoul_2022_1_2_Sun(); + jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = new SearchConditions( + List.of(2023), + List.of(1), + List.of(), + List.of(), + List.of(), + "서울특별시" + ); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun); + } + + @Test + void 설정하지_않으면_모든_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju_2023_2_1_Wed = jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = emptySearchConditions(); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly( + jeju_2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Test + void 감상이_없는_여행은_조회되지_않는다() { + // given + emptyPostTrip(); + + SearchConditions searchConditions = emptySearchConditions(); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).isEmpty(); + } + + private Trip jeju_2023_2_1_Wed() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2023, 2, 1, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); + return trip; + } + + private Trip seoul_2023_1_1_Sun() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2023, 1, 1, 10, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "서울특별시 송파구 신천동", "", member, trip.id())); + return trip; + } + + private Trip jeju_2023_1_1_Sun() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2023, 1, 1, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); + return trip; + } + + private Trip seoul_2022_1_2_Sun() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2022, 1, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "서울특별시 송파구 방이동", "", member, trip.id())); + return trip; + } + + private Trip yangyang_2021_3_2_Tue() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2021, 3, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "강원도 양양군", "", member, trip.id())); + return trip; + } + + private Trip emptyPostTrip() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2021, 3, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + return trip; + } + } } From 316f578e12a1f8718c2f4b479f94a3a2ad44966b Mon Sep 17 00:00:00 2001 From: Combi153 Date: Sun, 17 Sep 2023 03:04:47 +0900 Subject: [PATCH 058/119] =?UTF-8?q?[feat]=20=EA=B0=90=EC=83=81=EC=9D=B4=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EC=97=AC=ED=96=89=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=EC=B6=94=EA=B0=80=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/common/domain/Paging.java | 11 + .../dev/tripdraw/common/dto/SearchPaging.java | 9 + .../trip/application/TripService.java | 24 +- .../trip/domain/SearchConditions.java | 69 +- .../trip/domain/TripCustomRepositoryImpl.java | 9 +- .../trip/dto/TripSearchConditions.java | 25 + .../tripdraw/trip/dto/TripSearchRequest.java | 9 + .../tripdraw/trip/dto/TripSearchResponse.java | 22 +- .../trip/dto/TripSearchResponseOfMember.java | 31 + .../trip/dto/TripsSearchResponse.java | 15 +- .../trip/dto/TripsSearchResponseOfMember.java | 20 + .../trip/exception/TripExceptionType.java | 1 + .../trip/presentation/TripController.java | 30 +- .../tripdraw/common/domain/PagingTest.java | 13 + ...PostCreateEventHandlerIntegrationTest.java | 4 +- .../PostCreateEventHandlerTest.java | 4 +- ...TripUpdateEventHandlerIntegrationTest.java | 3 +- .../TripUpdateEventHandlerTest.java | 2 +- .../test/SearchConditionsTestFixture.java | 85 --- .../java/dev/tripdraw/test/TestFixture.java | 34 - .../test/fixture/SearchConditionsFixture.java | 85 +++ .../tripdraw/test/fixture/TestFixture.java | 124 ++++ .../fixture/TripSearchConditionsFixture.java | 84 +++ .../java/dev/tripdraw/test/step/PostStep.java | 30 + .../java/dev/tripdraw/test/step/TripStep.java | 62 ++ .../trip/application/TripServiceTest.java | 61 +- .../trip/domain/SearchConditionsTest.java | 76 +++ .../trip/domain/TripRepositoryTest.java | 54 +- ...va => TripSearchResponseOfMemberTest.java} | 6 +- .../trip/presentation/TripControllerTest.java | 622 +++++++++++++++--- 30 files changed, 1347 insertions(+), 277 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponseOfMember.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponseOfMember.java delete mode 100644 backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java delete mode 100644 backend/src/test/java/dev/tripdraw/test/TestFixture.java create mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java create mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java create mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java create mode 100644 backend/src/test/java/dev/tripdraw/test/step/PostStep.java create mode 100644 backend/src/test/java/dev/tripdraw/test/step/TripStep.java create mode 100644 backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java rename backend/src/test/java/dev/tripdraw/trip/dto/{TripSearchResponseTest.java => TripSearchResponseOfMemberTest.java} (82%) diff --git a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java b/backend/src/main/java/dev/tripdraw/common/domain/Paging.java index 44873b535..36b72a8de 100644 --- a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java +++ b/backend/src/main/java/dev/tripdraw/common/domain/Paging.java @@ -1,6 +1,17 @@ package dev.tripdraw.common.domain; public record Paging(Long lastViewedId, Integer limit) { + private static final int LIMIT_MAXIMUM = 100; + + public Paging(Long lastViewedId, Integer limit) { + this.lastViewedId = lastViewedId; + this.limit = ceil(limit); + } + + private int ceil(Integer limit) { + return Math.min(limit, LIMIT_MAXIMUM); + } + public boolean hasNextPage(int size) { return size > limit; } diff --git a/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java b/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java new file mode 100644 index 000000000..989ce5da8 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java @@ -0,0 +1,9 @@ +package dev.tripdraw.common.dto; + +import dev.tripdraw.common.domain.Paging; + +public record SearchPaging(Long lastViewedId, Integer limit) { + public Paging toPaging() { + return new Paging(lastViewedId, limit); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index 284fef946..f9a79b3d7 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -1,10 +1,12 @@ package dev.tripdraw.trip.application; import dev.tripdraw.common.auth.LoginUser; +import dev.tripdraw.common.domain.Paging; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.PointRepository; +import dev.tripdraw.trip.domain.SearchConditions; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; @@ -13,8 +15,10 @@ import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; @@ -68,10 +72,26 @@ public TripResponse readTripById(LoginUser loginUser, Long id) { } @Transactional(readOnly = true) - public TripsSearchResponse readAllTrips(LoginUser loginUser) { + public TripsSearchResponseOfMember readAllTripsOf(LoginUser loginUser) { Member member = memberRepository.getById(loginUser.memberId()); List trips = tripRepository.findAllByMemberId(member.id()); - return TripsSearchResponse.from(trips); + return TripsSearchResponseOfMember.from(trips); + } + + @Transactional(readOnly = true) + public TripsSearchResponse readAllTrips(TripSearchRequest tripSearchRequest) { + SearchConditions searchConditions = tripSearchRequest.condition().toSearchConditions(); + Paging paging = tripSearchRequest.paging().toPaging(); + + List trips = tripRepository.findAllByConditions( + searchConditions, + paging + ); + + if (paging.hasNextPage(trips.size())) { + return TripsSearchResponse.of(trips.subList(0, paging.limit()), true); + } + return TripsSearchResponse.of(trips, false); } public void updateTripById(LoginUser loginUser, Long tripId, TripUpdateRequest tripUpdateRequest) { diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java index 1a47fa905..fee25962e 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java @@ -1,13 +1,70 @@ package dev.tripdraw.trip.domain; -import java.util.List; +import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; + +import dev.tripdraw.trip.exception.TripException; +import java.util.HashSet; +import java.util.Set; public record SearchConditions( - List years, - List months, - List daysOfWeek, - List ageRanges, - List genders, + Set years, + Set months, + Set daysOfWeek, + Set ageRanges, + Set genders, String address ) { + + private static final int YEAR_MINIMUM = 2010; + private static final int YEAR_MAXIMUM = 2023; + private static final int MONTH_MINIMUM = 1; + private static final int MONTH_MAXIMUM = 12; + private static final int DAYS_OF_WEEK_MINIMUM = 1; + private static final int DAYS_OF_WEEK_MAXIMUM = 7; + private static final int AGE_RANGE_MINIMUM = 1; + private static final int AGE_RANGE_MAXIMUM = 10; + private static final int GENDER_MINIMUM = 1; + private static final int GENDER_MAXIMUM = 2; + + public SearchConditions( + Set years, + Set months, + Set daysOfWeek, + Set ageRanges, + Set genders, + String address + ) { + validate(years, months, daysOfWeek, ageRanges, genders); + this.years = new HashSet<>(years); + this.months = new HashSet<>(months); + this.daysOfWeek = new HashSet<>(daysOfWeek); + this.ageRanges = new HashSet<>(ageRanges); + this.genders = new HashSet<>(genders); + this.address = address; + } + + private void validate( + Set years, + Set months, + Set daysOfWeek, + Set ageRanges, + Set genders + ) { + validateRange(years, YEAR_MINIMUM, YEAR_MAXIMUM); + validateRange(months, MONTH_MINIMUM, MONTH_MAXIMUM); + validateRange(daysOfWeek, DAYS_OF_WEEK_MINIMUM, DAYS_OF_WEEK_MAXIMUM); + validateRange(ageRanges, AGE_RANGE_MINIMUM, AGE_RANGE_MAXIMUM); + validateRange(genders, GENDER_MINIMUM, GENDER_MAXIMUM); + } + + private void validateRange(Set conditions, int min, int max) { + if (isOutOfRange(conditions, min, max)) { + throw new TripException(INVALID_TRIP_SEARCH); + } + } + + private boolean isOutOfRange(Set conditions, int min, int max) { + return conditions.stream() + .anyMatch(condition -> condition < min || condition > max); + } } diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java index 6d98e01bf..17d4111ec 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java @@ -8,6 +8,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import dev.tripdraw.common.domain.Paging; import java.util.List; +import java.util.Set; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -42,21 +43,21 @@ private BooleanExpression tripsBeforeLastViewedId(Long lastViewedId) { return trip.id.lt(lastViewedId); } - private BooleanExpression tripsRecordedAtYears(List years) { + private BooleanExpression tripsRecordedAtYears(Set years) { if (years.isEmpty()) { return null; } return point.recordedAt.year().in(years); } - private BooleanExpression tripsRecordedAtMonths(List months) { + private BooleanExpression tripsRecordedAtMonths(Set months) { if (months.isEmpty()) { return null; } return point.recordedAt.month().in(months); } - private BooleanExpression tripsRecordedAtDaysOfWeek(List daysOfWeek) { + private BooleanExpression tripsRecordedAtDaysOfWeek(Set daysOfWeek) { if (daysOfWeek.isEmpty()) { return null; } @@ -67,6 +68,6 @@ private BooleanExpression tripsAddressed(String address) { if (address.isEmpty()) { return null; } - return post.address.contains(address); + return post.address.like(address + "%"); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java new file mode 100644 index 000000000..2bce1ca89 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java @@ -0,0 +1,25 @@ +package dev.tripdraw.trip.dto; + +import dev.tripdraw.trip.domain.SearchConditions; +import java.util.Set; + +public record TripSearchConditions( + Set years, + Set months, + Set daysOfWeek, + Set ageRanges, + Set genders, + String address +) { + + public SearchConditions toSearchConditions() { + return new SearchConditions( + years, + months, + daysOfWeek, + ageRanges, + genders, + address + ); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java new file mode 100644 index 000000000..842ee87e1 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java @@ -0,0 +1,9 @@ +package dev.tripdraw.trip.dto; + +import dev.tripdraw.common.dto.SearchPaging; + +public record TripSearchRequest( + TripSearchConditions condition, + SearchPaging paging +) { +} diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java index c388137f4..02ac94e1d 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java @@ -1,31 +1,25 @@ package dev.tripdraw.trip.dto; import dev.tripdraw.trip.domain.Trip; -import io.swagger.v3.oas.annotations.media.Schema; -import java.util.Objects; +import java.time.LocalDateTime; public record TripSearchResponse( - @Schema(description = "여행 Id", example = "1") Long tripId, - - @Schema(description = "여행명", example = "통후추의 여행") String name, - - @Schema(description = "이미지 주소", example = "https://tripdraw.site/post-images/cd678ca2-30d5-11ee-be56-0242ac120002.jpg") String imageUrl, - - @Schema(description = "경로 이미지 주소", example = "https://tripdraw.site/route-images/cd678ca2-30d5-11ee-be56-0242ac120002.png") - String routeImageUrl + String routeImageUrl, + LocalDateTime startTime, + LocalDateTime endTime ) { - private static final String EMPTY_IMAGE_URL = ""; - public static TripSearchResponse from(Trip trip) { return new TripSearchResponse( trip.id(), trip.nameValue(), - Objects.requireNonNullElse(trip.imageUrl(), EMPTY_IMAGE_URL), - Objects.requireNonNullElse(trip.routeImageUrl(), EMPTY_IMAGE_URL) + trip.imageUrl(), + trip.routeImageUrl(), + trip.createdAt(), + trip.updatedAt() ); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponseOfMember.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponseOfMember.java new file mode 100644 index 000000000..a801c6f9f --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponseOfMember.java @@ -0,0 +1,31 @@ +package dev.tripdraw.trip.dto; + +import dev.tripdraw.trip.domain.Trip; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.Objects; + +public record TripSearchResponseOfMember( + @Schema(description = "여행 Id", example = "1") + Long tripId, + + @Schema(description = "여행명", example = "통후추의 여행") + String name, + + @Schema(description = "이미지 주소", example = "https://tripdraw.site/post-images/cd678ca2-30d5-11ee-be56-0242ac120002.jpg") + String imageUrl, + + @Schema(description = "경로 이미지 주소", example = "https://tripdraw.site/route-images/cd678ca2-30d5-11ee-be56-0242ac120002.png") + String routeImageUrl +) { + + private static final String EMPTY_IMAGE_URL = ""; + + public static TripSearchResponseOfMember from(Trip trip) { + return new TripSearchResponseOfMember( + trip.id(), + trip.nameValue(), + Objects.requireNonNullElse(trip.imageUrl(), EMPTY_IMAGE_URL), + Objects.requireNonNullElse(trip.routeImageUrl(), EMPTY_IMAGE_URL) + ); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java index 5d7e375e0..0f08a8057 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java @@ -1,20 +1,17 @@ package dev.tripdraw.trip.dto; -import static java.util.stream.Collectors.collectingAndThen; -import static java.util.stream.Collectors.toList; - import dev.tripdraw.trip.domain.Trip; -import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; public record TripsSearchResponse( - @Schema(description = "여행 목록") - List trips + List trips, + boolean hasNextPage ) { - public static TripsSearchResponse from(List trips) { - return trips.stream() + public static TripsSearchResponse of(List trips, boolean hasNextPage) { + List tripsSearchResponse = trips.stream() .map(TripSearchResponse::from) - .collect(collectingAndThen(toList(), TripsSearchResponse::new)); + .toList(); + return new TripsSearchResponse(tripsSearchResponse, hasNextPage); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponseOfMember.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponseOfMember.java new file mode 100644 index 000000000..ab48cb05b --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponseOfMember.java @@ -0,0 +1,20 @@ +package dev.tripdraw.trip.dto; + +import static java.util.stream.Collectors.collectingAndThen; +import static java.util.stream.Collectors.toList; + +import dev.tripdraw.trip.domain.Trip; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; + +public record TripsSearchResponseOfMember( + @Schema(description = "여행 목록") + List trips +) { + + public static TripsSearchResponseOfMember from(List trips) { + return trips.stream() + .map(TripSearchResponseOfMember::from) + .collect(collectingAndThen(toList(), TripsSearchResponseOfMember::new)); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java b/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java index d4b03778d..1d057f31d 100644 --- a/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java @@ -16,6 +16,7 @@ public enum TripExceptionType implements ExceptionType { TRIP_INVALID_STATUS(BAD_REQUEST, "잘못된 여행 상태입니다."), POINT_ALREADY_HAS_POST(CONFLICT, "이미 감상이 등록된 위치입니다."), TRIP_ALREADY_DELETED(CONFLICT, "이미 삭제된 여행입니다."), + INVALID_TRIP_SEARCH(BAD_REQUEST, "유효하지 않은 여행 조회 조건입니다."), ; private final HttpStatus httpStatus; diff --git a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java index 66fe49b84..08a9f8f7d 100644 --- a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java +++ b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java @@ -12,8 +12,10 @@ import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; @@ -76,10 +78,10 @@ public ResponseEntity readPointById( return ResponseEntity.ok(response); } - @Operation(summary = "여행 조회 API", description = "단일 여행의 정보를 조회합니다.") + @Operation(summary = "나의 여행 조회 API", description = "회원 한 명의 단일 여행 정보를 조회합니다.") @ApiResponse( responseCode = "200", - description = "여행 조회 성공." + description = "나의 여행 조회 성공." ) @GetMapping("/trips/{tripId}") public ResponseEntity readById(@Auth LoginUser loginUser, @PathVariable Long tripId) { @@ -102,17 +104,31 @@ public ResponseEntity deletePoint( return ResponseEntity.noContent().build(); } - @Operation(summary = "여행 전체 조회 API", description = "모든 여행의 정보를 조회합니다.") + @Operation(summary = "나의 여행 전체 조회 API", description = "회원 한 명의 모든 여행 정보를 조회합니다.") @ApiResponse( responseCode = "200", - description = "여행 전체 조회 성공." + description = "나의 여행 전체 조회 성공." ) - @GetMapping("/trips") - public ResponseEntity readAll(@Auth LoginUser loginUser) { - TripsSearchResponse response = tripService.readAllTrips(loginUser); + @GetMapping("/trips/mine") + public ResponseEntity readAllOf(@Auth LoginUser loginUser) { + TripsSearchResponseOfMember response = tripService.readAllTripsOf(loginUser); return ResponseEntity.ok(response); } + @Operation(summary = "모든 회원 여행 전체 조회 API", description = "모든 회원의 여행 정보를 조건에 따라 조회합니다.") + @ApiResponse( + responseCode = "200", + description = "모든 회원 여행 전체 조회 성공." + ) + @GetMapping("/trips") + public ResponseEntity readAll( + @Auth LoginUser loginUser, + @RequestBody TripSearchRequest tripSearchRequest + ) { + TripsSearchResponse tripsSearchResponse = tripService.readAllTrips(tripSearchRequest); + return ResponseEntity.ok(tripsSearchResponse); + } + @Operation(summary = "여행 이름 수정 및 종료 API", description = "여행 이름을 수정하고, 여행을 종료합니다.") @ApiResponse( responseCode = "204", diff --git a/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java b/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java index 968b0bbc0..4c34fe304 100644 --- a/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java +++ b/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -23,4 +24,16 @@ class PagingTest { // then assertThat(actual).isEqualTo(expected); } + + @Test + void limit이_100을_넘기면_100으로_조정된다() { + // given + int limit = 101; + + // when + Paging paging = new Paging(1L, limit); + + // then + assertThat(paging.limit()).isEqualTo(100); + } } diff --git a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java index 6d8590913..536ab1536 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java @@ -1,7 +1,7 @@ package dev.tripdraw.draw.application; -import static dev.tripdraw.test.TestFixture.감상; -import static dev.tripdraw.test.TestFixture.여행; +import static dev.tripdraw.test.fixture.TestFixture.감상; +import static dev.tripdraw.test.fixture.TestFixture.여행; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; diff --git a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java index 8d818d527..18a809e52 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java @@ -1,7 +1,7 @@ package dev.tripdraw.draw.application; -import static dev.tripdraw.test.TestFixture.감상; -import static dev.tripdraw.test.TestFixture.여행; +import static dev.tripdraw.test.fixture.TestFixture.감상; +import static dev.tripdraw.test.fixture.TestFixture.여행; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; diff --git a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerIntegrationTest.java b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerIntegrationTest.java index dbbd7cae9..78523cbe2 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerIntegrationTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerIntegrationTest.java @@ -1,12 +1,11 @@ package dev.tripdraw.draw.application; -import static dev.tripdraw.test.TestFixture.여행; +import static dev.tripdraw.test.fixture.TestFixture.여행; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.timeout; -import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java index c524e59ee..45bdc12c8 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.draw.application; -import static dev.tripdraw.test.TestFixture.여행; +import static dev.tripdraw.test.fixture.TestFixture.여행; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; diff --git a/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java b/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java deleted file mode 100644 index 61c7b52a7..000000000 --- a/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java +++ /dev/null @@ -1,85 +0,0 @@ -package dev.tripdraw.test; - -import dev.tripdraw.trip.domain.SearchConditions; -import java.util.List; - - -public class SearchConditionsTestFixture { - - public static SearchConditions emptySearchConditions() { - return new SearchConditions( - List.of(), - List.of(), - List.of(), - List.of(), - List.of(), - "" - ); - } - - public static SearchConditions yearsSearchConditions(List years) { - return new SearchConditions( - years, - List.of(), - List.of(), - List.of(), - List.of(), - "" - ); - } - - public static SearchConditions monthsSearchConditions(List months) { - return new SearchConditions( - List.of(), - months, - List.of(), - List.of(), - List.of(), - "" - ); - } - - public static SearchConditions daysOfWeekSearchConditions(List daysOfWeek) { - return new SearchConditions( - List.of(), - List.of(), - daysOfWeek, - List.of(), - List.of(), - "" - ); - } - - public static SearchConditions ageRangesSearchConditions(List ageRanges) { - return new SearchConditions( - List.of(), - List.of(), - List.of(), - ageRanges, - List.of(), - "" - ); - } - - public static SearchConditions gendersSearchConditions(List genders) { - return new SearchConditions( - List.of(), - List.of(), - List.of(), - List.of(), - genders, - "" - ); - } - - public static SearchConditions addressSearchConditions(String address) { - return new SearchConditions( - List.of(), - List.of(), - List.of(), - List.of(), - List.of(), - address - ); - } -} diff --git a/backend/src/test/java/dev/tripdraw/test/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/TestFixture.java deleted file mode 100644 index 434233c23..000000000 --- a/backend/src/test/java/dev/tripdraw/test/TestFixture.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.tripdraw.test; - -import dev.tripdraw.common.auth.OauthType; -import dev.tripdraw.member.domain.Member; -import dev.tripdraw.post.domain.Post; -import dev.tripdraw.trip.domain.Point; -import dev.tripdraw.trip.domain.Trip; -import dev.tripdraw.trip.domain.TripName; -import dev.tripdraw.trip.domain.TripStatus; -import java.time.LocalDateTime; - -@SuppressWarnings("NonAsciiCharacters") -public class TestFixture { - - public static Member 사용자() { - return new Member(1L, "통후추", "", OauthType.KAKAO); - } - - public static Point 위치정보() { - return new Point(1L, 1.1, 2.2, false, LocalDateTime.now(), 여행()); - } - - public static Point 위치정보(int year, int month, int dayOfMonth, int hour, int minute) { - return new Point(1.1, 2.2, LocalDateTime.of(year, month, dayOfMonth, hour, minute)); - } - - public static Trip 여행() { - return new Trip(1L, TripName.from("통후추"), 사용자(), TripStatus.ONGOING, "", ""); - } - - public static Post 감상() { - return new Post("감상 제목", 위치정보(), "주소", "감상", 사용자(), 1L); - } -} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java new file mode 100644 index 000000000..c5e4c8d91 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java @@ -0,0 +1,85 @@ +package dev.tripdraw.test.fixture; + +import dev.tripdraw.trip.domain.SearchConditions; +import java.util.Set; + + +public class SearchConditionsFixture { + + public static SearchConditions emptySearchConditions() { + return new SearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static SearchConditions yearsSearchConditions(Set years) { + return new SearchConditions( + years, + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static SearchConditions monthsSearchConditions(Set months) { + return new SearchConditions( + Set.of(), + months, + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static SearchConditions daysOfWeekSearchConditions(Set daysOfWeek) { + return new SearchConditions( + Set.of(), + Set.of(), + daysOfWeek, + Set.of(), + Set.of(), + "" + ); + } + + public static SearchConditions ageRangesSearchConditions(Set ageRanges) { + return new SearchConditions( + Set.of(), + Set.of(), + Set.of(), + ageRanges, + Set.of(), + "" + ); + } + + public static SearchConditions gendersSearchConditions(Set genders) { + return new SearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + genders, + "" + ); + } + + public static SearchConditions addressSearchConditions(String address) { + return new SearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + address + ); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java new file mode 100644 index 000000000..8f5c37aed --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java @@ -0,0 +1,124 @@ +package dev.tripdraw.test.fixture; + +import static dev.tripdraw.trip.domain.TripStatus.FINISHED; + +import dev.tripdraw.common.auth.OauthType; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.dto.PostAndPointCreateRequest; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripName; +import dev.tripdraw.trip.domain.TripStatus; +import dev.tripdraw.trip.dto.PointCreateRequest; +import dev.tripdraw.trip.dto.TripUpdateRequest; +import java.time.LocalDateTime; + +@SuppressWarnings("NonAsciiCharacters") +public class TestFixture { + + public static Member 사용자() { + return new Member(1L, "통후추", "", OauthType.KAKAO); + } + + public static Point 위치정보() { + return new Point(1L, 1.1, 2.2, false, LocalDateTime.now(), 여행()); + } + + public static Point 위치정보(int year, int month, int dayOfMonth, int hour, int minute) { + return new Point(1.1, 2.2, LocalDateTime.of(year, month, dayOfMonth, hour, minute)); + } + + public static Trip 여행() { + return new Trip(1L, TripName.from("통후추"), 사용자(), TripStatus.ONGOING, "", ""); + } + + public static Post 감상() { + return new Post("감상 제목", 위치정보(), "주소", "감상", 사용자(), 1L); + } + + public static PointCreateRequest pointCreateRequest(Long tripId) { + return new PointCreateRequest( + tripId, + 1.1, + 2.2, + LocalDateTime.of(2023, 7, 18, 20, 24) + ); + } + + public static TripUpdateRequest tripUpdateRequest() { + return new TripUpdateRequest("제주도 여행", FINISHED); + } + + public static PostAndPointCreateRequest postAndPointCreateRequest(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "우도의 바닷가", + "제주특별자치도 제주시 애월읍 소길리", + "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", + 1.1, + 2.2, + LocalDateTime.of(2023, 7, 18, 20, 24) + ); + } + + public static PostAndPointCreateRequest 제주_2023_2_1_수(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "제목", + "제주특별자치도 제주시 애월읍", + "내용", + 0.0, + 0.0, + LocalDateTime.of(2023, 2, 1, 1, 1) + ); + } + + public static PostAndPointCreateRequest 서울_2023_1_1_일(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "제목", + "seoul_songpa_sincheon", + "내용", + 0.0, + 0.0, + LocalDateTime.of(2023, 1, 1, 10, 1) + ); + } + + public static PostAndPointCreateRequest 제주_2023_1_1_일(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "제목", + "제주특별자치도 제주시 애월읍", + "내용", + 0.0, + 0.0, + LocalDateTime.of(2023, 1, 1, 1, 1) + ); + } + + public static PostAndPointCreateRequest 서울_2022_1_2_일(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "제목", + "seoul_songpa_Bangi", + "내용", + 0.0, + 0.0, + LocalDateTime.of(2022, 1, 2, 1, 1) + ); + } + + public static PostAndPointCreateRequest 양양_2021_3_2_화(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "제목", + "강원도 양양", + "내용", + 0.0, + 0.0, + LocalDateTime.of(2021, 3, 2, 10, 1) + ); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java new file mode 100644 index 000000000..e4e78c2f5 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java @@ -0,0 +1,84 @@ +package dev.tripdraw.test.fixture; + +import dev.tripdraw.trip.dto.TripSearchConditions; +import java.util.Set; + +public class TripSearchConditionsFixture { + + public static TripSearchConditions emptyTripSearchConditions() { + return new TripSearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static TripSearchConditions yearsTripSearchConditions(Set years) { + return new TripSearchConditions( + years, + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static TripSearchConditions monthsTripSearchConditions(Set months) { + return new TripSearchConditions( + Set.of(), + months, + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static TripSearchConditions daysOfWeekTripSearchConditions(Set daysOfWeek) { + return new TripSearchConditions( + Set.of(), + Set.of(), + daysOfWeek, + Set.of(), + Set.of(), + "" + ); + } + + public static TripSearchConditions ageRangesTripSearchConditions(Set ageRanges) { + return new TripSearchConditions( + Set.of(), + Set.of(), + Set.of(), + ageRanges, + Set.of(), + "" + ); + } + + public static TripSearchConditions gendersTripSearchConditions(Set genders) { + return new TripSearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + genders, + "" + ); + } + + public static TripSearchConditions addressTripSearchConditions(String address) { + return new TripSearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + address + ); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/step/PostStep.java b/backend/src/test/java/dev/tripdraw/test/step/PostStep.java new file mode 100644 index 000000000..b75b76fbf --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/step/PostStep.java @@ -0,0 +1,30 @@ +package dev.tripdraw.test.step; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; + +import dev.tripdraw.post.dto.PostAndPointCreateRequest; +import dev.tripdraw.post.dto.PostCreateResponse; +import io.restassured.RestAssured; +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; + +public class PostStep { + + public static ExtractableResponse createPostAtCurrentPoint(PostAndPointCreateRequest request, + String token) { + return RestAssured.given().log().all() + .contentType(MULTIPART_FORM_DATA_VALUE) + .auth().preemptive().oauth2(token) + .multiPart("dto", request, APPLICATION_JSON_VALUE) + .when().post("/posts/current-location") + .then().log().all() + .extract(); + } + + public static PostCreateResponse createPostAtCurrentPointAndGetResponse(PostAndPointCreateRequest request, + String token) { + ExtractableResponse response = createPostAtCurrentPoint(request, token); + return response.as(PostCreateResponse.class); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/step/TripStep.java b/backend/src/test/java/dev/tripdraw/test/step/TripStep.java new file mode 100644 index 000000000..075ce1565 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/step/TripStep.java @@ -0,0 +1,62 @@ +package dev.tripdraw.test.step; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + +import dev.tripdraw.trip.dto.PointCreateRequest; +import dev.tripdraw.trip.dto.PointResponse; +import dev.tripdraw.trip.dto.TripCreateResponse; +import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripUpdateRequest; +import io.restassured.RestAssured; +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; + +public class TripStep { + + public static ExtractableResponse createTrip(String token) { + return RestAssured.given().log().all() + .auth().preemptive().oauth2(token) + .when().post("/trips") + .then().log().all() + .extract(); + } + + public static TripCreateResponse createTripAndGetResponse(String token) { + ExtractableResponse response = createTrip(token); + return response.as(TripCreateResponse.class); + } + + public static ExtractableResponse addPoint(PointCreateRequest request, String token) { + return RestAssured.given().log().all() + .contentType(APPLICATION_JSON_VALUE) + .auth().preemptive().oauth2(token) + .body(request) + .when().post("/points") + .then().log().all() + .extract(); + } + + public static PointResponse addPointAndGetResponse(PointCreateRequest request, String token) { + ExtractableResponse response = addPoint(request, token); + return response.as(PointResponse.class); + } + + public static ExtractableResponse updateTrip(TripUpdateRequest request, Long tripId, String token) { + return RestAssured.given().log().all() + .contentType(APPLICATION_JSON_VALUE) + .auth().preemptive().oauth2(token) + .body(request) + .when().patch("/trips/{tripId}", tripId) + .then().log().all() + .extract(); + } + + public static TripResponse searchTripAndGetResponse(Long tripId, String token) { + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(token) + .when().get("/trips/{tripId}", tripId) + .then().log().all() + .extract(); + return response.as(TripResponse.class); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index 2fa177ebd..37d13311a 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -9,11 +9,15 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import dev.tripdraw.common.auth.LoginUser; +import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.test.ServiceTest; +import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.dto.PointCreateRequest; @@ -21,13 +25,18 @@ import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchConditions; +import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripSearchResponse; +import dev.tripdraw.trip.dto.TripSearchResponseOfMember; import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; import java.util.Objects; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -45,6 +54,9 @@ class TripServiceTest { @Autowired private MemberRepository memberRepository; + @Autowired + private PostRepository postRepository; + @MockBean private RouteImageGenerator routeImageGenerator; @@ -54,8 +66,12 @@ class TripServiceTest { @BeforeEach void setUp() { Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - trip = tripRepository.save(Trip.from(member)); + Trip trip = Trip.from(member); + Point point = new Point(3.14, 5.25, LocalDateTime.now()); + trip.add(point); + this.trip = tripRepository.save(trip); loginUser = new LoginUser(member.id()); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); } @Test @@ -136,14 +152,14 @@ void setUp() { } @Test - void 전체_여행을_조회한다() { + void 특정_회원의_전체_여행을_조회한다() { // given & when - TripsSearchResponse tripsSearchResponse = tripService.readAllTrips(loginUser); + TripsSearchResponseOfMember tripsSearchResponseOfMember = tripService.readAllTripsOf(loginUser); // then - assertThat(tripsSearchResponse).usingRecursiveComparison().isEqualTo( - new TripsSearchResponse(List.of( - new TripSearchResponse( + assertThat(tripsSearchResponseOfMember).usingRecursiveComparison().isEqualTo( + new TripsSearchResponseOfMember(List.of( + new TripSearchResponseOfMember( trip.id(), trip.nameValue(), trip.imageUrl(), @@ -153,6 +169,39 @@ void setUp() { ); } + @Test + void 모든_회원의_감상이_있는_여행_전체를_조회한다() { + // given + TripSearchConditions emptyConditions = new TripSearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + SearchPaging searchPaging = new SearchPaging(null, 10); + TripSearchRequest tripSearchRequest = new TripSearchRequest(emptyConditions, searchPaging); + + // when + TripsSearchResponse tripsSearchResponse = tripService.readAllTrips(tripSearchRequest); + + // then + assertThat(tripsSearchResponse).usingRecursiveComparison().isEqualTo( + new TripsSearchResponse(List.of( + new TripSearchResponse( + trip.id(), + trip.nameValue(), + trip.imageUrl(), + trip.routeImageUrl(), + trip.createdAt(), + trip.updatedAt() + )), + false + ) + ); + } + @Test void 여행의_이름과_상태를_수정한다() { // given diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java new file mode 100644 index 000000000..0a8e16be6 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java @@ -0,0 +1,76 @@ +package dev.tripdraw.trip.domain; + +import static java.util.Set.of; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import dev.tripdraw.trip.exception.TripException; +import java.util.Set; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +class SearchConditionsTest { + + @ParameterizedTest + @ValueSource(ints = {2009, 2024}) + void 연도가_2010_미만_2023_초과이면_예외를_던진다(int year) { + // given + Set years = of(year); + + // expect + assertThatThrownBy(() -> new SearchConditions(years, of(), of(), of(), of(), "")) + .isInstanceOf(TripException.class) + .hasMessage("유효하지 않은 여행 조회 조건입니다."); + } + + @ParameterizedTest + @ValueSource(ints = {0, 13}) + void 월이_1_미만_12_초과이면_예외를_던진다(int month) { + // given + Set months = of(month); + + // expect + assertThatThrownBy(() -> new SearchConditions(of(), months, of(), of(), of(), "")) + .isInstanceOf(TripException.class) + .hasMessage("유효하지 않은 여행 조회 조건입니다."); + } + + @ParameterizedTest + @ValueSource(ints = {0, 8}) + void 요일이_1_미만_7_초과이면_예외를_던진다(int dayOfWeek) { + // given + Set daysOfWeek = of(dayOfWeek); + + // expect + assertThatThrownBy(() -> new SearchConditions(of(), of(), daysOfWeek, of(), of(), "")) + .isInstanceOf(TripException.class) + .hasMessage("유효하지 않은 여행 조회 조건입니다."); + } + + @ParameterizedTest + @ValueSource(ints = {0, 11}) + void 연령대가_1_미만_10_초과이면_예외를_던진다(int ageRange) { + // given + Set ageRanges = of(ageRange); + + // expect + assertThatThrownBy(() -> new SearchConditions(of(), of(), of(), ageRanges, of(), "")) + .isInstanceOf(TripException.class) + .hasMessage("유효하지 않은 여행 조회 조건입니다."); + } + + @ParameterizedTest + @ValueSource(ints = {0, 3}) + void 성별이_1_미만_2_초과이면_예외를_던진다(int gender) { + // given + Set genders = of(gender); + + // expect + assertThatThrownBy(() -> new SearchConditions(genders, of(), of(), of(), of(), "")) + .isInstanceOf(TripException.class) + .hasMessage("유효하지 않은 여행 조회 조건입니다."); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index 2b32c017e..a03be42b6 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -1,12 +1,12 @@ package dev.tripdraw.trip.domain; import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.test.SearchConditionsTestFixture.addressSearchConditions; -import static dev.tripdraw.test.SearchConditionsTestFixture.daysOfWeekSearchConditions; -import static dev.tripdraw.test.SearchConditionsTestFixture.emptySearchConditions; -import static dev.tripdraw.test.SearchConditionsTestFixture.monthsSearchConditions; -import static dev.tripdraw.test.SearchConditionsTestFixture.yearsSearchConditions; -import static dev.tripdraw.test.TestFixture.위치정보; +import static dev.tripdraw.test.fixture.SearchConditionsFixture.addressSearchConditions; +import static dev.tripdraw.test.fixture.SearchConditionsFixture.daysOfWeekSearchConditions; +import static dev.tripdraw.test.fixture.SearchConditionsFixture.emptySearchConditions; +import static dev.tripdraw.test.fixture.SearchConditionsFixture.monthsSearchConditions; +import static dev.tripdraw.test.fixture.SearchConditionsFixture.yearsSearchConditions; +import static dev.tripdraw.test.fixture.TestFixture.위치정보; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -22,6 +22,7 @@ import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -140,11 +141,11 @@ void setUp() { class 조건에_따라_여행을_조회할_때 { @Nested - class 개수_제한을_입력하면 { + class 개수_제한이 { @ParameterizedTest @CsvSource({"0, 1", "1, 2", "2, 3"}) - void 개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { + void 여행의_개수보다_적으면_개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { // given jeju_2023_1_1_Sun(); jeju_2023_1_1_Sun(); @@ -158,6 +159,21 @@ class 개수_제한을_입력하면 { // then assertThat(trips).hasSize(expectedSize); } + + @ParameterizedTest + @CsvSource({"1, 1", "2, 1"}) + void 여행의_개수보다_많거나_같으면_모든_여행을_반환한다(int limit, int expectedSize) { + // given + jeju_2023_1_1_Sun(); + + Paging paging = new Paging(null, limit); + + // when + List trips = tripRepository.findAllByConditions(emptySearchConditions(), paging); + + // then + assertThat(trips).hasSize(expectedSize); + } } @Nested @@ -213,7 +229,7 @@ class 조건으로_연도를 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - SearchConditions searchConditions = yearsSearchConditions(List.of(2023)); + SearchConditions searchConditions = yearsSearchConditions(Set.of(2023)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -231,7 +247,7 @@ class 조건으로_연도를 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - SearchConditions searchConditions = yearsSearchConditions(List.of(2023, 2021)); + SearchConditions searchConditions = yearsSearchConditions(Set.of(2023, 2021)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -257,7 +273,7 @@ class 조건으로_월을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - SearchConditions searchConditions = monthsSearchConditions(List.of(1)); + SearchConditions searchConditions = monthsSearchConditions(Set.of(1)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -275,7 +291,7 @@ class 조건으로_월을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - SearchConditions searchConditions = monthsSearchConditions(List.of(1, 3)); + SearchConditions searchConditions = monthsSearchConditions(Set.of(1, 3)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -301,7 +317,7 @@ class 조건으로_요일을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - SearchConditions searchConditions = daysOfWeekSearchConditions(List.of(1)); + SearchConditions searchConditions = daysOfWeekSearchConditions(Set.of(1)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -319,7 +335,7 @@ class 조건으로_요일을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - SearchConditions searchConditions = daysOfWeekSearchConditions(List.of(1, 3)); + SearchConditions searchConditions = daysOfWeekSearchConditions(Set.of(1, 3)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -399,11 +415,11 @@ class 조건을 { jeju_2023_2_1_Wed(); SearchConditions searchConditions = new SearchConditions( - List.of(2023), - List.of(1), - List.of(), - List.of(), - List.of(), + Set.of(2023), + Set.of(1), + Set.of(), + Set.of(), + Set.of(), "서울특별시" ); diff --git a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseOfMemberTest.java similarity index 82% rename from backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java rename to backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseOfMemberTest.java index 0009c1499..8f273eee4 100644 --- a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseOfMemberTest.java @@ -13,7 +13,7 @@ @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class TripSearchResponseTest { +class TripSearchResponseOfMemberTest { @Test void 여행_이미지와_경로_이미지가_null이면_빈값으로_변환해_생성한다() { @@ -23,11 +23,11 @@ class TripSearchResponseTest { Trip trip = new Trip(1L, tripName, member, ONGOING, null, null); // when - TripSearchResponse response = TripSearchResponse.from(trip); + TripSearchResponseOfMember response = TripSearchResponseOfMember.from(trip); // then assertThat(response).usingRecursiveComparison().isEqualTo( - TripSearchResponse.from(new Trip(1L, tripName, member, ONGOING, "", "")) + TripSearchResponseOfMember.from(new Trip(1L, tripName, member, ONGOING, "", "")) ); } } diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index 5bf763a3e..7c159efcf 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -1,8 +1,26 @@ package dev.tripdraw.trip.presentation; import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.TestFixture.pointCreateRequest; +import static dev.tripdraw.test.fixture.TestFixture.tripUpdateRequest; +import static dev.tripdraw.test.fixture.TestFixture.서울_2022_1_2_일; +import static dev.tripdraw.test.fixture.TestFixture.서울_2023_1_1_일; +import static dev.tripdraw.test.fixture.TestFixture.양양_2021_3_2_화; +import static dev.tripdraw.test.fixture.TestFixture.제주_2023_1_1_일; +import static dev.tripdraw.test.fixture.TestFixture.제주_2023_2_1_수; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.addressTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.daysOfWeekTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.emptyTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.monthsTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.yearsTripSearchConditions; +import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; +import static dev.tripdraw.test.step.TripStep.addPointAndGetResponse; +import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; +import static dev.tripdraw.test.step.TripStep.searchTripAndGetResponse; +import static dev.tripdraw.test.step.TripStep.updateTrip; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; @@ -10,29 +28,37 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import dev.tripdraw.auth.application.JwtTokenProvider; +import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.test.ControllerTest; -import dev.tripdraw.trip.domain.Trip; -import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.dto.PointCreateRequest; import dev.tripdraw.trip.dto.PointCreateResponse; import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchConditions; +import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripSearchResponse; +import dev.tripdraw.trip.dto.TripSearchResponseOfMember; import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import java.time.LocalDateTime; import java.util.List; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -42,9 +68,6 @@ class TripControllerTest extends ControllerTest { private static final String WRONG_TOKEN = "wrong.long.token"; - @Autowired - private TripRepository tripRepository; - @Autowired private MemberRepository memberRepository; @@ -54,16 +77,21 @@ class TripControllerTest extends ControllerTest { @MockBean private RouteImageGenerator routeImageGenerator; - private Trip trip; private String huchuToken; + private String leoToken; + private String herbToken; @BeforeEach public void setUp() { super.setUp(); - Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - trip = tripRepository.save(Trip.from(member)); - huchuToken = jwtTokenProvider.generateAccessToken(member.id().toString()); + Member huchu = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + Member leo = memberRepository.save(new Member("리오", "kakaoId", KAKAO)); + Member herb = memberRepository.save(new Member("허브", "kakaoId", KAKAO)); + + huchuToken = jwtTokenProvider.generateAccessToken(huchu.id().toString()); + leoToken = jwtTokenProvider.generateAccessToken(leo.id().toString()); + herbToken = jwtTokenProvider.generateAccessToken(herb.id().toString()); } @Test @@ -97,8 +125,9 @@ public void setUp() { @Test void 여행에_위치_정보를_추가한다() { // given + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); PointCreateRequest request = new PointCreateRequest( - trip.id(), + tripResponse.tripId(), 1.1, 2.2, LocalDateTime.of(2023, 7, 18, 20, 24) @@ -125,8 +154,9 @@ public void setUp() { @Test void 위치_정보_추가_시_인증에_실패하면_예외를_발생시킨다() { // given + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); PointCreateRequest request = new PointCreateRequest( - trip.id(), + tripResponse.tripId(), 1.1, 2.2, LocalDateTime.of(2023, 7, 18, 20, 24) @@ -144,10 +174,13 @@ public void setUp() { @Test void 여행을_ID로_조회한다() { - // given & when + // given + Long tripId = createTripAndGetResponse(huchuToken).tripId(); + + // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .when().get("/trips/{tripId}", trip.id()) + .when().get("/trips/{tripId}", tripId) .then().log().all() .extract(); @@ -166,28 +199,14 @@ public void setUp() { @Test void 특정_위치정보를_삭제한다() { // given - PointCreateRequest pointCreateRequest = new PointCreateRequest( - trip.id(), - 1.1, - 2.2, - LocalDateTime.of(2023, 7, 18, 20, 24) - ); - - ExtractableResponse response = RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) - .auth().preemptive().oauth2(huchuToken) - .body(pointCreateRequest) - .when().post("/points") - .then().log().all() - .extract(); - - PointResponse pointResponse = response.as(PointResponse.class); + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); + PointResponse pointResponse = addPointAndGetResponse(pointCreateRequest(tripResponse.tripId()), huchuToken); // expect RestAssured.given().log().all() .contentType(APPLICATION_JSON_VALUE) .auth().preemptive().oauth2(huchuToken) - .param("tripId", trip.id()) + .param("tripId", tripResponse.tripId()) .when().delete("/points/{pointId}", pointResponse.pointId()) .then().log().all() .statusCode(NO_CONTENT.value()); @@ -196,54 +215,45 @@ public void setUp() { @Test void 특정_위치정보_삭제시_인증에_실패하면_예외를_발생시킨다() { // given - PointCreateRequest pointCreateRequest = new PointCreateRequest( - trip.id(), - 1.1, - 2.2, - LocalDateTime.of(2023, 7, 18, 20, 24) - ); - - ExtractableResponse response = RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) - .auth().preemptive().oauth2(huchuToken) - .body(pointCreateRequest) - .when().post("/points") - .then().log().all() - .extract(); - - PointResponse pointResponse = response.as(PointResponse.class); + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); + PointResponse pointResponse = addPointAndGetResponse(pointCreateRequest(tripResponse.tripId()), huchuToken); // expect RestAssured.given().log().all() .contentType(APPLICATION_JSON_VALUE) .auth().preemptive().oauth2(WRONG_TOKEN) - .param("tripId", trip.id()) + .param("tripId", tripResponse.tripId()) .when().delete("/points/{pointId}", pointResponse.pointId()) .then().log().all() .statusCode(UNAUTHORIZED.value()); } @Test - void 전체_여행을_조회한다() { + void 특정_회원의_전체_여행을_조회한다() { // given + Long tripId = createTripAndGetResponse(huchuToken).tripId(); + updateTrip(tripUpdateRequest(), tripId, huchuToken); + + // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .when().get("/trips") + .when().get("/trips/mine") .then().log().all() .extract(); // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + TripsSearchResponseOfMember tripsSearchResponseOfMember = response.as(TripsSearchResponseOfMember.class); assertSoftly(softly -> { softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(tripsSearchResponse).usingRecursiveComparison().isEqualTo( - new TripsSearchResponse( - List.of(new TripSearchResponse( - trip.id(), - trip.nameValue(), - trip.imageUrl(), - trip.routeImageUrl()) + softly.assertThat(tripsSearchResponseOfMember).usingRecursiveComparison().isEqualTo( + new TripsSearchResponseOfMember( + List.of(new TripSearchResponseOfMember( + tripId, + "제주도 여행", + "", + "" + ) ) ) ); @@ -253,6 +263,7 @@ public void setUp() { @Test void 여행의_이름과_상태를_수정한다() { // given + Long tripId = createTripAndGetResponse(huchuToken).tripId(); TripUpdateRequest tripUpdateRequest = new TripUpdateRequest("제주도 여행", FINISHED); // when @@ -260,35 +271,30 @@ public void setUp() { .contentType(APPLICATION_JSON_VALUE) .auth().preemptive().oauth2(huchuToken) .body(tripUpdateRequest) - .when().patch("/trips/{tripId}", trip.id()) + .when().patch("/trips/{tripId}", tripId) .then().log().all() .extract(); // then - Trip updatedTrip = tripRepository.findById(trip.id()).get(); + TripResponse tripResponse = searchTripAndGetResponse(tripId, huchuToken); assertSoftly(softly -> { softly.assertThat(response.statusCode()).isEqualTo(NO_CONTENT.value()); - softly.assertThat(updatedTrip.nameValue()).isEqualTo("제주도 여행"); - softly.assertThat(updatedTrip.status()).isEqualTo(FINISHED); + softly.assertThat(tripResponse.name()).isEqualTo("제주도 여행"); + softly.assertThat(tripResponse.status()).isEqualTo(FINISHED); }); } @Test void 위치_정보를_조회한다() { // given - PointCreateRequest request = new PointCreateRequest( - trip.id(), - 1.1, - 2.2, - LocalDateTime.of(2023, 7, 18, 20, 24) - ); - Long pointId = createPointAndGetId(request).pointId(); + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); + Long pointId = addPointAndGetResponse(pointCreateRequest(tripResponse.tripId()), huchuToken).pointId(); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .param("tripId", trip.id()) + .param("tripId", tripResponse.tripId()) .when().get("/points/{pointId}", pointId) .then().log().all() .extract(); @@ -312,33 +318,487 @@ public void setUp() { @Test void 여행을_삭제한다() { + // given + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); + Long tripId = tripResponse.tripId(); + // expect RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .when().delete("/trips/{tripId}", trip.id()) + .when().delete("/trips/{tripId}", tripId) .then().log().all() .statusCode(NO_CONTENT.value()); } @Test void 여행을_삭제할_때_인증에_실패하면_예외가_발생한다() { + // given + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); + Long tripId = tripResponse.tripId(); + // expect RestAssured.given().log().all() .auth().preemptive().oauth2(WRONG_TOKEN) - .when().delete("/trips/{tripId}", trip.id()) + .when().delete("/trips/{tripId}", tripId) .then().log().all() .statusCode(UNAUTHORIZED.value()); } - private PointCreateResponse createPointAndGetId(PointCreateRequest request) { - ExtractableResponse response = RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) - .auth().preemptive().oauth2(huchuToken) - .body(request) - .when().post("/points") - .then().log().all() - .extract(); - - return response.as(PointCreateResponse.class); + @Nested + class 여러_회원이_여행에_감상을_남긴_후 { + + private Long lastViewedId; + private Long 후추_양양_2021_3_2_화; + private Long 후추_서울_2022_1_2_일; + private Long 리오_제주_2023_1_1_일; + private Long 리오_서울_2023_1_1_일; + private Long 허브_제주_2023_2_1_수; + + @BeforeEach + void setUp() { + 후추_양양_2021_3_2_화 = createTripAndGetResponse(huchuToken).tripId(); + createPostAtCurrentPoint(양양_2021_3_2_화(후추_양양_2021_3_2_화), huchuToken); + + 후추_서울_2022_1_2_일 = createTripAndGetResponse(huchuToken).tripId(); + createPostAtCurrentPoint(서울_2022_1_2_일(후추_서울_2022_1_2_일), huchuToken); + + 리오_제주_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); + createPostAtCurrentPoint(제주_2023_1_1_일(리오_제주_2023_1_1_일), leoToken); + + 리오_서울_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); + createPostAtCurrentPoint(서울_2023_1_1_일(리오_서울_2023_1_1_일), leoToken); + + 허브_제주_2023_2_1_수 = createTripAndGetResponse(herbToken).tripId(); + createPostAtCurrentPoint(제주_2023_2_1_수(허브_제주_2023_2_1_수), herbToken); + + lastViewedId = 허브_제주_2023_2_1_수; + } + + @Nested + class 감상이_있는_모든_여행을_페이지네이션으로_조회할_때 { + + @Nested + class 조회할_수_있는_여행_수_미만으로_개수_제한을_입력하면 { + + @ParameterizedTest + @CsvSource({"1, 1", "4, 4"}) + void 해당_개수만큼_여행이_조회된다(int limit, int expectedSize) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); + }); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + void 다음_페이지가_존재한다(int limit) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.hasNextPage()).isTrue(); + }); + } + } + + @Nested + class 조회할_수_있는_여행_수_이상으로_개수_제한을_입력하면 { + + @ParameterizedTest + @CsvSource({"5, 5", "6, 5"}) + void 모든_여행이_조회된다(int limit, int expectedSize) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); + }); + } + + @ParameterizedTest + @ValueSource(ints = {5, 6}) + void 다음_페이지가_존재하지_않는다(int limit) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.hasNextPage()).isFalse(); + }); + } + } + + @Nested + class 마지막으로_조회한_여행_ID를 { + + private static final int LIMIT = 10; + + @Test + void 입력하지_않으면_최신_여행부터_내림차순으로_조회된다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, LIMIT) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 입력하면_해당_여행_이하로_최신_여행을_내림차순으로_조회된다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(lastViewedId, LIMIT) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + } + } + + private List searchedTripIds(TripsSearchResponse tripsSearchResponse) { + return tripsSearchResponse.trips().stream() + .map(TripSearchResponse::tripId) + .toList(); + } + + @Nested + class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { + + private final SearchPaging nullLastViewedIdAnd10Limit = new SearchPaging(null, 10); + + @Test + void 조건없이_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 연도를_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + yearsTripSearchConditions(Set.of(2023)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일 + ); + }); + } + + @Test + void 월을_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + monthsTripSearchConditions(Set.of(1, 2)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일 + ); + }); + } + + @Test + void 요일을_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + daysOfWeekTripSearchConditions(Set.of(1, 3)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 주소를_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + addressTripSearchConditions("seoul_songpa"), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 후추_서울_2022_1_2_일 + ); + }); + } + + @Test + void 여러_조건으로_조회할_수_있다() { + // given + var multiSearchConditions = new TripSearchConditions( + Set.of(2023, 2021), + Set.of(), + Set.of(1), + Set.of(), + Set.of(), + "seoul" + ); + var tripSearchRequest = new TripSearchRequest( + multiSearchConditions, + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일 + ); + }); + } + + @Test + void 조건이_유효하지_않을_경우_예외를_발생시킨다() { + // given + var tripSearchRequest = new TripSearchRequest( + monthsTripSearchConditions(Set.of(Integer.MAX_VALUE)), + nullLastViewedIdAnd10Limit + ); + + // expect + RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .statusCode(BAD_REQUEST.value()); + } + + @Test + void 인증에_실패할_경우_예외를_발생시킨다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + nullLastViewedIdAnd10Limit + ); + + // expect + RestAssured.given().log().all() + .auth().preemptive().oauth2(WRONG_TOKEN) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .statusCode(UNAUTHORIZED.value()); + } + } } } From b164083acb63eb0a9186259af876e1420cc4ee7f Mon Sep 17 00:00:00 2001 From: ReO Date: Fri, 15 Sep 2023 18:05:12 +0900 Subject: [PATCH 059/119] =?UTF-8?q?feat:=20=EA=B0=90=EC=83=81=EC=9D=84=20?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=EB=B3=84=EB=A1=9C=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 21 ++++ .../common/config/QueryDslConfig.java | 19 ++++ .../dev/tripdraw/common/domain/Paging.java | 4 + .../dev/tripdraw/common/dto/SearchPaging.java | 9 ++ .../post/application/PostService.java | 20 ++++ .../post/domain/PostCustomRepository.java | 10 ++ .../post/domain/PostCustomRepositoryImpl.java | 61 +++++++++++ .../tripdraw/post/domain/PostRepository.java | 5 +- .../post/domain/SearchConditions.java | 17 +++ .../post/dto/PostSearchConditions.java | 29 +++++ .../tripdraw/post/dto/PostSearchRequest.java | 6 + .../tripdraw/post/dto/PostSearchResponse.java | 29 +++++ .../post/dto/PostsSearchResponse.java | 9 ++ .../post/presentation/PostController.java | 17 +++ .../domain/RefreshTokenRepositoryTest.java | 7 +- .../member/domain/MemberRepositoryTest.java | 7 +- .../post/application/PostServiceTest.java | 103 +++++++++++------- .../domain/PostCustomRepositoryImplTest.java | 82 ++++++++++++++ .../post/domain/PostRepositoryTest.java | 9 +- ...PostResponseAndPointCreateRequestTest.java | 6 +- .../post/presentation/PostControllerTest.java | 92 ++++++++++++---- .../trip/domain/PointRepositoryTest.java | 7 +- .../trip/domain/TripRepositoryTest.java | 9 +- 23 files changed, 501 insertions(+), 77 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java create mode 100644 backend/src/main/java/dev/tripdraw/common/domain/Paging.java create mode 100644 backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java create mode 100644 backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepository.java create mode 100644 backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java create mode 100644 backend/src/main/java/dev/tripdraw/post/domain/SearchConditions.java create mode 100644 backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java create mode 100644 backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java create mode 100644 backend/src/main/java/dev/tripdraw/post/dto/PostSearchResponse.java create mode 100644 backend/src/main/java/dev/tripdraw/post/dto/PostsSearchResponse.java create mode 100644 backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java diff --git a/backend/build.gradle b/backend/build.gradle index cb1b4be1c..6724178ae 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -54,6 +54,12 @@ dependencies { // lombok compileOnly 'org.projectlombok:lombok:1.18.28' annotationProcessor 'org.projectlombok:lombok:1.18.28' + + // querydsl + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" } processResources.dependsOn('copySecret') @@ -71,3 +77,18 @@ tasks.named('test') { tasks.named('compileJava') { inputs.files(tasks.named('processResources')) } + +// Querydsl +def querydslDir = "$buildDir/generated/querydsl" + +sourceSets { + main.java.srcDirs += [querydslDir] +} + +tasks.withType(JavaCompile).configureEach { + options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir) +} + +clean.doLast { + file(querydslDir).deleteDir() +} diff --git a/backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java b/backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java new file mode 100644 index 000000000..9df83f7ab --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java @@ -0,0 +1,19 @@ +package dev.tripdraw.common.config; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class QueryDslConfig { + + @PersistenceContext + private EntityManager entityManager; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(entityManager); + } +} diff --git a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java b/backend/src/main/java/dev/tripdraw/common/domain/Paging.java new file mode 100644 index 000000000..1788bf8ac --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/common/domain/Paging.java @@ -0,0 +1,4 @@ +package dev.tripdraw.common.domain; + +public record Paging(Long lastViewedId, Integer limit) { +} diff --git a/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java b/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java new file mode 100644 index 000000000..989ce5da8 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java @@ -0,0 +1,9 @@ +package dev.tripdraw.common.dto; + +import dev.tripdraw.common.domain.Paging; + +public record SearchPaging(Long lastViewedId, Integer limit) { + public Paging toPaging() { + return new Paging(lastViewedId, limit); + } +} diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index 3cd1e95bb..87222e369 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -5,18 +5,23 @@ import static java.util.stream.Collectors.toList; import dev.tripdraw.common.auth.LoginUser; +import dev.tripdraw.common.domain.Paging; import dev.tripdraw.file.application.FileUploader; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.domain.Post; import dev.tripdraw.post.domain.PostCreateEvent; import dev.tripdraw.post.domain.PostRepository; +import dev.tripdraw.post.domain.SearchConditions; import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; +import dev.tripdraw.post.dto.PostSearchRequest; +import dev.tripdraw.post.dto.PostSearchResponse; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; +import dev.tripdraw.post.dto.PostsSearchResponse; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.PointRepository; import dev.tripdraw.trip.domain.Trip; @@ -27,6 +32,8 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import java.util.List; + @RequiredArgsConstructor @Transactional @Service @@ -121,5 +128,18 @@ public void delete(LoginUser loginUser, Long postId) { post.validateAuthorization(member); postRepository.deleteById(postId); } + + public PostsSearchResponse readAll(PostSearchRequest postSearchRequest) { + SearchConditions searchConditions = postSearchRequest.condition().toSearchConditions(); + Paging paging = postSearchRequest.paging().toPaging(); + List posts = postRepository.findAllByConditions(searchConditions, paging); + + List postSearchResponses = posts.stream() + .map(PostSearchResponse::from) + .toList(); + boolean hasNextPage = (posts.size() == postSearchRequest.paging().limit() + 1); + + return PostsSearchResponse.of(postSearchResponses, hasNextPage); + } } diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepository.java b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepository.java new file mode 100644 index 000000000..638ccf45d --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepository.java @@ -0,0 +1,10 @@ +package dev.tripdraw.post.domain; + +import dev.tripdraw.common.domain.Paging; + +import java.util.List; + +public interface PostCustomRepository { + + List findAllByConditions(SearchConditions conditions, Paging paging); +} diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java new file mode 100644 index 000000000..006dd9dc2 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java @@ -0,0 +1,61 @@ +package dev.tripdraw.post.domain; + +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.NumberExpression; +import com.querydsl.core.types.dsl.StringPath; +import com.querydsl.jpa.impl.JPAQueryFactory; +import dev.tripdraw.common.domain.Paging; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@RequiredArgsConstructor +@Repository +public class PostCustomRepositoryImpl implements PostCustomRepository { + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public List findAllByConditions(SearchConditions conditions, Paging paging) { + QPost post = QPost.post; + + // TODO: 2023/09/16 연령대, 성별 추가 + return jpaQueryFactory.selectFrom(post) + .where( + ltLastViewedId(post, paging.lastViewedId()), + contains(post.point.recordedAt.year(), conditions.years()), + contains(post.point.recordedAt.month(), conditions.months()), + contains(post.point.recordedAt.dayOfWeek(), conditions.daysOfWeek()), + contains(post.point.recordedAt.hour(), conditions.hours()), + eqAdress(post.address, conditions.address()) + ) + .limit(paging.limit()) + .orderBy(post.id.desc()) + .fetch(); + } + + private BooleanExpression ltLastViewedId(QPost post, Long lastViewedId) { + if (lastViewedId == null) { + return null; + } + + return post.id.lt(lastViewedId); + } + + private BooleanExpression contains(NumberExpression value, List values) { + if (values == null || values.isEmpty()) { + return null; + } + + return value.in(values); + } + + private BooleanExpression eqAdress(StringPath address, String targetAddress) { + if (targetAddress == null || targetAddress.isEmpty()) { + return null; + } + + return address.eq(targetAddress); + } +} diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java index 09ad39711..8d93b416e 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java @@ -3,10 +3,11 @@ import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; import dev.tripdraw.post.exception.PostException; -import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; -public interface PostRepository extends JpaRepository { +import java.util.List; + +public interface PostRepository extends JpaRepository, PostCustomRepository { List findAllByTripId(Long tripId); diff --git a/backend/src/main/java/dev/tripdraw/post/domain/SearchConditions.java b/backend/src/main/java/dev/tripdraw/post/domain/SearchConditions.java new file mode 100644 index 000000000..d76ca3753 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/domain/SearchConditions.java @@ -0,0 +1,17 @@ +package dev.tripdraw.post.domain; + +import lombok.Builder; + +import java.util.List; + +@Builder +public record SearchConditions( + List years, + List months, + List daysOfWeek, + List hours, + List ageRanges, + List genders, + String address +) { +} diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java new file mode 100644 index 000000000..c7ed4d6e0 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java @@ -0,0 +1,29 @@ +package dev.tripdraw.post.dto; + +import dev.tripdraw.post.domain.SearchConditions; +import lombok.Builder; + +import java.util.List; + +@Builder +public record PostSearchConditions( + List years, + List months, + List daysOfWeek, + List hours, + List ageRanges, + List genders, + String address +) { + public SearchConditions toSearchConditions() { + return SearchConditions.builder() + .years(years) + .months(months) + .daysOfWeek(daysOfWeek) + .hours(hours) + .ageRanges(ageRanges) + .genders(genders) + .address(address) + .build(); + } +} diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java new file mode 100644 index 000000000..ee9432d98 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java @@ -0,0 +1,6 @@ +package dev.tripdraw.post.dto; + +import dev.tripdraw.common.dto.SearchPaging; + +public record PostSearchRequest(PostSearchConditions condition, SearchPaging paging) { +} diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchResponse.java b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchResponse.java new file mode 100644 index 000000000..28e9cf33c --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchResponse.java @@ -0,0 +1,29 @@ +package dev.tripdraw.post.dto; + +import dev.tripdraw.post.domain.Post; + +import java.time.LocalDateTime; + +public record PostSearchResponse( + Long postId, + Long tripId, + String title, + String address, + String writing, + String postImageUrl, + String routeImageUrl, + LocalDateTime recordedAt +) { + public static PostSearchResponse from(Post post) { + return new PostSearchResponse( + post.id(), + post.tripId(), + post.title(), + post.address(), + post.writing(), + post.postImageUrl(), + post.routeImageUrl(), + post.pointRecordedAt() + ); + } +} diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostsSearchResponse.java b/backend/src/main/java/dev/tripdraw/post/dto/PostsSearchResponse.java new file mode 100644 index 000000000..7e713d7d0 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostsSearchResponse.java @@ -0,0 +1,9 @@ +package dev.tripdraw.post.dto; + +import java.util.List; + +public record PostsSearchResponse(List posts, boolean hasNextPage) { + public static PostsSearchResponse of(List postSearchResponses, boolean hasNextPage) { + return new PostsSearchResponse(postSearchResponses, hasNextPage); + } +} diff --git a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java index fe0cffd08..c563d3394 100644 --- a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java +++ b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java @@ -13,8 +13,10 @@ import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; +import dev.tripdraw.post.dto.PostSearchRequest; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; +import dev.tripdraw.post.dto.PostsSearchResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -27,6 +29,7 @@ import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; @@ -121,6 +124,20 @@ public ResponseEntity readAllPostsOfTrip( return ResponseEntity.ok(response); } + @Operation(summary = "모든 감상 조회 API", description = "모든 감상을 조회합니다.") + @ApiResponse( + responseCode = "200", + description = "모든 감상 조회 성공." + ) + @GetMapping("/posts") + public ResponseEntity readAllPosts( + @Auth LoginUser loginUser, + @RequestBody PostSearchRequest postSearchRequest + ) { + PostsSearchResponse response = postService.readAll(postSearchRequest); + return ResponseEntity.ok(response); + } + @Operation(summary = "감상 수정 API", description = "주소를 제외한 감상의 모든 정보를 수정합니다.") @ApiResponse( responseCode = "204", diff --git a/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java index f652fdaa6..8bb735174 100644 --- a/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java @@ -2,16 +2,21 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.Optional; +import dev.tripdraw.common.config.JpaConfig; +import dev.tripdraw.common.config.QueryDslConfig; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +import java.util.Optional; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @DataJpaTest +@Import({JpaConfig.class, QueryDslConfig.class}) class RefreshTokenRepositoryTest { @Autowired diff --git a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java index 2a96e2981..f2745c7af 100644 --- a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java @@ -5,17 +5,22 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import dev.tripdraw.common.config.JpaConfig; +import dev.tripdraw.common.config.QueryDslConfig; import dev.tripdraw.member.exception.MemberException; -import java.util.Optional; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +import java.util.Optional; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @DataJpaTest +@Import({JpaConfig.class, QueryDslConfig.class}) class MemberRepositoryTest { @Autowired diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index 9ea9cb413..e9e8dc714 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -16,6 +16,7 @@ import static org.mockito.Mockito.mock; import dev.tripdraw.common.auth.LoginUser; +import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.file.application.FileUploader; import dev.tripdraw.member.domain.Member; @@ -25,8 +26,12 @@ import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; +import dev.tripdraw.post.dto.PostSearchConditions; +import dev.tripdraw.post.dto.PostSearchRequest; +import dev.tripdraw.post.dto.PostSearchResponse; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; +import dev.tripdraw.post.dto.PostsSearchResponse; import dev.tripdraw.post.exception.PostException; import dev.tripdraw.test.ServiceTest; import dev.tripdraw.trip.domain.Point; @@ -34,14 +39,15 @@ import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.exception.TripException; -import java.time.LocalDateTime; -import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.web.multipart.MultipartFile; +import java.time.LocalDateTime; +import java.util.List; + @ServiceTest class PostServiceTest { @@ -86,7 +92,7 @@ void setUp() { PostAndPointCreateRequest request = new PostAndPointCreateRequest( trip.id(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, @@ -107,7 +113,7 @@ void setUp() { PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( trip.id(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, @@ -126,7 +132,7 @@ void setUp() { PostAndPointCreateRequest requestOfNotExistedTripId = new PostAndPointCreateRequest( Long.MIN_VALUE, "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, @@ -146,7 +152,7 @@ void setUp() { trip.id(), point.id(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다." ); given(routeImageGenerator.generate(any(), any(), any(), any())).willReturn("hello.png"); @@ -166,7 +172,7 @@ void setUp() { trip.id(), point.id(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다." ); @@ -183,7 +189,7 @@ void setUp() { Long.MIN_VALUE, point.id(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다." ); @@ -200,7 +206,7 @@ void setUp() { trip.id(), Long.MIN_VALUE, "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다." ); @@ -213,7 +219,7 @@ void setUp() { @Test void 특정_감상을_조회한다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); // when PostResponse postResponse = postService.read(loginUser, postCreateResponse.postId()); @@ -237,7 +243,7 @@ void setUp() { @Test void 특정_감상을_조회할_때_존재하지_않는_사용자_닉네임이면_예외를_발생시킨다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); // expect @@ -249,7 +255,7 @@ void setUp() { @Test void 특정_감상을_조회할_때_로그인_한_사용자가_감상의_작성자가_아니면_예외가_발생한다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); // expect assertThatThrownBy(() -> postService.read(otherUser, postCreateResponse.postId())) @@ -260,8 +266,8 @@ void setUp() { @Test void 특정_여행의_모든_감상을_조회한다() { // given - createPost(); - createPost2(); + createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); + createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); // when PostsResponse postsResponse = postService.readAllByTripId(loginUser, trip.id()); @@ -270,10 +276,8 @@ void setUp() { List posts = postsResponse.posts(); assertSoftly(softly -> { softly.assertThat(posts.get(0).postId()).isNotNull(); - softly.assertThat(posts.get(0).title()).isEqualTo("우도의 땅콩 아이스크림"); softly.assertThat(posts.get(0).pointResponse().pointId()).isNotNull(); softly.assertThat(posts.get(1).postId()).isNotNull(); - softly.assertThat(posts.get(1).title()).isEqualTo("우도의 바닷가"); softly.assertThat(posts.get(1).pointResponse().pointId()).isNotNull(); }); } @@ -305,10 +309,41 @@ void setUp() { .hasMessage(NOT_AUTHORIZED_TO_TRIP.message()); } + @Test + void 조건에_해당하는_모든_여행을_조회한다() { + // given + PostCreateResponse jejuMay = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 5, 12, 15, 30)); + PostCreateResponse jejuJuly = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 12, 15, 30)); + PostCreateResponse seoulJuly = createPost("서울특별시 송파구 문정동", LocalDateTime.of(2023, 7, 12, 15, 30)); + + PostSearchRequest postSearchRequestJeju = new PostSearchRequest( + PostSearchConditions.builder() + .address("제주특별자치도 제주시 애월읍") + .build(), + new SearchPaging(null, 10) + ); + + PostSearchRequest postSearchRequestJuly = new PostSearchRequest( + PostSearchConditions.builder() + .months(List.of(7)) + .build(), + new SearchPaging(null, 10) + ); + + // when + PostsSearchResponse postsSearchJejuResponse = postService.readAll(postSearchRequestJeju); + PostsSearchResponse postsSearchJulyResponse = postService.readAll(postSearchRequestJuly); + + // then + assertThat(postsSearchJejuResponse.posts().stream().map(PostSearchResponse::postId).toList()).containsExactly(jejuJuly.postId(), jejuMay.postId()); + assertThat(postsSearchJulyResponse.posts().stream().map(PostSearchResponse::postId).toList()).containsExactly(seoulJuly.postId(), jejuJuly.postId()); + + } + @Test void 감상을_수정한다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); PostUpdateRequest postUpdateRequest = new PostUpdateRequest( "우도의 땅콩 아이스크림", "수정한 내용입니다." @@ -344,7 +379,7 @@ void setUp() { @Test void 감상을_수정할_때_존재하지_않는_사용자_닉네임이면_예외를_발생시킨다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); PostUpdateRequest postUpdateRequest = new PostUpdateRequest( "우도의 땅콩 아이스크림", "수정한 내용입니다." @@ -360,7 +395,7 @@ void setUp() { @Test void 감상을_수정할_때_로그인_한_사용자가_감상의_작성자가_아니면_예외가_발생한다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); PostUpdateRequest postUpdateRequest = new PostUpdateRequest( "우도의 땅콩 아이스크림", "수정한 내용입니다." @@ -375,7 +410,7 @@ void setUp() { @Test void 감상을_삭제한다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); // expect assertDoesNotThrow(() -> postService.delete(loginUser, postCreateResponse.postId())); @@ -396,7 +431,7 @@ void setUp() { @Test void 감상을_삭제할_때_존재하지_않는_사용자_닉네임이면_예외를_발생시킨다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); // expect @@ -408,7 +443,7 @@ void setUp() { @Test void 감상을_삭제할_때_로그인_한_사용자가_감상의_작성자가_아니면_예외가_발생한다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); // expect assertThatThrownBy(() -> postService.delete(otherUser, postCreateResponse.postId())) @@ -422,7 +457,7 @@ void setUp() { PostAndPointCreateRequest request = new PostAndPointCreateRequest( trip.id(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, @@ -438,31 +473,15 @@ void setUp() { assertThat(trip.imageUrl()).isEqualTo("hello.png"); } - private PostCreateResponse createPost() { + private PostCreateResponse createPost(String address, LocalDateTime localDateTime) { PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( trip.id(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + address, "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, - LocalDateTime.of(2023, 7, 18, 20, 24) - ); - - return postService.addAtCurrentPoint(loginUser, postAndPointCreateRequest, null); - } - - private PostCreateResponse createPost2() { - PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( - trip.id(), - "우도의 땅콩 아이스크림", - "제주특별자치도 제주시 애월읍 소길리", - "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", - 1.2, - 2.2, - LocalDateTime.of(2023, 7, 20, 12, 13) - ); - + localDateTime); return postService.addAtCurrentPoint(loginUser, postAndPointCreateRequest, null); } } diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java new file mode 100644 index 000000000..b17b33e27 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java @@ -0,0 +1,82 @@ +package dev.tripdraw.post.domain; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static org.assertj.core.api.Assertions.assertThat; + +import dev.tripdraw.common.config.JpaConfig; +import dev.tripdraw.common.config.QueryDslConfig; +import dev.tripdraw.common.domain.Paging; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripName; +import dev.tripdraw.trip.domain.TripRepository; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +import java.time.LocalDateTime; +import java.util.List; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@DataJpaTest +@Import({JpaConfig.class, QueryDslConfig.class}) +class PostCustomRepositoryImplTest { + + @Autowired + private PostCustomRepositoryImpl postCustomRepository; + + @Autowired + private TripRepository tripRepository; + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private PostRepository postRepository; + + @Test + void 조건에_해당하는_감상을_조회한다() { + // given + Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + Trip trip = tripRepository.save(new Trip(TripName.from("통후추의 여행"), member)); + Point firstPoint = new Point(3.14, 5.25, LocalDateTime.of(2023, 5, 1, 17, 30)); + Point secondPoint = new Point(3.14, 5.25, LocalDateTime.of(2023, 5, 3, 18, 30)); + Point thirdPoint = new Point(3.14, 5.25, LocalDateTime.of(2023, 7, 1, 18, 30)); + + trip.add(firstPoint); + trip.add(secondPoint); + trip.add(thirdPoint); + + Post firstPost = new Post("제목", firstPoint, "위치", "오늘은 날씨가 좋네요.", member, trip.id()); + Post secondPost = new Post("제목", secondPoint, "위치", "오늘은 날씨가 좋네요.", member, trip.id()); + Post thirdPost = new Post("제목", thirdPoint, "위치", "오늘은 날씨가 좋네요.", member, trip.id()); + + postRepository.save(firstPost); + postRepository.save(secondPost); + postRepository.save(thirdPost); + + SearchConditions firstConditions = SearchConditions.builder() + .months(List.of(5)) + .build(); + + SearchConditions secondConditions = SearchConditions.builder() + .hours(List.of(18)) + .build(); + + Paging paging = new Paging(null, 10); + + // when + List firstPosts = postCustomRepository.findAllByConditions(firstConditions, paging); + List secondPosts = postCustomRepository.findAllByConditions(secondConditions, paging); + + // then + assertThat(firstPosts.stream().map(Post::id).toList()).containsExactly(secondPost.id(), firstPost.id()); + assertThat(secondPosts.stream().map(Post::id).toList()).containsExactly(thirdPost.id(), secondPost.id()); + } +} diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java index 2029a0f18..6ec1d9680 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java @@ -5,6 +5,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import dev.tripdraw.common.config.JpaConfig; +import dev.tripdraw.common.config.QueryDslConfig; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.exception.PostException; @@ -12,18 +14,21 @@ import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; import dev.tripdraw.trip.domain.TripRepository; -import java.time.LocalDateTime; -import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +import java.time.LocalDateTime; +import java.util.List; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @DataJpaTest +@Import({JpaConfig.class, QueryDslConfig.class}) class PostRepositoryTest { @Autowired diff --git a/backend/src/test/java/dev/tripdraw/post/dto/PostResponseAndPointCreateRequestTest.java b/backend/src/test/java/dev/tripdraw/post/dto/PostResponseAndPointCreateRequestTest.java index 5ed47f316..e60c91238 100644 --- a/backend/src/test/java/dev/tripdraw/post/dto/PostResponseAndPointCreateRequestTest.java +++ b/backend/src/test/java/dev/tripdraw/post/dto/PostResponseAndPointCreateRequestTest.java @@ -2,13 +2,13 @@ import static org.assertj.core.api.Assertions.assertThat; -import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.trip.domain.Point; -import java.time.LocalDateTime; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; +import java.time.LocalDateTime; + @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class PostResponseAndPointCreateRequestTest { @@ -18,7 +18,7 @@ class PostResponseAndPointCreateRequestTest { PostAndPointCreateRequest request = new PostAndPointCreateRequest( 1L, "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index a41a2bda6..bba831836 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -1,6 +1,7 @@ package dev.tripdraw.post.presentation; import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CREATED; @@ -12,6 +13,7 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; import dev.tripdraw.auth.application.JwtTokenProvider; +import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; @@ -19,8 +21,11 @@ import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; +import dev.tripdraw.post.dto.PostSearchConditions; +import dev.tripdraw.post.dto.PostSearchRequest; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; +import dev.tripdraw.post.dto.PostsSearchResponse; import dev.tripdraw.test.ControllerTest; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; @@ -31,7 +36,6 @@ import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import io.restassured.specification.MultiPartSpecification; -import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -39,6 +43,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; +import java.time.LocalDateTime; +import java.util.List; + @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class PostControllerTest extends ControllerTest { @@ -74,7 +81,7 @@ public void setUp() { PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( trip.id(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, @@ -105,7 +112,7 @@ public void setUp() { PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( trip.id(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, @@ -128,7 +135,7 @@ public void setUp() { PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( Long.MIN_VALUE, "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, @@ -151,7 +158,7 @@ public void setUp() { PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( trip.id(), "", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, @@ -174,7 +181,7 @@ public void setUp() { PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( trip.id(), "a".repeat(101), - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, @@ -197,7 +204,7 @@ public void setUp() { PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( trip.id(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", null, 2.2, @@ -223,7 +230,7 @@ public void setUp() { trip.id(), pointResponse.pointId(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다." ); @@ -254,7 +261,7 @@ public void setUp() { trip.id(), pointResponse.pointId(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다." ); @@ -277,7 +284,7 @@ public void setUp() { Long.MIN_VALUE, pointResponse.pointId(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다." ); @@ -298,7 +305,7 @@ public void setUp() { trip.id(), Long.MIN_VALUE, "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다." ); @@ -344,7 +351,7 @@ public void setUp() { trip.id(), pointResponse.pointId(), "a".repeat(101), - "제주특별자치도 제주시 애월읍 소길리", + "제주특별자치도 제주시 애월읍", "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다." ); @@ -361,7 +368,7 @@ public void setUp() { @Test void 특정_감상을_조회한다() { // given - PostCreateResponse postResponse = createPost(); + PostCreateResponse postResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); // when ExtractableResponse findResponse = RestAssured.given().log().all() @@ -388,7 +395,7 @@ public void setUp() { @Test void 특정_감상을_조회할_때_인증에_실패하면_예외가_발생한다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); // expect RestAssured.given().log().all() @@ -413,8 +420,8 @@ public void setUp() { @Test void 특정_여행에_대한_모든_감상을_조회한다() { // given - createPost(); - createPost(); + createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); + createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); // when ExtractableResponse findResponse = RestAssured.given().log().all() @@ -465,7 +472,7 @@ public void setUp() { @Test void 감상을_수정한다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); PostUpdateRequest postUpdateRequest = new PostUpdateRequest( "우도의 땅콩 아이스크림", @@ -496,7 +503,7 @@ public void setUp() { @Test void 감상을_수정할_때_인증에_실패하면_예외가_발생한다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); PostUpdateRequest postUpdateRequest = new PostUpdateRequest( "우도의 땅콩 아이스크림", @@ -538,7 +545,7 @@ public void setUp() { @Test void 감상을_삭제한다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); // expect1 : 삭제하면 204 NO_CONTENT 응답 RestAssured.given().log().all() @@ -560,7 +567,7 @@ public void setUp() { @Test void 감상을_삭제할_때_인증에_실패하면_예외가_발생한다() { // given - PostCreateResponse postCreateResponse = createPost(); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); // expect RestAssured.given().log().all() @@ -582,6 +589,45 @@ public void setUp() { .statusCode(NOT_FOUND.value()); } + @Test + void 다른_사용자들의_감상을_조회한다() { + // given + // 제주특별자치도 제주시 애월읍, 시간 + PostCreateResponse jejuJuly20hourPostResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); + PostCreateResponse jejuAugust17hourPostResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 8, 18, 17, 24)); + PostCreateResponse jejuSeptember17hourPostResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 9, 18, 17, 24)); + PostCreateResponse seoulSeptember17hourPostResponse = createPost("서울특별시 송파구 잠실동", LocalDateTime.of(2023, 9, 18, 17, 24)); + + PostSearchRequest request = new PostSearchRequest( + new PostSearchConditions( + List.of(), + List.of(), + List.of(), + List.of(17), + List.of(), + List.of(), + "제주특별자치도 제주시 애월읍" + ), + new SearchPaging(null, 10) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .contentType(APPLICATION_JSON_VALUE) + .auth().preemptive().oauth2(huchuToken) + .body(request) + .when().get("/posts") + .then().log().all() + .statusCode(OK.value()) + .extract(); + + // then + PostsSearchResponse postsSearchResponse = response.as(PostsSearchResponse.class); + + assertThat(postsSearchResponse.posts().get(0).postId()).isEqualTo(jejuSeptember17hourPostResponse.postId()); + assertThat(postsSearchResponse.posts().get(1).postId()).isEqualTo(jejuAugust17hourPostResponse.postId()); + } + private PointResponse createPoint() { PointCreateRequest request = new PointCreateRequest( trip.id(), @@ -601,16 +647,16 @@ private PointResponse createPoint() { return response.as(PointResponse.class); } - private PostCreateResponse createPost() { + private PostCreateResponse createPost(String address, LocalDateTime localDateTime) { // given PostAndPointCreateRequest postAndPointCreateRequest = new PostAndPointCreateRequest( trip.id(), "우도의 바닷가", - "제주특별자치도 제주시 애월읍 소길리", + address, "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", 1.1, 2.2, - LocalDateTime.of(2023, 7, 18, 20, 24) + localDateTime ); MultiPartSpecification multiPartSpecification = new MultiPartSpecBuilder(postAndPointCreateRequest) diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java index 717a48695..db8b2fc55 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java @@ -5,20 +5,25 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import dev.tripdraw.common.config.JpaConfig; +import dev.tripdraw.common.config.QueryDslConfig; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.exception.TripException; -import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +import java.time.LocalDateTime; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @DataJpaTest +@Import({JpaConfig.class, QueryDslConfig.class}) class PointRepositoryTest { @Autowired diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index b448e684e..cf60953b3 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -6,21 +6,26 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; +import dev.tripdraw.common.config.JpaConfig; +import dev.tripdraw.common.config.QueryDslConfig; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.exception.TripException; -import java.time.LocalDateTime; -import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +import java.time.LocalDateTime; +import java.util.List; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @DataJpaTest +@Import({JpaConfig.class, QueryDslConfig.class}) class TripRepositoryTest { @Autowired From b6fb7772b7159817808fa5a999df3ffe7dfa3066 Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 03:35:56 +0900 Subject: [PATCH 060/119] =?UTF-8?q?refactor:=20=EC=93=B0=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20=EC=95=8A=EB=8A=94=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/post/presentation/PostControllerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index bba831836..6ce2e0eca 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -678,7 +678,6 @@ private PostCreateResponse createPost(String address, LocalDateTime localDateTim return postResponse; } - @Test PostResponse readPost(Long postId) { ExtractableResponse findResponse = RestAssured.given().log().all() .contentType(APPLICATION_JSON_VALUE) From 873bed34e98617a8127cb75ca862ad04df3caa36 Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 03:38:47 +0900 Subject: [PATCH 061/119] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EC=97=90=20=ED=95=9C=EA=B8=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/dto/PostResponseAndPointCreateRequestTest.java | 1 + .../dev/tripdraw/post/presentation/PostControllerTest.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/test/java/dev/tripdraw/post/dto/PostResponseAndPointCreateRequestTest.java b/backend/src/test/java/dev/tripdraw/post/dto/PostResponseAndPointCreateRequestTest.java index e60c91238..4c9f21c90 100644 --- a/backend/src/test/java/dev/tripdraw/post/dto/PostResponseAndPointCreateRequestTest.java +++ b/backend/src/test/java/dev/tripdraw/post/dto/PostResponseAndPointCreateRequestTest.java @@ -9,6 +9,7 @@ import java.time.LocalDateTime; +@SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class PostResponseAndPointCreateRequestTest { diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index 6ce2e0eca..159a789b9 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -46,6 +46,7 @@ import java.time.LocalDateTime; import java.util.List; +@SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class PostControllerTest extends ControllerTest { @@ -674,8 +675,7 @@ private PostCreateResponse createPost(String address, LocalDateTime localDateTim .then().log().all() .extract(); - PostCreateResponse postResponse = createResponse.as(PostCreateResponse.class); - return postResponse; + return createResponse.as(PostCreateResponse.class); } PostResponse readPost(Long postId) { From db7b266f37e634fa0253dfb1d9fb03efb28421a8 Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 03:42:23 +0900 Subject: [PATCH 062/119] =?UTF-8?q?refactor:=20=EB=B9=8C=EB=8D=94=ED=8C=A8?= =?UTF-8?q?=ED=84=B4=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/presentation/PostControllerTest.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index 159a789b9..ef9a9b226 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -14,7 +14,6 @@ import dev.tripdraw.auth.application.JwtTokenProvider; import dev.tripdraw.common.dto.SearchPaging; -import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.dto.PostAndPointCreateRequest; @@ -41,7 +40,6 @@ import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.MockBean; import java.time.LocalDateTime; import java.util.List; @@ -61,9 +59,6 @@ class PostControllerTest extends ControllerTest { @Autowired private JwtTokenProvider jwtTokenProvider; - @MockBean - private RouteImageGenerator routeImageGenerator; - private Trip trip; private String huchuToken; @@ -600,15 +595,10 @@ public void setUp() { PostCreateResponse seoulSeptember17hourPostResponse = createPost("서울특별시 송파구 잠실동", LocalDateTime.of(2023, 9, 18, 17, 24)); PostSearchRequest request = new PostSearchRequest( - new PostSearchConditions( - List.of(), - List.of(), - List.of(), - List.of(17), - List.of(), - List.of(), - "제주특별자치도 제주시 애월읍" - ), + PostSearchConditions.builder() + .hours(List.of(17)) + .address("제주특별자치도 제주시 애월읍") + .build(), new SearchPaging(null, 10) ); From b55f46253669fcd9fc5f6acce294049ecadeb991 Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 03:45:55 +0900 Subject: [PATCH 063/119] =?UTF-8?q?style:=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/post/presentation/PostControllerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index ef9a9b226..46c4430c3 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -588,7 +588,6 @@ public void setUp() { @Test void 다른_사용자들의_감상을_조회한다() { // given - // 제주특별자치도 제주시 애월읍, 시간 PostCreateResponse jejuJuly20hourPostResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); PostCreateResponse jejuAugust17hourPostResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 8, 18, 17, 24)); PostCreateResponse jejuSeptember17hourPostResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 9, 18, 17, 24)); From 918b769499133dc0385fc92ad7208d4193e4158e Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 18 Sep 2023 14:44:32 +0900 Subject: [PATCH 064/119] =?UTF-8?q?[refactor]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20API=20=EB=AA=85=EC=84=B8=20=EB=B0=8F=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=B3=80=EA=B2=BD=20(#369)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/common/config/AuthConfig.java | 3 +- .../member/application/MemberService.java | 10 ++-- .../member/presentation/MemberController.java | 15 +++--- .../member/application/MemberServiceTest.java | 49 ++++-------------- .../presentation/MemberControllerTest.java | 50 ++++--------------- 5 files changed, 35 insertions(+), 92 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/common/config/AuthConfig.java b/backend/src/main/java/dev/tripdraw/common/config/AuthConfig.java index 7a98c5fd7..b72575681 100644 --- a/backend/src/main/java/dev/tripdraw/common/config/AuthConfig.java +++ b/backend/src/main/java/dev/tripdraw/common/config/AuthConfig.java @@ -1,7 +1,7 @@ package dev.tripdraw.common.config; -import dev.tripdraw.auth.presentation.AuthArgumentResolver; import dev.tripdraw.auth.application.AuthExtractor; +import dev.tripdraw.auth.presentation.AuthArgumentResolver; import dev.tripdraw.auth.presentation.AuthInterceptor; import java.util.List; import lombok.RequiredArgsConstructor; @@ -25,7 +25,6 @@ public void addArgumentResolvers(List resolvers) @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(authInterceptor) - .excludePathPatterns("/members/**") .excludePathPatterns("/swagger-ui/**") .excludePathPatterns("/api-docs") .excludePathPatterns("/v3/api-docs/**") diff --git a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java index 52593a4b8..329c3bdc6 100644 --- a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java +++ b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java @@ -1,6 +1,7 @@ package dev.tripdraw.member.application; import dev.tripdraw.auth.application.JwtTokenProvider; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.dto.MemberSearchResponse; @@ -26,14 +27,13 @@ public boolean existsById(Long memberId) { } @Transactional(readOnly = true) - public MemberSearchResponse findByCode(String code) { - Long memberId = Long.valueOf(jwtTokenProvider.extractAccessToken(code)); - Member member = memberRepository.getById(memberId); + public MemberSearchResponse find(LoginUser loginUser) { + Member member = memberRepository.getById(loginUser.memberId()); return MemberSearchResponse.from(member); } - public void deleteByCode(String code) { - Long memberId = Long.valueOf(jwtTokenProvider.extractAccessToken(code)); + public void delete(LoginUser loginUser) { + Long memberId = loginUser.memberId(); postRepository.deleteByMemberId(memberId); tripRepository.deleteByMemberId(memberId); memberRepository.deleteById(memberId); diff --git a/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java b/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java index a88e8fbc6..5ee40bcc8 100644 --- a/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java +++ b/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java @@ -1,5 +1,7 @@ package dev.tripdraw.member.presentation; +import dev.tripdraw.common.auth.Auth; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.member.application.MemberService; import dev.tripdraw.member.dto.MemberSearchResponse; import io.swagger.v3.oas.annotations.Operation; @@ -10,7 +12,6 @@ import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @Tag(name = "Member", description = "사용자 관련 API 명세") @@ -26,9 +27,9 @@ public class MemberController { responseCode = "200", description = "사용자 조회 성공." ) - @GetMapping - public ResponseEntity findByCode(@RequestParam String code) { - MemberSearchResponse response = memberService.findByCode(code); + @GetMapping("/me") + public ResponseEntity findByCode(@Auth LoginUser loginUser) { + MemberSearchResponse response = memberService.find(loginUser); return ResponseEntity.ok(response); } @@ -37,9 +38,9 @@ public ResponseEntity findByCode(@RequestParam String code responseCode = "204", description = "사용자 삭제 성공." ) - @DeleteMapping - public ResponseEntity delete(@RequestParam String code) { - memberService.deleteByCode(code); + @DeleteMapping("/me") + public ResponseEntity delete(@Auth LoginUser loginUser) { + memberService.delete(loginUser); return ResponseEntity.noContent().build(); } } diff --git a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java index 3aac554fc..69054ebc4 100644 --- a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java @@ -1,16 +1,13 @@ package dev.tripdraw.member.application; import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import dev.tripdraw.auth.application.JwtTokenProvider; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.dto.MemberSearchResponse; -import dev.tripdraw.member.exception.MemberException; import dev.tripdraw.post.domain.Post; import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.test.ServiceTest; @@ -32,9 +29,6 @@ class MemberServiceTest { @Autowired private MemberRepository memberRepository; - @Autowired - private JwtTokenProvider jwtTokenProvider; - @Autowired private TripRepository tripRepository; @@ -42,15 +36,12 @@ class MemberServiceTest { private PostRepository postRepository; private Member member; - private String code; private Trip trip; private Post post; @BeforeEach void setUp() { member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - code = jwtTokenProvider.generateAccessToken(member.id().toString()); - trip = tripRepository.save(new Trip(TripName.from("통후추의 여행"), member)); Point point = new Point(3.14, 5.25, LocalDateTime.now()); trip.add(point); @@ -65,9 +56,12 @@ void setUp() { } @Test - void code를_입력_받아_사용자를_조회한다() { - // given & when - MemberSearchResponse response = memberService.findByCode(code); + void 사용자를_조회한다() { + // given + LoginUser loginUser = new LoginUser(member.id()); + + // when + MemberSearchResponse response = memberService.find(loginUser); // expect assertThat(response).usingRecursiveComparison().isEqualTo( @@ -76,33 +70,12 @@ void setUp() { } @Test - void code를_입력_받아_사용자를_조회할_때_이미_삭제된_사용자라면_예외를_발생시킨다() { + void 사용자를_삭제한다() { // given - Member member = memberRepository.save(new Member("순후추", "kakaoId", KAKAO)); - String code = jwtTokenProvider.generateAccessToken(member.id().toString()); - - memberRepository.deleteById(member.id()); + LoginUser loginUser = new LoginUser(member.id()); - // expect - assertThatThrownBy(() -> memberService.findByCode(code)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); - } - - @Test - void code를_입력_받아_사용자를_조회할_때_존재하지_않는_사용자라면_예외를_발생시킨다() { - String nonExistentCode = jwtTokenProvider.generateAccessToken("-1"); - - // expect - assertThatThrownBy(() -> memberService.findByCode(nonExistentCode)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); - } - - @Test - void code를_입력_받아_사용자를_삭제한다() { - // given & when - memberService.deleteByCode(code); + // when + memberService.delete(loginUser); // then assertSoftly(softly -> { diff --git a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java index 3c00128fe..03a5d11ee 100644 --- a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java @@ -3,7 +3,6 @@ import static dev.tripdraw.common.auth.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.springframework.http.HttpStatus.FORBIDDEN; -import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; @@ -54,15 +53,15 @@ public void setUp() { } @Test - void code를_입력_받아_사용자를_조회한다() { + void 사용자를_조회한다() { // given Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - String code = jwtTokenProvider.generateAccessToken(member.id().toString()); + String huchuToken = jwtTokenProvider.generateAccessToken(member.id().toString()); // when ExtractableResponse response = RestAssured.given().log().all() - .param("code", code) - .when().get("/members") + .auth().preemptive().oauth2(huchuToken) + .when().get("/members/me") .then().log().all() .extract(); @@ -78,39 +77,10 @@ public void setUp() { } @Test - void code를_입력_받아_사용자를_조회할_때_존재하지_않는_사용자라면_예외가_발생한다() { - // given - String code = jwtTokenProvider.generateAccessToken("-1"); - - // expect - RestAssured.given().log().all() - .param("code", code) - .when().get("/members") - .then().log().all() - .statusCode(NOT_FOUND.value()); - } - - @Test - void code를_입력_받아_사용자를_조회할_때_이미_삭제된_사용자라면_예외가_발생한다() { - // given - Member member = memberRepository.save(new Member("순후추", "kakaoId", KAKAO)); - String code = jwtTokenProvider.generateAccessToken(member.id().toString()); - - memberRepository.delete(member); - - // expect - RestAssured.given().log().all() - .param("code", code) - .when().get("/members") - .then().log().all() - .statusCode(NOT_FOUND.value()); - } - - @Test - void code를_입력_받아_사용자를_삭제한다() { + void 사용자를_삭제한다() { // given Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - String code = jwtTokenProvider.generateAccessToken(member.id().toString()); + String huchuToken = jwtTokenProvider.generateAccessToken(member.id().toString()); Trip trip = new Trip(TripName.from("통후추의 여행"), member); Point point = new Point(3.14, 5.25, LocalDateTime.now()); @@ -127,19 +97,19 @@ public void setUp() { // expect RestAssured.given().log().all() - .param("code", code) - .when().delete("/members") + .auth().preemptive().oauth2(huchuToken) + .when().delete("/members/me") .then().log().all() .statusCode(NO_CONTENT.value()); RestAssured.given().log().all() - .auth().preemptive().oauth2(code) + .auth().preemptive().oauth2(huchuToken) .when().get("/trips/{tripId}", trip.id()) .then().log().all() .statusCode(FORBIDDEN.value()); RestAssured.given().log().all() - .auth().preemptive().oauth2(code) + .auth().preemptive().oauth2(huchuToken) .when().get("/posts/{postId}", post.id()) .then().log().all() .statusCode(FORBIDDEN.value()); From 60d2172e59ffd7845e2201476d01902154f12b23 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 15:12:03 +0900 Subject: [PATCH 065/119] =?UTF-8?q?[refactor]=20TripCustomRepositoryImpl?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/domain/TripCustomRepositoryImpl.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java index 17d4111ec..7778a9ef9 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java @@ -25,46 +25,46 @@ public List findAllByConditions(SearchConditions searchConditions, Paging .join(post).on(trip.id.eq(post.tripId)) .join(point).on(post.point.id.eq(point.id)) .where( - tripsBeforeLastViewedId(paging.lastViewedId()), - tripsRecordedAtYears(searchConditions.years()), - tripsRecordedAtMonths(searchConditions.months()), - tripsRecordedAtDaysOfWeek(searchConditions.daysOfWeek()), - tripsAddressed(searchConditions.address()) + tripIdLt(paging.lastViewedId()), + yearIn(searchConditions.years()), + monthIn(searchConditions.months()), + dayOfWeekIn(searchConditions.daysOfWeek()), + addressLike(searchConditions.address()) ) .orderBy(trip.id.desc()) .limit(paging.limit() + 1) .fetch(); } - private BooleanExpression tripsBeforeLastViewedId(Long lastViewedId) { + private BooleanExpression tripIdLt(Long lastViewedId) { if (lastViewedId == null) { return null; } return trip.id.lt(lastViewedId); } - private BooleanExpression tripsRecordedAtYears(Set years) { + private BooleanExpression yearIn(Set years) { if (years.isEmpty()) { return null; } return point.recordedAt.year().in(years); } - private BooleanExpression tripsRecordedAtMonths(Set months) { + private BooleanExpression monthIn(Set months) { if (months.isEmpty()) { return null; } return point.recordedAt.month().in(months); } - private BooleanExpression tripsRecordedAtDaysOfWeek(Set daysOfWeek) { + private BooleanExpression dayOfWeekIn(Set daysOfWeek) { if (daysOfWeek.isEmpty()) { return null; } return point.recordedAt.dayOfWeek().in(daysOfWeek); } - private BooleanExpression tripsAddressed(String address) { + private BooleanExpression addressLike(String address) { if (address.isEmpty()) { return null; } From f5f96692c82269222549428e0cbd46a8d44dce52 Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 15:12:08 +0900 Subject: [PATCH 066/119] =?UTF-8?q?fix:=20=EC=A3=BC=EC=86=8C=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java index 006dd9dc2..0e3da58c7 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java @@ -56,6 +56,6 @@ private BooleanExpression eqAdress(StringPath address, String targetAddress) { return null; } - return address.eq(targetAddress); + return address.like(targetAddress + "%"); } } From 9546ec208ccaab9567e996af6a16f42e2f52c123 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Wed, 13 Sep 2023 15:08:18 +0900 Subject: [PATCH 067/119] =?UTF-8?q?[refactor]=20OAuth=20API=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C=EC=97=90=20=ED=95=B4=EB=8B=B9=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=EC=9D=84=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=EC=97=90=EC=84=9C=20=EC=A0=9C=EC=99=B8=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthService.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java index dcfddd589..5b7b15ea4 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java @@ -20,19 +20,19 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionTemplate; @RequiredArgsConstructor -@Transactional @Service public class AuthService { private static final String EMPTY_TOKEN = ""; + private final TransactionTemplate transactionTemplate; private final MemberRepository memberRepository; + private final RefreshTokenRepository refreshTokenRepository; private final OauthClientProvider oauthClientProvider; private final JwtTokenProvider jwtTokenProvider; - private final RefreshTokenRepository refreshTokenRepository; public OauthResponse login(OauthRequest oauthRequest) { OauthClient oauthClient = oauthClientProvider.provide(oauthRequest.oauthType()); @@ -51,25 +51,28 @@ public OauthResponse login(OauthRequest oauthRequest) { return generateToken(findMember.id()); } - private OauthResponse generateToken(Long memberId) { - String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); - String refreshToken = jwtTokenProvider.generateRefreshToken(); - refreshTokenRepository.deleteByMemberId(memberId); - RefreshToken savedRefreshToken = refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); - return new OauthResponse(accessToken, savedRefreshToken.token()); - } - public OauthResponse register(RegisterRequest registerRequest) { OauthClient oauthClient = oauthClientProvider.provide(registerRequest.oauthType()); OauthInfo oauthInfo = oauthClient.requestOauthInfo(registerRequest.oauthToken()); - Member member = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) - .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); + return transactionTemplate.execute(status -> { + Member member = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) + .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); + validateDuplicateNickname(registerRequest.nickname()); + member.changeNickname(registerRequest.nickname()); + return generateToken(member.id()); + }); + } - String nickname = registerRequest.nickname(); - validateDuplicateNickname(nickname); - member.changeNickname(nickname); - return generateToken(member.id()); + private OauthResponse generateToken(Long memberId) { + String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); + String refreshToken = jwtTokenProvider.generateRefreshToken(); + + RefreshToken savedRefreshToken = transactionTemplate.execute(status -> { + refreshTokenRepository.deleteByMemberId(memberId); + return refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); + }); + return new OauthResponse(accessToken, savedRefreshToken.token()); } private void validateDuplicateNickname(String nickname) { From 6125f8d21c211ec652ce1455d3a38580f31a49f3 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 15 Sep 2023 01:29:16 +0900 Subject: [PATCH 068/119] =?UTF-8?q?[feat]=20refreshToken=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EC=B6=94=EA=B0=80=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/auth/config/RefreshTokenConfig.java | 1 + .../src/main/java/dev/tripdraw/auth/domain/RefreshToken.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java index c3f05dc88..a1af2f37c 100644 --- a/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java +++ b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java @@ -7,4 +7,5 @@ public record RefreshTokenConfig( String secretKey, Long expirationTime ) { + } diff --git a/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java index 66caf2d23..7b393e55d 100644 --- a/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java +++ b/backend/src/main/java/dev/tripdraw/auth/domain/RefreshToken.java @@ -28,6 +28,11 @@ public class RefreshToken extends BaseEntity { private String token; public RefreshToken(Long memberId, String token) { + this(null, memberId, token); + } + + public RefreshToken(Long id, Long memberId, String token) { + this.id = id; this.memberId = memberId; this.token = token; } From 09bcbd7996a488c19cb2f0acf51984fe901fe8e4 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 15 Sep 2023 01:29:48 +0900 Subject: [PATCH 069/119] =?UTF-8?q?[refactor]=20Api=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=20OAuthService=EB=A1=9C=20=EB=B6=84=EB=A6=AC=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/OAuthService.java | 20 ++++++++ .../auth/application/OAuthServiceTest.java | 48 +++++++++++++++++++ .../tripdraw/test/fixture/MemberFixture.java | 11 +++++ 3 files changed, 79 insertions(+) create mode 100644 backend/src/main/java/dev/tripdraw/auth/application/OAuthService.java create mode 100644 backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java create mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/MemberFixture.java diff --git a/backend/src/main/java/dev/tripdraw/auth/application/OAuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/OAuthService.java new file mode 100644 index 000000000..3356a2c5e --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/application/OAuthService.java @@ -0,0 +1,20 @@ +package dev.tripdraw.auth.application; + +import dev.tripdraw.auth.dto.OauthInfo; +import dev.tripdraw.auth.oauth.OauthClient; +import dev.tripdraw.auth.oauth.OauthClientProvider; +import dev.tripdraw.common.auth.OauthType; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class OAuthService { + + private final OauthClientProvider oauthClientProvider; + + public OauthInfo request(OauthType oauthType, String oauthToken) { + OauthClient oauthClient = oauthClientProvider.provide(oauthType); + return oauthClient.requestOauthInfo(oauthToken); + } +} diff --git a/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java new file mode 100644 index 000000000..dea6fa39f --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java @@ -0,0 +1,48 @@ +package dev.tripdraw.auth.application; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.Mockito.when; + +import dev.tripdraw.auth.dto.OauthInfo; +import dev.tripdraw.auth.oauth.OauthClientProvider; +import dev.tripdraw.test.TestKakaoApiClient; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@SpringBootTest +class OAuthServiceTest { + + @Autowired + private OAuthService oAuthService; + + @MockBean + private OauthClientProvider oauthClientProvider; + + @BeforeEach + void setUp() { + when(oauthClientProvider.provide(KAKAO)).thenReturn(new TestKakaoApiClient()); + } + + @Test + void Oauth_공통_정보를_반환한다() { + // given + String oauthToken = "oauth.kakao.token"; + + // when + OauthInfo oauthInfo = oAuthService.request(KAKAO, oauthToken); + + // then + assertSoftly(softly -> { + softly.assertThat(oauthInfo.oauthId()).isEqualTo("kakaoId"); + softly.assertThat(oauthInfo.oauthType()).isEqualTo(KAKAO); + }); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/MemberFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/MemberFixture.java new file mode 100644 index 000000000..4b051817e --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/fixture/MemberFixture.java @@ -0,0 +1,11 @@ +package dev.tripdraw.test.fixture; + +import dev.tripdraw.common.auth.OauthType; +import dev.tripdraw.member.domain.Member; + +public class MemberFixture { + + public static Member 사용자() { + return new Member(1L, "통후추", "", OauthType.KAKAO); + } +} From 7e15dab58c8abf1ab33e00987b10d9d21ec0b42d Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 15 Sep 2023 01:30:14 +0900 Subject: [PATCH 070/119] =?UTF-8?q?[refactor]=20AuthService=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthFacadeService.java | 31 +++++ .../auth/application/AuthService.java | 77 ++++-------- .../auth/presentation/AuthController.java | 10 +- .../application/AuthFacadeServiceTest.java | 114 +++++++++++++++++ .../auth/application/AuthServiceTest.java | 119 ++++++++---------- 5 files changed, 225 insertions(+), 126 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java create mode 100644 backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java new file mode 100644 index 000000000..f8bfa11b2 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java @@ -0,0 +1,31 @@ +package dev.tripdraw.auth.application; + +import dev.tripdraw.auth.dto.OauthInfo; +import dev.tripdraw.auth.dto.OauthRequest; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.dto.RegisterRequest; +import dev.tripdraw.auth.dto.TokenRefreshRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class AuthFacadeService { + + private final OAuthService oAuthService; + private final AuthService authService; + + public OauthResponse login(OauthRequest oauthRequest) { + OauthInfo oauthInfo = oAuthService.request(oauthRequest.oauthType(), oauthRequest.oauthToken()); + return authService.login(oauthInfo); + } + + public OauthResponse register(RegisterRequest registerRequest) { + OauthInfo oauthInfo = oAuthService.request(registerRequest.oauthType(), registerRequest.oauthToken()); + return authService.register(oauthInfo, registerRequest.nickname()); + } + + public OauthResponse refresh(TokenRefreshRequest tokenRefreshRequest) { + return authService.refresh(tokenRefreshRequest.refreshToken()); + } +} diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java index 5b7b15ea4..b8f25f505 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java @@ -7,84 +7,59 @@ import dev.tripdraw.auth.domain.RefreshToken; import dev.tripdraw.auth.domain.RefreshTokenRepository; import dev.tripdraw.auth.dto.OauthInfo; -import dev.tripdraw.auth.dto.OauthRequest; import dev.tripdraw.auth.dto.OauthResponse; -import dev.tripdraw.auth.dto.RegisterRequest; -import dev.tripdraw.auth.dto.TokenRefreshRequest; import dev.tripdraw.auth.exception.AuthException; -import dev.tripdraw.auth.oauth.OauthClient; -import dev.tripdraw.auth.oauth.OauthClientProvider; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.support.TransactionTemplate; +import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor +@Transactional @Service public class AuthService { - private static final String EMPTY_TOKEN = ""; + private static final OauthResponse EMPTY_TOKEN_RESPONSE = new OauthResponse("", ""); - private final TransactionTemplate transactionTemplate; - private final MemberRepository memberRepository; - private final RefreshTokenRepository refreshTokenRepository; - private final OauthClientProvider oauthClientProvider; private final JwtTokenProvider jwtTokenProvider; + private final RefreshTokenRepository refreshTokenRepository; + private final MemberRepository memberRepository; - public OauthResponse login(OauthRequest oauthRequest) { - OauthClient oauthClient = oauthClientProvider.provide(oauthRequest.oauthType()); - OauthInfo oauthInfo = oauthClient.requestOauthInfo(oauthRequest.oauthToken()); - - Optional member = memberRepository.findByOauthIdAndOauthType( - oauthInfo.oauthId(), - oauthInfo.oauthType() - ); - if (member.isEmpty()) { - memberRepository.save(Member.of(oauthInfo.oauthId(), oauthInfo.oauthType())); - return new OauthResponse(EMPTY_TOKEN, EMPTY_TOKEN); - } - - Member findMember = member.orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); - return generateToken(findMember.id()); - } - - public OauthResponse register(RegisterRequest registerRequest) { - OauthClient oauthClient = oauthClientProvider.provide(registerRequest.oauthType()); - OauthInfo oauthInfo = oauthClient.requestOauthInfo(registerRequest.oauthToken()); - - return transactionTemplate.execute(status -> { - Member member = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) - .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); - validateDuplicateNickname(registerRequest.nickname()); - member.changeNickname(registerRequest.nickname()); - return generateToken(member.id()); - }); + public OauthResponse login(OauthInfo oauthInfo) { + return memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) + .map(member -> generateOAuthResponse(member.id())) + .orElseGet(() -> { + memberRepository.save(Member.of(oauthInfo.oauthId(), oauthInfo.oauthType())); + return EMPTY_TOKEN_RESPONSE; + }); } - private OauthResponse generateToken(Long memberId) { + private OauthResponse generateOAuthResponse(Long memberId) { String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); String refreshToken = jwtTokenProvider.generateRefreshToken(); - RefreshToken savedRefreshToken = transactionTemplate.execute(status -> { - refreshTokenRepository.deleteByMemberId(memberId); - return refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); - }); - return new OauthResponse(accessToken, savedRefreshToken.token()); + refreshTokenRepository.deleteByMemberId(memberId); + refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); + return new OauthResponse(accessToken, refreshToken); } - private void validateDuplicateNickname(String nickname) { + public OauthResponse register(OauthInfo oauthInfo, String nickname) { if (memberRepository.existsByNickname(nickname)) { throw new MemberException(DUPLICATE_NICKNAME); } + + Member member = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) + .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); + member.changeNickname(nickname); + return generateOAuthResponse(member.id()); } - public OauthResponse refresh(TokenRefreshRequest tokenRefreshRequest) { - jwtTokenProvider.validateRefreshToken(tokenRefreshRequest.refreshToken()); - RefreshToken refreshToken = refreshTokenRepository.findByToken(tokenRefreshRequest.refreshToken()) + public OauthResponse refresh(String token) { + jwtTokenProvider.validateRefreshToken(token); + RefreshToken refreshToken = refreshTokenRepository.findByToken(token) .orElseThrow(() -> new AuthException(INVALID_TOKEN)); - return generateToken(refreshToken.memberId()); + return generateOAuthResponse(refreshToken.memberId()); } } diff --git a/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java index ce2b7b7ce..8a6e313f0 100644 --- a/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java +++ b/backend/src/main/java/dev/tripdraw/auth/presentation/AuthController.java @@ -1,6 +1,6 @@ package dev.tripdraw.auth.presentation; -import dev.tripdraw.auth.application.AuthService; +import dev.tripdraw.auth.application.AuthFacadeService; import dev.tripdraw.auth.dto.OauthRequest; import dev.tripdraw.auth.dto.OauthResponse; import dev.tripdraw.auth.dto.RegisterRequest; @@ -20,7 +20,7 @@ @RestController public class AuthController { - private final AuthService authService; + private final AuthFacadeService authFacadeService; @Operation(summary = "소셜 로그인 API", description = "소셜 로그인을 합니다.") @ApiResponse( @@ -29,7 +29,7 @@ public class AuthController { ) @PostMapping("/oauth/login") public ResponseEntity login(@RequestBody OauthRequest oauthRequest) { - OauthResponse oauthResponse = authService.login(oauthRequest); + OauthResponse oauthResponse = authFacadeService.login(oauthRequest); return ResponseEntity.ok(oauthResponse); } @@ -40,7 +40,7 @@ public ResponseEntity login(@RequestBody OauthRequest oauthReques ) @PostMapping("/oauth/register") public ResponseEntity register(@Valid @RequestBody RegisterRequest registerRequest) { - OauthResponse oauthResponse = authService.register(registerRequest); + OauthResponse oauthResponse = authFacadeService.register(registerRequest); return ResponseEntity.ok(oauthResponse); } @@ -51,7 +51,7 @@ public ResponseEntity register(@Valid @RequestBody RegisterReques ) @PostMapping("/oauth/refresh") public ResponseEntity refresh(@Valid @RequestBody TokenRefreshRequest tokenRefreshRequest) { - OauthResponse oauthResponse = authService.refresh(tokenRefreshRequest); + OauthResponse oauthResponse = authFacadeService.refresh(tokenRefreshRequest); return ResponseEntity.ok(oauthResponse); } } diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java new file mode 100644 index 000000000..60eb17e0d --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java @@ -0,0 +1,114 @@ +package dev.tripdraw.auth.application; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.Mockito.when; + +import dev.tripdraw.auth.domain.RefreshToken; +import dev.tripdraw.auth.domain.RefreshTokenRepository; +import dev.tripdraw.auth.dto.OauthRequest; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.dto.RegisterRequest; +import dev.tripdraw.auth.dto.TokenRefreshRequest; +import dev.tripdraw.auth.oauth.OauthClientProvider; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.test.ServiceTest; +import dev.tripdraw.test.TestKakaoApiClient; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; + +@ServiceTest +class AuthFacadeServiceTest { + + @Autowired + private AuthFacadeService authFacadeService; + + @MockBean + private OauthClientProvider oauthClientProvider; + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private RefreshTokenRepository refreshTokenRepository; + + @Autowired + private JwtTokenProvider jwtTokenProvider; + + @BeforeEach + void setUp() { + when(oauthClientProvider.provide(KAKAO)).thenReturn(new TestKakaoApiClient()); + } + + @Test + void 가입된_회원이_카카오_소셜_로그인하면_토큰이_포함된_응답을_반환한다() { + // given + memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + OauthRequest oauthRequest = new OauthRequest(KAKAO, "oauth.kakao.token"); + + // when + OauthResponse response = authFacadeService.login(oauthRequest); + + // then + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isNotEmpty(); + softly.assertThat(response.refreshToken()).isNotEmpty(); + }); + } + + @Test + void 신규_회원이_로그인하면_회원을_저장하고_빈_토큰이_포함된_응답을_반환한다() { + // given + OauthRequest oauthRequest = new OauthRequest(KAKAO, "oauth.kakao.token"); + + // when + OauthResponse response = authFacadeService.login(oauthRequest); + + // then + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isEmpty(); + softly.assertThat(response.refreshToken()).isEmpty(); + }); + } + + @Test + void 신규_회원의_닉네임을_등록하면_토큰이_포함된_응답을_반환한다() { + // given + Member member = Member.of("kakaoId", KAKAO); + memberRepository.save(member); + + RegisterRequest registerRequest = new RegisterRequest("통후추", KAKAO, "oauth.kakao.token"); + + // when + OauthResponse response = authFacadeService.register(registerRequest); + + // then + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isNotEmpty(); + softly.assertThat(response.refreshToken()).isNotEmpty(); + }); + } + + @Test + void Refresh_토큰을_입력받아_Access_토큰과_Refresh_토큰을_재발급한다() { + // given + Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + String refreshToken = jwtTokenProvider.generateRefreshToken(); + refreshTokenRepository.save(new RefreshToken(member.id(), refreshToken)); + TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(refreshToken); + + // when + OauthResponse response = authFacadeService.refresh(tokenRefreshRequest); + + // then + assertSoftly(softly -> { + softly.assertThat(response.accessToken()).isNotEmpty(); + softly.assertThat(response.refreshToken()).isNotEmpty(); + softly.assertThat(refreshTokenRepository.findByToken(refreshToken)).isEmpty(); + softly.assertThat(refreshTokenRepository.findByToken(response.refreshToken())).isPresent(); + }); + } +} diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index dcc32a829..262081029 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -1,79 +1,60 @@ package dev.tripdraw.auth.application; import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_REFRESH_TOKEN; +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_ACCESS_TOKEN_설정; import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_REFRESH_TOKEN_설정; +import static dev.tripdraw.test.fixture.MemberFixture.사용자; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.mockito.Mockito.when; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; import dev.tripdraw.auth.domain.RefreshToken; import dev.tripdraw.auth.domain.RefreshTokenRepository; -import dev.tripdraw.auth.dto.OauthRequest; +import dev.tripdraw.auth.dto.OauthInfo; import dev.tripdraw.auth.dto.OauthResponse; -import dev.tripdraw.auth.dto.RegisterRequest; -import dev.tripdraw.auth.dto.TokenRefreshRequest; import dev.tripdraw.auth.exception.AuthException; -import dev.tripdraw.auth.oauth.OauthClientProvider; -import dev.tripdraw.member.domain.Member; +import dev.tripdraw.common.auth.OauthType; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; -import dev.tripdraw.test.ServiceTest; -import dev.tripdraw.test.TestKakaoApiClient; -import org.junit.jupiter.api.BeforeEach; +import java.util.Optional; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; -@ServiceTest +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@SpringBootTest class AuthServiceTest { @Autowired private AuthService authService; - @MockBean - private OauthClientProvider oauthClientProvider; - - @Autowired - private MemberRepository memberRepository; - - @Autowired - private RefreshTokenRepository refreshTokenRepository; - @Autowired private JwtTokenProvider jwtTokenProvider; - @BeforeEach - void setUp() { - when(oauthClientProvider.provide(KAKAO)).thenReturn(new TestKakaoApiClient()); - } - - @Test - void 가입된_회원이_카카오_소셜_로그인하면_토큰이_포함된_응답을_반환한다() { - // given - memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - OauthRequest oauthRequest = new OauthRequest(KAKAO, "oauth.kakao.token"); - - // when - OauthResponse response = authService.login(oauthRequest); + @MockBean + private MemberRepository memberRepository; - // then - assertSoftly(softly -> { - softly.assertThat(response.accessToken()).isNotEmpty(); - softly.assertThat(response.refreshToken()).isNotEmpty(); - }); - } + @MockBean + private RefreshTokenRepository refreshTokenRepository; @Test void 신규_회원이_로그인하면_회원을_저장하고_빈_토큰이_포함된_응답을_반환한다() { // given - OauthRequest oauthRequest = new OauthRequest(KAKAO, "oauth.kakao.token"); + given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) + .willReturn(Optional.empty()); + + OauthInfo oauthInfo = new OauthInfo("id", KAKAO); // when - OauthResponse response = authService.login(oauthRequest); + OauthResponse response = authService.login(oauthInfo); // then assertSoftly(softly -> { @@ -85,13 +66,13 @@ void setUp() { @Test void 신규_회원의_닉네임을_등록하면_토큰이_포함된_응답을_반환한다() { // given - Member member = Member.of("kakaoId", KAKAO); - memberRepository.save(member); + given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) + .willReturn(Optional.of(사용자())); - RegisterRequest registerRequest = new RegisterRequest("통후추", KAKAO, "oauth.kakao.token"); + OauthInfo oauthInfo = new OauthInfo("id", KAKAO); // when - OauthResponse response = authService.register(registerRequest); + OauthResponse response = authService.register(oauthInfo, "통후추"); // then assertSoftly(softly -> { @@ -103,61 +84,59 @@ void setUp() { @Test void 신규_회원의_닉네임을_등록할_때_회원이_존재하지_않으면_예외가_발생한다() { // given - RegisterRequest registerRequest = new RegisterRequest("저장안된후추", KAKAO, "oauth.kakao.token"); - - // expect - assertThatThrownBy(() -> authService.register(registerRequest)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); - } + given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) + .willReturn(Optional.empty()); - @Test - void 신규_회원의_닉네임을_등록할_때_이미_존재하는_닉네임이면_예외가_발생한다() { - // given - memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - RegisterRequest registerRequest = new RegisterRequest("통후추", KAKAO, "oauth.kakao.token"); + OauthInfo unregisteredOauthInfo = new OauthInfo("id", KAKAO); // expect - assertThatThrownBy(() -> authService.register(registerRequest)) + assertThatThrownBy(() -> authService.register(unregisteredOauthInfo, "통후추")) .isInstanceOf(MemberException.class) - .hasMessage(DUPLICATE_NICKNAME.message()); + .hasMessage(MEMBER_NOT_FOUND.message()); } @Test - void Refresh_토큰_재발급시_입력받은_토큰이_만료되는_경우_예외가_발생한다() { + void Refresh_토큰_재발급시_입력받은_Refresh_토큰이_만료된_경우_예외가_발생한다() { // given - Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); JwtTokenProvider expiredTokenProvider = new JwtTokenProvider( 만료된_토큰_생성용_ACCESS_TOKEN_설정(), 만료된_토큰_생성용_REFRESH_TOKEN_설정() ); String expiredToken = expiredTokenProvider.generateRefreshToken(); - refreshTokenRepository.save(new RefreshToken(member.id(), expiredToken)); - TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(expiredToken); // expect - assertThatThrownBy(() -> authService.refresh(tokenRefreshRequest)) + assertThatThrownBy(() -> authService.refresh(expiredToken)) .isInstanceOf(AuthException.class) .hasMessage(EXPIRED_REFRESH_TOKEN.message()); } + @Test + void Refresh_토큰_재발급시_입력받은_Refresh_토큰이_존재하지_않는_토큰인_경우_예외가_발생한다() { + // given + given(refreshTokenRepository.findByToken(any(String.class))).willReturn(Optional.empty()); + String token = jwtTokenProvider.generateRefreshToken(); + + // expect + assertThatThrownBy(() -> authService.refresh(token)) + .isInstanceOf(AuthException.class) + .hasMessage(INVALID_TOKEN.message()); + } + @Test void Refresh_토큰을_입력받아_Access_토큰과_Refresh_토큰을_재발급한다() { // given - Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); String refreshToken = jwtTokenProvider.generateRefreshToken(); - refreshTokenRepository.save(new RefreshToken(member.id(), refreshToken)); - TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(refreshToken); + given(refreshTokenRepository.findByToken(any(String.class))) + .willReturn(Optional.of(new RefreshToken(1L, 1L, refreshToken))); // when - OauthResponse response = authService.refresh(tokenRefreshRequest); + OauthResponse response = authService.refresh(refreshToken); // then assertSoftly(softly -> { softly.assertThat(response.accessToken()).isNotEmpty(); softly.assertThat(response.refreshToken()).isNotEmpty(); - softly.assertThat(refreshTokenRepository.findByToken(refreshToken)).isEmpty(); - softly.assertThat(refreshTokenRepository.findByToken(response.refreshToken())).isPresent(); + softly.assertThat(response.refreshToken()).isNotEqualTo(refreshToken); }); } } From bacda4d094e97baea6c9b6e93dc16dbbf04d5176 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 16 Sep 2023 15:16:56 +0900 Subject: [PATCH 071/119] =?UTF-8?q?[refactor]=20Token=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=B6=84=EB=A6=AC=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthFacadeService.java | 11 +- .../auth/application/AuthService.java | 37 ++----- .../application/TokenGenerateService.java | 39 +++++++ .../application/AuthFacadeServiceTest.java | 10 +- .../auth/application/AuthServiceTest.java | 101 ++++++------------ .../application/TokenGenerateServiceTest.java | 92 ++++++++++++++++ 6 files changed, 186 insertions(+), 104 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java create mode 100644 backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java index f8bfa11b2..e1d2edace 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java @@ -14,18 +14,23 @@ public class AuthFacadeService { private final OAuthService oAuthService; private final AuthService authService; + private final TokenGenerateService tokenGenerateService; public OauthResponse login(OauthRequest oauthRequest) { OauthInfo oauthInfo = oAuthService.request(oauthRequest.oauthType(), oauthRequest.oauthToken()); - return authService.login(oauthInfo); + return authService.login(oauthInfo) + .map(member -> tokenGenerateService.generate(member.id())) + .orElseGet(tokenGenerateService::generateEmptyToken); } public OauthResponse register(RegisterRequest registerRequest) { OauthInfo oauthInfo = oAuthService.request(registerRequest.oauthType(), registerRequest.oauthToken()); - return authService.register(oauthInfo, registerRequest.nickname()); + return authService.register(oauthInfo, registerRequest.nickname()) + .map(member -> tokenGenerateService.generate(member.id())) + .orElseGet(tokenGenerateService::generateEmptyToken); } public OauthResponse refresh(TokenRefreshRequest tokenRefreshRequest) { - return authService.refresh(tokenRefreshRequest.refreshToken()); + return tokenGenerateService.refresh(tokenRefreshRequest.refreshToken()); } } diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java index b8f25f505..dc75fcbc7 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthService.java @@ -1,17 +1,13 @@ package dev.tripdraw.auth.application; -import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import dev.tripdraw.auth.domain.RefreshToken; -import dev.tripdraw.auth.domain.RefreshTokenRepository; import dev.tripdraw.auth.dto.OauthInfo; -import dev.tripdraw.auth.dto.OauthResponse; -import dev.tripdraw.auth.exception.AuthException; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; +import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,31 +17,17 @@ @Service public class AuthService { - private static final OauthResponse EMPTY_TOKEN_RESPONSE = new OauthResponse("", ""); - - private final JwtTokenProvider jwtTokenProvider; - private final RefreshTokenRepository refreshTokenRepository; private final MemberRepository memberRepository; - public OauthResponse login(OauthInfo oauthInfo) { + public Optional login(OauthInfo oauthInfo) { return memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) - .map(member -> generateOAuthResponse(member.id())) - .orElseGet(() -> { + .or(() -> { memberRepository.save(Member.of(oauthInfo.oauthId(), oauthInfo.oauthType())); - return EMPTY_TOKEN_RESPONSE; + return Optional.empty(); }); } - private OauthResponse generateOAuthResponse(Long memberId) { - String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); - String refreshToken = jwtTokenProvider.generateRefreshToken(); - - refreshTokenRepository.deleteByMemberId(memberId); - refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); - return new OauthResponse(accessToken, refreshToken); - } - - public OauthResponse register(OauthInfo oauthInfo, String nickname) { + public Optional register(OauthInfo oauthInfo, String nickname) { if (memberRepository.existsByNickname(nickname)) { throw new MemberException(DUPLICATE_NICKNAME); } @@ -53,13 +35,6 @@ public OauthResponse register(OauthInfo oauthInfo, String nickname) { Member member = memberRepository.findByOauthIdAndOauthType(oauthInfo.oauthId(), oauthInfo.oauthType()) .orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND)); member.changeNickname(nickname); - return generateOAuthResponse(member.id()); - } - - public OauthResponse refresh(String token) { - jwtTokenProvider.validateRefreshToken(token); - RefreshToken refreshToken = refreshTokenRepository.findByToken(token) - .orElseThrow(() -> new AuthException(INVALID_TOKEN)); - return generateOAuthResponse(refreshToken.memberId()); + return Optional.of(member); } } diff --git a/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java b/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java new file mode 100644 index 000000000..ea96e6f50 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java @@ -0,0 +1,39 @@ +package dev.tripdraw.auth.application; + +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; + +import dev.tripdraw.auth.domain.RefreshToken; +import dev.tripdraw.auth.domain.RefreshTokenRepository; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.exception.AuthException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Transactional +@Service +public class TokenGenerateService { + + private final JwtTokenProvider jwtTokenProvider; + private final RefreshTokenRepository refreshTokenRepository; + + public OauthResponse refresh(String token) { + jwtTokenProvider.validateRefreshToken(token); + RefreshToken refreshToken = refreshTokenRepository.findByToken(token) + .orElseThrow(() -> new AuthException(INVALID_TOKEN)); + return generate(refreshToken.memberId()); + } + + public OauthResponse generate(Long memberId) { + String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); + String refreshToken = jwtTokenProvider.generateRefreshToken(); + refreshTokenRepository.deleteByMemberId(memberId); + refreshTokenRepository.save(new RefreshToken(memberId, refreshToken)); + return new OauthResponse(accessToken, refreshToken); + } + + public OauthResponse generateEmptyToken() { + return new OauthResponse("", ""); + } +} diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java index 60eb17e0d..6231009f4 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java @@ -13,14 +13,20 @@ import dev.tripdraw.auth.oauth.OauthClientProvider; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.test.ServiceTest; import dev.tripdraw.test.TestKakaoApiClient; +import jakarta.transaction.Transactional; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; -@ServiceTest +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@Transactional +@SpringBootTest class AuthFacadeServiceTest { @Autowired diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index 262081029..f68d4fb23 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -1,23 +1,20 @@ package dev.tripdraw.auth.application; -import static dev.tripdraw.auth.exception.AuthExceptionType.EXPIRED_REFRESH_TOKEN; -import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.member.exception.MemberExceptionType.DUPLICATE_NICKNAME; import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_ACCESS_TOKEN_설정; -import static dev.tripdraw.test.fixture.AuthFixture.만료된_토큰_생성용_REFRESH_TOKEN_설정; import static dev.tripdraw.test.fixture.MemberFixture.사용자; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; -import dev.tripdraw.auth.domain.RefreshToken; -import dev.tripdraw.auth.domain.RefreshTokenRepository; import dev.tripdraw.auth.dto.OauthInfo; -import dev.tripdraw.auth.dto.OauthResponse; -import dev.tripdraw.auth.exception.AuthException; import dev.tripdraw.common.auth.OauthType; +import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; import java.util.Optional; @@ -36,107 +33,75 @@ class AuthServiceTest { @Autowired private AuthService authService; - @Autowired - private JwtTokenProvider jwtTokenProvider; - @MockBean private MemberRepository memberRepository; - @MockBean - private RefreshTokenRepository refreshTokenRepository; + private final OauthInfo oauthInfo = new OauthInfo("id", KAKAO); @Test - void 신규_회원이_로그인하면_회원을_저장하고_빈_토큰이_포함된_응답을_반환한다() { + void 신규_회원이_로그인하면_회원을_저장_후_빈_회원을_반환한다() { // given given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) .willReturn(Optional.empty()); - OauthInfo oauthInfo = new OauthInfo("id", KAKAO); - // when - OauthResponse response = authService.login(oauthInfo); + Optional member = authService.login(oauthInfo); // then assertSoftly(softly -> { - softly.assertThat(response.accessToken()).isEmpty(); - softly.assertThat(response.refreshToken()).isEmpty(); + softly.assertThat(member).isNotPresent(); + verify(memberRepository, times(1)).save(any(Member.class)); }); } @Test - void 신규_회원의_닉네임을_등록하면_토큰이_포함된_응답을_반환한다() { + void 기존의_회원이_로그인하면_회원_정보를_반환한다() { // given + Member 사용자 = 사용자(); given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) - .willReturn(Optional.of(사용자())); - - OauthInfo oauthInfo = new OauthInfo("id", KAKAO); + .willReturn(Optional.of(사용자)); // when - OauthResponse response = authService.register(oauthInfo, "통후추"); + Optional member = authService.login(oauthInfo); // then - assertSoftly(softly -> { - softly.assertThat(response.accessToken()).isNotEmpty(); - softly.assertThat(response.refreshToken()).isNotEmpty(); - }); + assertThat(member).isPresent(); } @Test - void 신규_회원의_닉네임을_등록할_때_회원이_존재하지_않으면_예외가_발생한다() { + void 신규_회원의_닉네임을_등록_후_회원_정보를_반환한다() { // given given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) - .willReturn(Optional.empty()); + .willReturn(Optional.of(사용자())); - OauthInfo unregisteredOauthInfo = new OauthInfo("id", KAKAO); + // when + Optional member = authService.register(oauthInfo, "통후추"); - // expect - assertThatThrownBy(() -> authService.register(unregisteredOauthInfo, "통후추")) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); + // then + assertThat(member).isPresent(); } @Test - void Refresh_토큰_재발급시_입력받은_Refresh_토큰이_만료된_경우_예외가_발생한다() { + void 신규_회원의_닉네임을_등록할_때_회원이_존재하지_않으면_예외가_발생한다() { // given - JwtTokenProvider expiredTokenProvider = new JwtTokenProvider( - 만료된_토큰_생성용_ACCESS_TOKEN_설정(), - 만료된_토큰_생성용_REFRESH_TOKEN_설정() - ); - String expiredToken = expiredTokenProvider.generateRefreshToken(); + given(memberRepository.findByOauthIdAndOauthType(any(String.class), any(OauthType.class))) + .willReturn(Optional.empty()); // expect - assertThatThrownBy(() -> authService.refresh(expiredToken)) - .isInstanceOf(AuthException.class) - .hasMessage(EXPIRED_REFRESH_TOKEN.message()); + assertThatThrownBy(() -> authService.register(oauthInfo, "통후추")) + .isInstanceOf(MemberException.class) + .hasMessage(MEMBER_NOT_FOUND.message()); } @Test - void Refresh_토큰_재발급시_입력받은_Refresh_토큰이_존재하지_않는_토큰인_경우_예외가_발생한다() { + void 신규_회원의_닉네임을_등록할_때_이미_존재하는_닉네임이라면_예외가_발생한다() { // given - given(refreshTokenRepository.findByToken(any(String.class))).willReturn(Optional.empty()); - String token = jwtTokenProvider.generateRefreshToken(); + given(memberRepository.existsByNickname(any(String.class))) + .willReturn(true); // expect - assertThatThrownBy(() -> authService.refresh(token)) - .isInstanceOf(AuthException.class) - .hasMessage(INVALID_TOKEN.message()); - } - - @Test - void Refresh_토큰을_입력받아_Access_토큰과_Refresh_토큰을_재발급한다() { - // given - String refreshToken = jwtTokenProvider.generateRefreshToken(); - given(refreshTokenRepository.findByToken(any(String.class))) - .willReturn(Optional.of(new RefreshToken(1L, 1L, refreshToken))); - - // when - OauthResponse response = authService.refresh(refreshToken); - - // then - assertSoftly(softly -> { - softly.assertThat(response.accessToken()).isNotEmpty(); - softly.assertThat(response.refreshToken()).isNotEmpty(); - softly.assertThat(response.refreshToken()).isNotEqualTo(refreshToken); - }); + assertThatThrownBy(() -> authService.register(oauthInfo, "통후추")) + .isInstanceOf(MemberException.class) + .hasMessage(DUPLICATE_NICKNAME.message()); } } diff --git a/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java new file mode 100644 index 000000000..7e262ee32 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java @@ -0,0 +1,92 @@ +package dev.tripdraw.auth.application; + +import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import dev.tripdraw.auth.domain.RefreshToken; +import dev.tripdraw.auth.domain.RefreshTokenRepository; +import dev.tripdraw.auth.dto.OauthResponse; +import dev.tripdraw.auth.exception.AuthException; +import java.util.Optional; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@SpringBootTest +class TokenGenerateServiceTest { + + @Autowired + private TokenGenerateService tokenGenerateService; + + @Autowired + private JwtTokenProvider jwtTokenProvider; + + @MockBean + private RefreshTokenRepository refreshTokenRepository; + + @Test + void refreshToken을_발급하여_저장하고_Access_토큰과_Refresh_토큰을_반환한다() { + // given + Long memberId = 1L; + + // when + OauthResponse result = tokenGenerateService.generate(memberId); + + // then + assertSoftly(softly -> { + softly.assertThat(result.accessToken()).isNotEmpty(); + softly.assertThat(result.refreshToken()).isNotEmpty(); + verify(refreshTokenRepository, times(1)).save(any(RefreshToken.class)); + }); + } + + @Test + void Refresh_토큰_재발급시_입력받은_Refresh_토큰이_존재하지_않는_토큰인_경우_예외가_발생한다() { + // given + given(refreshTokenRepository.findByToken(any(String.class))).willReturn(Optional.empty()); + String token = jwtTokenProvider.generateRefreshToken(); + + // expect + assertThatThrownBy(() -> tokenGenerateService.refresh(token)) + .isInstanceOf(AuthException.class) + .hasMessage(INVALID_TOKEN.message()); + } + + @Test + void Refresh_토큰을_입력받아_Access_토큰과_Refresh_토큰을_재발급한다() { + // given + String refreshToken = jwtTokenProvider.generateRefreshToken(); + given(refreshTokenRepository.findByToken(any(String.class))) + .willReturn(Optional.of(new RefreshToken(1L, 1L, refreshToken))); + + // when + OauthResponse result = tokenGenerateService.refresh(refreshToken); + + // then + assertSoftly(softly -> { + softly.assertThat(result.accessToken()).isNotEmpty(); + softly.assertThat(result.refreshToken()).isNotEmpty(); + softly.assertThat(result.refreshToken()).isNotEqualTo(refreshToken); + }); + } + + @Test + void 빈_토큰을_발급한다() { + // given + OauthResponse emptyToken = new OauthResponse("", ""); + + // expect + assertThat(tokenGenerateService.generateEmptyToken()).isEqualTo(emptyToken); + } +} From 9fe86f1972a431b9d0486c7f2428457b4d649236 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 16 Sep 2023 16:11:11 +0900 Subject: [PATCH 072/119] =?UTF-8?q?[refactor]=20transactionTemplate=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20AuthService=EC=99=80=20T?= =?UTF-8?q?okenGenerateService=20=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98?= =?UTF-8?q?=EC=9D=84=20=EB=AC=B6=EA=B8=B0=20(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/AuthFacadeService.java | 10 ++++---- .../application/TokenGenerateService.java | 3 ++- .../auth/config/RefreshTokenConfig.java | 1 - .../application/AuthFacadeServiceTest.java | 4 ++-- .../auth/application/AuthServiceTest.java | 13 ++++++----- .../auth/application/OAuthServiceTest.java | 13 ++++++----- .../application/TokenGenerateServiceTest.java | 23 ++++++++++++------- 7 files changed, 39 insertions(+), 28 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java index e1d2edace..30a65a004 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/AuthFacadeService.java @@ -7,6 +7,7 @@ import dev.tripdraw.auth.dto.TokenRefreshRequest; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.support.TransactionTemplate; @RequiredArgsConstructor @Service @@ -15,19 +16,20 @@ public class AuthFacadeService { private final OAuthService oAuthService; private final AuthService authService; private final TokenGenerateService tokenGenerateService; + private final TransactionTemplate transactionTemplate; public OauthResponse login(OauthRequest oauthRequest) { OauthInfo oauthInfo = oAuthService.request(oauthRequest.oauthType(), oauthRequest.oauthToken()); - return authService.login(oauthInfo) + return transactionTemplate.execute(status -> authService.login(oauthInfo) .map(member -> tokenGenerateService.generate(member.id())) - .orElseGet(tokenGenerateService::generateEmptyToken); + .orElseGet(tokenGenerateService::generateEmptyToken)); } public OauthResponse register(RegisterRequest registerRequest) { OauthInfo oauthInfo = oAuthService.request(registerRequest.oauthType(), registerRequest.oauthToken()); - return authService.register(oauthInfo, registerRequest.nickname()) + return transactionTemplate.execute(status -> authService.register(oauthInfo, registerRequest.nickname()) .map(member -> tokenGenerateService.generate(member.id())) - .orElseGet(tokenGenerateService::generateEmptyToken); + .orElseGet(tokenGenerateService::generateEmptyToken)); } public OauthResponse refresh(TokenRefreshRequest tokenRefreshRequest) { diff --git a/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java b/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java index ea96e6f50..ff1e088f8 100644 --- a/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java +++ b/backend/src/main/java/dev/tripdraw/auth/application/TokenGenerateService.java @@ -11,13 +11,13 @@ import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor -@Transactional @Service public class TokenGenerateService { private final JwtTokenProvider jwtTokenProvider; private final RefreshTokenRepository refreshTokenRepository; + @Transactional public OauthResponse refresh(String token) { jwtTokenProvider.validateRefreshToken(token); RefreshToken refreshToken = refreshTokenRepository.findByToken(token) @@ -25,6 +25,7 @@ public OauthResponse refresh(String token) { return generate(refreshToken.memberId()); } + @Transactional public OauthResponse generate(Long memberId) { String accessToken = jwtTokenProvider.generateAccessToken(memberId.toString()); String refreshToken = jwtTokenProvider.generateRefreshToken(); diff --git a/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java index a1af2f37c..c3f05dc88 100644 --- a/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java +++ b/backend/src/main/java/dev/tripdraw/auth/config/RefreshTokenConfig.java @@ -7,5 +7,4 @@ public record RefreshTokenConfig( String secretKey, Long expirationTime ) { - } diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java index 6231009f4..92d3f535c 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthFacadeServiceTest.java @@ -2,7 +2,7 @@ import static dev.tripdraw.common.auth.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; import dev.tripdraw.auth.domain.RefreshToken; import dev.tripdraw.auth.domain.RefreshTokenRepository; @@ -46,7 +46,7 @@ class AuthFacadeServiceTest { @BeforeEach void setUp() { - when(oauthClientProvider.provide(KAKAO)).thenReturn(new TestKakaoApiClient()); + given(oauthClientProvider.provide(KAKAO)).willReturn(new TestKakaoApiClient()); } @Test diff --git a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java index f68d4fb23..27eefe303 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/AuthServiceTest.java @@ -21,19 +21,20 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -@SpringBootTest +@ExtendWith(MockitoExtension.class) class AuthServiceTest { - @Autowired + @InjectMocks private AuthService authService; - @MockBean + @Mock private MemberRepository memberRepository; private final OauthInfo oauthInfo = new OauthInfo("id", KAKAO); diff --git a/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java index dea6fa39f..b37f56102 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/OAuthServiceTest.java @@ -11,19 +11,20 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -@SpringBootTest +@ExtendWith(MockitoExtension.class) class OAuthServiceTest { - @Autowired + @InjectMocks private OAuthService oAuthService; - @MockBean + @Mock private OauthClientProvider oauthClientProvider; @BeforeEach diff --git a/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java b/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java index 7e262ee32..a0dc881bc 100644 --- a/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/application/TokenGenerateServiceTest.java @@ -1,6 +1,8 @@ package dev.tripdraw.auth.application; import static dev.tripdraw.auth.exception.AuthExceptionType.INVALID_TOKEN; +import static dev.tripdraw.test.fixture.AuthFixture.테스트_ACCESS_TOKEN_설정; +import static dev.tripdraw.test.fixture.AuthFixture.테스트_REFRESH_TOKEN_설정; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -17,22 +19,27 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -@SpringBootTest +@ExtendWith(MockitoExtension.class) class TokenGenerateServiceTest { - @Autowired + @InjectMocks private TokenGenerateService tokenGenerateService; - @Autowired - private JwtTokenProvider jwtTokenProvider; + @Spy + private JwtTokenProvider jwtTokenProvider = new JwtTokenProvider( + 테스트_ACCESS_TOKEN_설정(), + 테스트_REFRESH_TOKEN_설정() + ); - @MockBean + @Mock private RefreshTokenRepository refreshTokenRepository; @Test From 173c7b9145557ab9c99a6ecfabd590eee2d501c1 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 18 Sep 2023 14:44:32 +0900 Subject: [PATCH 073/119] =?UTF-8?q?[refactor]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20API=20=EB=AA=85=EC=84=B8=20=EB=B0=8F=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=B3=80=EA=B2=BD=20(#369)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/common/config/AuthConfig.java | 3 +- .../member/application/MemberService.java | 12 ++--- .../member/presentation/MemberController.java | 15 +++--- .../member/application/MemberServiceTest.java | 49 ++++-------------- .../presentation/MemberControllerTest.java | 50 ++++--------------- 5 files changed, 35 insertions(+), 94 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/common/config/AuthConfig.java b/backend/src/main/java/dev/tripdraw/common/config/AuthConfig.java index 7a98c5fd7..b72575681 100644 --- a/backend/src/main/java/dev/tripdraw/common/config/AuthConfig.java +++ b/backend/src/main/java/dev/tripdraw/common/config/AuthConfig.java @@ -1,7 +1,7 @@ package dev.tripdraw.common.config; -import dev.tripdraw.auth.presentation.AuthArgumentResolver; import dev.tripdraw.auth.application.AuthExtractor; +import dev.tripdraw.auth.presentation.AuthArgumentResolver; import dev.tripdraw.auth.presentation.AuthInterceptor; import java.util.List; import lombok.RequiredArgsConstructor; @@ -25,7 +25,6 @@ public void addArgumentResolvers(List resolvers) @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(authInterceptor) - .excludePathPatterns("/members/**") .excludePathPatterns("/swagger-ui/**") .excludePathPatterns("/api-docs") .excludePathPatterns("/v3/api-docs/**") diff --git a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java index 2f056fd01..eb59ec703 100644 --- a/backend/src/main/java/dev/tripdraw/member/application/MemberService.java +++ b/backend/src/main/java/dev/tripdraw/member/application/MemberService.java @@ -1,6 +1,6 @@ package dev.tripdraw.member.application; -import dev.tripdraw.auth.application.JwtTokenProvider; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberDeleteEvent; import dev.tripdraw.member.domain.MemberRepository; @@ -16,7 +16,6 @@ public class MemberService { private final MemberRepository memberRepository; - private final JwtTokenProvider jwtTokenProvider; private final ApplicationEventPublisher publisher; @Transactional(readOnly = true) @@ -25,14 +24,13 @@ public boolean existsById(Long memberId) { } @Transactional(readOnly = true) - public MemberSearchResponse findByCode(String code) { - Long memberId = Long.valueOf(jwtTokenProvider.extractAccessToken(code)); - Member member = memberRepository.getById(memberId); + public MemberSearchResponse find(LoginUser loginUser) { + Member member = memberRepository.getById(loginUser.memberId()); return MemberSearchResponse.from(member); } - public void deleteByCode(String code) { - Long memberId = Long.valueOf(jwtTokenProvider.extractAccessToken(code)); + public void delete(LoginUser loginUser) { + Long memberId = loginUser.memberId(); publisher.publishEvent(new MemberDeleteEvent(memberId)); memberRepository.deleteById(memberId); } diff --git a/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java b/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java index a88e8fbc6..5ee40bcc8 100644 --- a/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java +++ b/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java @@ -1,5 +1,7 @@ package dev.tripdraw.member.presentation; +import dev.tripdraw.common.auth.Auth; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.member.application.MemberService; import dev.tripdraw.member.dto.MemberSearchResponse; import io.swagger.v3.oas.annotations.Operation; @@ -10,7 +12,6 @@ import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @Tag(name = "Member", description = "사용자 관련 API 명세") @@ -26,9 +27,9 @@ public class MemberController { responseCode = "200", description = "사용자 조회 성공." ) - @GetMapping - public ResponseEntity findByCode(@RequestParam String code) { - MemberSearchResponse response = memberService.findByCode(code); + @GetMapping("/me") + public ResponseEntity findByCode(@Auth LoginUser loginUser) { + MemberSearchResponse response = memberService.find(loginUser); return ResponseEntity.ok(response); } @@ -37,9 +38,9 @@ public ResponseEntity findByCode(@RequestParam String code responseCode = "204", description = "사용자 삭제 성공." ) - @DeleteMapping - public ResponseEntity delete(@RequestParam String code) { - memberService.deleteByCode(code); + @DeleteMapping("/me") + public ResponseEntity delete(@Auth LoginUser loginUser) { + memberService.delete(loginUser); return ResponseEntity.noContent().build(); } } diff --git a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java index 42f7c7200..d2a168944 100644 --- a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java @@ -1,17 +1,14 @@ package dev.tripdraw.member.application; import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import dev.tripdraw.auth.application.JwtTokenProvider; +import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberDeleteEvent; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.dto.MemberSearchResponse; -import dev.tripdraw.member.exception.MemberException; import dev.tripdraw.post.domain.Post; import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.test.ServiceTest; @@ -39,9 +36,6 @@ class MemberServiceTest { @Autowired private MemberRepository memberRepository; - @Autowired - private JwtTokenProvider jwtTokenProvider; - @Autowired private TripRepository tripRepository; @@ -49,14 +43,11 @@ class MemberServiceTest { private PostRepository postRepository; private Member member; - private String code; private Trip trip; @BeforeEach void setUp() { member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - code = jwtTokenProvider.generateAccessToken(member.id().toString()); - trip = tripRepository.save(new Trip(TripName.from("통후추의 여행"), member)); Point point = new Point(3.14, 5.25, LocalDateTime.now()); trip.add(point); @@ -71,9 +62,12 @@ void setUp() { } @Test - void code를_입력_받아_사용자를_조회한다() { - // given & when - MemberSearchResponse response = memberService.findByCode(code); + void 사용자를_조회한다() { + // given + LoginUser loginUser = new LoginUser(member.id()); + + // when + MemberSearchResponse response = memberService.find(loginUser); // expect assertThat(response).usingRecursiveComparison().isEqualTo( @@ -82,33 +76,12 @@ void setUp() { } @Test - void code를_입력_받아_사용자를_조회할_때_이미_삭제된_사용자라면_예외를_발생시킨다() { + void 사용자를_삭제한다() { // given - Member member = memberRepository.save(new Member("순후추", "kakaoId", KAKAO)); - String code = jwtTokenProvider.generateAccessToken(member.id().toString()); - - memberRepository.deleteById(member.id()); + LoginUser loginUser = new LoginUser(member.id()); - // expect - assertThatThrownBy(() -> memberService.findByCode(code)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); - } - - @Test - void code를_입력_받아_사용자를_조회할_때_존재하지_않는_사용자라면_예외를_발생시킨다() { - String nonExistentCode = jwtTokenProvider.generateAccessToken("-1"); - - // expect - assertThatThrownBy(() -> memberService.findByCode(nonExistentCode)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); - } - - @Test - void code를_입력_받아_사용자를_삭제한다() { - // given & when - memberService.deleteByCode(code); + // when + memberService.delete(loginUser); // then long publishedEvents = applicationEvents.stream(MemberDeleteEvent.class) diff --git a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java index 3c00128fe..03a5d11ee 100644 --- a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java @@ -3,7 +3,6 @@ import static dev.tripdraw.common.auth.OauthType.KAKAO; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.springframework.http.HttpStatus.FORBIDDEN; -import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; @@ -54,15 +53,15 @@ public void setUp() { } @Test - void code를_입력_받아_사용자를_조회한다() { + void 사용자를_조회한다() { // given Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - String code = jwtTokenProvider.generateAccessToken(member.id().toString()); + String huchuToken = jwtTokenProvider.generateAccessToken(member.id().toString()); // when ExtractableResponse response = RestAssured.given().log().all() - .param("code", code) - .when().get("/members") + .auth().preemptive().oauth2(huchuToken) + .when().get("/members/me") .then().log().all() .extract(); @@ -78,39 +77,10 @@ public void setUp() { } @Test - void code를_입력_받아_사용자를_조회할_때_존재하지_않는_사용자라면_예외가_발생한다() { - // given - String code = jwtTokenProvider.generateAccessToken("-1"); - - // expect - RestAssured.given().log().all() - .param("code", code) - .when().get("/members") - .then().log().all() - .statusCode(NOT_FOUND.value()); - } - - @Test - void code를_입력_받아_사용자를_조회할_때_이미_삭제된_사용자라면_예외가_발생한다() { - // given - Member member = memberRepository.save(new Member("순후추", "kakaoId", KAKAO)); - String code = jwtTokenProvider.generateAccessToken(member.id().toString()); - - memberRepository.delete(member); - - // expect - RestAssured.given().log().all() - .param("code", code) - .when().get("/members") - .then().log().all() - .statusCode(NOT_FOUND.value()); - } - - @Test - void code를_입력_받아_사용자를_삭제한다() { + void 사용자를_삭제한다() { // given Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - String code = jwtTokenProvider.generateAccessToken(member.id().toString()); + String huchuToken = jwtTokenProvider.generateAccessToken(member.id().toString()); Trip trip = new Trip(TripName.from("통후추의 여행"), member); Point point = new Point(3.14, 5.25, LocalDateTime.now()); @@ -127,19 +97,19 @@ public void setUp() { // expect RestAssured.given().log().all() - .param("code", code) - .when().delete("/members") + .auth().preemptive().oauth2(huchuToken) + .when().delete("/members/me") .then().log().all() .statusCode(NO_CONTENT.value()); RestAssured.given().log().all() - .auth().preemptive().oauth2(code) + .auth().preemptive().oauth2(huchuToken) .when().get("/trips/{tripId}", trip.id()) .then().log().all() .statusCode(FORBIDDEN.value()); RestAssured.given().log().all() - .auth().preemptive().oauth2(code) + .auth().preemptive().oauth2(huchuToken) .when().get("/posts/{postId}", post.id()) .then().log().all() .statusCode(FORBIDDEN.value()); From 86745de730d6b33cdae60416932b0db33e8252c0 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 15:17:24 +0900 Subject: [PATCH 074/119] =?UTF-8?q?[chore]=20conflict=20=ED=95=B4=EA=B2=B0?= =?UTF-8?q?=20(#346)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/member/presentation/MemberController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java b/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java index 5ee40bcc8..843c6436d 100644 --- a/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java +++ b/backend/src/main/java/dev/tripdraw/member/presentation/MemberController.java @@ -2,6 +2,7 @@ import dev.tripdraw.common.auth.Auth; import dev.tripdraw.common.auth.LoginUser; +import dev.tripdraw.common.swagger.SwaggerAuthorizationRequired; import dev.tripdraw.member.application.MemberService; import dev.tripdraw.member.dto.MemberSearchResponse; import io.swagger.v3.oas.annotations.Operation; @@ -16,6 +17,7 @@ @Tag(name = "Member", description = "사용자 관련 API 명세") @RequiredArgsConstructor +@SwaggerAuthorizationRequired @RequestMapping("/members") @RestController public class MemberController { @@ -28,7 +30,7 @@ public class MemberController { description = "사용자 조회 성공." ) @GetMapping("/me") - public ResponseEntity findByCode(@Auth LoginUser loginUser) { + public ResponseEntity find(@Auth LoginUser loginUser) { MemberSearchResponse response = memberService.find(loginUser); return ResponseEntity.ok(response); } From c354e7d56bc80932ff3391aa14cba61ca39f06e6 Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 15:28:56 +0900 Subject: [PATCH 075/119] =?UTF-8?q?refactor:=20q=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20static=EC=9C=BC=EB=A1=9C=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/post/domain/PostCustomRepositoryImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java index 0e3da58c7..588cfde41 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java @@ -1,5 +1,7 @@ package dev.tripdraw.post.domain; +import static dev.tripdraw.post.domain.QPost.post; + import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.core.types.dsl.NumberExpression; import com.querydsl.core.types.dsl.StringPath; @@ -18,12 +20,10 @@ public class PostCustomRepositoryImpl implements PostCustomRepository { @Override public List findAllByConditions(SearchConditions conditions, Paging paging) { - QPost post = QPost.post; - // TODO: 2023/09/16 연령대, 성별 추가 return jpaQueryFactory.selectFrom(post) .where( - ltLastViewedId(post, paging.lastViewedId()), + ltLastViewedId(paging.lastViewedId()), contains(post.point.recordedAt.year(), conditions.years()), contains(post.point.recordedAt.month(), conditions.months()), contains(post.point.recordedAt.dayOfWeek(), conditions.daysOfWeek()), @@ -35,7 +35,7 @@ public List findAllByConditions(SearchConditions conditions, Paging paging .fetch(); } - private BooleanExpression ltLastViewedId(QPost post, Long lastViewedId) { + private BooleanExpression ltLastViewedId(Long lastViewedId) { if (lastViewedId == null) { return null; } From beec873db0243f85a9def1e648eac90454a239f0 Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 15:34:27 +0900 Subject: [PATCH 076/119] =?UTF-8?q?refactor:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/domain/PostCustomRepositoryImpl.java | 52 +++++++++++++------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java index 588cfde41..2aabdb718 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java @@ -3,8 +3,6 @@ import static dev.tripdraw.post.domain.QPost.post; import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.core.types.dsl.NumberExpression; -import com.querydsl.core.types.dsl.StringPath; import com.querydsl.jpa.impl.JPAQueryFactory; import dev.tripdraw.common.domain.Paging; import lombok.RequiredArgsConstructor; @@ -23,19 +21,19 @@ public List findAllByConditions(SearchConditions conditions, Paging paging // TODO: 2023/09/16 연령대, 성별 추가 return jpaQueryFactory.selectFrom(post) .where( - ltLastViewedId(paging.lastViewedId()), - contains(post.point.recordedAt.year(), conditions.years()), - contains(post.point.recordedAt.month(), conditions.months()), - contains(post.point.recordedAt.dayOfWeek(), conditions.daysOfWeek()), - contains(post.point.recordedAt.hour(), conditions.hours()), - eqAdress(post.address, conditions.address()) + postIdLt(paging.lastViewedId()), + yearIn(conditions.years()), + monthIn(conditions.months()), + dayOfWeekIn(conditions.daysOfWeek()), + hourIn(conditions.hours()), + addressLike(conditions.address()) ) .limit(paging.limit()) .orderBy(post.id.desc()) .fetch(); } - private BooleanExpression ltLastViewedId(Long lastViewedId) { + private BooleanExpression postIdLt(Long lastViewedId) { if (lastViewedId == null) { return null; } @@ -43,19 +41,43 @@ private BooleanExpression ltLastViewedId(Long lastViewedId) { return post.id.lt(lastViewedId); } - private BooleanExpression contains(NumberExpression value, List values) { - if (values == null || values.isEmpty()) { + private BooleanExpression yearIn(List years) { + if (years == null || years.isEmpty()) { return null; } - return value.in(values); + return post.point.recordedAt.year().in(years); } - private BooleanExpression eqAdress(StringPath address, String targetAddress) { - if (targetAddress == null || targetAddress.isEmpty()) { + private BooleanExpression monthIn(List months) { + if (months == null || months.isEmpty()) { return null; } - return address.like(targetAddress + "%"); + return post.point.recordedAt.month().in(months); + } + + private BooleanExpression dayOfWeekIn(List daysOfWeek) { + if (daysOfWeek == null || daysOfWeek.isEmpty()) { + return null; + } + + return post.point.recordedAt.dayOfWeek().in(daysOfWeek); + } + + private BooleanExpression hourIn(List hours) { + if (hours == null || hours.isEmpty()) { + return null; + } + + return post.point.recordedAt.hour().in(hours); + } + + private BooleanExpression addressLike(String address) { + if (address == null || address.isEmpty()) { + return null; + } + + return post.address.like(address + "%"); } } From bba1c0e01ce7ccd753039d1648f0980959ae881a Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 15:40:59 +0900 Subject: [PATCH 077/119] =?UTF-8?q?refactor:=20long=20value=EB=A1=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java index 2aabdb718..d35df673f 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java @@ -28,7 +28,7 @@ public List findAllByConditions(SearchConditions conditions, Paging paging hourIn(conditions.hours()), addressLike(conditions.address()) ) - .limit(paging.limit()) + .limit(paging.limit().longValue() + 1L) .orderBy(post.id.desc()) .fetch(); } From 99f4c48c99ca322a0627afc0339699b64f43c77b Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 16:23:26 +0900 Subject: [PATCH 078/119] =?UTF-8?q?refactor:=20query=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/common/dto/SearchPaging.java | 9 --------- .../dev/tripdraw/post/application/PostService.java | 6 +----- .../post/application/query/PostQueryService.java | 5 +++++ .../tripdraw/post/domain/PostCustomRepository.java | 10 ---------- .../dev/tripdraw/post/domain/PostRepository.java | 1 + .../post/domain/query/PostCustomRepository.java | 12 ++++++++++++ .../domain/{ => query}/PostCustomRepositoryImpl.java | 8 +++++--- .../dev/tripdraw/post/dto/PostSearchRequest.java | 5 +++-- .../query/PostSearchConditions.java} | 4 ++-- .../tripdraw/post/dto/query/PostSearchPaging.java | 4 ++++ .../tripdraw/post/application/PostServiceTest.java | 8 ++++---- .../post/domain/PostCustomRepositoryImplTest.java | 10 ++++++---- .../post/presentation/PostControllerTest.java | 10 +++++----- 13 files changed, 48 insertions(+), 44 deletions(-) delete mode 100644 backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java create mode 100644 backend/src/main/java/dev/tripdraw/post/application/query/PostQueryService.java delete mode 100644 backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepository.java create mode 100644 backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepository.java rename backend/src/main/java/dev/tripdraw/post/domain/{ => query}/PostCustomRepositoryImpl.java (88%) rename backend/src/main/java/dev/tripdraw/post/{domain/SearchConditions.java => dto/query/PostSearchConditions.java} (78%) create mode 100644 backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchPaging.java diff --git a/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java b/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java deleted file mode 100644 index 989ce5da8..000000000 --- a/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.tripdraw.common.dto; - -import dev.tripdraw.common.domain.Paging; - -public record SearchPaging(Long lastViewedId, Integer limit) { - public Paging toPaging() { - return new Paging(lastViewedId, limit); - } -} diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index 87222e369..9ad215b9d 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -5,14 +5,12 @@ import static java.util.stream.Collectors.toList; import dev.tripdraw.common.auth.LoginUser; -import dev.tripdraw.common.domain.Paging; import dev.tripdraw.file.application.FileUploader; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.domain.Post; import dev.tripdraw.post.domain.PostCreateEvent; import dev.tripdraw.post.domain.PostRepository; -import dev.tripdraw.post.domain.SearchConditions; import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; @@ -130,9 +128,7 @@ public void delete(LoginUser loginUser, Long postId) { } public PostsSearchResponse readAll(PostSearchRequest postSearchRequest) { - SearchConditions searchConditions = postSearchRequest.condition().toSearchConditions(); - Paging paging = postSearchRequest.paging().toPaging(); - List posts = postRepository.findAllByConditions(searchConditions, paging); + List posts = postRepository.findAllByConditions(postSearchRequest.conditions(), postSearchRequest.paging()); List postSearchResponses = posts.stream() .map(PostSearchResponse::from) diff --git a/backend/src/main/java/dev/tripdraw/post/application/query/PostQueryService.java b/backend/src/main/java/dev/tripdraw/post/application/query/PostQueryService.java new file mode 100644 index 000000000..eae0d1002 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/application/query/PostQueryService.java @@ -0,0 +1,5 @@ +package dev.tripdraw.post.application.query; + +public class PostQueryService { + +} diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepository.java b/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepository.java deleted file mode 100644 index 638ccf45d..000000000 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.tripdraw.post.domain; - -import dev.tripdraw.common.domain.Paging; - -import java.util.List; - -public interface PostCustomRepository { - - List findAllByConditions(SearchConditions conditions, Paging paging); -} diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java index 8d93b416e..faf73c2d4 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java @@ -2,6 +2,7 @@ import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; +import dev.tripdraw.post.domain.query.PostCustomRepository; import dev.tripdraw.post.exception.PostException; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepository.java b/backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepository.java new file mode 100644 index 000000000..9ba178832 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepository.java @@ -0,0 +1,12 @@ +package dev.tripdraw.post.domain.query; + +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.dto.query.PostSearchConditions; +import dev.tripdraw.post.dto.query.PostSearchPaging; + +import java.util.List; + +public interface PostCustomRepository { + + List findAllByConditions(PostSearchConditions conditions, PostSearchPaging paging); +} diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepositoryImpl.java similarity index 88% rename from backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java rename to backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepositoryImpl.java index d35df673f..372b6dede 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepositoryImpl.java @@ -1,10 +1,12 @@ -package dev.tripdraw.post.domain; +package dev.tripdraw.post.domain.query; import static dev.tripdraw.post.domain.QPost.post; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; -import dev.tripdraw.common.domain.Paging; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.dto.query.PostSearchConditions; +import dev.tripdraw.post.dto.query.PostSearchPaging; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -17,7 +19,7 @@ public class PostCustomRepositoryImpl implements PostCustomRepository { private final JPAQueryFactory jpaQueryFactory; @Override - public List findAllByConditions(SearchConditions conditions, Paging paging) { + public List findAllByConditions(PostSearchConditions conditions, PostSearchPaging paging) { // TODO: 2023/09/16 연령대, 성별 추가 return jpaQueryFactory.selectFrom(post) .where( diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java index ee9432d98..501eaa6d8 100644 --- a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java @@ -1,6 +1,7 @@ package dev.tripdraw.post.dto; -import dev.tripdraw.common.dto.SearchPaging; +import dev.tripdraw.post.dto.query.PostSearchConditions; +import dev.tripdraw.post.dto.query.PostSearchPaging; -public record PostSearchRequest(PostSearchConditions condition, SearchPaging paging) { +public record PostSearchRequest(PostSearchConditions conditions, PostSearchPaging paging) { } diff --git a/backend/src/main/java/dev/tripdraw/post/domain/SearchConditions.java b/backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchConditions.java similarity index 78% rename from backend/src/main/java/dev/tripdraw/post/domain/SearchConditions.java rename to backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchConditions.java index d76ca3753..e36e95617 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/SearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchConditions.java @@ -1,11 +1,11 @@ -package dev.tripdraw.post.domain; +package dev.tripdraw.post.dto.query; import lombok.Builder; import java.util.List; @Builder -public record SearchConditions( +public record PostSearchConditions( List years, List months, List daysOfWeek, diff --git a/backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchPaging.java b/backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchPaging.java new file mode 100644 index 000000000..cbd7375e1 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchPaging.java @@ -0,0 +1,4 @@ +package dev.tripdraw.post.dto.query; + +public record PostSearchPaging(Long lastViewedId, Integer limit) { +} diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index e9e8dc714..d644b302f 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -16,7 +16,6 @@ import static org.mockito.Mockito.mock; import dev.tripdraw.common.auth.LoginUser; -import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.file.application.FileUploader; import dev.tripdraw.member.domain.Member; @@ -26,12 +25,13 @@ import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; -import dev.tripdraw.post.dto.PostSearchConditions; import dev.tripdraw.post.dto.PostSearchRequest; import dev.tripdraw.post.dto.PostSearchResponse; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; import dev.tripdraw.post.dto.PostsSearchResponse; +import dev.tripdraw.post.dto.query.PostSearchConditions; +import dev.tripdraw.post.dto.query.PostSearchPaging; import dev.tripdraw.post.exception.PostException; import dev.tripdraw.test.ServiceTest; import dev.tripdraw.trip.domain.Point; @@ -320,14 +320,14 @@ void setUp() { PostSearchConditions.builder() .address("제주특별자치도 제주시 애월읍") .build(), - new SearchPaging(null, 10) + new PostSearchPaging(null, 10) ); PostSearchRequest postSearchRequestJuly = new PostSearchRequest( PostSearchConditions.builder() .months(List.of(7)) .build(), - new SearchPaging(null, 10) + new PostSearchPaging(null, 10) ); // when diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java index b17b33e27..74a340806 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java @@ -5,9 +5,11 @@ import dev.tripdraw.common.config.JpaConfig; import dev.tripdraw.common.config.QueryDslConfig; -import dev.tripdraw.common.domain.Paging; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.post.domain.query.PostCustomRepositoryImpl; +import dev.tripdraw.post.dto.query.PostSearchConditions; +import dev.tripdraw.post.dto.query.PostSearchPaging; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; @@ -61,15 +63,15 @@ class PostCustomRepositoryImplTest { postRepository.save(secondPost); postRepository.save(thirdPost); - SearchConditions firstConditions = SearchConditions.builder() + PostSearchConditions firstConditions = PostSearchConditions.builder() .months(List.of(5)) .build(); - SearchConditions secondConditions = SearchConditions.builder() + PostSearchConditions secondConditions = PostSearchConditions.builder() .hours(List.of(18)) .build(); - Paging paging = new Paging(null, 10); + PostSearchPaging paging = new PostSearchPaging(null, 10); // when List firstPosts = postCustomRepository.findAllByConditions(firstConditions, paging); diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index 46c4430c3..4406e2a77 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -13,18 +13,18 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; import dev.tripdraw.auth.application.JwtTokenProvider; -import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; -import dev.tripdraw.post.dto.PostSearchConditions; import dev.tripdraw.post.dto.PostSearchRequest; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; import dev.tripdraw.post.dto.PostsSearchResponse; +import dev.tripdraw.post.dto.query.PostSearchConditions; +import dev.tripdraw.post.dto.query.PostSearchPaging; import dev.tripdraw.test.ControllerTest; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; @@ -417,7 +417,7 @@ public void setUp() { void 특정_여행에_대한_모든_감상을_조회한다() { // given createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); - createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); + createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 21, 24)); // when ExtractableResponse findResponse = RestAssured.given().log().all() @@ -468,7 +468,7 @@ public void setUp() { @Test void 감상을_수정한다() { // given - PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 17, 20, 24)); PostUpdateRequest postUpdateRequest = new PostUpdateRequest( "우도의 땅콩 아이스크림", @@ -598,7 +598,7 @@ public void setUp() { .hours(List.of(17)) .address("제주특별자치도 제주시 애월읍") .build(), - new SearchPaging(null, 10) + new PostSearchPaging(null, 10) ); // when From f7092500b00ae8d5180b1b64e36edd6a1fb1c57b Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 16:23:41 +0900 Subject: [PATCH 079/119] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20VO=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/common/domain/Paging.java | 4 --- .../post/dto/PostSearchConditions.java | 29 ------------------- 2 files changed, 33 deletions(-) delete mode 100644 backend/src/main/java/dev/tripdraw/common/domain/Paging.java delete mode 100644 backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java diff --git a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java b/backend/src/main/java/dev/tripdraw/common/domain/Paging.java deleted file mode 100644 index 1788bf8ac..000000000 --- a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java +++ /dev/null @@ -1,4 +0,0 @@ -package dev.tripdraw.common.domain; - -public record Paging(Long lastViewedId, Integer limit) { -} diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java deleted file mode 100644 index c7ed4d6e0..000000000 --- a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java +++ /dev/null @@ -1,29 +0,0 @@ -package dev.tripdraw.post.dto; - -import dev.tripdraw.post.domain.SearchConditions; -import lombok.Builder; - -import java.util.List; - -@Builder -public record PostSearchConditions( - List years, - List months, - List daysOfWeek, - List hours, - List ageRanges, - List genders, - String address -) { - public SearchConditions toSearchConditions() { - return SearchConditions.builder() - .years(years) - .months(months) - .daysOfWeek(daysOfWeek) - .hours(hours) - .ageRanges(ageRanges) - .genders(genders) - .address(address) - .build(); - } -} From 303d1e5224163d5c24885dab3727665f3ba0ec6d Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 16:31:54 +0900 Subject: [PATCH 080/119] =?UTF-8?q?refactor:=20=EC=B6=94=EA=B0=80=EC=A0=81?= =?UTF-8?q?=EC=9D=B8=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/post/domain/PostRepository.java | 4 ++- .../post/application/PostServiceTest.java | 33 +++++++++++++------ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java index faf73c2d4..6be9f147d 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java @@ -4,6 +4,7 @@ import dev.tripdraw.post.domain.query.PostCustomRepository; import dev.tripdraw.post.exception.PostException; +import lombok.NonNull; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; @@ -12,7 +13,8 @@ public interface PostRepository extends JpaRepository, PostCustomRep List findAllByTripId(Long tripId); - default Post getById(Long id) { + @NonNull + default Post getById(@NonNull Long id) { return findById(id) .orElseThrow(() -> new PostException(POST_NOT_FOUND)); } diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index d644b302f..fdf919695 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -40,6 +40,8 @@ import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.exception.TripException; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -48,6 +50,8 @@ import java.time.LocalDateTime; import java.util.List; +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ServiceTest class PostServiceTest { @@ -247,7 +251,8 @@ void setUp() { LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); // expect - assertThatThrownBy(() -> postService.read(wrongUser, postCreateResponse.postId())) + Long postId = postCreateResponse.postId(); + assertThatThrownBy(() -> postService.read(wrongUser, postId)) .isInstanceOf(MemberException.class) .hasMessage(MEMBER_NOT_FOUND.message()); } @@ -258,7 +263,8 @@ void setUp() { PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); // expect - assertThatThrownBy(() -> postService.read(otherUser, postCreateResponse.postId())) + Long postId = postCreateResponse.postId(); + assertThatThrownBy(() -> postService.read(otherUser, postId)) .isInstanceOf(PostException.class) .hasMessage(NOT_AUTHORIZED_TO_POST.message()); } @@ -288,7 +294,8 @@ void setUp() { LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); // expect - assertThatThrownBy(() -> postService.readAllByTripId(wrongUser, trip.id())) + Long tripId = trip.id(); + assertThatThrownBy(() -> postService.readAllByTripId(wrongUser, tripId)) .isInstanceOf(MemberException.class) .hasMessage(MEMBER_NOT_FOUND.message()); } @@ -304,7 +311,8 @@ void setUp() { @Test void 특정_여행의_모든_감상을_조회할_때_로그인_한_사용자가_여행의_주인이_아니면_예외가_발생한다() { // expect - assertThatThrownBy(() -> postService.readAllByTripId(otherUser, trip.id())) + Long tripId = trip.id(); + assertThatThrownBy(() -> postService.readAllByTripId(otherUser, tripId)) .isInstanceOf(TripException.class) .hasMessage(NOT_AUTHORIZED_TO_TRIP.message()); } @@ -387,7 +395,8 @@ void setUp() { LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); // expect - assertThatThrownBy(() -> postService.update(wrongUser, postCreateResponse.postId(), postUpdateRequest, null)) + Long postId = postCreateResponse.postId(); + assertThatThrownBy(() -> postService.update(wrongUser, postId, postUpdateRequest, null)) .isInstanceOf(MemberException.class) .hasMessage(MEMBER_NOT_FOUND.message()); } @@ -402,7 +411,8 @@ void setUp() { ); // expect - assertThatThrownBy(() -> postService.update(otherUser, postCreateResponse.postId(), postUpdateRequest, null)) + Long postId = postCreateResponse.postId(); + assertThatThrownBy(() -> postService.update(otherUser, postId, postUpdateRequest, null)) .isInstanceOf(PostException.class) .hasMessage(NOT_AUTHORIZED_TO_POST.message()); } @@ -413,9 +423,10 @@ void setUp() { PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); // expect - assertDoesNotThrow(() -> postService.delete(loginUser, postCreateResponse.postId())); + Long postId = postCreateResponse.postId(); + assertDoesNotThrow(() -> postService.delete(loginUser, postId)); - assertThatThrownBy(() -> postService.read(loginUser, postCreateResponse.postId())) + assertThatThrownBy(() -> postService.read(loginUser, postId)) .isInstanceOf(PostException.class) .hasMessage(POST_NOT_FOUND.message()); } @@ -435,7 +446,8 @@ void setUp() { LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); // expect - assertThatThrownBy(() -> postService.delete(wrongUser, postCreateResponse.postId())) + Long postId = postCreateResponse.postId(); + assertThatThrownBy(() -> postService.delete(wrongUser, postId)) .isInstanceOf(MemberException.class) .hasMessage(MEMBER_NOT_FOUND.message()); } @@ -446,7 +458,8 @@ void setUp() { PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); // expect - assertThatThrownBy(() -> postService.delete(otherUser, postCreateResponse.postId())) + Long postId = postCreateResponse.postId(); + assertThatThrownBy(() -> postService.delete(otherUser, postId)) .isInstanceOf(PostException.class) .hasMessage(NOT_AUTHORIZED_TO_POST.message()); } From e64d81aeb81f2f8046818c677c1a73075bcf2be5 Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 16:53:29 +0900 Subject: [PATCH 081/119] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/presentation/PostControllerTest.java | 59 ++++++++++++++++--- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index 4406e2a77..b0404ca6d 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -19,12 +19,12 @@ import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; +import dev.tripdraw.post.dto.PostSearchConditions; +import dev.tripdraw.post.dto.PostSearchPaging; import dev.tripdraw.post.dto.PostSearchRequest; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; import dev.tripdraw.post.dto.PostsSearchResponse; -import dev.tripdraw.post.dto.query.PostSearchConditions; -import dev.tripdraw.post.dto.query.PostSearchPaging; import dev.tripdraw.test.ControllerTest; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; @@ -593,7 +593,14 @@ public void setUp() { PostCreateResponse jejuSeptember17hourPostResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 9, 18, 17, 24)); PostCreateResponse seoulSeptember17hourPostResponse = createPost("서울특별시 송파구 잠실동", LocalDateTime.of(2023, 9, 18, 17, 24)); - PostSearchRequest request = new PostSearchRequest( + PostSearchRequest jejuRequest = new PostSearchRequest( + PostSearchConditions.builder() + .address("제주특별자치도 제주시 애월읍") + .build(), + new PostSearchPaging(null, 10) + ); + + PostSearchRequest jeju17hourRequest = new PostSearchRequest( PostSearchConditions.builder() .hours(List.of(17)) .address("제주특별자치도 제주시 애월읍") @@ -601,21 +608,57 @@ public void setUp() { new PostSearchPaging(null, 10) ); + PostSearchRequest hour17Request = new PostSearchRequest( + PostSearchConditions.builder() + .hours(List.of(17)) + .build(), + new PostSearchPaging(null, 10) + ); + // when - ExtractableResponse response = RestAssured.given().log().all() + ExtractableResponse jejuResponse = RestAssured.given().log().all() .contentType(APPLICATION_JSON_VALUE) .auth().preemptive().oauth2(huchuToken) - .body(request) + .body(jejuRequest) + .when().get("/posts") + .then().log().all() + .statusCode(OK.value()) + .extract(); + + ExtractableResponse jeju17hourResponse = RestAssured.given().log().all() + .contentType(APPLICATION_JSON_VALUE) + .auth().preemptive().oauth2(huchuToken) + .body(jeju17hourRequest) + .when().get("/posts") + .then().log().all() + .statusCode(OK.value()) + .extract(); + + ExtractableResponse hour17Response = RestAssured.given().log().all() + .contentType(APPLICATION_JSON_VALUE) + .auth().preemptive().oauth2(huchuToken) + .body(hour17Request) .when().get("/posts") .then().log().all() .statusCode(OK.value()) .extract(); // then - PostsSearchResponse postsSearchResponse = response.as(PostsSearchResponse.class); + PostsSearchResponse jejuPostsSearchResponse = jejuResponse.as(PostsSearchResponse.class); + PostsSearchResponse jeju17hourPostsSearchResponse = jeju17hourResponse.as(PostsSearchResponse.class); + PostsSearchResponse hour17PostsSearchResponse = hour17Response.as(PostsSearchResponse.class); + + assertThat(jejuPostsSearchResponse.posts().get(0).postId()).isEqualTo(jejuSeptember17hourPostResponse.postId()); + assertThat(jejuPostsSearchResponse.posts().get(1).postId()).isEqualTo(jejuAugust17hourPostResponse.postId()); + assertThat(jejuPostsSearchResponse.posts().get(2).postId()).isEqualTo(jejuJuly20hourPostResponse.postId()); + + + assertThat(jeju17hourPostsSearchResponse.posts().get(0).postId()).isEqualTo(jejuSeptember17hourPostResponse.postId()); + assertThat(jeju17hourPostsSearchResponse.posts().get(1).postId()).isEqualTo(jejuAugust17hourPostResponse.postId()); - assertThat(postsSearchResponse.posts().get(0).postId()).isEqualTo(jejuSeptember17hourPostResponse.postId()); - assertThat(postsSearchResponse.posts().get(1).postId()).isEqualTo(jejuAugust17hourPostResponse.postId()); + assertThat(hour17PostsSearchResponse.posts().get(0).postId()).isEqualTo(seoulSeptember17hourPostResponse.postId()); + assertThat(hour17PostsSearchResponse.posts().get(1).postId()).isEqualTo(jejuSeptember17hourPostResponse.postId()); + assertThat(hour17PostsSearchResponse.posts().get(2).postId()).isEqualTo(jejuAugust17hourPostResponse.postId()); } private PointResponse createPoint() { From be6bb5c68d3599d4903abd54b768443fb337fdab Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 16:55:15 +0900 Subject: [PATCH 082/119] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/draw/application/PostCreateEventHandler.java | 5 +++-- .../dev/tripdraw/post/application/PostQueryService.java | 4 ++++ .../java/dev/tripdraw/post/application/PostService.java | 6 +++--- .../tripdraw/post/application/query/PostQueryService.java | 5 ----- .../main/java/dev/tripdraw/post/domain/PostRepository.java | 6 ++---- .../tripdraw/post/dto/{query => }/PostSearchConditions.java | 2 +- .../dev/tripdraw/post/dto/{query => }/PostSearchPaging.java | 2 +- .../main/java/dev/tripdraw/post/dto/PostSearchRequest.java | 3 --- .../post/{domain => }/query/PostCustomRepository.java | 6 +++--- .../post/{domain => }/query/PostCustomRepositoryImpl.java | 6 +++--- .../application/PostCreateEventHandlerIntegrationTest.java | 4 ++-- .../draw/application/PostCreateEventHandlerTest.java | 2 +- .../java/dev/tripdraw/post/application/PostServiceTest.java | 4 ++-- .../tripdraw/post/domain/PostCustomRepositoryImplTest.java | 6 +++--- .../java/dev/tripdraw/post/domain/PostRepositoryTest.java | 4 ++-- 15 files changed, 30 insertions(+), 35 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/post/application/PostQueryService.java delete mode 100644 backend/src/main/java/dev/tripdraw/post/application/query/PostQueryService.java rename backend/src/main/java/dev/tripdraw/post/dto/{query => }/PostSearchConditions.java (89%) rename backend/src/main/java/dev/tripdraw/post/dto/{query => }/PostSearchPaging.java (65%) rename backend/src/main/java/dev/tripdraw/post/{domain => }/query/PostCustomRepository.java (57%) rename backend/src/main/java/dev/tripdraw/post/{domain => }/query/PostCustomRepositoryImpl.java (94%) diff --git a/backend/src/main/java/dev/tripdraw/draw/application/PostCreateEventHandler.java b/backend/src/main/java/dev/tripdraw/draw/application/PostCreateEventHandler.java index a7b7a4354..9b6f0e324 100644 --- a/backend/src/main/java/dev/tripdraw/draw/application/PostCreateEventHandler.java +++ b/backend/src/main/java/dev/tripdraw/draw/application/PostCreateEventHandler.java @@ -7,11 +7,12 @@ import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; -import java.util.List; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.transaction.event.TransactionalEventListener; +import java.util.List; + @Component public class PostCreateEventHandler { @@ -33,7 +34,7 @@ public PostCreateEventHandler( @TransactionalEventListener(phase = AFTER_COMMIT) public void handle(PostCreateEvent postCreateEvent) { Trip trip = tripRepository.getTripWithPoints(postCreateEvent.tripId()); - Post post = postRepository.getById(postCreateEvent.postId()); + Post post = postRepository.getByPostId(postCreateEvent.postId()); String imageUrl = routeImageGenerator.generate( trip.getLatitudes(), diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostQueryService.java b/backend/src/main/java/dev/tripdraw/post/application/PostQueryService.java new file mode 100644 index 000000000..a4cece05d --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/post/application/PostQueryService.java @@ -0,0 +1,4 @@ +package dev.tripdraw.post.application; + +public class PostQueryService { +} diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index 9ad215b9d..7abdeb527 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -91,7 +91,7 @@ public PostCreateResponse addAtExistingLocation( @Transactional(readOnly = true) public PostResponse read(LoginUser loginUser, Long postId) { - Post post = postRepository.getById(postId); + Post post = postRepository.getByPostId(postId); Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); return PostResponse.from(post); @@ -109,7 +109,7 @@ public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { } public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdateRequest, MultipartFile file) { - Post post = postRepository.getById(postId); + Post post = postRepository.getByPostId(postId); Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); Trip trip = tripRepository.getById(post.tripId()); @@ -121,7 +121,7 @@ public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdat } public void delete(LoginUser loginUser, Long postId) { - Post post = postRepository.getById(postId); + Post post = postRepository.getByPostId(postId); Member member = memberRepository.getById(loginUser.memberId()); post.validateAuthorization(member); postRepository.deleteById(postId); diff --git a/backend/src/main/java/dev/tripdraw/post/application/query/PostQueryService.java b/backend/src/main/java/dev/tripdraw/post/application/query/PostQueryService.java deleted file mode 100644 index eae0d1002..000000000 --- a/backend/src/main/java/dev/tripdraw/post/application/query/PostQueryService.java +++ /dev/null @@ -1,5 +0,0 @@ -package dev.tripdraw.post.application.query; - -public class PostQueryService { - -} diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java index 6be9f147d..bd4e7a8c4 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java @@ -2,9 +2,8 @@ import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; -import dev.tripdraw.post.domain.query.PostCustomRepository; import dev.tripdraw.post.exception.PostException; -import lombok.NonNull; +import dev.tripdraw.post.query.PostCustomRepository; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; @@ -13,8 +12,7 @@ public interface PostRepository extends JpaRepository, PostCustomRep List findAllByTripId(Long tripId); - @NonNull - default Post getById(@NonNull Long id) { + default Post getByPostId(Long id) { return findById(id) .orElseThrow(() -> new PostException(POST_NOT_FOUND)); } diff --git a/backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchConditions.java b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java similarity index 89% rename from backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchConditions.java rename to backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java index e36e95617..d68549c5c 100644 --- a/backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java @@ -1,4 +1,4 @@ -package dev.tripdraw.post.dto.query; +package dev.tripdraw.post.dto; import lombok.Builder; diff --git a/backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchPaging.java b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchPaging.java similarity index 65% rename from backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchPaging.java rename to backend/src/main/java/dev/tripdraw/post/dto/PostSearchPaging.java index cbd7375e1..80c1ec661 100644 --- a/backend/src/main/java/dev/tripdraw/post/dto/query/PostSearchPaging.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchPaging.java @@ -1,4 +1,4 @@ -package dev.tripdraw.post.dto.query; +package dev.tripdraw.post.dto; public record PostSearchPaging(Long lastViewedId, Integer limit) { } diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java index 501eaa6d8..5e8edab4c 100644 --- a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java @@ -1,7 +1,4 @@ package dev.tripdraw.post.dto; -import dev.tripdraw.post.dto.query.PostSearchConditions; -import dev.tripdraw.post.dto.query.PostSearchPaging; - public record PostSearchRequest(PostSearchConditions conditions, PostSearchPaging paging) { } diff --git a/backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepository.java b/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepository.java similarity index 57% rename from backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepository.java rename to backend/src/main/java/dev/tripdraw/post/query/PostCustomRepository.java index 9ba178832..8cf61e940 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepository.java +++ b/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepository.java @@ -1,8 +1,8 @@ -package dev.tripdraw.post.domain.query; +package dev.tripdraw.post.query; import dev.tripdraw.post.domain.Post; -import dev.tripdraw.post.dto.query.PostSearchConditions; -import dev.tripdraw.post.dto.query.PostSearchPaging; +import dev.tripdraw.post.dto.PostSearchConditions; +import dev.tripdraw.post.dto.PostSearchPaging; import java.util.List; diff --git a/backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java similarity index 94% rename from backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepositoryImpl.java rename to backend/src/main/java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java index 372b6dede..17ab504c6 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/query/PostCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java @@ -1,12 +1,12 @@ -package dev.tripdraw.post.domain.query; +package dev.tripdraw.post.query; import static dev.tripdraw.post.domain.QPost.post; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import dev.tripdraw.post.domain.Post; -import dev.tripdraw.post.dto.query.PostSearchConditions; -import dev.tripdraw.post.dto.query.PostSearchPaging; +import dev.tripdraw.post.dto.PostSearchConditions; +import dev.tripdraw.post.dto.PostSearchPaging; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; diff --git a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java index 6d8590913..6665d0ce7 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java @@ -22,7 +22,7 @@ @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @SpringBootTest -public class PostCreateEventHandlerIntegrationTest { +class PostCreateEventHandlerIntegrationTest { @MockBean private RouteImageGenerator routeImageGenerator; @@ -45,7 +45,7 @@ public class PostCreateEventHandlerIntegrationTest { PostCreateEvent postCreateEvent = new PostCreateEvent(1L, 1L); given(tripRepository.getTripWithPoints(postCreateEvent.tripId())) .willReturn(여행()); - given(postRepository.getById(postCreateEvent.postId())) + given(postRepository.getByPostId(postCreateEvent.postId())) .willReturn(감상()); // when diff --git a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java index 8d818d527..88e722a97 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java @@ -41,7 +41,7 @@ class PostCreateEventHandlerTest { PostCreateEvent postCreateEvent = new PostCreateEvent(1L, 1L); given(tripRepository.getTripWithPoints(postCreateEvent.tripId())) .willReturn(여행()); - given(postRepository.getById(postCreateEvent.postId())) + given(postRepository.getByPostId(postCreateEvent.postId())) .willReturn(감상()); // when diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index fdf919695..c5dce5cdd 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -25,13 +25,13 @@ import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; +import dev.tripdraw.post.dto.PostSearchConditions; +import dev.tripdraw.post.dto.PostSearchPaging; import dev.tripdraw.post.dto.PostSearchRequest; import dev.tripdraw.post.dto.PostSearchResponse; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; import dev.tripdraw.post.dto.PostsSearchResponse; -import dev.tripdraw.post.dto.query.PostSearchConditions; -import dev.tripdraw.post.dto.query.PostSearchPaging; import dev.tripdraw.post.exception.PostException; import dev.tripdraw.test.ServiceTest; import dev.tripdraw.trip.domain.Point; diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java index 74a340806..6722f9cd9 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java @@ -7,9 +7,9 @@ import dev.tripdraw.common.config.QueryDslConfig; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.post.domain.query.PostCustomRepositoryImpl; -import dev.tripdraw.post.dto.query.PostSearchConditions; -import dev.tripdraw.post.dto.query.PostSearchPaging; +import dev.tripdraw.post.dto.PostSearchConditions; +import dev.tripdraw.post.dto.PostSearchPaging; +import dev.tripdraw.post.query.PostCustomRepositoryImpl; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java index 6ec1d9680..28d3a3144 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java @@ -84,7 +84,7 @@ void setUp() { Post post = postRepository.save(new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, trip.id())); // when - Post foundPost = postRepository.getById(post.id()); + Post foundPost = postRepository.getByPostId(post.id()); // then assertThat(foundPost).isEqualTo(post); @@ -96,7 +96,7 @@ void setUp() { Long wrongId = Long.MIN_VALUE; // expect - assertThatThrownBy(() -> postRepository.getById(wrongId)) + assertThatThrownBy(() -> postRepository.getByPostId(wrongId)) .isInstanceOf(PostException.class) .hasMessage(POST_NOT_FOUND.message()); } From da46c969e76cccdace70ad076be12128547f22d1 Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 17:20:47 +0900 Subject: [PATCH 083/119] =?UTF-8?q?refactor:=20QueryService=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/application/PostQueryService.java | 21 +++++++++++++++++++ .../post/application/PostService.java | 3 ++- .../tripdraw/post/domain/PostRepository.java | 3 +-- .../domain/PostCustomRepositoryImplTest.java | 14 +++++++------ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostQueryService.java b/backend/src/main/java/dev/tripdraw/post/application/PostQueryService.java index a4cece05d..38d59e772 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostQueryService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostQueryService.java @@ -1,4 +1,25 @@ package dev.tripdraw.post.application; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.dto.PostSearchConditions; +import dev.tripdraw.post.dto.PostSearchPaging; +import dev.tripdraw.post.query.PostCustomRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service public class PostQueryService { + + private final PostCustomRepository postCustomRepository; + + public PostQueryService(PostCustomRepository postCustomRepository) { + this.postCustomRepository = postCustomRepository; + } + + @Transactional(readOnly = true) + public List findAllByConditions(PostSearchConditions conditions, PostSearchPaging paging) { + return postCustomRepository.findAllByConditions(conditions, paging); + } } diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index 7abdeb527..8277fad51 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -37,6 +37,7 @@ @Service public class PostService { + private final PostQueryService postQueryService; private final PostRepository postRepository; private final TripRepository tripRepository; private final PointRepository pointRepository; @@ -128,7 +129,7 @@ public void delete(LoginUser loginUser, Long postId) { } public PostsSearchResponse readAll(PostSearchRequest postSearchRequest) { - List posts = postRepository.findAllByConditions(postSearchRequest.conditions(), postSearchRequest.paging()); + List posts = postQueryService.findAllByConditions(postSearchRequest.conditions(), postSearchRequest.paging()); List postSearchResponses = posts.stream() .map(PostSearchResponse::from) diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java index bd4e7a8c4..f8c12c541 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java @@ -3,12 +3,11 @@ import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; import dev.tripdraw.post.exception.PostException; -import dev.tripdraw.post.query.PostCustomRepository; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; -public interface PostRepository extends JpaRepository, PostCustomRepository { +public interface PostRepository extends JpaRepository { List findAllByTripId(Long tripId); diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java index 6722f9cd9..62e200f1f 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java @@ -9,16 +9,15 @@ import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.dto.PostSearchConditions; import dev.tripdraw.post.dto.PostSearchPaging; -import dev.tripdraw.post.query.PostCustomRepositoryImpl; +import dev.tripdraw.post.query.PostCustomRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; -import dev.tripdraw.trip.domain.TripName; import dev.tripdraw.trip.domain.TripRepository; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; import java.time.LocalDateTime; @@ -26,12 +25,12 @@ @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -@DataJpaTest +@SpringBootTest @Import({JpaConfig.class, QueryDslConfig.class}) class PostCustomRepositoryImplTest { @Autowired - private PostCustomRepositoryImpl postCustomRepository; + private PostCustomRepository postCustomRepository; @Autowired private TripRepository tripRepository; @@ -46,7 +45,8 @@ class PostCustomRepositoryImplTest { void 조건에_해당하는_감상을_조회한다() { // given Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - Trip trip = tripRepository.save(new Trip(TripName.from("통후추의 여행"), member)); + Trip trip = Trip.from(member); + Point firstPoint = new Point(3.14, 5.25, LocalDateTime.of(2023, 5, 1, 17, 30)); Point secondPoint = new Point(3.14, 5.25, LocalDateTime.of(2023, 5, 3, 18, 30)); Point thirdPoint = new Point(3.14, 5.25, LocalDateTime.of(2023, 7, 1, 18, 30)); @@ -55,6 +55,8 @@ class PostCustomRepositoryImplTest { trip.add(secondPoint); trip.add(thirdPoint); + tripRepository.save(trip); + Post firstPost = new Post("제목", firstPoint, "위치", "오늘은 날씨가 좋네요.", member, trip.id()); Post secondPost = new Post("제목", secondPoint, "위치", "오늘은 날씨가 좋네요.", member, trip.id()); Post thirdPost = new Post("제목", thirdPoint, "위치", "오늘은 날씨가 좋네요.", member, trip.id()); From 2a8219d834586ef9cdcd850bab67eb7630b5cceb Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 17:45:02 +0900 Subject: [PATCH 084/119] =?UTF-8?q?[build]=20gradle.build=20=EC=9E=AC?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/build.gradle b/backend/build.gradle index b178d3561..86a5c24bb 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -86,7 +86,7 @@ sourceSets { } tasks.withType(JavaCompile).configureEach { - options.compilerArgs += ["-s", querydslDir] + options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir) } clean.doLast { From 68cee551c05254220a6afadaf12bdfce70c28a1e Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 17:46:02 +0900 Subject: [PATCH 085/119] =?UTF-8?q?[test]=20TripController=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=B6=84=EB=A6=AC=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acceptance/TripSearchAcceptanceTest.java | 523 ++++++++++++++++++ .../trip/presentation/TripControllerTest.java | 487 ---------------- 2 files changed, 523 insertions(+), 487 deletions(-) create mode 100644 backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java diff --git a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java new file mode 100644 index 000000000..9d77bd2b9 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java @@ -0,0 +1,523 @@ +package dev.tripdraw.trip.acceptance; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.TestFixture.서울_2022_1_2_일; +import static dev.tripdraw.test.fixture.TestFixture.서울_2023_1_1_일; +import static dev.tripdraw.test.fixture.TestFixture.양양_2021_3_2_화; +import static dev.tripdraw.test.fixture.TestFixture.제주_2023_1_1_일; +import static dev.tripdraw.test.fixture.TestFixture.제주_2023_2_1_수; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.addressTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.daysOfWeekTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.emptyTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.monthsTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.yearsTripSearchConditions; +import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; +import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.UNAUTHORIZED; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + +import dev.tripdraw.auth.application.JwtTokenProvider; +import dev.tripdraw.common.dto.SearchPaging; +import dev.tripdraw.draw.application.RouteImageGenerator; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.test.ControllerTest; +import dev.tripdraw.trip.dto.TripSearchConditions; +import dev.tripdraw.trip.dto.TripSearchRequest; +import dev.tripdraw.trip.dto.TripSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponse; +import io.restassured.RestAssured; +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +public class TripSearchAcceptanceTest extends ControllerTest { + + private static final String WRONG_TOKEN = "wrong.long.token"; + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private JwtTokenProvider jwtTokenProvider; + + @MockBean + private RouteImageGenerator routeImageGenerator; + + private String huchuToken; + private Long lastViewedId; + private Long 후추_양양_2021_3_2_화; + private Long 후추_서울_2022_1_2_일; + private Long 리오_제주_2023_1_1_일; + private Long 리오_서울_2023_1_1_일; + private Long 허브_제주_2023_2_1_수; + + @BeforeEach + public void setUp() { + super.setUp(); + + Member huchu = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + Member leo = memberRepository.save(new Member("리오", "kakaoId", KAKAO)); + Member herb = memberRepository.save(new Member("허브", "kakaoId", KAKAO)); + + huchuToken = jwtTokenProvider.generateAccessToken(huchu.id().toString()); + String leoToken = jwtTokenProvider.generateAccessToken(leo.id().toString()); + String herbToken = jwtTokenProvider.generateAccessToken(herb.id().toString()); + + 후추_양양_2021_3_2_화 = createTripAndGetResponse(huchuToken).tripId(); + createPostAtCurrentPoint(양양_2021_3_2_화(후추_양양_2021_3_2_화), huchuToken); + + 후추_서울_2022_1_2_일 = createTripAndGetResponse(huchuToken).tripId(); + createPostAtCurrentPoint(서울_2022_1_2_일(후추_서울_2022_1_2_일), huchuToken); + + 리오_제주_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); + createPostAtCurrentPoint(제주_2023_1_1_일(리오_제주_2023_1_1_일), leoToken); + + 리오_서울_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); + createPostAtCurrentPoint(서울_2023_1_1_일(리오_서울_2023_1_1_일), leoToken); + + 허브_제주_2023_2_1_수 = createTripAndGetResponse(herbToken).tripId(); + createPostAtCurrentPoint(제주_2023_2_1_수(허브_제주_2023_2_1_수), herbToken); + + lastViewedId = 허브_제주_2023_2_1_수; + } + + + @Nested + class 감상이_있는_모든_여행을_페이지네이션으로_조회할_때 { + + @Nested + class 개수_제한을 { + + @ParameterizedTest + @CsvSource({"1, 1", "4, 4"}) + void 조회할_수_있는_여행_수_미만으로_입력하면_해당_개수만큼_여행이_조회된다(int limit, int expectedSize) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); + }); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + void 조회할_수_있는_여행_수_미만으로_입력하면_다음_페이지가_존재한다(int limit) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.hasNextPage()).isTrue(); + }); + } + + @ParameterizedTest + @CsvSource({"5, 5", "6, 5"}) + void 조회할_수_있는_여행_수_이상으로_입력하면_모든_여행이_조회된다(int limit, int expectedSize) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); + }); + } + + @ParameterizedTest + @ValueSource(ints = {5, 6}) + void 조회할_수_있는_여행_수_이상으로_입력하면_다음_페이지가_존재하지_않는다(int limit) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.hasNextPage()).isFalse(); + }); + } + } + + @Nested + class 마지막으로_조회한_여행_ID를 { + + private static final int LIMIT = 10; + + @Test + void 입력하지_않으면_최신_여행부터_내림차순으로_조회된다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, LIMIT) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 입력하면_해당_여행_이하로_최신_여행을_내림차순으로_조회된다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(lastViewedId, LIMIT) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + } + } + + @Nested + class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { + + private final SearchPaging nullLastViewedIdAnd10Limit = new SearchPaging(null, 10); + + @Test + void 조건없이_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 연도를_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + yearsTripSearchConditions(Set.of(2023)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일 + ); + }); + } + + @Test + void 월을_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + monthsTripSearchConditions(Set.of(1, 2)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일 + ); + }); + } + + @Test + void 요일을_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + daysOfWeekTripSearchConditions(Set.of(1, 3)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 주소를_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + addressTripSearchConditions("seoul_songpa"), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 후추_서울_2022_1_2_일 + ); + }); + } + + @Test + void 여러_조건으로_조회할_수_있다() { + // given + var multiSearchConditions = new TripSearchConditions( + Set.of(2023, 2021), + Set.of(), + Set.of(1), + Set.of(), + Set.of(), + "seoul" + ); + var tripSearchRequest = new TripSearchRequest( + multiSearchConditions, + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일 + ); + }); + } + + @Test + void 조건이_유효하지_않을_경우_예외를_발생시킨다() { + // given + var tripSearchRequest = new TripSearchRequest( + monthsTripSearchConditions(Set.of(Integer.MAX_VALUE)), + nullLastViewedIdAnd10Limit + ); + + // expect + RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .statusCode(BAD_REQUEST.value()); + } + + @Test + void 인증에_실패할_경우_예외를_발생시킨다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + nullLastViewedIdAnd10Limit + ); + + // expect + RestAssured.given().log().all() + .auth().preemptive().oauth2(WRONG_TOKEN) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .statusCode(UNAUTHORIZED.value()); + } + } + + private List searchedTripIds(TripsSearchResponse tripsSearchResponse) { + return tripsSearchResponse.trips().stream() + .map(TripSearchResponse::tripId) + .toList(); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index 7c159efcf..4fe6899b9 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -3,24 +3,12 @@ import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.test.fixture.TestFixture.pointCreateRequest; import static dev.tripdraw.test.fixture.TestFixture.tripUpdateRequest; -import static dev.tripdraw.test.fixture.TestFixture.서울_2022_1_2_일; -import static dev.tripdraw.test.fixture.TestFixture.서울_2023_1_1_일; -import static dev.tripdraw.test.fixture.TestFixture.양양_2021_3_2_화; -import static dev.tripdraw.test.fixture.TestFixture.제주_2023_1_1_일; -import static dev.tripdraw.test.fixture.TestFixture.제주_2023_2_1_수; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.addressTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.daysOfWeekTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.emptyTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.monthsTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.yearsTripSearchConditions; -import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; import static dev.tripdraw.test.step.TripStep.addPointAndGetResponse; import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; import static dev.tripdraw.test.step.TripStep.searchTripAndGetResponse; import static dev.tripdraw.test.step.TripStep.updateTrip; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; @@ -28,7 +16,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import dev.tripdraw.auth.application.JwtTokenProvider; -import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; @@ -38,27 +25,18 @@ import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; -import dev.tripdraw.trip.dto.TripSearchConditions; -import dev.tripdraw.trip.dto.TripSearchRequest; -import dev.tripdraw.trip.dto.TripSearchResponse; import dev.tripdraw.trip.dto.TripSearchResponseOfMember; import dev.tripdraw.trip.dto.TripUpdateRequest; -import dev.tripdraw.trip.dto.TripsSearchResponse; import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import java.time.LocalDateTime; import java.util.List; -import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -78,20 +56,13 @@ class TripControllerTest extends ControllerTest { private RouteImageGenerator routeImageGenerator; private String huchuToken; - private String leoToken; - private String herbToken; @BeforeEach public void setUp() { super.setUp(); Member huchu = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - Member leo = memberRepository.save(new Member("리오", "kakaoId", KAKAO)); - Member herb = memberRepository.save(new Member("허브", "kakaoId", KAKAO)); - huchuToken = jwtTokenProvider.generateAccessToken(huchu.id().toString()); - leoToken = jwtTokenProvider.generateAccessToken(leo.id().toString()); - herbToken = jwtTokenProvider.generateAccessToken(herb.id().toString()); } @Test @@ -343,462 +314,4 @@ public void setUp() { .then().log().all() .statusCode(UNAUTHORIZED.value()); } - - @Nested - class 여러_회원이_여행에_감상을_남긴_후 { - - private Long lastViewedId; - private Long 후추_양양_2021_3_2_화; - private Long 후추_서울_2022_1_2_일; - private Long 리오_제주_2023_1_1_일; - private Long 리오_서울_2023_1_1_일; - private Long 허브_제주_2023_2_1_수; - - @BeforeEach - void setUp() { - 후추_양양_2021_3_2_화 = createTripAndGetResponse(huchuToken).tripId(); - createPostAtCurrentPoint(양양_2021_3_2_화(후추_양양_2021_3_2_화), huchuToken); - - 후추_서울_2022_1_2_일 = createTripAndGetResponse(huchuToken).tripId(); - createPostAtCurrentPoint(서울_2022_1_2_일(후추_서울_2022_1_2_일), huchuToken); - - 리오_제주_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); - createPostAtCurrentPoint(제주_2023_1_1_일(리오_제주_2023_1_1_일), leoToken); - - 리오_서울_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); - createPostAtCurrentPoint(서울_2023_1_1_일(리오_서울_2023_1_1_일), leoToken); - - 허브_제주_2023_2_1_수 = createTripAndGetResponse(herbToken).tripId(); - createPostAtCurrentPoint(제주_2023_2_1_수(허브_제주_2023_2_1_수), herbToken); - - lastViewedId = 허브_제주_2023_2_1_수; - } - - @Nested - class 감상이_있는_모든_여행을_페이지네이션으로_조회할_때 { - - @Nested - class 조회할_수_있는_여행_수_미만으로_개수_제한을_입력하면 { - - @ParameterizedTest - @CsvSource({"1, 1", "4, 4"}) - void 해당_개수만큼_여행이_조회된다(int limit, int expectedSize) { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(null, limit) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); - }); - } - - @ParameterizedTest - @ValueSource(ints = {1, 4}) - void 다음_페이지가_존재한다(int limit) { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(null, limit) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(tripsSearchResponse.hasNextPage()).isTrue(); - }); - } - } - - @Nested - class 조회할_수_있는_여행_수_이상으로_개수_제한을_입력하면 { - - @ParameterizedTest - @CsvSource({"5, 5", "6, 5"}) - void 모든_여행이_조회된다(int limit, int expectedSize) { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(null, limit) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); - }); - } - - @ParameterizedTest - @ValueSource(ints = {5, 6}) - void 다음_페이지가_존재하지_않는다(int limit) { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(null, limit) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(tripsSearchResponse.hasNextPage()).isFalse(); - }); - } - } - - @Nested - class 마지막으로_조회한_여행_ID를 { - - private static final int LIMIT = 10; - - @Test - void 입력하지_않으면_최신_여행부터_내림차순으로_조회된다() { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(null, LIMIT) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 허브_제주_2023_2_1_수, - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일, - 후추_서울_2022_1_2_일, - 후추_양양_2021_3_2_화 - ); - }); - } - - @Test - void 입력하면_해당_여행_이하로_최신_여행을_내림차순으로_조회된다() { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(lastViewedId, LIMIT) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일, - 후추_서울_2022_1_2_일, - 후추_양양_2021_3_2_화 - ); - }); - } - - } - } - - private List searchedTripIds(TripsSearchResponse tripsSearchResponse) { - return tripsSearchResponse.trips().stream() - .map(TripSearchResponse::tripId) - .toList(); - } - - @Nested - class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { - - private final SearchPaging nullLastViewedIdAnd10Limit = new SearchPaging(null, 10); - - @Test - void 조건없이_조회할_수_있다() { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 허브_제주_2023_2_1_수, - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일, - 후추_서울_2022_1_2_일, - 후추_양양_2021_3_2_화 - ); - }); - } - - @Test - void 연도를_조건으로_조회할_수_있다() { - // given - var tripSearchRequest = new TripSearchRequest( - yearsTripSearchConditions(Set.of(2023)), - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 허브_제주_2023_2_1_수, - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일 - ); - }); - } - - @Test - void 월을_조건으로_조회할_수_있다() { - // given - var tripSearchRequest = new TripSearchRequest( - monthsTripSearchConditions(Set.of(1, 2)), - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 허브_제주_2023_2_1_수, - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일, - 후추_서울_2022_1_2_일 - ); - }); - } - - @Test - void 요일을_조건으로_조회할_수_있다() { - // given - var tripSearchRequest = new TripSearchRequest( - daysOfWeekTripSearchConditions(Set.of(1, 3)), - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일, - 후추_서울_2022_1_2_일, - 후추_양양_2021_3_2_화 - ); - }); - } - - @Test - void 주소를_조건으로_조회할_수_있다() { - // given - var tripSearchRequest = new TripSearchRequest( - addressTripSearchConditions("seoul_songpa"), - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 리오_서울_2023_1_1_일, - 후추_서울_2022_1_2_일 - ); - }); - } - - @Test - void 여러_조건으로_조회할_수_있다() { - // given - var multiSearchConditions = new TripSearchConditions( - Set.of(2023, 2021), - Set.of(), - Set.of(1), - Set.of(), - Set.of(), - "seoul" - ); - var tripSearchRequest = new TripSearchRequest( - multiSearchConditions, - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 리오_서울_2023_1_1_일 - ); - }); - } - - @Test - void 조건이_유효하지_않을_경우_예외를_발생시킨다() { - // given - var tripSearchRequest = new TripSearchRequest( - monthsTripSearchConditions(Set.of(Integer.MAX_VALUE)), - nullLastViewedIdAnd10Limit - ); - - // expect - RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .statusCode(BAD_REQUEST.value()); - } - - @Test - void 인증에_실패할_경우_예외를_발생시킨다() { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - nullLastViewedIdAnd10Limit - ); - - // expect - RestAssured.given().log().all() - .auth().preemptive().oauth2(WRONG_TOKEN) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .statusCode(UNAUTHORIZED.value()); - } - } - } } From 9b932d9137a9002156791af302c7ed46c2ff3689 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 17:46:17 +0900 Subject: [PATCH 086/119] =?UTF-8?q?[chore]=20.gitignore=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index be58d40a8..e7a649a6c 100644 --- a/.gitignore +++ b/.gitignore @@ -192,3 +192,4 @@ fabric.properties !/gradle/wrapper/gradle-wrapper.jar # End of https://www.toptal.com/developers/gitignore/api/android,androidstudio,kotlin +/backend/src/main/generated/ From 5cdaf4738c7ce546039d0d2ec30ca8cdede949e2 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 17:46:44 +0900 Subject: [PATCH 087/119] =?UTF-8?q?[refactor]=20TripCustomRepositoryImpl?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/domain/TripCustomRepositoryImpl.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java index 7778a9ef9..9ddb28eb9 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java @@ -7,10 +7,12 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import dev.tripdraw.common.domain.Paging; +import io.micrometer.common.util.StringUtils; import java.util.List; import java.util.Set; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; +import org.springframework.util.CollectionUtils; @RequiredArgsConstructor @Repository @@ -32,7 +34,7 @@ public List findAllByConditions(SearchConditions searchConditions, Paging addressLike(searchConditions.address()) ) .orderBy(trip.id.desc()) - .limit(paging.limit() + 1) + .limit(paging.limit().longValue() + 1L) .fetch(); } @@ -44,28 +46,28 @@ private BooleanExpression tripIdLt(Long lastViewedId) { } private BooleanExpression yearIn(Set years) { - if (years.isEmpty()) { + if (CollectionUtils.isEmpty(years)) { return null; } return point.recordedAt.year().in(years); } private BooleanExpression monthIn(Set months) { - if (months.isEmpty()) { + if (CollectionUtils.isEmpty(months)) { return null; } return point.recordedAt.month().in(months); } private BooleanExpression dayOfWeekIn(Set daysOfWeek) { - if (daysOfWeek.isEmpty()) { + if (CollectionUtils.isEmpty(daysOfWeek)) { return null; } return point.recordedAt.dayOfWeek().in(daysOfWeek); } private BooleanExpression addressLike(String address) { - if (address.isEmpty()) { + if (StringUtils.isBlank(address)) { return null; } return post.address.like(address + "%"); From 6a05b94a73329144a0304751487b635b3a148739 Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 17:48:06 +0900 Subject: [PATCH 088/119] =?UTF-8?q?refactor:=20List=20=EC=9E=90=EB=A3=8C?= =?UTF-8?q?=ED=98=95=20Set=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripdraw/post/dto/PostSearchConditions.java | 14 +++++++------- .../post/query/PostCustomRepositoryImpl.java | 9 +++++---- .../tripdraw/post/application/PostServiceTest.java | 3 ++- .../post/presentation/PostControllerTest.java | 6 +++--- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java index d68549c5c..b9917e369 100644 --- a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchConditions.java @@ -2,16 +2,16 @@ import lombok.Builder; -import java.util.List; +import java.util.Set; @Builder public record PostSearchConditions( - List years, - List months, - List daysOfWeek, - List hours, - List ageRanges, - List genders, + Set years, + Set months, + Set daysOfWeek, + Set hours, + Set ageRanges, + Set genders, String address ) { } diff --git a/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java index 17ab504c6..9d713bc80 100644 --- a/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Set; @RequiredArgsConstructor @Repository @@ -43,7 +44,7 @@ private BooleanExpression postIdLt(Long lastViewedId) { return post.id.lt(lastViewedId); } - private BooleanExpression yearIn(List years) { + private BooleanExpression yearIn(Set years) { if (years == null || years.isEmpty()) { return null; } @@ -51,7 +52,7 @@ private BooleanExpression yearIn(List years) { return post.point.recordedAt.year().in(years); } - private BooleanExpression monthIn(List months) { + private BooleanExpression monthIn(Set months) { if (months == null || months.isEmpty()) { return null; } @@ -59,7 +60,7 @@ private BooleanExpression monthIn(List months) { return post.point.recordedAt.month().in(months); } - private BooleanExpression dayOfWeekIn(List daysOfWeek) { + private BooleanExpression dayOfWeekIn(Set daysOfWeek) { if (daysOfWeek == null || daysOfWeek.isEmpty()) { return null; } @@ -67,7 +68,7 @@ private BooleanExpression dayOfWeekIn(List daysOfWeek) { return post.point.recordedAt.dayOfWeek().in(daysOfWeek); } - private BooleanExpression hourIn(List hours) { + private BooleanExpression hourIn(Set hours) { if (hours == null || hours.isEmpty()) { return null; } diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index c5dce5cdd..740e7e5e8 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -49,6 +49,7 @@ import java.time.LocalDateTime; import java.util.List; +import java.util.Set; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -333,7 +334,7 @@ void setUp() { PostSearchRequest postSearchRequestJuly = new PostSearchRequest( PostSearchConditions.builder() - .months(List.of(7)) + .months(Set.of(7)) .build(), new PostSearchPaging(null, 10) ); diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index b0404ca6d..115953362 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -42,7 +42,7 @@ import org.springframework.beans.factory.annotation.Autowired; import java.time.LocalDateTime; -import java.util.List; +import java.util.Set; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -602,7 +602,7 @@ public void setUp() { PostSearchRequest jeju17hourRequest = new PostSearchRequest( PostSearchConditions.builder() - .hours(List.of(17)) + .hours(Set.of(17)) .address("제주특별자치도 제주시 애월읍") .build(), new PostSearchPaging(null, 10) @@ -610,7 +610,7 @@ public void setUp() { PostSearchRequest hour17Request = new PostSearchRequest( PostSearchConditions.builder() - .hours(List.of(17)) + .hours(Set.of(17)) .build(), new PostSearchPaging(null, 10) ); From c287c5fd4ea81d11f7090e7826cf06294f77771f Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 17:48:46 +0900 Subject: [PATCH 089/119] =?UTF-8?q?fix:=20SpringBootTest=EC=97=90=20Transa?= =?UTF-8?q?ction=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/domain/PostCustomRepositoryImplTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java index 62e200f1f..2e7533668 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java @@ -19,12 +19,15 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.List; +import java.util.Set; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@Transactional @SpringBootTest @Import({JpaConfig.class, QueryDslConfig.class}) class PostCustomRepositoryImplTest { @@ -66,11 +69,11 @@ class PostCustomRepositoryImplTest { postRepository.save(thirdPost); PostSearchConditions firstConditions = PostSearchConditions.builder() - .months(List.of(5)) + .months(Set.of(5)) .build(); PostSearchConditions secondConditions = PostSearchConditions.builder() - .hours(List.of(18)) + .hours(Set.of(18)) .build(); PostSearchPaging paging = new PostSearchPaging(null, 10); @@ -84,3 +87,4 @@ class PostCustomRepositoryImplTest { assertThat(secondPosts.stream().map(Post::id).toList()).containsExactly(thirdPost.id(), secondPost.id()); } } + From 2e2802790d88d25beabf9a791a08baa3005379fa Mon Sep 17 00:00:00 2001 From: ReO Date: Mon, 18 Sep 2023 17:55:39 +0900 Subject: [PATCH 090/119] =?UTF-8?q?fix:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/post/presentation/PostControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index 115953362..0fcda5155 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -468,7 +468,7 @@ public void setUp() { @Test void 감상을_수정한다() { // given - PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 17, 20, 24)); + PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); PostUpdateRequest postUpdateRequest = new PostUpdateRequest( "우도의 땅콩 아이스크림", From 73d5b112a935ac9f8e7747a98f0ecb8ef4cd7234 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 19:58:00 +0900 Subject: [PATCH 091/119] =?UTF-8?q?[refactor]=20TripQueryService=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=9D=98=EC=A1=B4=20=EB=B0=A9?= =?UTF-8?q?=ED=96=A5=20=EC=88=98=EC=A0=95=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/common/dto/SearchPaging.java | 9 - .../trip/application/TripQueryService.java | 27 + .../trip/application/TripService.java | 21 +- .../trip/domain/TripCustomRepository.java | 9 - .../tripdraw/trip/domain/TripRepository.java | 2 +- .../trip/dto/TripSearchConditions.java | 15 +- .../tripdraw/trip/dto/TripSearchPaging.java | 9 + .../tripdraw/trip/dto/TripSearchRequest.java | 13 +- .../trip/presentation/TripController.java | 6 +- .../trip/query/TripCustomRepository.java | 9 + .../TripCustomRepositoryImpl.java | 18 +- .../query/TripPaging.java} | 8 +- .../TripQueryConditions.java} | 6 +- .../{PagingTest.java => TripPagingTest.java} | 13 +- ...e.java => TripQueryConditionsFixture.java} | 32 +- .../acceptance/TripSearchAcceptanceTest.java | 18 +- .../application/TripQueryServiceTest.java | 59 ++ .../trip/application/TripServiceTest.java | 8 +- ...Test.java => TripQueryConditionsTest.java} | 13 +- .../trip/domain/TripRepositoryTest.java | 782 +++++++++--------- .../trip/presentation/TripControllerTest.java | 2 +- .../query/TripCustomRepositoryImplTest.java | 454 ++++++++++ 22 files changed, 1033 insertions(+), 500 deletions(-) delete mode 100644 backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java delete mode 100644 backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/dto/TripSearchPaging.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java rename backend/src/main/java/dev/tripdraw/trip/{domain => query}/TripCustomRepositoryImpl.java (77%) rename backend/src/main/java/dev/tripdraw/{common/domain/Paging.java => trip/query/TripPaging.java} (60%) rename backend/src/main/java/dev/tripdraw/trip/{domain/SearchConditions.java => query/TripQueryConditions.java} (95%) rename backend/src/test/java/dev/tripdraw/common/domain/{PagingTest.java => TripPagingTest.java} (74%) rename backend/src/test/java/dev/tripdraw/test/fixture/{SearchConditionsFixture.java => TripQueryConditionsFixture.java} (56%) create mode 100644 backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java rename backend/src/test/java/dev/tripdraw/trip/domain/{SearchConditionsTest.java => TripQueryConditionsTest.java} (80%) create mode 100644 backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java diff --git a/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java b/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java deleted file mode 100644 index 989ce5da8..000000000 --- a/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.tripdraw.common.dto; - -import dev.tripdraw.common.domain.Paging; - -public record SearchPaging(Long lastViewedId, Integer limit) { - public Paging toPaging() { - return new Paging(lastViewedId, limit); - } -} diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java new file mode 100644 index 000000000..d572e45df --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java @@ -0,0 +1,27 @@ +package dev.tripdraw.trip.application; + +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.query.TripCustomRepository; +import dev.tripdraw.trip.query.TripPaging; +import dev.tripdraw.trip.query.TripQueryConditions; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Transactional +@Service +public class TripQueryService { + + private final TripCustomRepository tripCustomRepository; + + @Transactional(readOnly = true) + public List readAllByQueryConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging) { + return tripCustomRepository.findAllByConditions( + tripQueryConditions, + tripPaging + ); + } +} + diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index f9a79b3d7..e2a924725 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -1,12 +1,10 @@ package dev.tripdraw.trip.application; import dev.tripdraw.common.auth.LoginUser; -import dev.tripdraw.common.domain.Paging; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.PointRepository; -import dev.tripdraw.trip.domain.SearchConditions; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; @@ -19,6 +17,8 @@ import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; +import dev.tripdraw.trip.query.TripPaging; +import dev.tripdraw.trip.query.TripQueryConditions; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; @@ -30,9 +30,11 @@ @Service public class TripService { + private static final int FIRST_INDEX = 0; private final TripRepository tripRepository; private final PointRepository pointRepository; private final MemberRepository memberRepository; + private final TripQueryService tripQueryService; private final ApplicationEventPublisher applicationEventPublisher; public TripCreateResponse create(LoginUser loginUser) { @@ -79,17 +81,14 @@ public TripsSearchResponseOfMember readAllTripsOf(LoginUser loginUser) { } @Transactional(readOnly = true) - public TripsSearchResponse readAllTrips(TripSearchRequest tripSearchRequest) { - SearchConditions searchConditions = tripSearchRequest.condition().toSearchConditions(); - Paging paging = tripSearchRequest.paging().toPaging(); + public TripsSearchResponse readAll(TripSearchRequest tripSearchRequest) { + TripQueryConditions tripQueryConditions = tripSearchRequest.toTripQueryConditions(); + TripPaging tripPaging = tripSearchRequest.toTripPaging(); - List trips = tripRepository.findAllByConditions( - searchConditions, - paging - ); + List trips = tripQueryService.readAllByQueryConditions(tripQueryConditions, tripPaging); - if (paging.hasNextPage(trips.size())) { - return TripsSearchResponse.of(trips.subList(0, paging.limit()), true); + if (tripPaging.hasNextPage(trips.size())) { + return TripsSearchResponse.of(trips.subList(FIRST_INDEX, tripPaging.limit()), true); } return TripsSearchResponse.of(trips, false); } diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java deleted file mode 100644 index 4f99ea52d..000000000 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.tripdraw.trip.domain; - -import dev.tripdraw.common.domain.Paging; -import java.util.List; - -public interface TripCustomRepository { - - List findAllByConditions(SearchConditions searchConditions, Paging paging); -} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java index 5dab56ecd..edb45c393 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java @@ -9,7 +9,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -public interface TripRepository extends JpaRepository, TripCustomRepository { +public interface TripRepository extends JpaRepository { List findAllByMemberId(Long memberId); diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java index 2bce1ca89..df81efeeb 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java @@ -1,8 +1,10 @@ package dev.tripdraw.trip.dto; -import dev.tripdraw.trip.domain.SearchConditions; +import dev.tripdraw.trip.query.TripQueryConditions; import java.util.Set; +import lombok.Builder; +@Builder public record TripSearchConditions( Set years, Set months, @@ -12,14 +14,7 @@ public record TripSearchConditions( String address ) { - public SearchConditions toSearchConditions() { - return new SearchConditions( - years, - months, - daysOfWeek, - ageRanges, - genders, - address - ); + public TripQueryConditions toTripQueryConditions() { + return new TripQueryConditions(years(), months(), daysOfWeek(), ageRanges(), genders(), address()); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchPaging.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchPaging.java new file mode 100644 index 000000000..da83f1bdd --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchPaging.java @@ -0,0 +1,9 @@ +package dev.tripdraw.trip.dto; + +import dev.tripdraw.trip.query.TripPaging; + +public record TripSearchPaging(Long lastViewedId, Integer limit) { + public TripPaging toTripPaging() { + return new TripPaging(lastViewedId, limit); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java index 842ee87e1..0289a16c3 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java @@ -1,9 +1,18 @@ package dev.tripdraw.trip.dto; -import dev.tripdraw.common.dto.SearchPaging; +import dev.tripdraw.trip.query.TripPaging; +import dev.tripdraw.trip.query.TripQueryConditions; public record TripSearchRequest( TripSearchConditions condition, - SearchPaging paging + TripSearchPaging paging ) { + + public TripQueryConditions toTripQueryConditions() { + return condition.toTripQueryConditions(); + } + + public TripPaging toTripPaging() { + return paging.toTripPaging(); + } } diff --git a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java index 08a9f8f7d..7492f0b09 100644 --- a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java +++ b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java @@ -109,7 +109,7 @@ public ResponseEntity deletePoint( responseCode = "200", description = "나의 여행 전체 조회 성공." ) - @GetMapping("/trips/mine") + @GetMapping("/trips/me") public ResponseEntity readAllOf(@Auth LoginUser loginUser) { TripsSearchResponseOfMember response = tripService.readAllTripsOf(loginUser); return ResponseEntity.ok(response); @@ -125,8 +125,8 @@ public ResponseEntity readAll( @Auth LoginUser loginUser, @RequestBody TripSearchRequest tripSearchRequest ) { - TripsSearchResponse tripsSearchResponse = tripService.readAllTrips(tripSearchRequest); - return ResponseEntity.ok(tripsSearchResponse); + TripsSearchResponse response = tripService.readAll(tripSearchRequest); + return ResponseEntity.ok(response); } @Operation(summary = "여행 이름 수정 및 종료 API", description = "여행 이름을 수정하고, 여행을 종료합니다.") diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java new file mode 100644 index 000000000..9d8ace9f6 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java @@ -0,0 +1,9 @@ +package dev.tripdraw.trip.query; + +import dev.tripdraw.trip.domain.Trip; +import java.util.List; + +public interface TripCustomRepository { + + List findAllByConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging); +} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java similarity index 77% rename from backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java rename to backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java index 9ddb28eb9..86066939f 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java @@ -1,4 +1,4 @@ -package dev.tripdraw.trip.domain; +package dev.tripdraw.trip.query; import static dev.tripdraw.post.domain.QPost.post; import static dev.tripdraw.trip.domain.QPoint.point; @@ -6,7 +6,7 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; -import dev.tripdraw.common.domain.Paging; +import dev.tripdraw.trip.domain.Trip; import io.micrometer.common.util.StringUtils; import java.util.List; import java.util.Set; @@ -21,20 +21,20 @@ public class TripCustomRepositoryImpl implements TripCustomRepository { private final JPAQueryFactory query; @Override - public List findAllByConditions(SearchConditions searchConditions, Paging paging) { + public List findAllByConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging) { return query .selectFrom(trip) .join(post).on(trip.id.eq(post.tripId)) .join(point).on(post.point.id.eq(point.id)) .where( - tripIdLt(paging.lastViewedId()), - yearIn(searchConditions.years()), - monthIn(searchConditions.months()), - dayOfWeekIn(searchConditions.daysOfWeek()), - addressLike(searchConditions.address()) + tripIdLt(tripPaging.lastViewedId()), + yearIn(tripQueryConditions.years()), + monthIn(tripQueryConditions.months()), + dayOfWeekIn(tripQueryConditions.daysOfWeek()), + addressLike(tripQueryConditions.address()) ) .orderBy(trip.id.desc()) - .limit(paging.limit().longValue() + 1L) + .limit(tripPaging.limit().longValue() + 1L) .fetch(); } diff --git a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java b/backend/src/main/java/dev/tripdraw/trip/query/TripPaging.java similarity index 60% rename from backend/src/main/java/dev/tripdraw/common/domain/Paging.java rename to backend/src/main/java/dev/tripdraw/trip/query/TripPaging.java index 36b72a8de..650c8c3e7 100644 --- a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripPaging.java @@ -1,9 +1,9 @@ -package dev.tripdraw.common.domain; +package dev.tripdraw.trip.query; -public record Paging(Long lastViewedId, Integer limit) { +public record TripPaging(Long lastViewedId, Integer limit) { private static final int LIMIT_MAXIMUM = 100; - public Paging(Long lastViewedId, Integer limit) { + public TripPaging(Long lastViewedId, Integer limit) { this.lastViewedId = lastViewedId; this.limit = ceil(limit); } @@ -13,6 +13,6 @@ private int ceil(Integer limit) { } public boolean hasNextPage(int size) { - return size > limit; + return limit < size; } } diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java rename to backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java index fee25962e..c856633bd 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java @@ -1,4 +1,4 @@ -package dev.tripdraw.trip.domain; +package dev.tripdraw.trip.query; import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; @@ -6,7 +6,7 @@ import java.util.HashSet; import java.util.Set; -public record SearchConditions( +public record TripQueryConditions( Set years, Set months, Set daysOfWeek, @@ -26,7 +26,7 @@ public record SearchConditions( private static final int GENDER_MINIMUM = 1; private static final int GENDER_MAXIMUM = 2; - public SearchConditions( + public TripQueryConditions( Set years, Set months, Set daysOfWeek, diff --git a/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java b/backend/src/test/java/dev/tripdraw/common/domain/TripPagingTest.java similarity index 74% rename from backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java rename to backend/src/test/java/dev/tripdraw/common/domain/TripPagingTest.java index 4c34fe304..d02967ce2 100644 --- a/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java +++ b/backend/src/test/java/dev/tripdraw/common/domain/TripPagingTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import dev.tripdraw.trip.query.TripPaging; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -10,16 +11,16 @@ @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class PagingTest { +class TripPagingTest { @ParameterizedTest @CsvSource({"19, false", "20, false", "21, true"}) void 다음_페이지가_있는지_확인한다(int size, boolean expected) { // given - Paging paging = new Paging(1L, 20); + TripPaging tripPaging = new TripPaging(1L, 20); // when - boolean actual = paging.hasNextPage(size); + boolean actual = tripPaging.hasNextPage(size); // then assertThat(actual).isEqualTo(expected); @@ -31,9 +32,9 @@ class PagingTest { int limit = 101; // when - Paging paging = new Paging(1L, limit); - + TripPaging tripPaging = new TripPaging(1L, limit); + // then - assertThat(paging.limit()).isEqualTo(100); + assertThat(tripPaging.limit()).isEqualTo(100); } } diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java similarity index 56% rename from backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java rename to backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java index c5e4c8d91..a99ae9fd3 100644 --- a/backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java @@ -1,13 +1,13 @@ package dev.tripdraw.test.fixture; -import dev.tripdraw.trip.domain.SearchConditions; +import dev.tripdraw.trip.query.TripQueryConditions; import java.util.Set; -public class SearchConditionsFixture { +public class TripQueryConditionsFixture { - public static SearchConditions emptySearchConditions() { - return new SearchConditions( + public static TripQueryConditions emptySearchConditions() { + return new TripQueryConditions( Set.of(), Set.of(), Set.of(), @@ -17,8 +17,8 @@ public static SearchConditions emptySearchConditions() { ); } - public static SearchConditions yearsSearchConditions(Set years) { - return new SearchConditions( + public static TripQueryConditions yearsSearchConditions(Set years) { + return new TripQueryConditions( years, Set.of(), Set.of(), @@ -28,8 +28,8 @@ public static SearchConditions yearsSearchConditions(Set years) { ); } - public static SearchConditions monthsSearchConditions(Set months) { - return new SearchConditions( + public static TripQueryConditions monthsSearchConditions(Set months) { + return new TripQueryConditions( Set.of(), months, Set.of(), @@ -39,8 +39,8 @@ public static SearchConditions monthsSearchConditions(Set months) { ); } - public static SearchConditions daysOfWeekSearchConditions(Set daysOfWeek) { - return new SearchConditions( + public static TripQueryConditions daysOfWeekSearchConditions(Set daysOfWeek) { + return new TripQueryConditions( Set.of(), Set.of(), daysOfWeek, @@ -50,8 +50,8 @@ public static SearchConditions daysOfWeekSearchConditions(Set daysOfWee ); } - public static SearchConditions ageRangesSearchConditions(Set ageRanges) { - return new SearchConditions( + public static TripQueryConditions ageRangesSearchConditions(Set ageRanges) { + return new TripQueryConditions( Set.of(), Set.of(), Set.of(), @@ -61,8 +61,8 @@ public static SearchConditions ageRangesSearchConditions(Set ageRanges) ); } - public static SearchConditions gendersSearchConditions(Set genders) { - return new SearchConditions( + public static TripQueryConditions gendersSearchConditions(Set genders) { + return new TripQueryConditions( Set.of(), Set.of(), Set.of(), @@ -72,8 +72,8 @@ public static SearchConditions gendersSearchConditions(Set genders) { ); } - public static SearchConditions addressSearchConditions(String address) { - return new SearchConditions( + public static TripQueryConditions addressSearchConditions(String address) { + return new TripQueryConditions( Set.of(), Set.of(), Set.of(), diff --git a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java index 9d77bd2b9..2f7e10c15 100644 --- a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java @@ -20,12 +20,12 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import dev.tripdraw.auth.application.JwtTokenProvider; -import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.test.ControllerTest; import dev.tripdraw.trip.dto.TripSearchConditions; +import dev.tripdraw.trip.dto.TripSearchPaging; import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripSearchResponse; import dev.tripdraw.trip.dto.TripsSearchResponse; @@ -111,7 +111,7 @@ class 개수_제한을 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(null, limit) + new TripSearchPaging(null, limit) ); // when @@ -138,7 +138,7 @@ class 개수_제한을 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(null, limit) + new TripSearchPaging(null, limit) ); // when @@ -165,7 +165,7 @@ class 개수_제한을 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(null, limit) + new TripSearchPaging(null, limit) ); // when @@ -192,7 +192,7 @@ class 개수_제한을 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(null, limit) + new TripSearchPaging(null, limit) ); // when @@ -213,7 +213,7 @@ class 개수_제한을 { }); } } - + @Nested class 마지막으로_조회한_여행_ID를 { @@ -224,7 +224,7 @@ class 마지막으로_조회한_여행_ID를 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(null, LIMIT) + new TripSearchPaging(null, LIMIT) ); // when @@ -256,7 +256,7 @@ class 마지막으로_조회한_여행_ID를 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(lastViewedId, LIMIT) + new TripSearchPaging(lastViewedId, LIMIT) ); // when @@ -287,7 +287,7 @@ class 마지막으로_조회한_여행_ID를 { @Nested class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { - private final SearchPaging nullLastViewedIdAnd10Limit = new SearchPaging(null, 10); + private final TripSearchPaging nullLastViewedIdAnd10Limit = new TripSearchPaging(null, 10); @Test void 조건없이_조회할_수_있다() { diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java new file mode 100644 index 000000000..d3ec76e13 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java @@ -0,0 +1,59 @@ +package dev.tripdraw.trip.application; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.query.TripCustomRepository; +import dev.tripdraw.trip.query.TripPaging; +import dev.tripdraw.trip.query.TripQueryConditions; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@ExtendWith(MockitoExtension.class) +class TripQueryServiceTest { + + @Mock + private TripCustomRepository tripCustomRepository; + + @InjectMocks + private TripQueryService tripQueryService; + + @Test + void 쿼리_조건에_따라_여행을_조회한다() { + // given + TripQueryConditions tripQueryConditions = new TripQueryConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + TripPaging tripPaging = new TripPaging(1L, 10); + + given(tripCustomRepository.findAllByConditions(tripQueryConditions, tripPaging)) + .willReturn(new ArrayList<>()); + + // when + List trips = tripQueryService.readAllByQueryConditions(tripQueryConditions, tripPaging); + + // then + assertThat(trips).isEmpty(); + then(tripCustomRepository) + .should(times(1)) + .findAllByConditions(tripQueryConditions, tripPaging); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index 37d13311a..42da32f94 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -9,7 +9,6 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import dev.tripdraw.common.auth.LoginUser; -import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; @@ -26,6 +25,7 @@ import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; import dev.tripdraw.trip.dto.TripSearchConditions; +import dev.tripdraw.trip.dto.TripSearchPaging; import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripSearchResponse; import dev.tripdraw.trip.dto.TripSearchResponseOfMember; @@ -180,11 +180,11 @@ void setUp() { Set.of(), "" ); - SearchPaging searchPaging = new SearchPaging(null, 10); - TripSearchRequest tripSearchRequest = new TripSearchRequest(emptyConditions, searchPaging); + TripSearchPaging tripSearchPaging = new TripSearchPaging(null, 10); + TripSearchRequest tripSearchRequest = new TripSearchRequest(emptyConditions, tripSearchPaging); // when - TripsSearchResponse tripsSearchResponse = tripService.readAllTrips(tripSearchRequest); + TripsSearchResponse tripsSearchResponse = tripService.readAll(tripSearchRequest); // then assertThat(tripsSearchResponse).usingRecursiveComparison().isEqualTo( diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java similarity index 80% rename from backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java rename to backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java index 0a8e16be6..b2b9f99e7 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.trip.exception.TripException; +import dev.tripdraw.trip.query.TripQueryConditions; import java.util.Set; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -12,7 +13,7 @@ @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class SearchConditionsTest { +class TripQueryConditionsTest { @ParameterizedTest @ValueSource(ints = {2009, 2024}) @@ -21,7 +22,7 @@ class SearchConditionsTest { Set years = of(year); // expect - assertThatThrownBy(() -> new SearchConditions(years, of(), of(), of(), of(), "")) + assertThatThrownBy(() -> new TripQueryConditions(years, of(), of(), of(), of(), "")) .isInstanceOf(TripException.class) .hasMessage("유효하지 않은 여행 조회 조건입니다."); } @@ -33,7 +34,7 @@ class SearchConditionsTest { Set months = of(month); // expect - assertThatThrownBy(() -> new SearchConditions(of(), months, of(), of(), of(), "")) + assertThatThrownBy(() -> new TripQueryConditions(of(), months, of(), of(), of(), "")) .isInstanceOf(TripException.class) .hasMessage("유효하지 않은 여행 조회 조건입니다."); } @@ -45,7 +46,7 @@ class SearchConditionsTest { Set daysOfWeek = of(dayOfWeek); // expect - assertThatThrownBy(() -> new SearchConditions(of(), of(), daysOfWeek, of(), of(), "")) + assertThatThrownBy(() -> new TripQueryConditions(of(), of(), daysOfWeek, of(), of(), "")) .isInstanceOf(TripException.class) .hasMessage("유효하지 않은 여행 조회 조건입니다."); } @@ -57,7 +58,7 @@ class SearchConditionsTest { Set ageRanges = of(ageRange); // expect - assertThatThrownBy(() -> new SearchConditions(of(), of(), of(), ageRanges, of(), "")) + assertThatThrownBy(() -> new TripQueryConditions(of(), of(), of(), ageRanges, of(), "")) .isInstanceOf(TripException.class) .hasMessage("유효하지 않은 여행 조회 조건입니다."); } @@ -69,7 +70,7 @@ class SearchConditionsTest { Set genders = of(gender); // expect - assertThatThrownBy(() -> new SearchConditions(genders, of(), of(), of(), of(), "")) + assertThatThrownBy(() -> new TripQueryConditions(genders, of(), of(), of(), of(), "")) .isInstanceOf(TripException.class) .hasMessage("유효하지 않은 여행 조회 조건입니다."); } diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index a03be42b6..549f20f2c 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -1,12 +1,6 @@ package dev.tripdraw.trip.domain; import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.test.fixture.SearchConditionsFixture.addressSearchConditions; -import static dev.tripdraw.test.fixture.SearchConditionsFixture.daysOfWeekSearchConditions; -import static dev.tripdraw.test.fixture.SearchConditionsFixture.emptySearchConditions; -import static dev.tripdraw.test.fixture.SearchConditionsFixture.monthsSearchConditions; -import static dev.tripdraw.test.fixture.SearchConditionsFixture.yearsSearchConditions; -import static dev.tripdraw.test.fixture.TestFixture.위치정보; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -14,22 +8,16 @@ import dev.tripdraw.common.config.JpaConfig; import dev.tripdraw.common.config.QueryDslConfig; -import dev.tripdraw.common.domain.Paging; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.post.domain.Post; import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; -import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; @@ -137,389 +125,389 @@ void setUp() { .hasMessage(TRIP_NOT_FOUND.message()); } - @Nested - class 조건에_따라_여행을_조회할_때 { - - @Nested - class 개수_제한이 { - - @ParameterizedTest - @CsvSource({"0, 1", "1, 2", "2, 3"}) - void 여행의_개수보다_적으면_개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { - // given - jeju_2023_1_1_Sun(); - jeju_2023_1_1_Sun(); - jeju_2023_1_1_Sun(); - - Paging paging = new Paging(null, limit); - - // when - List trips = tripRepository.findAllByConditions(emptySearchConditions(), paging); - - // then - assertThat(trips).hasSize(expectedSize); - } - - @ParameterizedTest - @CsvSource({"1, 1", "2, 1"}) - void 여행의_개수보다_많거나_같으면_모든_여행을_반환한다(int limit, int expectedSize) { - // given - jeju_2023_1_1_Sun(); - - Paging paging = new Paging(null, limit); - - // when - List trips = tripRepository.findAllByConditions(emptySearchConditions(), paging); - - // then - assertThat(trips).hasSize(expectedSize); - } - } - - @Nested - class 마지막으로_조회한_Id를 { - - @Test - void 입력하지_않으면_가장_최신_여행부터_내림차순으로_반환한다() { - // given - Trip jeju_2023_1_1_sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - - Long lastViewedId = null; - - // when - List trips = tripRepository.findAllByConditions(emptySearchConditions(), - new Paging(lastViewedId, 10)); - - // then - assertThat(trips).containsExactly( - jeju2023_2_1_Wed, - seoul2023_1_1_Sun, - jeju_2023_1_1_sun - ); - } - - @Test - void 입력하면_해당_Id_이하의_최신_여행을_내림차순으로_반환한다() { - // given - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - - Long lastViewedId = jeju2023_2_1_Wed.id(); - - // when - List trips = tripRepository.findAllByConditions(emptySearchConditions(), - new Paging(lastViewedId, 10)); - - // then - assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun); - } - } - - @Nested - class 조건으로_연도를 { - - @Test - void 한_개_설정하면_해당_연도의_여행을_반환한다() { - // given - seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = yearsSearchConditions(Set.of(2023)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(jeju2023_2_1_Wed, seoul2023_1_1_Sun, jeju2023_1_1_Sun); - } - - @Test - void 여러_개_설정하면_해당_연도들의_여행을_반환한다() { - // given - Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); - seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = yearsSearchConditions(Set.of(2023, 2021)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly( - jeju2023_2_1_Wed, - seoul2023_1_1_Sun, - jeju2023_1_1_Sun, - yangyang2021_3_2_Tue - ); - } - } - - @Nested - class 조건으로_월을 { - - @Test - void 한_개_설정하면_해당_월의_여행을_반환한다() { - // given - Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = monthsSearchConditions(Set.of(1)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); - } - - @Test - void 여러_개_설정하면_해당_월들의_여행을_반환한다() { - // given - Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); - Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = monthsSearchConditions(Set.of(1, 3)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly( - seoul2023_1_1_Sun, - jeju2023_1_1_Sun, - seoul2022_1_2_Sun, - yangyang2021_3_2_Tue - ); - } - } - - @Nested - class 조건으로_요일을 { - - @Test - void 한_개_설정하면_해당_요일의_여행을_반환한다() { - // given - Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = daysOfWeekSearchConditions(Set.of(1)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); - } - - @Test - void 여러_개_설정하면_해당_요일들의_여행을_반환한다() { - // given - Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); - Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = daysOfWeekSearchConditions(Set.of(1, 3)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly( - seoul2023_1_1_Sun, - jeju2023_1_1_Sun, - seoul2022_1_2_Sun, - yangyang2021_3_2_Tue - ); - } - } - - @Nested - class 조건으로_주소를 { - - @Test - void 시도_시군구_읍면동_형식으로_입력하면_해당하는_여행을_반환한다() { - // given - Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); - Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); - Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - - SearchConditions searchConditions = addressSearchConditions("서울특별시 송파구 신천동"); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul_songpa_sincheon); - } - - @Test - void 시도_시군구_형식으로_입력하면_해당하는_여행을_반환한다() { - // given - Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); - Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); - Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - - SearchConditions searchConditions = addressSearchConditions("서울특별시 송파구"); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); - } - - @Test - void 시도_형식으로_입력하면_해당하는_여행을_반환한다() { - // given - Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); - Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); - Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - - SearchConditions searchConditions = addressSearchConditions("서울특별시"); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); - } - } - - @Nested - class 조건을 { - - @Test - void 여러_개_설정하면_해당하는_여행을_반환한다() { - // given - yangyang_2021_3_2_Tue(); - seoul_2022_1_2_Sun(); - jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = new SearchConditions( - Set.of(2023), - Set.of(1), - Set.of(), - Set.of(), - Set.of(), - "서울특별시" - ); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul2023_1_1_Sun); - } - - @Test - void 설정하지_않으면_모든_여행을_반환한다() { - // given - Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); - Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - Trip jeju_2023_2_1_Wed = jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = emptySearchConditions(); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly( - jeju_2023_2_1_Wed, - seoul2023_1_1_Sun, - jeju2023_1_1_Sun, - seoul2022_1_2_Sun, - yangyang2021_3_2_Tue - ); - } - } - - @Test - void 감상이_없는_여행은_조회되지_않는다() { - // given - emptyPostTrip(); - - SearchConditions searchConditions = emptySearchConditions(); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).isEmpty(); - } - - private Trip jeju_2023_2_1_Wed() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2023, 2, 1, 1, 1); - trip.add(point); - tripRepository.save(trip); - postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); - return trip; - } - - private Trip seoul_2023_1_1_Sun() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2023, 1, 1, 10, 1); - trip.add(point); - tripRepository.save(trip); - postRepository.save(new Post("", point, "서울특별시 송파구 신천동", "", member, trip.id())); - return trip; - } - - private Trip jeju_2023_1_1_Sun() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2023, 1, 1, 1, 1); - trip.add(point); - tripRepository.save(trip); - postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); - return trip; - } - - private Trip seoul_2022_1_2_Sun() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2022, 1, 2, 1, 1); - trip.add(point); - tripRepository.save(trip); - postRepository.save(new Post("", point, "서울특별시 송파구 방이동", "", member, trip.id())); - return trip; - } - - private Trip yangyang_2021_3_2_Tue() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2021, 3, 2, 1, 1); - trip.add(point); - tripRepository.save(trip); - postRepository.save(new Post("", point, "강원도 양양군", "", member, trip.id())); - return trip; - } - - private Trip emptyPostTrip() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2021, 3, 2, 1, 1); - trip.add(point); - tripRepository.save(trip); - return trip; - } - } +// @Nested +// class 조건에_따라_여행을_조회할_때 { +// +// @Nested +// class 개수_제한이 { +// +// @ParameterizedTest +// @CsvSource({"0, 1", "1, 2", "2, 3"}) +// void 여행의_개수보다_적으면_개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { +// // given +// jeju_2023_1_1_Sun(); +// jeju_2023_1_1_Sun(); +// jeju_2023_1_1_Sun(); +// +// TripPaging tripPaging = new TripPaging(null, limit); +// +// // when +// List trips = tripRepository.findAllByConditions(emptySearchConditions(), tripPaging); +// +// // then +// assertThat(trips).hasSize(expectedSize); +// } +// +// @ParameterizedTest +// @CsvSource({"1, 1", "2, 1"}) +// void 여행의_개수보다_많거나_같으면_모든_여행을_반환한다(int limit, int expectedSize) { +// // given +// jeju_2023_1_1_Sun(); +// +// TripPaging tripPaging = new TripPaging(null, limit); +// +// // when +// List trips = tripRepository.findAllByConditions(emptySearchConditions(), tripPaging); +// +// // then +// assertThat(trips).hasSize(expectedSize); +// } +// } +// +// @Nested +// class 마지막으로_조회한_Id를 { +// +// @Test +// void 입력하지_않으면_가장_최신_여행부터_내림차순으로_반환한다() { +// // given +// Trip jeju_2023_1_1_sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); +// +// Long lastViewedId = null; +// +// // when +// List trips = tripRepository.findAllByConditions(emptySearchConditions(), +// new TripPaging(lastViewedId, 10)); +// +// // then +// assertThat(trips).containsExactly( +// jeju2023_2_1_Wed, +// seoul2023_1_1_Sun, +// jeju_2023_1_1_sun +// ); +// } +// +// @Test +// void 입력하면_해당_Id_이하의_최신_여행을_내림차순으로_반환한다() { +// // given +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); +// +// Long lastViewedId = jeju2023_2_1_Wed.id(); +// +// // when +// List trips = tripRepository.findAllByConditions(emptySearchConditions(), +// new TripPaging(lastViewedId, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun); +// } +// } +// +// @Nested +// class 조건으로_연도를 { +// +// @Test +// void 한_개_설정하면_해당_연도의_여행을_반환한다() { +// // given +// seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(jeju2023_2_1_Wed, seoul2023_1_1_Sun, jeju2023_1_1_Sun); +// } +// +// @Test +// void 여러_개_설정하면_해당_연도들의_여행을_반환한다() { +// // given +// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); +// seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023, 2021)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly( +// jeju2023_2_1_Wed, +// seoul2023_1_1_Sun, +// jeju2023_1_1_Sun, +// yangyang2021_3_2_Tue +// ); +// } +// } +// +// @Nested +// class 조건으로_월을 { +// +// @Test +// void 한_개_설정하면_해당_월의_여행을_반환한다() { +// // given +// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); +// } +// +// @Test +// void 여러_개_설정하면_해당_월들의_여행을_반환한다() { +// // given +// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); +// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1, 3)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly( +// seoul2023_1_1_Sun, +// jeju2023_1_1_Sun, +// seoul2022_1_2_Sun, +// yangyang2021_3_2_Tue +// ); +// } +// } +// +// @Nested +// class 조건으로_요일을 { +// +// @Test +// void 한_개_설정하면_해당_요일의_여행을_반환한다() { +// // given +// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); +// } +// +// @Test +// void 여러_개_설정하면_해당_요일들의_여행을_반환한다() { +// // given +// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); +// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1, 3)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly( +// seoul2023_1_1_Sun, +// jeju2023_1_1_Sun, +// seoul2022_1_2_Sun, +// yangyang2021_3_2_Tue +// ); +// } +// } +// +// @Nested +// class 조건으로_주소를 { +// +// @Test +// void 시도_시군구_읍면동_형식으로_입력하면_해당하는_여행을_반환한다() { +// // given +// Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); +// Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); +// Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); +// +// TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구 신천동"); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul_songpa_sincheon); +// } +// +// @Test +// void 시도_시군구_형식으로_입력하면_해당하는_여행을_반환한다() { +// // given +// Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); +// Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); +// Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); +// +// TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구"); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); +// } +// +// @Test +// void 시도_형식으로_입력하면_해당하는_여행을_반환한다() { +// // given +// Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); +// Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); +// Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); +// +// TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시"); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); +// } +// } +// +// @Nested +// class 조건을 { +// +// @Test +// void 여러_개_설정하면_해당하는_여행을_반환한다() { +// // given +// yangyang_2021_3_2_Tue(); +// seoul_2022_1_2_Sun(); +// jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = new TripQueryConditions( +// Set.of(2023), +// Set.of(1), +// Set.of(), +// Set.of(), +// Set.of(), +// "서울특별시" +// ); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul2023_1_1_Sun); +// } +// +// @Test +// void 설정하지_않으면_모든_여행을_반환한다() { +// // given +// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); +// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// Trip jeju_2023_2_1_Wed = jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = emptySearchConditions(); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly( +// jeju_2023_2_1_Wed, +// seoul2023_1_1_Sun, +// jeju2023_1_1_Sun, +// seoul2022_1_2_Sun, +// yangyang2021_3_2_Tue +// ); +// } +// } +// +// @Test +// void 감상이_없는_여행은_조회되지_않는다() { +// // given +// emptyPostTrip(); +// +// TripQueryConditions tripQueryConditions = emptySearchConditions(); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).isEmpty(); +// } +// +// private Trip jeju_2023_2_1_Wed() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2023, 2, 1, 1, 1); +// trip.add(point); +// tripRepository.save(trip); +// postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); +// return trip; +// } +// +// private Trip seoul_2023_1_1_Sun() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2023, 1, 1, 10, 1); +// trip.add(point); +// tripRepository.save(trip); +// postRepository.save(new Post("", point, "서울특별시 송파구 신천동", "", member, trip.id())); +// return trip; +// } +// +// private Trip jeju_2023_1_1_Sun() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2023, 1, 1, 1, 1); +// trip.add(point); +// tripRepository.save(trip); +// postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); +// return trip; +// } +// +// private Trip seoul_2022_1_2_Sun() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2022, 1, 2, 1, 1); +// trip.add(point); +// tripRepository.save(trip); +// postRepository.save(new Post("", point, "서울특별시 송파구 방이동", "", member, trip.id())); +// return trip; +// } +// +// private Trip yangyang_2021_3_2_Tue() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2021, 3, 2, 1, 1); +// trip.add(point); +// tripRepository.save(trip); +// postRepository.save(new Post("", point, "강원도 양양군", "", member, trip.id())); +// return trip; +// } +// +// private Trip emptyPostTrip() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2021, 3, 2, 1, 1); +// trip.add(point); +// tripRepository.save(trip); +// return trip; +// } +// } } diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index 4fe6899b9..d8759184f 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -208,7 +208,7 @@ public void setUp() { // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .when().get("/trips/mine") + .when().get("/trips/me") .then().log().all() .extract(); diff --git a/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java b/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java new file mode 100644 index 000000000..90b2c94e0 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java @@ -0,0 +1,454 @@ +package dev.tripdraw.trip.query; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.TestFixture.위치정보; +import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.addressSearchConditions; +import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.daysOfWeekSearchConditions; +import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.emptySearchConditions; +import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.monthsSearchConditions; +import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.yearsSearchConditions; +import static org.assertj.core.api.Assertions.assertThat; + +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.domain.PostRepository; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@Transactional +@SpringBootTest +class TripCustomRepositoryImplTest { + + @Autowired + private TripCustomRepository tripCustomRepository; + + @Autowired + private TripRepository tripRepository; + + @Autowired + private PostRepository postRepository; + + @Autowired + private MemberRepository memberRepository; + + private Member member; + + @BeforeEach + void setUp() { + member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + } + + @Nested + class 조건에_따라_여행을_조회할_때 { + + @Nested + class 개수_제한이 { + + @ParameterizedTest + @CsvSource({"0, 1", "1, 2", "2, 3"}) + void 여행의_개수보다_적으면_개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { + // given + jeju_2023_1_1_Sun(); + jeju_2023_1_1_Sun(); + jeju_2023_1_1_Sun(); + + TripPaging tripPaging = new TripPaging(null, limit); + + // when + List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), tripPaging); + + // then + assertThat(trips).hasSize(expectedSize); + } + + @ParameterizedTest + @CsvSource({"1, 1", "2, 1"}) + void 여행의_개수보다_많거나_같으면_모든_여행을_반환한다(int limit, int expectedSize) { + // given + jeju_2023_1_1_Sun(); + + TripPaging tripPaging = new TripPaging(null, limit); + + // when + List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), tripPaging); + + // then + assertThat(trips).hasSize(expectedSize); + } + } + + @Nested + class 마지막으로_조회한_Id를 { + + @Test + void 입력하지_않으면_가장_최신_여행부터_내림차순으로_반환한다() { + // given + Trip jeju_2023_1_1_sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + Long lastViewedId = null; + + // when + List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), + new TripPaging(lastViewedId, 10)); + + // then + assertThat(trips).containsExactly( + jeju2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju_2023_1_1_sun + ); + } + + @Test + void 입력하면_해당_Id_이하의_최신_여행을_내림차순으로_반환한다() { + // given + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + Long lastViewedId = jeju2023_2_1_Wed.id(); + + // when + List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), + new TripPaging(lastViewedId, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun); + } + } + + @Nested + class 조건으로_연도를 { + + @Test + void 한_개_설정하면_해당_연도의_여행을_반환한다() { + // given + seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(jeju2023_2_1_Wed, seoul2023_1_1_Sun, jeju2023_1_1_Sun); + } + + @Test + void 여러_개_설정하면_해당_연도들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023, 2021)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly( + jeju2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_월을 { + + @Test + void 한_개_설정하면_해당_월의_여행을_반환한다() { + // given + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); + } + + @Test + void 여러_개_설정하면_해당_월들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1, 3)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly( + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_요일을 { + + @Test + void 한_개_설정하면_해당_요일의_여행을_반환한다() { + // given + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); + } + + @Test + void 여러_개_설정하면_해당_요일들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1, 3)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly( + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_주소를 { + + @Test + void 시도_시군구_읍면동_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구 신천동"); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon); + } + + @Test + void 시도_시군구_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구"); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); + } + + @Test + void 시도_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시"); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); + } + } + + @Nested + class 조건을 { + + @Test + void 여러_개_설정하면_해당하는_여행을_반환한다() { + // given + yangyang_2021_3_2_Tue(); + seoul_2022_1_2_Sun(); + jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = new TripQueryConditions( + Set.of(2023), + Set.of(1), + Set.of(), + Set.of(), + Set.of(), + "서울특별시" + ); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun); + } + + @Test + void 설정하지_않으면_모든_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju_2023_2_1_Wed = jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = emptySearchConditions(); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly( + jeju_2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Test + void 감상이_없는_여행은_조회되지_않는다() { + // given + emptyPostTrip(); + + TripQueryConditions tripQueryConditions = emptySearchConditions(); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); + + // then + assertThat(trips).isEmpty(); + } + + private Trip jeju_2023_2_1_Wed() { + Trip trip = Trip.from(member); + Point point = 위치정보(2023, 2, 1, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); + return trip; + } + + private Trip seoul_2023_1_1_Sun() { + Trip trip = Trip.from(member); + Point point = 위치정보(2023, 1, 1, 10, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "서울특별시 송파구 신천동", "", member, trip.id())); + return trip; + } + + private Trip jeju_2023_1_1_Sun() { + Trip trip = Trip.from(member); + Point point = 위치정보(2023, 1, 1, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); + return trip; + } + + private Trip seoul_2022_1_2_Sun() { + Trip trip = Trip.from(member); + Point point = 위치정보(2022, 1, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "서울특별시 송파구 방이동", "", member, trip.id())); + return trip; + } + + private Trip yangyang_2021_3_2_Tue() { + Trip trip = Trip.from(member); + Point point = 위치정보(2021, 3, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "강원도 양양군", "", member, trip.id())); + return trip; + } + + private Trip emptyPostTrip() { + Trip trip = Trip.from(member); + Point point = 위치정보(2021, 3, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + return trip; + } + } + +} From dbe04770920b7691dd51df534aee2852b649412e Mon Sep 17 00:00:00 2001 From: ReO Date: Tue, 19 Sep 2023 10:14:35 +0900 Subject: [PATCH 092/119] =?UTF-8?q?fix:=20=EA=B2=BD=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=83=9D=EC=84=B1=20Mocking=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20RollBack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/post/presentation/PostControllerTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index 0fcda5155..c1f2f03f9 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -13,6 +13,7 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; import dev.tripdraw.auth.application.JwtTokenProvider; +import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.dto.PostAndPointCreateRequest; @@ -40,6 +41,7 @@ import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; import java.time.LocalDateTime; import java.util.Set; @@ -59,6 +61,10 @@ class PostControllerTest extends ControllerTest { @Autowired private JwtTokenProvider jwtTokenProvider; + // 이벤트를 통해 비동기로 경로 이미지를 생성하기 때문에, MockBean으로 둡니다. + @MockBean + private RouteImageGenerator routeImageGenerator; + private Trip trip; private String huchuToken; From 62c1bf8b47e8371497f25b9ed5731490d37a2925 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Tue, 19 Sep 2023 13:25:37 +0900 Subject: [PATCH 093/119] =?UTF-8?q?[refactor]=20validate=20=EC=9D=BC?= =?UTF-8?q?=EB=8B=A8=20=EB=B9=BC=EA=B8=B0=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/dev/tripdraw/common/config/QueryDslConfig.java | 3 --- .../java/dev/tripdraw/trip/application/TripQueryService.java | 5 +---- .../java/dev/tripdraw/trip/query/TripQueryConditions.java | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java b/backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java index e3e15a840..9df83f7ab 100644 --- a/backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java +++ b/backend/src/main/java/dev/tripdraw/common/config/QueryDslConfig.java @@ -12,9 +12,6 @@ public class QueryDslConfig { @PersistenceContext private EntityManager entityManager; - public QueryDslConfig() { - } - @Bean public JPAQueryFactory jpaQueryFactory() { return new JPAQueryFactory(entityManager); diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java index d572e45df..1d41a72a3 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java @@ -18,10 +18,7 @@ public class TripQueryService { @Transactional(readOnly = true) public List readAllByQueryConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging) { - return tripCustomRepository.findAllByConditions( - tripQueryConditions, - tripPaging - ); + return tripCustomRepository.findAllByConditions(tripQueryConditions, tripPaging); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java index c856633bd..91a3291a7 100644 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java @@ -34,7 +34,7 @@ public TripQueryConditions( Set genders, String address ) { - validate(years, months, daysOfWeek, ageRanges, genders); +// validate(years, months, daysOfWeek, ageRanges, genders); this.years = new HashSet<>(years); this.months = new HashSet<>(months); this.daysOfWeek = new HashSet<>(daysOfWeek); From 2168d1d6a5423da4534231c6c2110c5b383cfa9a Mon Sep 17 00:00:00 2001 From: ReO Date: Tue, 19 Sep 2023 13:27:56 +0900 Subject: [PATCH 094/119] =?UTF-8?q?fix:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/dev/tripdraw/post/application/PostService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index 8277fad51..0d004002f 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -136,6 +136,10 @@ public PostsSearchResponse readAll(PostSearchRequest postSearchRequest) { .toList(); boolean hasNextPage = (posts.size() == postSearchRequest.paging().limit() + 1); + if (hasNextPage) { + postSearchResponses = postSearchResponses.subList(0, postSearchRequest.paging().limit()); + } + return PostsSearchResponse.of(postSearchResponses, hasNextPage); } } From e110b1a3000367e16d19e147ec1fce94a9f229ee Mon Sep 17 00:00:00 2001 From: Combi153 Date: Tue, 19 Sep 2023 13:33:59 +0900 Subject: [PATCH 095/119] =?UTF-8?q?[refactor]=20validate=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=EB=84=A3=EA=B8=B0=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/application/TripService.java | 20 +++++-------------- .../tripdraw/trip/dto/TripSearchResponse.java | 13 ++++++++++++ .../trip/query/TripQueryConditions.java | 7 ++++--- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index e2a924725..a0fd69ec8 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -3,34 +3,24 @@ import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.trip.domain.Point; -import dev.tripdraw.trip.domain.PointRepository; -import dev.tripdraw.trip.domain.Trip; -import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.trip.domain.TripUpdateEvent; -import dev.tripdraw.trip.dto.PointCreateRequest; -import dev.tripdraw.trip.dto.PointCreateResponse; -import dev.tripdraw.trip.dto.PointResponse; -import dev.tripdraw.trip.dto.TripCreateResponse; -import dev.tripdraw.trip.dto.TripResponse; -import dev.tripdraw.trip.dto.TripSearchRequest; -import dev.tripdraw.trip.dto.TripUpdateRequest; -import dev.tripdraw.trip.dto.TripsSearchResponse; -import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; +import dev.tripdraw.trip.domain.*; +import dev.tripdraw.trip.dto.*; import dev.tripdraw.trip.query.TripPaging; import dev.tripdraw.trip.query.TripQueryConditions; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @RequiredArgsConstructor @Transactional @Service public class TripService { private static final int FIRST_INDEX = 0; + private final TripRepository tripRepository; private final PointRepository pointRepository; private final MemberRepository memberRepository; diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java index 02ac94e1d..b7103ce5d 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java @@ -1,14 +1,27 @@ package dev.tripdraw.trip.dto; import dev.tripdraw.trip.domain.Trip; +import io.swagger.v3.oas.annotations.media.Schema; + import java.time.LocalDateTime; public record TripSearchResponse( + @Schema(description = "여행 Id", example = "1") Long tripId, + + @Schema(description = "여행명", example = "통후추의 여행") String name, + + @Schema(description = "이미지 주소", example = "https://tripdraw.site/post-images/cd678ca2-30d5-11ee-be56-0242ac120002.jpg") String imageUrl, + + @Schema(description = "경로 이미지 주소", example = "https://tripdraw.site/route-images/cd678ca2-30d5-11ee-be56-0242ac120002.png") String routeImageUrl, + + @Schema(description = "여행 시작 시각", example = "2023-07-23T19:48:27") LocalDateTime startTime, + + @Schema(description = "여행 종료 시각", example = "2023-07-23T19:48:27") LocalDateTime endTime ) { diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java index 91a3291a7..03bf64e7a 100644 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java @@ -1,11 +1,12 @@ package dev.tripdraw.trip.query; -import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; - import dev.tripdraw.trip.exception.TripException; + import java.util.HashSet; import java.util.Set; +import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; + public record TripQueryConditions( Set years, Set months, @@ -34,7 +35,7 @@ public TripQueryConditions( Set genders, String address ) { -// validate(years, months, daysOfWeek, ageRanges, genders); + validate(years, months, daysOfWeek, ageRanges, genders); this.years = new HashSet<>(years); this.months = new HashSet<>(months); this.daysOfWeek = new HashSet<>(daysOfWeek); From b182a07da01e829795071f45698f0cc2fbeeea4a Mon Sep 17 00:00:00 2001 From: Combi153 Date: Tue, 19 Sep 2023 14:01:08 +0900 Subject: [PATCH 096/119] =?UTF-8?q?[feat]=20builder=20=EC=A0=81=EC=9A=A9?= =?UTF-8?q?=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/dto/TripSearchConditions.java | 12 +- .../trip/query/TripQueryConditions.java | 2 + .../fixture/TripQueryConditionsFixture.java | 113 +++++++++--------- .../fixture/TripSearchConditionsFixture.java | 113 +++++++++--------- 4 files changed, 126 insertions(+), 114 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java index df81efeeb..de91dc5e7 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java @@ -1,9 +1,10 @@ package dev.tripdraw.trip.dto; import dev.tripdraw.trip.query.TripQueryConditions; -import java.util.Set; import lombok.Builder; +import java.util.Set; + @Builder public record TripSearchConditions( Set years, @@ -15,6 +16,13 @@ public record TripSearchConditions( ) { public TripQueryConditions toTripQueryConditions() { - return new TripQueryConditions(years(), months(), daysOfWeek(), ageRanges(), genders(), address()); + return TripQueryConditions.builder() + .years(years) + .months(months) + .daysOfWeek(daysOfWeek) + .ageRanges(ageRanges) + .genders(genders) + .address(address) + .build(); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java index 03bf64e7a..cd7c12ae4 100644 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java @@ -1,12 +1,14 @@ package dev.tripdraw.trip.query; import dev.tripdraw.trip.exception.TripException; +import lombok.Builder; import java.util.HashSet; import java.util.Set; import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; +@Builder public record TripQueryConditions( Set years, Set months, diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java index a99ae9fd3..f0d9710cd 100644 --- a/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java @@ -1,85 +1,86 @@ package dev.tripdraw.test.fixture; import dev.tripdraw.trip.query.TripQueryConditions; + import java.util.Set; public class TripQueryConditionsFixture { public static TripQueryConditions emptySearchConditions() { - return new TripQueryConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripQueryConditions yearsSearchConditions(Set years) { - return new TripQueryConditions( - years, - Set.of(), - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripQueryConditions.builder() + .years(years) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripQueryConditions monthsSearchConditions(Set months) { - return new TripQueryConditions( - Set.of(), - months, - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(months) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripQueryConditions daysOfWeekSearchConditions(Set daysOfWeek) { - return new TripQueryConditions( - Set.of(), - Set.of(), - daysOfWeek, - Set.of(), - Set.of(), - "" - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(daysOfWeek) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripQueryConditions ageRangesSearchConditions(Set ageRanges) { - return new TripQueryConditions( - Set.of(), - Set.of(), - Set.of(), - ageRanges, - Set.of(), - "" - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(ageRanges) + .genders(Set.of()) + .address("") + .build(); } public static TripQueryConditions gendersSearchConditions(Set genders) { - return new TripQueryConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - genders, - "" - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(genders) + .address("") + .build(); } public static TripQueryConditions addressSearchConditions(String address) { - return new TripQueryConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - Set.of(), - address - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address(address) + .build(); } } diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java index e4e78c2f5..d3d5e67f8 100644 --- a/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java @@ -1,84 +1,85 @@ package dev.tripdraw.test.fixture; import dev.tripdraw.trip.dto.TripSearchConditions; + import java.util.Set; public class TripSearchConditionsFixture { public static TripSearchConditions emptyTripSearchConditions() { - return new TripSearchConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripSearchConditions yearsTripSearchConditions(Set years) { - return new TripSearchConditions( - years, - Set.of(), - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripSearchConditions.builder() + .years(years) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripSearchConditions monthsTripSearchConditions(Set months) { - return new TripSearchConditions( - Set.of(), - months, - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(months) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripSearchConditions daysOfWeekTripSearchConditions(Set daysOfWeek) { - return new TripSearchConditions( - Set.of(), - Set.of(), - daysOfWeek, - Set.of(), - Set.of(), - "" - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(daysOfWeek) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripSearchConditions ageRangesTripSearchConditions(Set ageRanges) { - return new TripSearchConditions( - Set.of(), - Set.of(), - Set.of(), - ageRanges, - Set.of(), - "" - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(ageRanges) + .genders(Set.of()) + .address("") + .build(); } public static TripSearchConditions gendersTripSearchConditions(Set genders) { - return new TripSearchConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - genders, - "" - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(genders) + .address("") + .build(); } public static TripSearchConditions addressTripSearchConditions(String address) { - return new TripSearchConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - Set.of(), - address - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address(address) + .build(); } } From d36391e302aa90d2fd4e137a3b7e47733164a1f0 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Tue, 19 Sep 2023 15:03:14 +0900 Subject: [PATCH 097/119] =?UTF-8?q?[refactor]=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EA=B0=9D=EC=B2=B4=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F?= =?UTF-8?q?=20VO=EB=A1=9C=20=ED=86=B5=EC=9D=BC=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/application/TripQueryService.java | 9 +- .../trip/application/TripService.java | 7 +- .../trip/dto/TripSearchConditions.java | 12 -- .../tripdraw/trip/dto/TripSearchRequest.java | 6 +- .../trip/presentation/TripController.java | 25 +-- .../trip/query/TripCustomRepository.java | 4 +- .../trip/query/TripCustomRepositoryImpl.java | 24 +-- .../trip/query/TripQueryConditions.java | 73 --------- .../fixture/TripQueryConditionsFixture.java | 86 ---------- .../fixture/TripSearchConditionsFixture.java | 36 ----- .../acceptance/TripSearchAcceptanceTest.java | 64 ++------ .../application/TripQueryServiceTest.java | 34 ++-- .../trip/domain/TripQueryConditionsTest.java | 77 --------- .../query/TripCustomRepositoryImplTest.java | 148 ++++++++++-------- 14 files changed, 143 insertions(+), 462 deletions(-) delete mode 100644 backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java delete mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java delete mode 100644 backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java index 1d41a72a3..34edc3b69 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java @@ -1,14 +1,15 @@ package dev.tripdraw.trip.application; import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.dto.TripSearchConditions; import dev.tripdraw.trip.query.TripCustomRepository; import dev.tripdraw.trip.query.TripPaging; -import dev.tripdraw.trip.query.TripQueryConditions; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @RequiredArgsConstructor @Transactional @Service @@ -17,8 +18,8 @@ public class TripQueryService { private final TripCustomRepository tripCustomRepository; @Transactional(readOnly = true) - public List readAllByQueryConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging) { - return tripCustomRepository.findAllByConditions(tripQueryConditions, tripPaging); + public List readAllByQueryConditions(TripSearchConditions tripSearchConditions, TripPaging tripPaging) { + return tripCustomRepository.findAllByConditions(tripSearchConditions, tripPaging); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index a0fd69ec8..b422eb5be 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -6,7 +6,6 @@ import dev.tripdraw.trip.domain.*; import dev.tripdraw.trip.dto.*; import dev.tripdraw.trip.query.TripPaging; -import dev.tripdraw.trip.query.TripQueryConditions; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; @@ -20,7 +19,7 @@ public class TripService { private static final int FIRST_INDEX = 0; - + private final TripRepository tripRepository; private final PointRepository pointRepository; private final MemberRepository memberRepository; @@ -72,10 +71,10 @@ public TripsSearchResponseOfMember readAllTripsOf(LoginUser loginUser) { @Transactional(readOnly = true) public TripsSearchResponse readAll(TripSearchRequest tripSearchRequest) { - TripQueryConditions tripQueryConditions = tripSearchRequest.toTripQueryConditions(); + TripSearchConditions condition = tripSearchRequest.condition(); TripPaging tripPaging = tripSearchRequest.toTripPaging(); - List trips = tripQueryService.readAllByQueryConditions(tripQueryConditions, tripPaging); + List trips = tripQueryService.readAllByQueryConditions(condition, tripPaging); if (tripPaging.hasNextPage(trips.size())) { return TripsSearchResponse.of(trips.subList(FIRST_INDEX, tripPaging.limit()), true); diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java index de91dc5e7..785818f63 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java @@ -1,6 +1,5 @@ package dev.tripdraw.trip.dto; -import dev.tripdraw.trip.query.TripQueryConditions; import lombok.Builder; import java.util.Set; @@ -14,15 +13,4 @@ public record TripSearchConditions( Set genders, String address ) { - - public TripQueryConditions toTripQueryConditions() { - return TripQueryConditions.builder() - .years(years) - .months(months) - .daysOfWeek(daysOfWeek) - .ageRanges(ageRanges) - .genders(genders) - .address(address) - .build(); - } } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java index 0289a16c3..867f24c6f 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java @@ -1,17 +1,13 @@ package dev.tripdraw.trip.dto; import dev.tripdraw.trip.query.TripPaging; -import dev.tripdraw.trip.query.TripQueryConditions; public record TripSearchRequest( + TripSearchConditions condition, TripSearchPaging paging ) { - public TripQueryConditions toTripQueryConditions() { - return condition.toTripQueryConditions(); - } - public TripPaging toTripPaging() { return paging.toTripPaging(); } diff --git a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java index 7492f0b09..9c96a9db0 100644 --- a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java +++ b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java @@ -1,34 +1,19 @@ package dev.tripdraw.trip.presentation; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.NO_CONTENT; - import dev.tripdraw.common.auth.Auth; import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.common.swagger.SwaggerAuthorizationRequired; import dev.tripdraw.trip.application.TripService; -import dev.tripdraw.trip.dto.PointCreateRequest; -import dev.tripdraw.trip.dto.PointCreateResponse; -import dev.tripdraw.trip.dto.PointResponse; -import dev.tripdraw.trip.dto.TripCreateResponse; -import dev.tripdraw.trip.dto.TripResponse; -import dev.tripdraw.trip.dto.TripSearchRequest; -import dev.tripdraw.trip.dto.TripUpdateRequest; -import dev.tripdraw.trip.dto.TripsSearchResponse; -import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; +import dev.tripdraw.trip.dto.*; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NO_CONTENT; @Tag(name = "Trip", description = "여행 관련 API 명세") @SwaggerAuthorizationRequired diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java index 9d8ace9f6..8c89d9b70 100644 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java @@ -1,9 +1,11 @@ package dev.tripdraw.trip.query; import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.dto.TripSearchConditions; + import java.util.List; public interface TripCustomRepository { - List findAllByConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging); + List findAllByConditions(TripSearchConditions tripSearchConditions, TripPaging tripPaging); } diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java index 86066939f..cf0888ef9 100644 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java @@ -1,19 +1,21 @@ package dev.tripdraw.trip.query; -import static dev.tripdraw.post.domain.QPost.post; -import static dev.tripdraw.trip.domain.QPoint.point; -import static dev.tripdraw.trip.domain.QTrip.trip; - import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.dto.TripSearchConditions; import io.micrometer.common.util.StringUtils; -import java.util.List; -import java.util.Set; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; import org.springframework.util.CollectionUtils; +import java.util.List; +import java.util.Set; + +import static dev.tripdraw.post.domain.QPost.post; +import static dev.tripdraw.trip.domain.QPoint.point; +import static dev.tripdraw.trip.domain.QTrip.trip; + @RequiredArgsConstructor @Repository public class TripCustomRepositoryImpl implements TripCustomRepository { @@ -21,17 +23,17 @@ public class TripCustomRepositoryImpl implements TripCustomRepository { private final JPAQueryFactory query; @Override - public List findAllByConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging) { + public List findAllByConditions(TripSearchConditions tripSearchConditions, TripPaging tripPaging) { return query .selectFrom(trip) .join(post).on(trip.id.eq(post.tripId)) .join(point).on(post.point.id.eq(point.id)) .where( tripIdLt(tripPaging.lastViewedId()), - yearIn(tripQueryConditions.years()), - monthIn(tripQueryConditions.months()), - dayOfWeekIn(tripQueryConditions.daysOfWeek()), - addressLike(tripQueryConditions.address()) + yearIn(tripSearchConditions.years()), + monthIn(tripSearchConditions.months()), + dayOfWeekIn(tripSearchConditions.daysOfWeek()), + addressLike(tripSearchConditions.address()) ) .orderBy(trip.id.desc()) .limit(tripPaging.limit().longValue() + 1L) diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java deleted file mode 100644 index cd7c12ae4..000000000 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java +++ /dev/null @@ -1,73 +0,0 @@ -package dev.tripdraw.trip.query; - -import dev.tripdraw.trip.exception.TripException; -import lombok.Builder; - -import java.util.HashSet; -import java.util.Set; - -import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; - -@Builder -public record TripQueryConditions( - Set years, - Set months, - Set daysOfWeek, - Set ageRanges, - Set genders, - String address -) { - - private static final int YEAR_MINIMUM = 2010; - private static final int YEAR_MAXIMUM = 2023; - private static final int MONTH_MINIMUM = 1; - private static final int MONTH_MAXIMUM = 12; - private static final int DAYS_OF_WEEK_MINIMUM = 1; - private static final int DAYS_OF_WEEK_MAXIMUM = 7; - private static final int AGE_RANGE_MINIMUM = 1; - private static final int AGE_RANGE_MAXIMUM = 10; - private static final int GENDER_MINIMUM = 1; - private static final int GENDER_MAXIMUM = 2; - - public TripQueryConditions( - Set years, - Set months, - Set daysOfWeek, - Set ageRanges, - Set genders, - String address - ) { - validate(years, months, daysOfWeek, ageRanges, genders); - this.years = new HashSet<>(years); - this.months = new HashSet<>(months); - this.daysOfWeek = new HashSet<>(daysOfWeek); - this.ageRanges = new HashSet<>(ageRanges); - this.genders = new HashSet<>(genders); - this.address = address; - } - - private void validate( - Set years, - Set months, - Set daysOfWeek, - Set ageRanges, - Set genders - ) { - validateRange(years, YEAR_MINIMUM, YEAR_MAXIMUM); - validateRange(months, MONTH_MINIMUM, MONTH_MAXIMUM); - validateRange(daysOfWeek, DAYS_OF_WEEK_MINIMUM, DAYS_OF_WEEK_MAXIMUM); - validateRange(ageRanges, AGE_RANGE_MINIMUM, AGE_RANGE_MAXIMUM); - validateRange(genders, GENDER_MINIMUM, GENDER_MAXIMUM); - } - - private void validateRange(Set conditions, int min, int max) { - if (isOutOfRange(conditions, min, max)) { - throw new TripException(INVALID_TRIP_SEARCH); - } - } - - private boolean isOutOfRange(Set conditions, int min, int max) { - return conditions.stream() - .anyMatch(condition -> condition < min || condition > max); - } -} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java deleted file mode 100644 index f0d9710cd..000000000 --- a/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java +++ /dev/null @@ -1,86 +0,0 @@ -package dev.tripdraw.test.fixture; - -import dev.tripdraw.trip.query.TripQueryConditions; - -import java.util.Set; - - -public class TripQueryConditionsFixture { - - public static TripQueryConditions emptySearchConditions() { - return TripQueryConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") - .build(); - } - - public static TripQueryConditions yearsSearchConditions(Set years) { - return TripQueryConditions.builder() - .years(years) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") - .build(); - } - - public static TripQueryConditions monthsSearchConditions(Set months) { - return TripQueryConditions.builder() - .years(Set.of()) - .months(months) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") - .build(); - } - - public static TripQueryConditions daysOfWeekSearchConditions(Set daysOfWeek) { - return TripQueryConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(daysOfWeek) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") - .build(); - } - - public static TripQueryConditions ageRangesSearchConditions(Set ageRanges) { - return TripQueryConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(ageRanges) - .genders(Set.of()) - .address("") - .build(); - } - - public static TripQueryConditions gendersSearchConditions(Set genders) { - return TripQueryConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(genders) - .address("") - .build(); - } - - public static TripQueryConditions addressSearchConditions(String address) { - return TripQueryConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address(address) - .build(); - } -} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java index d3d5e67f8..9cbcdf4e7 100644 --- a/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java @@ -8,77 +8,41 @@ public class TripSearchConditionsFixture { public static TripSearchConditions emptyTripSearchConditions() { return TripSearchConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") .build(); } public static TripSearchConditions yearsTripSearchConditions(Set years) { return TripSearchConditions.builder() .years(years) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") .build(); } public static TripSearchConditions monthsTripSearchConditions(Set months) { return TripSearchConditions.builder() - .years(Set.of()) .months(months) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") .build(); } public static TripSearchConditions daysOfWeekTripSearchConditions(Set daysOfWeek) { return TripSearchConditions.builder() - .years(Set.of()) - .months(Set.of()) .daysOfWeek(daysOfWeek) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") .build(); } public static TripSearchConditions ageRangesTripSearchConditions(Set ageRanges) { return TripSearchConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) .ageRanges(ageRanges) - .genders(Set.of()) - .address("") .build(); } public static TripSearchConditions gendersTripSearchConditions(Set genders) { return TripSearchConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) .genders(genders) - .address("") .build(); } public static TripSearchConditions addressTripSearchConditions(String address) { return TripSearchConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) .address(address) .build(); } diff --git a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java index 2f7e10c15..bd133613c 100644 --- a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java @@ -1,50 +1,34 @@ package dev.tripdraw.trip.acceptance; -import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.test.fixture.TestFixture.서울_2022_1_2_일; -import static dev.tripdraw.test.fixture.TestFixture.서울_2023_1_1_일; -import static dev.tripdraw.test.fixture.TestFixture.양양_2021_3_2_화; -import static dev.tripdraw.test.fixture.TestFixture.제주_2023_1_1_일; -import static dev.tripdraw.test.fixture.TestFixture.제주_2023_2_1_수; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.addressTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.daysOfWeekTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.emptyTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.monthsTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.yearsTripSearchConditions; -import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; -import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; -import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.springframework.http.HttpStatus.BAD_REQUEST; -import static org.springframework.http.HttpStatus.OK; -import static org.springframework.http.HttpStatus.UNAUTHORIZED; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; - import dev.tripdraw.auth.application.JwtTokenProvider; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.test.ControllerTest; -import dev.tripdraw.trip.dto.TripSearchConditions; -import dev.tripdraw.trip.dto.TripSearchPaging; -import dev.tripdraw.trip.dto.TripSearchRequest; -import dev.tripdraw.trip.dto.TripSearchResponse; -import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.*; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; -import java.util.List; -import java.util.Set; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; +import java.util.List; +import java.util.Set; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.TestFixture.*; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.*; +import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; +import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.UNAUTHORIZED; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class TripSearchAcceptanceTest extends ControllerTest { @@ -478,24 +462,6 @@ class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { }); } - @Test - void 조건이_유효하지_않을_경우_예외를_발생시킨다() { - // given - var tripSearchRequest = new TripSearchRequest( - monthsTripSearchConditions(Set.of(Integer.MAX_VALUE)), - nullLastViewedIdAnd10Limit - ); - - // expect - RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .statusCode(BAD_REQUEST.value()); - } - @Test void 인증에_실패할_경우_예외를_발생시킨다() { // given diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java index d3ec76e13..aea4bbf77 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java @@ -1,17 +1,10 @@ package dev.tripdraw.trip.application; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.times; - +import dev.tripdraw.test.fixture.TripSearchConditionsFixture; import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.dto.TripSearchConditions; import dev.tripdraw.trip.query.TripCustomRepository; import dev.tripdraw.trip.query.TripPaging; -import dev.tripdraw.trip.query.TripQueryConditions; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -20,6 +13,14 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ExtendWith(MockitoExtension.class) @@ -34,26 +35,19 @@ class TripQueryServiceTest { @Test void 쿼리_조건에_따라_여행을_조회한다() { // given - TripQueryConditions tripQueryConditions = new TripQueryConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - Set.of(), - "" - ); + TripSearchConditions tripSearchConditions = TripSearchConditionsFixture.emptyTripSearchConditions(); TripPaging tripPaging = new TripPaging(1L, 10); - given(tripCustomRepository.findAllByConditions(tripQueryConditions, tripPaging)) + given(tripCustomRepository.findAllByConditions(tripSearchConditions, tripPaging)) .willReturn(new ArrayList<>()); // when - List trips = tripQueryService.readAllByQueryConditions(tripQueryConditions, tripPaging); + List trips = tripQueryService.readAllByQueryConditions(tripSearchConditions, tripPaging); // then assertThat(trips).isEmpty(); then(tripCustomRepository) .should(times(1)) - .findAllByConditions(tripQueryConditions, tripPaging); + .findAllByConditions(tripSearchConditions, tripPaging); } } diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java deleted file mode 100644 index b2b9f99e7..000000000 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package dev.tripdraw.trip.domain; - -import static java.util.Set.of; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import dev.tripdraw.trip.exception.TripException; -import dev.tripdraw.trip.query.TripQueryConditions; -import java.util.Set; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -@SuppressWarnings("NonAsciiCharacters") -@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class TripQueryConditionsTest { - - @ParameterizedTest - @ValueSource(ints = {2009, 2024}) - void 연도가_2010_미만_2023_초과이면_예외를_던진다(int year) { - // given - Set years = of(year); - - // expect - assertThatThrownBy(() -> new TripQueryConditions(years, of(), of(), of(), of(), "")) - .isInstanceOf(TripException.class) - .hasMessage("유효하지 않은 여행 조회 조건입니다."); - } - - @ParameterizedTest - @ValueSource(ints = {0, 13}) - void 월이_1_미만_12_초과이면_예외를_던진다(int month) { - // given - Set months = of(month); - - // expect - assertThatThrownBy(() -> new TripQueryConditions(of(), months, of(), of(), of(), "")) - .isInstanceOf(TripException.class) - .hasMessage("유효하지 않은 여행 조회 조건입니다."); - } - - @ParameterizedTest - @ValueSource(ints = {0, 8}) - void 요일이_1_미만_7_초과이면_예외를_던진다(int dayOfWeek) { - // given - Set daysOfWeek = of(dayOfWeek); - - // expect - assertThatThrownBy(() -> new TripQueryConditions(of(), of(), daysOfWeek, of(), of(), "")) - .isInstanceOf(TripException.class) - .hasMessage("유효하지 않은 여행 조회 조건입니다."); - } - - @ParameterizedTest - @ValueSource(ints = {0, 11}) - void 연령대가_1_미만_10_초과이면_예외를_던진다(int ageRange) { - // given - Set ageRanges = of(ageRange); - - // expect - assertThatThrownBy(() -> new TripQueryConditions(of(), of(), of(), ageRanges, of(), "")) - .isInstanceOf(TripException.class) - .hasMessage("유효하지 않은 여행 조회 조건입니다."); - } - - @ParameterizedTest - @ValueSource(ints = {0, 3}) - void 성별이_1_미만_2_초과이면_예외를_던진다(int gender) { - // given - Set genders = of(gender); - - // expect - assertThatThrownBy(() -> new TripQueryConditions(genders, of(), of(), of(), of(), "")) - .isInstanceOf(TripException.class) - .hasMessage("유효하지 않은 여행 조회 조건입니다."); - } -} diff --git a/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java b/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java index 90b2c94e0..cc69dde71 100644 --- a/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java @@ -1,14 +1,5 @@ package dev.tripdraw.trip.query; -import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.test.fixture.TestFixture.위치정보; -import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.addressSearchConditions; -import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.daysOfWeekSearchConditions; -import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.emptySearchConditions; -import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.monthsSearchConditions; -import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.yearsSearchConditions; -import static org.assertj.core.api.Assertions.assertThat; - import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.domain.Post; @@ -16,19 +7,22 @@ import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; -import java.util.List; -import java.util.Set; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import dev.tripdraw.trip.dto.TripSearchConditions; +import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.Set; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.TestFixture.위치정보; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.*; +import static org.assertj.core.api.Assertions.assertThat; + @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @Transactional @@ -71,7 +65,7 @@ class 개수_제한이 { TripPaging tripPaging = new TripPaging(null, limit); // when - List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), tripPaging); + List trips = tripCustomRepository.findAllByConditions(emptyTripSearchConditions(), tripPaging); // then assertThat(trips).hasSize(expectedSize); @@ -86,7 +80,7 @@ class 개수_제한이 { TripPaging tripPaging = new TripPaging(null, limit); // when - List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), tripPaging); + List trips = tripCustomRepository.findAllByConditions(emptyTripSearchConditions(), tripPaging); // then assertThat(trips).hasSize(expectedSize); @@ -106,8 +100,10 @@ class 마지막으로_조회한_Id를 { Long lastViewedId = null; // when - List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), - new TripPaging(lastViewedId, 10)); + List trips = tripCustomRepository.findAllByConditions( + emptyTripSearchConditions(), + new TripPaging(lastViewedId, 10) + ); // then assertThat(trips).containsExactly( @@ -127,8 +123,10 @@ class 마지막으로_조회한_Id를 { Long lastViewedId = jeju2023_2_1_Wed.id(); // when - List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), - new TripPaging(lastViewedId, 10)); + List trips = tripCustomRepository.findAllByConditions( + emptyTripSearchConditions(), + new TripPaging(lastViewedId, 10) + ); // then assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun); @@ -146,11 +144,13 @@ class 조건으로_연도를 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023)); + TripSearchConditions tripSearchConditions = yearsTripSearchConditions(Set.of(2023)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(jeju2023_2_1_Wed, seoul2023_1_1_Sun, jeju2023_1_1_Sun); @@ -165,11 +165,13 @@ class 조건으로_연도를 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023, 2021)); + TripSearchConditions tripSearchConditions = yearsTripSearchConditions(Set.of(2023, 2021)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly( @@ -192,11 +194,13 @@ class 조건으로_월을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1)); + TripSearchConditions tripSearchConditions = monthsTripSearchConditions(Set.of(1)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); @@ -211,11 +215,13 @@ class 조건으로_월을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1, 3)); + TripSearchConditions tripSearchConditions = monthsTripSearchConditions(Set.of(1, 3)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly( @@ -238,11 +244,13 @@ class 조건으로_요일을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1)); + TripSearchConditions tripSearchConditions = daysOfWeekTripSearchConditions(Set.of(1)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); @@ -257,11 +265,13 @@ class 조건으로_요일을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1, 3)); + TripSearchConditions tripSearchConditions = daysOfWeekTripSearchConditions(Set.of(1, 3)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly( @@ -283,11 +293,13 @@ class 조건으로_주소를 { Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구 신천동"); + TripSearchConditions tripSearchConditions = addressTripSearchConditions("서울특별시 송파구 신천동"); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul_songpa_sincheon); @@ -300,11 +312,13 @@ class 조건으로_주소를 { Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구"); + TripSearchConditions tripSearchConditions = addressTripSearchConditions("서울특별시 송파구"); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); @@ -317,11 +331,13 @@ class 조건으로_주소를 { Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시"); + TripSearchConditions tripSearchConditions = addressTripSearchConditions("서울특별시"); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); @@ -340,18 +356,17 @@ class 조건을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = new TripQueryConditions( - Set.of(2023), - Set.of(1), - Set.of(), - Set.of(), - Set.of(), - "서울특별시" - ); + TripSearchConditions tripSearchConditions = TripSearchConditions.builder() + .years(Set.of(2023)) + .months(Set.of(1)) + .address("서울특별시") + .build(); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul2023_1_1_Sun); @@ -366,11 +381,13 @@ class 조건을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); Trip jeju_2023_2_1_Wed = jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = emptySearchConditions(); + TripSearchConditions tripSearchConditions = emptyTripSearchConditions(); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly( @@ -388,10 +405,13 @@ class 조건을 { // given emptyPostTrip(); - TripQueryConditions tripQueryConditions = emptySearchConditions(); + TripSearchConditions tripSearchConditions = emptyTripSearchConditions(); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).isEmpty(); From e1519e9a493641d904f22cf8806d16ccf68080e2 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Sat, 16 Sep 2023 18:15:56 +0900 Subject: [PATCH 098/119] =?UTF-8?q?[build]=20Querydsl=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/build.gradle b/backend/build.gradle index 6724178ae..b178d3561 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -57,9 +57,9 @@ dependencies { // querydsl implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' - annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" - annotationProcessor "jakarta.annotation:jakarta.annotation-api" - annotationProcessor "jakarta.persistence:jakarta.persistence-api" + annotationProcessor 'com.querydsl:querydsl-apt:5.0.0:jakarta' + annotationProcessor 'jakarta.annotation:jakarta.annotation-api' + annotationProcessor 'jakarta.persistence:jakarta.persistence-api' } processResources.dependsOn('copySecret') @@ -86,7 +86,7 @@ sourceSets { } tasks.withType(JavaCompile).configureEach { - options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir) + options.compilerArgs += ["-s", querydslDir] } clean.doLast { From f151e3a6821809c1b09f97064998e2cc6b209b83 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Tue, 19 Sep 2023 15:13:23 +0900 Subject: [PATCH 099/119] =?UTF-8?q?[chore]=20conflict=20=ED=95=B4=EA=B2=B0?= =?UTF-8?q?=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/common/domain/Paging.java | 7 + .../trip/domain/SearchConditions.java | 13 + .../trip/domain/TripCustomRepository.java | 9 + .../trip/domain/TripCustomRepositoryImpl.java | 72 ++++ .../tripdraw/trip/domain/TripRepository.java | 2 +- .../domain/RefreshTokenRepositoryTest.java | 3 +- .../tripdraw/common/domain/PagingTest.java | 26 ++ .../TripUpdateEventHandlerTest.java | 2 - .../member/domain/MemberRepositoryTest.java | 10 +- .../post/domain/PostRepositoryTest.java | 5 +- .../test/SearchConditionsTestFixture.java | 85 ++++ .../java/dev/tripdraw/test/TestFixture.java | 4 + .../trip/domain/PointRepositoryTest.java | 3 +- .../trip/domain/TripRepositoryTest.java | 405 +++++++++++++++++- 14 files changed, 614 insertions(+), 32 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/common/domain/Paging.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java create mode 100644 backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java create mode 100644 backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java diff --git a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java b/backend/src/main/java/dev/tripdraw/common/domain/Paging.java new file mode 100644 index 000000000..44873b535 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/common/domain/Paging.java @@ -0,0 +1,7 @@ +package dev.tripdraw.common.domain; + +public record Paging(Long lastViewedId, Integer limit) { + public boolean hasNextPage(int size) { + return size > limit; + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java new file mode 100644 index 000000000..1a47fa905 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java @@ -0,0 +1,13 @@ +package dev.tripdraw.trip.domain; + +import java.util.List; + +public record SearchConditions( + List years, + List months, + List daysOfWeek, + List ageRanges, + List genders, + String address +) { +} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java new file mode 100644 index 000000000..4f99ea52d --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java @@ -0,0 +1,9 @@ +package dev.tripdraw.trip.domain; + +import dev.tripdraw.common.domain.Paging; +import java.util.List; + +public interface TripCustomRepository { + + List findAllByConditions(SearchConditions searchConditions, Paging paging); +} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java new file mode 100644 index 000000000..6d98e01bf --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java @@ -0,0 +1,72 @@ +package dev.tripdraw.trip.domain; + +import static dev.tripdraw.post.domain.QPost.post; +import static dev.tripdraw.trip.domain.QPoint.point; +import static dev.tripdraw.trip.domain.QTrip.trip; + +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; +import dev.tripdraw.common.domain.Paging; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@RequiredArgsConstructor +@Repository +public class TripCustomRepositoryImpl implements TripCustomRepository { + + private final JPAQueryFactory query; + + @Override + public List findAllByConditions(SearchConditions searchConditions, Paging paging) { + return query + .selectFrom(trip) + .join(post).on(trip.id.eq(post.tripId)) + .join(point).on(post.point.id.eq(point.id)) + .where( + tripsBeforeLastViewedId(paging.lastViewedId()), + tripsRecordedAtYears(searchConditions.years()), + tripsRecordedAtMonths(searchConditions.months()), + tripsRecordedAtDaysOfWeek(searchConditions.daysOfWeek()), + tripsAddressed(searchConditions.address()) + ) + .orderBy(trip.id.desc()) + .limit(paging.limit() + 1) + .fetch(); + } + + private BooleanExpression tripsBeforeLastViewedId(Long lastViewedId) { + if (lastViewedId == null) { + return null; + } + return trip.id.lt(lastViewedId); + } + + private BooleanExpression tripsRecordedAtYears(List years) { + if (years.isEmpty()) { + return null; + } + return point.recordedAt.year().in(years); + } + + private BooleanExpression tripsRecordedAtMonths(List months) { + if (months.isEmpty()) { + return null; + } + return point.recordedAt.month().in(months); + } + + private BooleanExpression tripsRecordedAtDaysOfWeek(List daysOfWeek) { + if (daysOfWeek.isEmpty()) { + return null; + } + return point.recordedAt.dayOfWeek().in(daysOfWeek); + } + + private BooleanExpression tripsAddressed(String address) { + if (address.isEmpty()) { + return null; + } + return post.address.contains(address); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java index edb45c393..5dab56ecd 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java @@ -9,7 +9,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -public interface TripRepository extends JpaRepository { +public interface TripRepository extends JpaRepository, TripCustomRepository { List findAllByMemberId(Long memberId); diff --git a/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java index 8bb735174..71b40a828 100644 --- a/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/auth/domain/RefreshTokenRepositoryTest.java @@ -4,6 +4,7 @@ import dev.tripdraw.common.config.JpaConfig; import dev.tripdraw.common.config.QueryDslConfig; +import java.util.Optional; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -11,8 +12,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import java.util.Optional; - @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @DataJpaTest diff --git a/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java b/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java new file mode 100644 index 000000000..968b0bbc0 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java @@ -0,0 +1,26 @@ +package dev.tripdraw.common.domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +class PagingTest { + + @ParameterizedTest + @CsvSource({"19, false", "20, false", "21, true"}) + void 다음_페이지가_있는지_확인한다(int size, boolean expected) { + // given + Paging paging = new Paging(1L, 20); + + // when + boolean actual = paging.hasNextPage(size); + + // then + assertThat(actual).isEqualTo(expected); + } +} diff --git a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java index 6f4d8b140..c524e59ee 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java @@ -6,8 +6,6 @@ import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; -import dev.tripdraw.draw.application.RouteImageGenerator; -import dev.tripdraw.draw.application.TripUpdateEventHandler; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java index f2745c7af..576b80ea8 100644 --- a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java @@ -1,10 +1,5 @@ package dev.tripdraw.member.domain; -import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import dev.tripdraw.common.config.JpaConfig; import dev.tripdraw.common.config.QueryDslConfig; import dev.tripdraw.member.exception.MemberException; @@ -17,6 +12,11 @@ import java.util.Optional; +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @DataJpaTest diff --git a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java index 28d3a3144..f795e8f36 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java @@ -14,6 +14,8 @@ import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripName; import dev.tripdraw.trip.domain.TripRepository; +import java.time.LocalDateTime; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -22,9 +24,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import java.time.LocalDateTime; -import java.util.List; - @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @DataJpaTest diff --git a/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java b/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java new file mode 100644 index 000000000..61c7b52a7 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java @@ -0,0 +1,85 @@ +package dev.tripdraw.test; + +import dev.tripdraw.trip.domain.SearchConditions; +import java.util.List; + + +public class SearchConditionsTestFixture { + + public static SearchConditions emptySearchConditions() { + return new SearchConditions( + List.of(), + List.of(), + List.of(), + List.of(), + List.of(), + "" + ); + } + + public static SearchConditions yearsSearchConditions(List years) { + return new SearchConditions( + years, + List.of(), + List.of(), + List.of(), + List.of(), + "" + ); + } + + public static SearchConditions monthsSearchConditions(List months) { + return new SearchConditions( + List.of(), + months, + List.of(), + List.of(), + List.of(), + "" + ); + } + + public static SearchConditions daysOfWeekSearchConditions(List daysOfWeek) { + return new SearchConditions( + List.of(), + List.of(), + daysOfWeek, + List.of(), + List.of(), + "" + ); + } + + public static SearchConditions ageRangesSearchConditions(List ageRanges) { + return new SearchConditions( + List.of(), + List.of(), + List.of(), + ageRanges, + List.of(), + "" + ); + } + + public static SearchConditions gendersSearchConditions(List genders) { + return new SearchConditions( + List.of(), + List.of(), + List.of(), + List.of(), + genders, + "" + ); + } + + public static SearchConditions addressSearchConditions(String address) { + return new SearchConditions( + List.of(), + List.of(), + List.of(), + List.of(), + List.of(), + address + ); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/TestFixture.java index 924049ed2..434233c23 100644 --- a/backend/src/test/java/dev/tripdraw/test/TestFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/TestFixture.java @@ -20,6 +20,10 @@ public class TestFixture { return new Point(1L, 1.1, 2.2, false, LocalDateTime.now(), 여행()); } + public static Point 위치정보(int year, int month, int dayOfMonth, int hour, int minute) { + return new Point(1.1, 2.2, LocalDateTime.of(year, month, dayOfMonth, hour, minute)); + } + public static Trip 여행() { return new Trip(1L, TripName.from("통후추"), 사용자(), TripStatus.ONGOING, "", ""); } diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java index db8b2fc55..541138ac7 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java @@ -10,6 +10,7 @@ import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.exception.TripException; +import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -18,8 +19,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import java.time.LocalDateTime; - @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @DataJpaTest diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index 607af9f84..d6ea61727 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -1,6 +1,12 @@ package dev.tripdraw.trip.domain; import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.SearchConditionsTestFixture.addressSearchConditions; +import static dev.tripdraw.test.SearchConditionsTestFixture.daysOfWeekSearchConditions; +import static dev.tripdraw.test.SearchConditionsTestFixture.emptySearchConditions; +import static dev.tripdraw.test.SearchConditionsTestFixture.monthsSearchConditions; +import static dev.tripdraw.test.SearchConditionsTestFixture.yearsSearchConditions; +import static dev.tripdraw.test.TestFixture.위치정보; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -8,20 +14,25 @@ import dev.tripdraw.common.config.JpaConfig; import dev.tripdraw.common.config.QueryDslConfig; +import dev.tripdraw.common.domain.Paging; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.exception.TripException; +import java.time.LocalDateTime; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import java.time.LocalDateTime; -import java.util.List; - @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @DataJpaTest @@ -31,6 +42,9 @@ class TripRepositoryTest { @Autowired private TripRepository tripRepository; + @Autowired + private PostRepository postRepository; + @Autowired private MemberRepository memberRepository; @@ -99,20 +113,6 @@ void setUp() { assertThat(tripRepository.findById(trip.id())).isEmpty(); } - @Test - void 회원_ID로_모든_여행을_삭제한다() { - // given - Trip trip = new Trip(TripName.from("제주도 여행"), member); - tripRepository.save(trip); - tripRepository.save(new Trip(TripName.from("제주도 여행"), member)); - - // when - tripRepository.deleteByMemberId(member.id()); - - // then - assertThat(tripRepository.findById(trip.id())).isEmpty(); - } - @Test void 여행_ID로_여행을_조회한다() { // given @@ -135,4 +135,375 @@ void setUp() { .isInstanceOf(TripException.class) .hasMessage(TRIP_NOT_FOUND.message()); } + + @Nested + class 조건에_따라_여행을_조회할_때 { + + @Nested + class 개수_제한을_입력하면 { + + @ParameterizedTest + @CsvSource({"0, 1", "1, 2", "2, 3"}) + void 개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { + // given + jeju_2023_1_1_Sun(); + jeju_2023_1_1_Sun(); + jeju_2023_1_1_Sun(); + + Paging paging = new Paging(null, limit); + + // when + List trips = tripRepository.findAllByConditions(emptySearchConditions(), paging); + + // then + assertThat(trips).hasSize(expectedSize); + } + } + + @Nested + class 마지막으로_조회한_Id를 { + + @Test + void 입력하지_않으면_가장_최신_여행부터_내림차순으로_반환한다() { + // given + Trip jeju_2023_1_1_sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + Long lastViewedId = null; + + // when + List trips = tripRepository.findAllByConditions(emptySearchConditions(), + new Paging(lastViewedId, 10)); + + // then + assertThat(trips).containsExactly( + jeju2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju_2023_1_1_sun + ); + } + + @Test + void 입력하면_해당_Id_이하의_최신_여행을_내림차순으로_반환한다() { + // given + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + Long lastViewedId = jeju2023_2_1_Wed.id(); + + // when + List trips = tripRepository.findAllByConditions(emptySearchConditions(), + new Paging(lastViewedId, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun); + } + } + + @Nested + class 조건으로_연도를 { + + @Test + void 한_개_설정하면_해당_연도의_여행을_반환한다() { + // given + seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = yearsSearchConditions(List.of(2023)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(jeju2023_2_1_Wed, seoul2023_1_1_Sun, jeju2023_1_1_Sun); + } + + @Test + void 여러_개_설정하면_해당_연도들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = yearsSearchConditions(List.of(2023, 2021)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly( + jeju2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_월을 { + + @Test + void 한_개_설정하면_해당_월의_여행을_반환한다() { + // given + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = monthsSearchConditions(List.of(1)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); + } + + @Test + void 여러_개_설정하면_해당_월들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = monthsSearchConditions(List.of(1, 3)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly( + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_요일을 { + + @Test + void 한_개_설정하면_해당_요일의_여행을_반환한다() { + // given + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = daysOfWeekSearchConditions(List.of(1)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); + } + + @Test + void 여러_개_설정하면_해당_요일들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = daysOfWeekSearchConditions(List.of(1, 3)); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly( + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_주소를 { + + @Test + void 시도_시군구_읍면동_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + SearchConditions searchConditions = addressSearchConditions("서울특별시 송파구 신천동"); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon); + } + + @Test + void 시도_시군구_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + SearchConditions searchConditions = addressSearchConditions("서울특별시 송파구"); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); + } + + @Test + void 시도_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + SearchConditions searchConditions = addressSearchConditions("서울특별시"); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); + } + } + + @Nested + class 조건을 { + + @Test + void 여러_개_설정하면_해당하는_여행을_반환한다() { + // given + yangyang_2021_3_2_Tue(); + seoul_2022_1_2_Sun(); + jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = new SearchConditions( + List.of(2023), + List.of(1), + List.of(), + List.of(), + List.of(), + "서울특별시" + ); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun); + } + + @Test + void 설정하지_않으면_모든_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju_2023_2_1_Wed = jeju_2023_2_1_Wed(); + + SearchConditions searchConditions = emptySearchConditions(); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).containsExactly( + jeju_2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Test + void 감상이_없는_여행은_조회되지_않는다() { + // given + emptyPostTrip(); + + SearchConditions searchConditions = emptySearchConditions(); + + // when + List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); + + // then + assertThat(trips).isEmpty(); + } + + private Trip jeju_2023_2_1_Wed() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2023, 2, 1, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); + return trip; + } + + private Trip seoul_2023_1_1_Sun() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2023, 1, 1, 10, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "서울특별시 송파구 신천동", "", member, trip.id())); + return trip; + } + + private Trip jeju_2023_1_1_Sun() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2023, 1, 1, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); + return trip; + } + + private Trip seoul_2022_1_2_Sun() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2022, 1, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "서울특별시 송파구 방이동", "", member, trip.id())); + return trip; + } + + private Trip yangyang_2021_3_2_Tue() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2021, 3, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "강원도 양양군", "", member, trip.id())); + return trip; + } + + private Trip emptyPostTrip() { + Trip trip = new Trip(TripName.from(""), member); + Point point = 위치정보(2021, 3, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + return trip; + } + } } From 57b0b1bcb7a20fef7a85b3bc04c78bd1cc3f7644 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Sun, 17 Sep 2023 03:04:47 +0900 Subject: [PATCH 100/119] =?UTF-8?q?[feat]=20=EA=B0=90=EC=83=81=EC=9D=B4=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EC=97=AC=ED=96=89=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=EC=B6=94=EA=B0=80=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/common/domain/Paging.java | 11 + .../dev/tripdraw/common/dto/SearchPaging.java | 9 + .../trip/application/TripService.java | 24 +- .../trip/domain/SearchConditions.java | 69 +- .../trip/domain/TripCustomRepositoryImpl.java | 9 +- .../trip/dto/TripSearchConditions.java | 25 + .../tripdraw/trip/dto/TripSearchRequest.java | 9 + .../tripdraw/trip/dto/TripSearchResponse.java | 22 +- .../trip/dto/TripSearchResponseOfMember.java | 31 + .../trip/dto/TripsSearchResponse.java | 15 +- .../trip/dto/TripsSearchResponseOfMember.java | 20 + .../trip/exception/TripExceptionType.java | 1 + .../trip/presentation/TripController.java | 30 +- .../tripdraw/common/domain/PagingTest.java | 13 + ...PostCreateEventHandlerIntegrationTest.java | 4 +- .../PostCreateEventHandlerTest.java | 4 +- ...TripUpdateEventHandlerIntegrationTest.java | 3 +- .../TripUpdateEventHandlerTest.java | 2 +- .../test/SearchConditionsTestFixture.java | 85 --- .../java/dev/tripdraw/test/TestFixture.java | 34 - .../test/fixture/SearchConditionsFixture.java | 85 +++ .../tripdraw/test/fixture/TestFixture.java | 124 ++++ .../fixture/TripSearchConditionsFixture.java | 84 +++ .../java/dev/tripdraw/test/step/PostStep.java | 30 + .../java/dev/tripdraw/test/step/TripStep.java | 62 ++ .../trip/application/TripServiceTest.java | 61 +- .../trip/domain/SearchConditionsTest.java | 76 +++ .../trip/domain/TripRepositoryTest.java | 54 +- ...va => TripSearchResponseOfMemberTest.java} | 6 +- .../trip/presentation/TripControllerTest.java | 622 +++++++++++++++--- 30 files changed, 1347 insertions(+), 277 deletions(-) create mode 100644 backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponseOfMember.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponseOfMember.java delete mode 100644 backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java delete mode 100644 backend/src/test/java/dev/tripdraw/test/TestFixture.java create mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java create mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java create mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java create mode 100644 backend/src/test/java/dev/tripdraw/test/step/PostStep.java create mode 100644 backend/src/test/java/dev/tripdraw/test/step/TripStep.java create mode 100644 backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java rename backend/src/test/java/dev/tripdraw/trip/dto/{TripSearchResponseTest.java => TripSearchResponseOfMemberTest.java} (82%) diff --git a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java b/backend/src/main/java/dev/tripdraw/common/domain/Paging.java index 44873b535..36b72a8de 100644 --- a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java +++ b/backend/src/main/java/dev/tripdraw/common/domain/Paging.java @@ -1,6 +1,17 @@ package dev.tripdraw.common.domain; public record Paging(Long lastViewedId, Integer limit) { + private static final int LIMIT_MAXIMUM = 100; + + public Paging(Long lastViewedId, Integer limit) { + this.lastViewedId = lastViewedId; + this.limit = ceil(limit); + } + + private int ceil(Integer limit) { + return Math.min(limit, LIMIT_MAXIMUM); + } + public boolean hasNextPage(int size) { return size > limit; } diff --git a/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java b/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java new file mode 100644 index 000000000..989ce5da8 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java @@ -0,0 +1,9 @@ +package dev.tripdraw.common.dto; + +import dev.tripdraw.common.domain.Paging; + +public record SearchPaging(Long lastViewedId, Integer limit) { + public Paging toPaging() { + return new Paging(lastViewedId, limit); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index 284fef946..f9a79b3d7 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -1,10 +1,12 @@ package dev.tripdraw.trip.application; import dev.tripdraw.common.auth.LoginUser; +import dev.tripdraw.common.domain.Paging; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.PointRepository; +import dev.tripdraw.trip.domain.SearchConditions; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; @@ -13,8 +15,10 @@ import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; @@ -68,10 +72,26 @@ public TripResponse readTripById(LoginUser loginUser, Long id) { } @Transactional(readOnly = true) - public TripsSearchResponse readAllTrips(LoginUser loginUser) { + public TripsSearchResponseOfMember readAllTripsOf(LoginUser loginUser) { Member member = memberRepository.getById(loginUser.memberId()); List trips = tripRepository.findAllByMemberId(member.id()); - return TripsSearchResponse.from(trips); + return TripsSearchResponseOfMember.from(trips); + } + + @Transactional(readOnly = true) + public TripsSearchResponse readAllTrips(TripSearchRequest tripSearchRequest) { + SearchConditions searchConditions = tripSearchRequest.condition().toSearchConditions(); + Paging paging = tripSearchRequest.paging().toPaging(); + + List trips = tripRepository.findAllByConditions( + searchConditions, + paging + ); + + if (paging.hasNextPage(trips.size())) { + return TripsSearchResponse.of(trips.subList(0, paging.limit()), true); + } + return TripsSearchResponse.of(trips, false); } public void updateTripById(LoginUser loginUser, Long tripId, TripUpdateRequest tripUpdateRequest) { diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java index 1a47fa905..fee25962e 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java @@ -1,13 +1,70 @@ package dev.tripdraw.trip.domain; -import java.util.List; +import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; + +import dev.tripdraw.trip.exception.TripException; +import java.util.HashSet; +import java.util.Set; public record SearchConditions( - List years, - List months, - List daysOfWeek, - List ageRanges, - List genders, + Set years, + Set months, + Set daysOfWeek, + Set ageRanges, + Set genders, String address ) { + + private static final int YEAR_MINIMUM = 2010; + private static final int YEAR_MAXIMUM = 2023; + private static final int MONTH_MINIMUM = 1; + private static final int MONTH_MAXIMUM = 12; + private static final int DAYS_OF_WEEK_MINIMUM = 1; + private static final int DAYS_OF_WEEK_MAXIMUM = 7; + private static final int AGE_RANGE_MINIMUM = 1; + private static final int AGE_RANGE_MAXIMUM = 10; + private static final int GENDER_MINIMUM = 1; + private static final int GENDER_MAXIMUM = 2; + + public SearchConditions( + Set years, + Set months, + Set daysOfWeek, + Set ageRanges, + Set genders, + String address + ) { + validate(years, months, daysOfWeek, ageRanges, genders); + this.years = new HashSet<>(years); + this.months = new HashSet<>(months); + this.daysOfWeek = new HashSet<>(daysOfWeek); + this.ageRanges = new HashSet<>(ageRanges); + this.genders = new HashSet<>(genders); + this.address = address; + } + + private void validate( + Set years, + Set months, + Set daysOfWeek, + Set ageRanges, + Set genders + ) { + validateRange(years, YEAR_MINIMUM, YEAR_MAXIMUM); + validateRange(months, MONTH_MINIMUM, MONTH_MAXIMUM); + validateRange(daysOfWeek, DAYS_OF_WEEK_MINIMUM, DAYS_OF_WEEK_MAXIMUM); + validateRange(ageRanges, AGE_RANGE_MINIMUM, AGE_RANGE_MAXIMUM); + validateRange(genders, GENDER_MINIMUM, GENDER_MAXIMUM); + } + + private void validateRange(Set conditions, int min, int max) { + if (isOutOfRange(conditions, min, max)) { + throw new TripException(INVALID_TRIP_SEARCH); + } + } + + private boolean isOutOfRange(Set conditions, int min, int max) { + return conditions.stream() + .anyMatch(condition -> condition < min || condition > max); + } } diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java index 6d98e01bf..17d4111ec 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java @@ -8,6 +8,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import dev.tripdraw.common.domain.Paging; import java.util.List; +import java.util.Set; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -42,21 +43,21 @@ private BooleanExpression tripsBeforeLastViewedId(Long lastViewedId) { return trip.id.lt(lastViewedId); } - private BooleanExpression tripsRecordedAtYears(List years) { + private BooleanExpression tripsRecordedAtYears(Set years) { if (years.isEmpty()) { return null; } return point.recordedAt.year().in(years); } - private BooleanExpression tripsRecordedAtMonths(List months) { + private BooleanExpression tripsRecordedAtMonths(Set months) { if (months.isEmpty()) { return null; } return point.recordedAt.month().in(months); } - private BooleanExpression tripsRecordedAtDaysOfWeek(List daysOfWeek) { + private BooleanExpression tripsRecordedAtDaysOfWeek(Set daysOfWeek) { if (daysOfWeek.isEmpty()) { return null; } @@ -67,6 +68,6 @@ private BooleanExpression tripsAddressed(String address) { if (address.isEmpty()) { return null; } - return post.address.contains(address); + return post.address.like(address + "%"); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java new file mode 100644 index 000000000..2bce1ca89 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java @@ -0,0 +1,25 @@ +package dev.tripdraw.trip.dto; + +import dev.tripdraw.trip.domain.SearchConditions; +import java.util.Set; + +public record TripSearchConditions( + Set years, + Set months, + Set daysOfWeek, + Set ageRanges, + Set genders, + String address +) { + + public SearchConditions toSearchConditions() { + return new SearchConditions( + years, + months, + daysOfWeek, + ageRanges, + genders, + address + ); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java new file mode 100644 index 000000000..842ee87e1 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java @@ -0,0 +1,9 @@ +package dev.tripdraw.trip.dto; + +import dev.tripdraw.common.dto.SearchPaging; + +public record TripSearchRequest( + TripSearchConditions condition, + SearchPaging paging +) { +} diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java index c388137f4..02ac94e1d 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java @@ -1,31 +1,25 @@ package dev.tripdraw.trip.dto; import dev.tripdraw.trip.domain.Trip; -import io.swagger.v3.oas.annotations.media.Schema; -import java.util.Objects; +import java.time.LocalDateTime; public record TripSearchResponse( - @Schema(description = "여행 Id", example = "1") Long tripId, - - @Schema(description = "여행명", example = "통후추의 여행") String name, - - @Schema(description = "이미지 주소", example = "https://tripdraw.site/post-images/cd678ca2-30d5-11ee-be56-0242ac120002.jpg") String imageUrl, - - @Schema(description = "경로 이미지 주소", example = "https://tripdraw.site/route-images/cd678ca2-30d5-11ee-be56-0242ac120002.png") - String routeImageUrl + String routeImageUrl, + LocalDateTime startTime, + LocalDateTime endTime ) { - private static final String EMPTY_IMAGE_URL = ""; - public static TripSearchResponse from(Trip trip) { return new TripSearchResponse( trip.id(), trip.nameValue(), - Objects.requireNonNullElse(trip.imageUrl(), EMPTY_IMAGE_URL), - Objects.requireNonNullElse(trip.routeImageUrl(), EMPTY_IMAGE_URL) + trip.imageUrl(), + trip.routeImageUrl(), + trip.createdAt(), + trip.updatedAt() ); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponseOfMember.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponseOfMember.java new file mode 100644 index 000000000..a801c6f9f --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponseOfMember.java @@ -0,0 +1,31 @@ +package dev.tripdraw.trip.dto; + +import dev.tripdraw.trip.domain.Trip; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.Objects; + +public record TripSearchResponseOfMember( + @Schema(description = "여행 Id", example = "1") + Long tripId, + + @Schema(description = "여행명", example = "통후추의 여행") + String name, + + @Schema(description = "이미지 주소", example = "https://tripdraw.site/post-images/cd678ca2-30d5-11ee-be56-0242ac120002.jpg") + String imageUrl, + + @Schema(description = "경로 이미지 주소", example = "https://tripdraw.site/route-images/cd678ca2-30d5-11ee-be56-0242ac120002.png") + String routeImageUrl +) { + + private static final String EMPTY_IMAGE_URL = ""; + + public static TripSearchResponseOfMember from(Trip trip) { + return new TripSearchResponseOfMember( + trip.id(), + trip.nameValue(), + Objects.requireNonNullElse(trip.imageUrl(), EMPTY_IMAGE_URL), + Objects.requireNonNullElse(trip.routeImageUrl(), EMPTY_IMAGE_URL) + ); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java index 5d7e375e0..0f08a8057 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponse.java @@ -1,20 +1,17 @@ package dev.tripdraw.trip.dto; -import static java.util.stream.Collectors.collectingAndThen; -import static java.util.stream.Collectors.toList; - import dev.tripdraw.trip.domain.Trip; -import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; public record TripsSearchResponse( - @Schema(description = "여행 목록") - List trips + List trips, + boolean hasNextPage ) { - public static TripsSearchResponse from(List trips) { - return trips.stream() + public static TripsSearchResponse of(List trips, boolean hasNextPage) { + List tripsSearchResponse = trips.stream() .map(TripSearchResponse::from) - .collect(collectingAndThen(toList(), TripsSearchResponse::new)); + .toList(); + return new TripsSearchResponse(tripsSearchResponse, hasNextPage); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponseOfMember.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponseOfMember.java new file mode 100644 index 000000000..ab48cb05b --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripsSearchResponseOfMember.java @@ -0,0 +1,20 @@ +package dev.tripdraw.trip.dto; + +import static java.util.stream.Collectors.collectingAndThen; +import static java.util.stream.Collectors.toList; + +import dev.tripdraw.trip.domain.Trip; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; + +public record TripsSearchResponseOfMember( + @Schema(description = "여행 목록") + List trips +) { + + public static TripsSearchResponseOfMember from(List trips) { + return trips.stream() + .map(TripSearchResponseOfMember::from) + .collect(collectingAndThen(toList(), TripsSearchResponseOfMember::new)); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java b/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java index d4b03778d..1d057f31d 100644 --- a/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/trip/exception/TripExceptionType.java @@ -16,6 +16,7 @@ public enum TripExceptionType implements ExceptionType { TRIP_INVALID_STATUS(BAD_REQUEST, "잘못된 여행 상태입니다."), POINT_ALREADY_HAS_POST(CONFLICT, "이미 감상이 등록된 위치입니다."), TRIP_ALREADY_DELETED(CONFLICT, "이미 삭제된 여행입니다."), + INVALID_TRIP_SEARCH(BAD_REQUEST, "유효하지 않은 여행 조회 조건입니다."), ; private final HttpStatus httpStatus; diff --git a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java index 66fe49b84..08a9f8f7d 100644 --- a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java +++ b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java @@ -12,8 +12,10 @@ import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; @@ -76,10 +78,10 @@ public ResponseEntity readPointById( return ResponseEntity.ok(response); } - @Operation(summary = "여행 조회 API", description = "단일 여행의 정보를 조회합니다.") + @Operation(summary = "나의 여행 조회 API", description = "회원 한 명의 단일 여행 정보를 조회합니다.") @ApiResponse( responseCode = "200", - description = "여행 조회 성공." + description = "나의 여행 조회 성공." ) @GetMapping("/trips/{tripId}") public ResponseEntity readById(@Auth LoginUser loginUser, @PathVariable Long tripId) { @@ -102,17 +104,31 @@ public ResponseEntity deletePoint( return ResponseEntity.noContent().build(); } - @Operation(summary = "여행 전체 조회 API", description = "모든 여행의 정보를 조회합니다.") + @Operation(summary = "나의 여행 전체 조회 API", description = "회원 한 명의 모든 여행 정보를 조회합니다.") @ApiResponse( responseCode = "200", - description = "여행 전체 조회 성공." + description = "나의 여행 전체 조회 성공." ) - @GetMapping("/trips") - public ResponseEntity readAll(@Auth LoginUser loginUser) { - TripsSearchResponse response = tripService.readAllTrips(loginUser); + @GetMapping("/trips/mine") + public ResponseEntity readAllOf(@Auth LoginUser loginUser) { + TripsSearchResponseOfMember response = tripService.readAllTripsOf(loginUser); return ResponseEntity.ok(response); } + @Operation(summary = "모든 회원 여행 전체 조회 API", description = "모든 회원의 여행 정보를 조건에 따라 조회합니다.") + @ApiResponse( + responseCode = "200", + description = "모든 회원 여행 전체 조회 성공." + ) + @GetMapping("/trips") + public ResponseEntity readAll( + @Auth LoginUser loginUser, + @RequestBody TripSearchRequest tripSearchRequest + ) { + TripsSearchResponse tripsSearchResponse = tripService.readAllTrips(tripSearchRequest); + return ResponseEntity.ok(tripsSearchResponse); + } + @Operation(summary = "여행 이름 수정 및 종료 API", description = "여행 이름을 수정하고, 여행을 종료합니다.") @ApiResponse( responseCode = "204", diff --git a/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java b/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java index 968b0bbc0..4c34fe304 100644 --- a/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java +++ b/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -23,4 +24,16 @@ class PagingTest { // then assertThat(actual).isEqualTo(expected); } + + @Test + void limit이_100을_넘기면_100으로_조정된다() { + // given + int limit = 101; + + // when + Paging paging = new Paging(1L, limit); + + // then + assertThat(paging.limit()).isEqualTo(100); + } } diff --git a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java index 6665d0ce7..e33f0391b 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerIntegrationTest.java @@ -1,7 +1,7 @@ package dev.tripdraw.draw.application; -import static dev.tripdraw.test.TestFixture.감상; -import static dev.tripdraw.test.TestFixture.여행; +import static dev.tripdraw.test.fixture.TestFixture.감상; +import static dev.tripdraw.test.fixture.TestFixture.여행; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; diff --git a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java index 88e722a97..d9323942c 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/PostCreateEventHandlerTest.java @@ -1,7 +1,7 @@ package dev.tripdraw.draw.application; -import static dev.tripdraw.test.TestFixture.감상; -import static dev.tripdraw.test.TestFixture.여행; +import static dev.tripdraw.test.fixture.TestFixture.감상; +import static dev.tripdraw.test.fixture.TestFixture.여행; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; diff --git a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerIntegrationTest.java b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerIntegrationTest.java index dbbd7cae9..78523cbe2 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerIntegrationTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerIntegrationTest.java @@ -1,12 +1,11 @@ package dev.tripdraw.draw.application; -import static dev.tripdraw.test.TestFixture.여행; +import static dev.tripdraw.test.fixture.TestFixture.여행; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.timeout; -import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java index c524e59ee..45bdc12c8 100644 --- a/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java +++ b/backend/src/test/java/dev/tripdraw/draw/application/TripUpdateEventHandlerTest.java @@ -1,6 +1,6 @@ package dev.tripdraw.draw.application; -import static dev.tripdraw.test.TestFixture.여행; +import static dev.tripdraw.test.fixture.TestFixture.여행; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; diff --git a/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java b/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java deleted file mode 100644 index 61c7b52a7..000000000 --- a/backend/src/test/java/dev/tripdraw/test/SearchConditionsTestFixture.java +++ /dev/null @@ -1,85 +0,0 @@ -package dev.tripdraw.test; - -import dev.tripdraw.trip.domain.SearchConditions; -import java.util.List; - - -public class SearchConditionsTestFixture { - - public static SearchConditions emptySearchConditions() { - return new SearchConditions( - List.of(), - List.of(), - List.of(), - List.of(), - List.of(), - "" - ); - } - - public static SearchConditions yearsSearchConditions(List years) { - return new SearchConditions( - years, - List.of(), - List.of(), - List.of(), - List.of(), - "" - ); - } - - public static SearchConditions monthsSearchConditions(List months) { - return new SearchConditions( - List.of(), - months, - List.of(), - List.of(), - List.of(), - "" - ); - } - - public static SearchConditions daysOfWeekSearchConditions(List daysOfWeek) { - return new SearchConditions( - List.of(), - List.of(), - daysOfWeek, - List.of(), - List.of(), - "" - ); - } - - public static SearchConditions ageRangesSearchConditions(List ageRanges) { - return new SearchConditions( - List.of(), - List.of(), - List.of(), - ageRanges, - List.of(), - "" - ); - } - - public static SearchConditions gendersSearchConditions(List genders) { - return new SearchConditions( - List.of(), - List.of(), - List.of(), - List.of(), - genders, - "" - ); - } - - public static SearchConditions addressSearchConditions(String address) { - return new SearchConditions( - List.of(), - List.of(), - List.of(), - List.of(), - List.of(), - address - ); - } -} diff --git a/backend/src/test/java/dev/tripdraw/test/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/TestFixture.java deleted file mode 100644 index 434233c23..000000000 --- a/backend/src/test/java/dev/tripdraw/test/TestFixture.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.tripdraw.test; - -import dev.tripdraw.common.auth.OauthType; -import dev.tripdraw.member.domain.Member; -import dev.tripdraw.post.domain.Post; -import dev.tripdraw.trip.domain.Point; -import dev.tripdraw.trip.domain.Trip; -import dev.tripdraw.trip.domain.TripName; -import dev.tripdraw.trip.domain.TripStatus; -import java.time.LocalDateTime; - -@SuppressWarnings("NonAsciiCharacters") -public class TestFixture { - - public static Member 사용자() { - return new Member(1L, "통후추", "", OauthType.KAKAO); - } - - public static Point 위치정보() { - return new Point(1L, 1.1, 2.2, false, LocalDateTime.now(), 여행()); - } - - public static Point 위치정보(int year, int month, int dayOfMonth, int hour, int minute) { - return new Point(1.1, 2.2, LocalDateTime.of(year, month, dayOfMonth, hour, minute)); - } - - public static Trip 여행() { - return new Trip(1L, TripName.from("통후추"), 사용자(), TripStatus.ONGOING, "", ""); - } - - public static Post 감상() { - return new Post("감상 제목", 위치정보(), "주소", "감상", 사용자(), 1L); - } -} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java new file mode 100644 index 000000000..c5e4c8d91 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java @@ -0,0 +1,85 @@ +package dev.tripdraw.test.fixture; + +import dev.tripdraw.trip.domain.SearchConditions; +import java.util.Set; + + +public class SearchConditionsFixture { + + public static SearchConditions emptySearchConditions() { + return new SearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static SearchConditions yearsSearchConditions(Set years) { + return new SearchConditions( + years, + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static SearchConditions monthsSearchConditions(Set months) { + return new SearchConditions( + Set.of(), + months, + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static SearchConditions daysOfWeekSearchConditions(Set daysOfWeek) { + return new SearchConditions( + Set.of(), + Set.of(), + daysOfWeek, + Set.of(), + Set.of(), + "" + ); + } + + public static SearchConditions ageRangesSearchConditions(Set ageRanges) { + return new SearchConditions( + Set.of(), + Set.of(), + Set.of(), + ageRanges, + Set.of(), + "" + ); + } + + public static SearchConditions gendersSearchConditions(Set genders) { + return new SearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + genders, + "" + ); + } + + public static SearchConditions addressSearchConditions(String address) { + return new SearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + address + ); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java new file mode 100644 index 000000000..8f5c37aed --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java @@ -0,0 +1,124 @@ +package dev.tripdraw.test.fixture; + +import static dev.tripdraw.trip.domain.TripStatus.FINISHED; + +import dev.tripdraw.common.auth.OauthType; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.dto.PostAndPointCreateRequest; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripName; +import dev.tripdraw.trip.domain.TripStatus; +import dev.tripdraw.trip.dto.PointCreateRequest; +import dev.tripdraw.trip.dto.TripUpdateRequest; +import java.time.LocalDateTime; + +@SuppressWarnings("NonAsciiCharacters") +public class TestFixture { + + public static Member 사용자() { + return new Member(1L, "통후추", "", OauthType.KAKAO); + } + + public static Point 위치정보() { + return new Point(1L, 1.1, 2.2, false, LocalDateTime.now(), 여행()); + } + + public static Point 위치정보(int year, int month, int dayOfMonth, int hour, int minute) { + return new Point(1.1, 2.2, LocalDateTime.of(year, month, dayOfMonth, hour, minute)); + } + + public static Trip 여행() { + return new Trip(1L, TripName.from("통후추"), 사용자(), TripStatus.ONGOING, "", ""); + } + + public static Post 감상() { + return new Post("감상 제목", 위치정보(), "주소", "감상", 사용자(), 1L); + } + + public static PointCreateRequest pointCreateRequest(Long tripId) { + return new PointCreateRequest( + tripId, + 1.1, + 2.2, + LocalDateTime.of(2023, 7, 18, 20, 24) + ); + } + + public static TripUpdateRequest tripUpdateRequest() { + return new TripUpdateRequest("제주도 여행", FINISHED); + } + + public static PostAndPointCreateRequest postAndPointCreateRequest(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "우도의 바닷가", + "제주특별자치도 제주시 애월읍 소길리", + "우도에서 땅콩 아이스크림을 먹었다.\\n너무 맛있었다.", + 1.1, + 2.2, + LocalDateTime.of(2023, 7, 18, 20, 24) + ); + } + + public static PostAndPointCreateRequest 제주_2023_2_1_수(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "제목", + "제주특별자치도 제주시 애월읍", + "내용", + 0.0, + 0.0, + LocalDateTime.of(2023, 2, 1, 1, 1) + ); + } + + public static PostAndPointCreateRequest 서울_2023_1_1_일(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "제목", + "seoul_songpa_sincheon", + "내용", + 0.0, + 0.0, + LocalDateTime.of(2023, 1, 1, 10, 1) + ); + } + + public static PostAndPointCreateRequest 제주_2023_1_1_일(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "제목", + "제주특별자치도 제주시 애월읍", + "내용", + 0.0, + 0.0, + LocalDateTime.of(2023, 1, 1, 1, 1) + ); + } + + public static PostAndPointCreateRequest 서울_2022_1_2_일(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "제목", + "seoul_songpa_Bangi", + "내용", + 0.0, + 0.0, + LocalDateTime.of(2022, 1, 2, 1, 1) + ); + } + + public static PostAndPointCreateRequest 양양_2021_3_2_화(Long tripId) { + return new PostAndPointCreateRequest( + tripId, + "제목", + "강원도 양양", + "내용", + 0.0, + 0.0, + LocalDateTime.of(2021, 3, 2, 10, 1) + ); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java new file mode 100644 index 000000000..e4e78c2f5 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java @@ -0,0 +1,84 @@ +package dev.tripdraw.test.fixture; + +import dev.tripdraw.trip.dto.TripSearchConditions; +import java.util.Set; + +public class TripSearchConditionsFixture { + + public static TripSearchConditions emptyTripSearchConditions() { + return new TripSearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static TripSearchConditions yearsTripSearchConditions(Set years) { + return new TripSearchConditions( + years, + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static TripSearchConditions monthsTripSearchConditions(Set months) { + return new TripSearchConditions( + Set.of(), + months, + Set.of(), + Set.of(), + Set.of(), + "" + ); + } + + public static TripSearchConditions daysOfWeekTripSearchConditions(Set daysOfWeek) { + return new TripSearchConditions( + Set.of(), + Set.of(), + daysOfWeek, + Set.of(), + Set.of(), + "" + ); + } + + public static TripSearchConditions ageRangesTripSearchConditions(Set ageRanges) { + return new TripSearchConditions( + Set.of(), + Set.of(), + Set.of(), + ageRanges, + Set.of(), + "" + ); + } + + public static TripSearchConditions gendersTripSearchConditions(Set genders) { + return new TripSearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + genders, + "" + ); + } + + public static TripSearchConditions addressTripSearchConditions(String address) { + return new TripSearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + address + ); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/step/PostStep.java b/backend/src/test/java/dev/tripdraw/test/step/PostStep.java new file mode 100644 index 000000000..b75b76fbf --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/step/PostStep.java @@ -0,0 +1,30 @@ +package dev.tripdraw.test.step; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; + +import dev.tripdraw.post.dto.PostAndPointCreateRequest; +import dev.tripdraw.post.dto.PostCreateResponse; +import io.restassured.RestAssured; +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; + +public class PostStep { + + public static ExtractableResponse createPostAtCurrentPoint(PostAndPointCreateRequest request, + String token) { + return RestAssured.given().log().all() + .contentType(MULTIPART_FORM_DATA_VALUE) + .auth().preemptive().oauth2(token) + .multiPart("dto", request, APPLICATION_JSON_VALUE) + .when().post("/posts/current-location") + .then().log().all() + .extract(); + } + + public static PostCreateResponse createPostAtCurrentPointAndGetResponse(PostAndPointCreateRequest request, + String token) { + ExtractableResponse response = createPostAtCurrentPoint(request, token); + return response.as(PostCreateResponse.class); + } +} diff --git a/backend/src/test/java/dev/tripdraw/test/step/TripStep.java b/backend/src/test/java/dev/tripdraw/test/step/TripStep.java new file mode 100644 index 000000000..075ce1565 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/step/TripStep.java @@ -0,0 +1,62 @@ +package dev.tripdraw.test.step; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + +import dev.tripdraw.trip.dto.PointCreateRequest; +import dev.tripdraw.trip.dto.PointResponse; +import dev.tripdraw.trip.dto.TripCreateResponse; +import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripUpdateRequest; +import io.restassured.RestAssured; +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; + +public class TripStep { + + public static ExtractableResponse createTrip(String token) { + return RestAssured.given().log().all() + .auth().preemptive().oauth2(token) + .when().post("/trips") + .then().log().all() + .extract(); + } + + public static TripCreateResponse createTripAndGetResponse(String token) { + ExtractableResponse response = createTrip(token); + return response.as(TripCreateResponse.class); + } + + public static ExtractableResponse addPoint(PointCreateRequest request, String token) { + return RestAssured.given().log().all() + .contentType(APPLICATION_JSON_VALUE) + .auth().preemptive().oauth2(token) + .body(request) + .when().post("/points") + .then().log().all() + .extract(); + } + + public static PointResponse addPointAndGetResponse(PointCreateRequest request, String token) { + ExtractableResponse response = addPoint(request, token); + return response.as(PointResponse.class); + } + + public static ExtractableResponse updateTrip(TripUpdateRequest request, Long tripId, String token) { + return RestAssured.given().log().all() + .contentType(APPLICATION_JSON_VALUE) + .auth().preemptive().oauth2(token) + .body(request) + .when().patch("/trips/{tripId}", tripId) + .then().log().all() + .extract(); + } + + public static TripResponse searchTripAndGetResponse(Long tripId, String token) { + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(token) + .when().get("/trips/{tripId}", tripId) + .then().log().all() + .extract(); + return response.as(TripResponse.class); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index 2fa177ebd..37d13311a 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -9,11 +9,15 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import dev.tripdraw.common.auth.LoginUser; +import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.member.exception.MemberException; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.test.ServiceTest; +import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.dto.PointCreateRequest; @@ -21,13 +25,18 @@ import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchConditions; +import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripSearchResponse; +import dev.tripdraw.trip.dto.TripSearchResponseOfMember; import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; import java.util.Objects; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -45,6 +54,9 @@ class TripServiceTest { @Autowired private MemberRepository memberRepository; + @Autowired + private PostRepository postRepository; + @MockBean private RouteImageGenerator routeImageGenerator; @@ -54,8 +66,12 @@ class TripServiceTest { @BeforeEach void setUp() { Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - trip = tripRepository.save(Trip.from(member)); + Trip trip = Trip.from(member); + Point point = new Point(3.14, 5.25, LocalDateTime.now()); + trip.add(point); + this.trip = tripRepository.save(trip); loginUser = new LoginUser(member.id()); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); } @Test @@ -136,14 +152,14 @@ void setUp() { } @Test - void 전체_여행을_조회한다() { + void 특정_회원의_전체_여행을_조회한다() { // given & when - TripsSearchResponse tripsSearchResponse = tripService.readAllTrips(loginUser); + TripsSearchResponseOfMember tripsSearchResponseOfMember = tripService.readAllTripsOf(loginUser); // then - assertThat(tripsSearchResponse).usingRecursiveComparison().isEqualTo( - new TripsSearchResponse(List.of( - new TripSearchResponse( + assertThat(tripsSearchResponseOfMember).usingRecursiveComparison().isEqualTo( + new TripsSearchResponseOfMember(List.of( + new TripSearchResponseOfMember( trip.id(), trip.nameValue(), trip.imageUrl(), @@ -153,6 +169,39 @@ void setUp() { ); } + @Test + void 모든_회원의_감상이_있는_여행_전체를_조회한다() { + // given + TripSearchConditions emptyConditions = new TripSearchConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + SearchPaging searchPaging = new SearchPaging(null, 10); + TripSearchRequest tripSearchRequest = new TripSearchRequest(emptyConditions, searchPaging); + + // when + TripsSearchResponse tripsSearchResponse = tripService.readAllTrips(tripSearchRequest); + + // then + assertThat(tripsSearchResponse).usingRecursiveComparison().isEqualTo( + new TripsSearchResponse(List.of( + new TripSearchResponse( + trip.id(), + trip.nameValue(), + trip.imageUrl(), + trip.routeImageUrl(), + trip.createdAt(), + trip.updatedAt() + )), + false + ) + ); + } + @Test void 여행의_이름과_상태를_수정한다() { // given diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java new file mode 100644 index 000000000..0a8e16be6 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java @@ -0,0 +1,76 @@ +package dev.tripdraw.trip.domain; + +import static java.util.Set.of; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import dev.tripdraw.trip.exception.TripException; +import java.util.Set; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +class SearchConditionsTest { + + @ParameterizedTest + @ValueSource(ints = {2009, 2024}) + void 연도가_2010_미만_2023_초과이면_예외를_던진다(int year) { + // given + Set years = of(year); + + // expect + assertThatThrownBy(() -> new SearchConditions(years, of(), of(), of(), of(), "")) + .isInstanceOf(TripException.class) + .hasMessage("유효하지 않은 여행 조회 조건입니다."); + } + + @ParameterizedTest + @ValueSource(ints = {0, 13}) + void 월이_1_미만_12_초과이면_예외를_던진다(int month) { + // given + Set months = of(month); + + // expect + assertThatThrownBy(() -> new SearchConditions(of(), months, of(), of(), of(), "")) + .isInstanceOf(TripException.class) + .hasMessage("유효하지 않은 여행 조회 조건입니다."); + } + + @ParameterizedTest + @ValueSource(ints = {0, 8}) + void 요일이_1_미만_7_초과이면_예외를_던진다(int dayOfWeek) { + // given + Set daysOfWeek = of(dayOfWeek); + + // expect + assertThatThrownBy(() -> new SearchConditions(of(), of(), daysOfWeek, of(), of(), "")) + .isInstanceOf(TripException.class) + .hasMessage("유효하지 않은 여행 조회 조건입니다."); + } + + @ParameterizedTest + @ValueSource(ints = {0, 11}) + void 연령대가_1_미만_10_초과이면_예외를_던진다(int ageRange) { + // given + Set ageRanges = of(ageRange); + + // expect + assertThatThrownBy(() -> new SearchConditions(of(), of(), of(), ageRanges, of(), "")) + .isInstanceOf(TripException.class) + .hasMessage("유효하지 않은 여행 조회 조건입니다."); + } + + @ParameterizedTest + @ValueSource(ints = {0, 3}) + void 성별이_1_미만_2_초과이면_예외를_던진다(int gender) { + // given + Set genders = of(gender); + + // expect + assertThatThrownBy(() -> new SearchConditions(genders, of(), of(), of(), of(), "")) + .isInstanceOf(TripException.class) + .hasMessage("유효하지 않은 여행 조회 조건입니다."); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index d6ea61727..dcfbe1ce1 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -1,12 +1,12 @@ package dev.tripdraw.trip.domain; import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.test.SearchConditionsTestFixture.addressSearchConditions; -import static dev.tripdraw.test.SearchConditionsTestFixture.daysOfWeekSearchConditions; -import static dev.tripdraw.test.SearchConditionsTestFixture.emptySearchConditions; -import static dev.tripdraw.test.SearchConditionsTestFixture.monthsSearchConditions; -import static dev.tripdraw.test.SearchConditionsTestFixture.yearsSearchConditions; -import static dev.tripdraw.test.TestFixture.위치정보; +import static dev.tripdraw.test.fixture.SearchConditionsFixture.addressSearchConditions; +import static dev.tripdraw.test.fixture.SearchConditionsFixture.daysOfWeekSearchConditions; +import static dev.tripdraw.test.fixture.SearchConditionsFixture.emptySearchConditions; +import static dev.tripdraw.test.fixture.SearchConditionsFixture.monthsSearchConditions; +import static dev.tripdraw.test.fixture.SearchConditionsFixture.yearsSearchConditions; +import static dev.tripdraw.test.fixture.TestFixture.위치정보; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -22,6 +22,7 @@ import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -140,11 +141,11 @@ void setUp() { class 조건에_따라_여행을_조회할_때 { @Nested - class 개수_제한을_입력하면 { + class 개수_제한이 { @ParameterizedTest @CsvSource({"0, 1", "1, 2", "2, 3"}) - void 개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { + void 여행의_개수보다_적으면_개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { // given jeju_2023_1_1_Sun(); jeju_2023_1_1_Sun(); @@ -158,6 +159,21 @@ class 개수_제한을_입력하면 { // then assertThat(trips).hasSize(expectedSize); } + + @ParameterizedTest + @CsvSource({"1, 1", "2, 1"}) + void 여행의_개수보다_많거나_같으면_모든_여행을_반환한다(int limit, int expectedSize) { + // given + jeju_2023_1_1_Sun(); + + Paging paging = new Paging(null, limit); + + // when + List trips = tripRepository.findAllByConditions(emptySearchConditions(), paging); + + // then + assertThat(trips).hasSize(expectedSize); + } } @Nested @@ -213,7 +229,7 @@ class 조건으로_연도를 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - SearchConditions searchConditions = yearsSearchConditions(List.of(2023)); + SearchConditions searchConditions = yearsSearchConditions(Set.of(2023)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -231,7 +247,7 @@ class 조건으로_연도를 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - SearchConditions searchConditions = yearsSearchConditions(List.of(2023, 2021)); + SearchConditions searchConditions = yearsSearchConditions(Set.of(2023, 2021)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -257,7 +273,7 @@ class 조건으로_월을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - SearchConditions searchConditions = monthsSearchConditions(List.of(1)); + SearchConditions searchConditions = monthsSearchConditions(Set.of(1)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -275,7 +291,7 @@ class 조건으로_월을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - SearchConditions searchConditions = monthsSearchConditions(List.of(1, 3)); + SearchConditions searchConditions = monthsSearchConditions(Set.of(1, 3)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -301,7 +317,7 @@ class 조건으로_요일을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - SearchConditions searchConditions = daysOfWeekSearchConditions(List.of(1)); + SearchConditions searchConditions = daysOfWeekSearchConditions(Set.of(1)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -319,7 +335,7 @@ class 조건으로_요일을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - SearchConditions searchConditions = daysOfWeekSearchConditions(List.of(1, 3)); + SearchConditions searchConditions = daysOfWeekSearchConditions(Set.of(1, 3)); // when List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); @@ -399,11 +415,11 @@ class 조건을 { jeju_2023_2_1_Wed(); SearchConditions searchConditions = new SearchConditions( - List.of(2023), - List.of(1), - List.of(), - List.of(), - List.of(), + Set.of(2023), + Set.of(1), + Set.of(), + Set.of(), + Set.of(), "서울특별시" ); diff --git a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseOfMemberTest.java similarity index 82% rename from backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java rename to backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseOfMemberTest.java index 0009c1499..8f273eee4 100644 --- a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseOfMemberTest.java @@ -13,7 +13,7 @@ @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class TripSearchResponseTest { +class TripSearchResponseOfMemberTest { @Test void 여행_이미지와_경로_이미지가_null이면_빈값으로_변환해_생성한다() { @@ -23,11 +23,11 @@ class TripSearchResponseTest { Trip trip = new Trip(1L, tripName, member, ONGOING, null, null); // when - TripSearchResponse response = TripSearchResponse.from(trip); + TripSearchResponseOfMember response = TripSearchResponseOfMember.from(trip); // then assertThat(response).usingRecursiveComparison().isEqualTo( - TripSearchResponse.from(new Trip(1L, tripName, member, ONGOING, "", "")) + TripSearchResponseOfMember.from(new Trip(1L, tripName, member, ONGOING, "", "")) ); } } diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index 5bf763a3e..7c159efcf 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -1,8 +1,26 @@ package dev.tripdraw.trip.presentation; import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.TestFixture.pointCreateRequest; +import static dev.tripdraw.test.fixture.TestFixture.tripUpdateRequest; +import static dev.tripdraw.test.fixture.TestFixture.서울_2022_1_2_일; +import static dev.tripdraw.test.fixture.TestFixture.서울_2023_1_1_일; +import static dev.tripdraw.test.fixture.TestFixture.양양_2021_3_2_화; +import static dev.tripdraw.test.fixture.TestFixture.제주_2023_1_1_일; +import static dev.tripdraw.test.fixture.TestFixture.제주_2023_2_1_수; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.addressTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.daysOfWeekTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.emptyTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.monthsTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.yearsTripSearchConditions; +import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; +import static dev.tripdraw.test.step.TripStep.addPointAndGetResponse; +import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; +import static dev.tripdraw.test.step.TripStep.searchTripAndGetResponse; +import static dev.tripdraw.test.step.TripStep.updateTrip; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; @@ -10,29 +28,37 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import dev.tripdraw.auth.application.JwtTokenProvider; +import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.test.ControllerTest; -import dev.tripdraw.trip.domain.Trip; -import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.dto.PointCreateRequest; import dev.tripdraw.trip.dto.PointCreateResponse; import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchConditions; +import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripSearchResponse; +import dev.tripdraw.trip.dto.TripSearchResponseOfMember; import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import java.time.LocalDateTime; import java.util.List; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -42,9 +68,6 @@ class TripControllerTest extends ControllerTest { private static final String WRONG_TOKEN = "wrong.long.token"; - @Autowired - private TripRepository tripRepository; - @Autowired private MemberRepository memberRepository; @@ -54,16 +77,21 @@ class TripControllerTest extends ControllerTest { @MockBean private RouteImageGenerator routeImageGenerator; - private Trip trip; private String huchuToken; + private String leoToken; + private String herbToken; @BeforeEach public void setUp() { super.setUp(); - Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - trip = tripRepository.save(Trip.from(member)); - huchuToken = jwtTokenProvider.generateAccessToken(member.id().toString()); + Member huchu = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + Member leo = memberRepository.save(new Member("리오", "kakaoId", KAKAO)); + Member herb = memberRepository.save(new Member("허브", "kakaoId", KAKAO)); + + huchuToken = jwtTokenProvider.generateAccessToken(huchu.id().toString()); + leoToken = jwtTokenProvider.generateAccessToken(leo.id().toString()); + herbToken = jwtTokenProvider.generateAccessToken(herb.id().toString()); } @Test @@ -97,8 +125,9 @@ public void setUp() { @Test void 여행에_위치_정보를_추가한다() { // given + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); PointCreateRequest request = new PointCreateRequest( - trip.id(), + tripResponse.tripId(), 1.1, 2.2, LocalDateTime.of(2023, 7, 18, 20, 24) @@ -125,8 +154,9 @@ public void setUp() { @Test void 위치_정보_추가_시_인증에_실패하면_예외를_발생시킨다() { // given + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); PointCreateRequest request = new PointCreateRequest( - trip.id(), + tripResponse.tripId(), 1.1, 2.2, LocalDateTime.of(2023, 7, 18, 20, 24) @@ -144,10 +174,13 @@ public void setUp() { @Test void 여행을_ID로_조회한다() { - // given & when + // given + Long tripId = createTripAndGetResponse(huchuToken).tripId(); + + // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .when().get("/trips/{tripId}", trip.id()) + .when().get("/trips/{tripId}", tripId) .then().log().all() .extract(); @@ -166,28 +199,14 @@ public void setUp() { @Test void 특정_위치정보를_삭제한다() { // given - PointCreateRequest pointCreateRequest = new PointCreateRequest( - trip.id(), - 1.1, - 2.2, - LocalDateTime.of(2023, 7, 18, 20, 24) - ); - - ExtractableResponse response = RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) - .auth().preemptive().oauth2(huchuToken) - .body(pointCreateRequest) - .when().post("/points") - .then().log().all() - .extract(); - - PointResponse pointResponse = response.as(PointResponse.class); + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); + PointResponse pointResponse = addPointAndGetResponse(pointCreateRequest(tripResponse.tripId()), huchuToken); // expect RestAssured.given().log().all() .contentType(APPLICATION_JSON_VALUE) .auth().preemptive().oauth2(huchuToken) - .param("tripId", trip.id()) + .param("tripId", tripResponse.tripId()) .when().delete("/points/{pointId}", pointResponse.pointId()) .then().log().all() .statusCode(NO_CONTENT.value()); @@ -196,54 +215,45 @@ public void setUp() { @Test void 특정_위치정보_삭제시_인증에_실패하면_예외를_발생시킨다() { // given - PointCreateRequest pointCreateRequest = new PointCreateRequest( - trip.id(), - 1.1, - 2.2, - LocalDateTime.of(2023, 7, 18, 20, 24) - ); - - ExtractableResponse response = RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) - .auth().preemptive().oauth2(huchuToken) - .body(pointCreateRequest) - .when().post("/points") - .then().log().all() - .extract(); - - PointResponse pointResponse = response.as(PointResponse.class); + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); + PointResponse pointResponse = addPointAndGetResponse(pointCreateRequest(tripResponse.tripId()), huchuToken); // expect RestAssured.given().log().all() .contentType(APPLICATION_JSON_VALUE) .auth().preemptive().oauth2(WRONG_TOKEN) - .param("tripId", trip.id()) + .param("tripId", tripResponse.tripId()) .when().delete("/points/{pointId}", pointResponse.pointId()) .then().log().all() .statusCode(UNAUTHORIZED.value()); } @Test - void 전체_여행을_조회한다() { + void 특정_회원의_전체_여행을_조회한다() { // given + Long tripId = createTripAndGetResponse(huchuToken).tripId(); + updateTrip(tripUpdateRequest(), tripId, huchuToken); + + // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .when().get("/trips") + .when().get("/trips/mine") .then().log().all() .extract(); // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + TripsSearchResponseOfMember tripsSearchResponseOfMember = response.as(TripsSearchResponseOfMember.class); assertSoftly(softly -> { softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(tripsSearchResponse).usingRecursiveComparison().isEqualTo( - new TripsSearchResponse( - List.of(new TripSearchResponse( - trip.id(), - trip.nameValue(), - trip.imageUrl(), - trip.routeImageUrl()) + softly.assertThat(tripsSearchResponseOfMember).usingRecursiveComparison().isEqualTo( + new TripsSearchResponseOfMember( + List.of(new TripSearchResponseOfMember( + tripId, + "제주도 여행", + "", + "" + ) ) ) ); @@ -253,6 +263,7 @@ public void setUp() { @Test void 여행의_이름과_상태를_수정한다() { // given + Long tripId = createTripAndGetResponse(huchuToken).tripId(); TripUpdateRequest tripUpdateRequest = new TripUpdateRequest("제주도 여행", FINISHED); // when @@ -260,35 +271,30 @@ public void setUp() { .contentType(APPLICATION_JSON_VALUE) .auth().preemptive().oauth2(huchuToken) .body(tripUpdateRequest) - .when().patch("/trips/{tripId}", trip.id()) + .when().patch("/trips/{tripId}", tripId) .then().log().all() .extract(); // then - Trip updatedTrip = tripRepository.findById(trip.id()).get(); + TripResponse tripResponse = searchTripAndGetResponse(tripId, huchuToken); assertSoftly(softly -> { softly.assertThat(response.statusCode()).isEqualTo(NO_CONTENT.value()); - softly.assertThat(updatedTrip.nameValue()).isEqualTo("제주도 여행"); - softly.assertThat(updatedTrip.status()).isEqualTo(FINISHED); + softly.assertThat(tripResponse.name()).isEqualTo("제주도 여행"); + softly.assertThat(tripResponse.status()).isEqualTo(FINISHED); }); } @Test void 위치_정보를_조회한다() { // given - PointCreateRequest request = new PointCreateRequest( - trip.id(), - 1.1, - 2.2, - LocalDateTime.of(2023, 7, 18, 20, 24) - ); - Long pointId = createPointAndGetId(request).pointId(); + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); + Long pointId = addPointAndGetResponse(pointCreateRequest(tripResponse.tripId()), huchuToken).pointId(); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .param("tripId", trip.id()) + .param("tripId", tripResponse.tripId()) .when().get("/points/{pointId}", pointId) .then().log().all() .extract(); @@ -312,33 +318,487 @@ public void setUp() { @Test void 여행을_삭제한다() { + // given + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); + Long tripId = tripResponse.tripId(); + // expect RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .when().delete("/trips/{tripId}", trip.id()) + .when().delete("/trips/{tripId}", tripId) .then().log().all() .statusCode(NO_CONTENT.value()); } @Test void 여행을_삭제할_때_인증에_실패하면_예외가_발생한다() { + // given + TripCreateResponse tripResponse = createTripAndGetResponse(huchuToken); + Long tripId = tripResponse.tripId(); + // expect RestAssured.given().log().all() .auth().preemptive().oauth2(WRONG_TOKEN) - .when().delete("/trips/{tripId}", trip.id()) + .when().delete("/trips/{tripId}", tripId) .then().log().all() .statusCode(UNAUTHORIZED.value()); } - private PointCreateResponse createPointAndGetId(PointCreateRequest request) { - ExtractableResponse response = RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) - .auth().preemptive().oauth2(huchuToken) - .body(request) - .when().post("/points") - .then().log().all() - .extract(); - - return response.as(PointCreateResponse.class); + @Nested + class 여러_회원이_여행에_감상을_남긴_후 { + + private Long lastViewedId; + private Long 후추_양양_2021_3_2_화; + private Long 후추_서울_2022_1_2_일; + private Long 리오_제주_2023_1_1_일; + private Long 리오_서울_2023_1_1_일; + private Long 허브_제주_2023_2_1_수; + + @BeforeEach + void setUp() { + 후추_양양_2021_3_2_화 = createTripAndGetResponse(huchuToken).tripId(); + createPostAtCurrentPoint(양양_2021_3_2_화(후추_양양_2021_3_2_화), huchuToken); + + 후추_서울_2022_1_2_일 = createTripAndGetResponse(huchuToken).tripId(); + createPostAtCurrentPoint(서울_2022_1_2_일(후추_서울_2022_1_2_일), huchuToken); + + 리오_제주_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); + createPostAtCurrentPoint(제주_2023_1_1_일(리오_제주_2023_1_1_일), leoToken); + + 리오_서울_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); + createPostAtCurrentPoint(서울_2023_1_1_일(리오_서울_2023_1_1_일), leoToken); + + 허브_제주_2023_2_1_수 = createTripAndGetResponse(herbToken).tripId(); + createPostAtCurrentPoint(제주_2023_2_1_수(허브_제주_2023_2_1_수), herbToken); + + lastViewedId = 허브_제주_2023_2_1_수; + } + + @Nested + class 감상이_있는_모든_여행을_페이지네이션으로_조회할_때 { + + @Nested + class 조회할_수_있는_여행_수_미만으로_개수_제한을_입력하면 { + + @ParameterizedTest + @CsvSource({"1, 1", "4, 4"}) + void 해당_개수만큼_여행이_조회된다(int limit, int expectedSize) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); + }); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + void 다음_페이지가_존재한다(int limit) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.hasNextPage()).isTrue(); + }); + } + } + + @Nested + class 조회할_수_있는_여행_수_이상으로_개수_제한을_입력하면 { + + @ParameterizedTest + @CsvSource({"5, 5", "6, 5"}) + void 모든_여행이_조회된다(int limit, int expectedSize) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); + }); + } + + @ParameterizedTest + @ValueSource(ints = {5, 6}) + void 다음_페이지가_존재하지_않는다(int limit) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.hasNextPage()).isFalse(); + }); + } + } + + @Nested + class 마지막으로_조회한_여행_ID를 { + + private static final int LIMIT = 10; + + @Test + void 입력하지_않으면_최신_여행부터_내림차순으로_조회된다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, LIMIT) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 입력하면_해당_여행_이하로_최신_여행을_내림차순으로_조회된다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(lastViewedId, LIMIT) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + } + } + + private List searchedTripIds(TripsSearchResponse tripsSearchResponse) { + return tripsSearchResponse.trips().stream() + .map(TripSearchResponse::tripId) + .toList(); + } + + @Nested + class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { + + private final SearchPaging nullLastViewedIdAnd10Limit = new SearchPaging(null, 10); + + @Test + void 조건없이_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 연도를_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + yearsTripSearchConditions(Set.of(2023)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일 + ); + }); + } + + @Test + void 월을_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + monthsTripSearchConditions(Set.of(1, 2)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일 + ); + }); + } + + @Test + void 요일을_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + daysOfWeekTripSearchConditions(Set.of(1, 3)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 주소를_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + addressTripSearchConditions("seoul_songpa"), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 후추_서울_2022_1_2_일 + ); + }); + } + + @Test + void 여러_조건으로_조회할_수_있다() { + // given + var multiSearchConditions = new TripSearchConditions( + Set.of(2023, 2021), + Set.of(), + Set.of(1), + Set.of(), + Set.of(), + "seoul" + ); + var tripSearchRequest = new TripSearchRequest( + multiSearchConditions, + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일 + ); + }); + } + + @Test + void 조건이_유효하지_않을_경우_예외를_발생시킨다() { + // given + var tripSearchRequest = new TripSearchRequest( + monthsTripSearchConditions(Set.of(Integer.MAX_VALUE)), + nullLastViewedIdAnd10Limit + ); + + // expect + RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .statusCode(BAD_REQUEST.value()); + } + + @Test + void 인증에_실패할_경우_예외를_발생시킨다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + nullLastViewedIdAnd10Limit + ); + + // expect + RestAssured.given().log().all() + .auth().preemptive().oauth2(WRONG_TOKEN) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .statusCode(UNAUTHORIZED.value()); + } + } } } From 2b64b53ff80c99f879c8acdaac2c125897a0fd16 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 15:12:03 +0900 Subject: [PATCH 101/119] =?UTF-8?q?[refactor]=20TripCustomRepositoryImpl?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/domain/TripCustomRepositoryImpl.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java index 17d4111ec..7778a9ef9 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java @@ -25,46 +25,46 @@ public List findAllByConditions(SearchConditions searchConditions, Paging .join(post).on(trip.id.eq(post.tripId)) .join(point).on(post.point.id.eq(point.id)) .where( - tripsBeforeLastViewedId(paging.lastViewedId()), - tripsRecordedAtYears(searchConditions.years()), - tripsRecordedAtMonths(searchConditions.months()), - tripsRecordedAtDaysOfWeek(searchConditions.daysOfWeek()), - tripsAddressed(searchConditions.address()) + tripIdLt(paging.lastViewedId()), + yearIn(searchConditions.years()), + monthIn(searchConditions.months()), + dayOfWeekIn(searchConditions.daysOfWeek()), + addressLike(searchConditions.address()) ) .orderBy(trip.id.desc()) .limit(paging.limit() + 1) .fetch(); } - private BooleanExpression tripsBeforeLastViewedId(Long lastViewedId) { + private BooleanExpression tripIdLt(Long lastViewedId) { if (lastViewedId == null) { return null; } return trip.id.lt(lastViewedId); } - private BooleanExpression tripsRecordedAtYears(Set years) { + private BooleanExpression yearIn(Set years) { if (years.isEmpty()) { return null; } return point.recordedAt.year().in(years); } - private BooleanExpression tripsRecordedAtMonths(Set months) { + private BooleanExpression monthIn(Set months) { if (months.isEmpty()) { return null; } return point.recordedAt.month().in(months); } - private BooleanExpression tripsRecordedAtDaysOfWeek(Set daysOfWeek) { + private BooleanExpression dayOfWeekIn(Set daysOfWeek) { if (daysOfWeek.isEmpty()) { return null; } return point.recordedAt.dayOfWeek().in(daysOfWeek); } - private BooleanExpression tripsAddressed(String address) { + private BooleanExpression addressLike(String address) { if (address.isEmpty()) { return null; } From 115a3f80009467a076c6ed730b2988f0c4d4733e Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 17:45:02 +0900 Subject: [PATCH 102/119] =?UTF-8?q?[build]=20gradle.build=20=EC=9E=AC?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/build.gradle b/backend/build.gradle index b178d3561..86a5c24bb 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -86,7 +86,7 @@ sourceSets { } tasks.withType(JavaCompile).configureEach { - options.compilerArgs += ["-s", querydslDir] + options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir) } clean.doLast { From 7fb432cdc18eb6f5bf139af357fa816c2ea006a8 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 17:46:02 +0900 Subject: [PATCH 103/119] =?UTF-8?q?[test]=20TripController=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=B6=84=EB=A6=AC=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acceptance/TripSearchAcceptanceTest.java | 523 ++++++++++++++++++ .../trip/presentation/TripControllerTest.java | 487 ---------------- 2 files changed, 523 insertions(+), 487 deletions(-) create mode 100644 backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java diff --git a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java new file mode 100644 index 000000000..9d77bd2b9 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java @@ -0,0 +1,523 @@ +package dev.tripdraw.trip.acceptance; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.TestFixture.서울_2022_1_2_일; +import static dev.tripdraw.test.fixture.TestFixture.서울_2023_1_1_일; +import static dev.tripdraw.test.fixture.TestFixture.양양_2021_3_2_화; +import static dev.tripdraw.test.fixture.TestFixture.제주_2023_1_1_일; +import static dev.tripdraw.test.fixture.TestFixture.제주_2023_2_1_수; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.addressTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.daysOfWeekTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.emptyTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.monthsTripSearchConditions; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.yearsTripSearchConditions; +import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; +import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.UNAUTHORIZED; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + +import dev.tripdraw.auth.application.JwtTokenProvider; +import dev.tripdraw.common.dto.SearchPaging; +import dev.tripdraw.draw.application.RouteImageGenerator; +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.test.ControllerTest; +import dev.tripdraw.trip.dto.TripSearchConditions; +import dev.tripdraw.trip.dto.TripSearchRequest; +import dev.tripdraw.trip.dto.TripSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponse; +import io.restassured.RestAssured; +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +public class TripSearchAcceptanceTest extends ControllerTest { + + private static final String WRONG_TOKEN = "wrong.long.token"; + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private JwtTokenProvider jwtTokenProvider; + + @MockBean + private RouteImageGenerator routeImageGenerator; + + private String huchuToken; + private Long lastViewedId; + private Long 후추_양양_2021_3_2_화; + private Long 후추_서울_2022_1_2_일; + private Long 리오_제주_2023_1_1_일; + private Long 리오_서울_2023_1_1_일; + private Long 허브_제주_2023_2_1_수; + + @BeforeEach + public void setUp() { + super.setUp(); + + Member huchu = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + Member leo = memberRepository.save(new Member("리오", "kakaoId", KAKAO)); + Member herb = memberRepository.save(new Member("허브", "kakaoId", KAKAO)); + + huchuToken = jwtTokenProvider.generateAccessToken(huchu.id().toString()); + String leoToken = jwtTokenProvider.generateAccessToken(leo.id().toString()); + String herbToken = jwtTokenProvider.generateAccessToken(herb.id().toString()); + + 후추_양양_2021_3_2_화 = createTripAndGetResponse(huchuToken).tripId(); + createPostAtCurrentPoint(양양_2021_3_2_화(후추_양양_2021_3_2_화), huchuToken); + + 후추_서울_2022_1_2_일 = createTripAndGetResponse(huchuToken).tripId(); + createPostAtCurrentPoint(서울_2022_1_2_일(후추_서울_2022_1_2_일), huchuToken); + + 리오_제주_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); + createPostAtCurrentPoint(제주_2023_1_1_일(리오_제주_2023_1_1_일), leoToken); + + 리오_서울_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); + createPostAtCurrentPoint(서울_2023_1_1_일(리오_서울_2023_1_1_일), leoToken); + + 허브_제주_2023_2_1_수 = createTripAndGetResponse(herbToken).tripId(); + createPostAtCurrentPoint(제주_2023_2_1_수(허브_제주_2023_2_1_수), herbToken); + + lastViewedId = 허브_제주_2023_2_1_수; + } + + + @Nested + class 감상이_있는_모든_여행을_페이지네이션으로_조회할_때 { + + @Nested + class 개수_제한을 { + + @ParameterizedTest + @CsvSource({"1, 1", "4, 4"}) + void 조회할_수_있는_여행_수_미만으로_입력하면_해당_개수만큼_여행이_조회된다(int limit, int expectedSize) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); + }); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + void 조회할_수_있는_여행_수_미만으로_입력하면_다음_페이지가_존재한다(int limit) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.hasNextPage()).isTrue(); + }); + } + + @ParameterizedTest + @CsvSource({"5, 5", "6, 5"}) + void 조회할_수_있는_여행_수_이상으로_입력하면_모든_여행이_조회된다(int limit, int expectedSize) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); + }); + } + + @ParameterizedTest + @ValueSource(ints = {5, 6}) + void 조회할_수_있는_여행_수_이상으로_입력하면_다음_페이지가_존재하지_않는다(int limit) { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, limit) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(tripsSearchResponse.hasNextPage()).isFalse(); + }); + } + } + + @Nested + class 마지막으로_조회한_여행_ID를 { + + private static final int LIMIT = 10; + + @Test + void 입력하지_않으면_최신_여행부터_내림차순으로_조회된다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(null, LIMIT) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 입력하면_해당_여행_이하로_최신_여행을_내림차순으로_조회된다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + new SearchPaging(lastViewedId, LIMIT) + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + } + } + + @Nested + class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { + + private final SearchPaging nullLastViewedIdAnd10Limit = new SearchPaging(null, 10); + + @Test + void 조건없이_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 연도를_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + yearsTripSearchConditions(Set.of(2023)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일 + ); + }); + } + + @Test + void 월을_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + monthsTripSearchConditions(Set.of(1, 2)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 허브_제주_2023_2_1_수, + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일 + ); + }); + } + + @Test + void 요일을_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + daysOfWeekTripSearchConditions(Set.of(1, 3)), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 리오_제주_2023_1_1_일, + 후추_서울_2022_1_2_일, + 후추_양양_2021_3_2_화 + ); + }); + } + + @Test + void 주소를_조건으로_조회할_수_있다() { + // given + var tripSearchRequest = new TripSearchRequest( + addressTripSearchConditions("seoul_songpa"), + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일, + 후추_서울_2022_1_2_일 + ); + }); + } + + @Test + void 여러_조건으로_조회할_수_있다() { + // given + var multiSearchConditions = new TripSearchConditions( + Set.of(2023, 2021), + Set.of(), + Set.of(1), + Set.of(), + Set.of(), + "seoul" + ); + var tripSearchRequest = new TripSearchRequest( + multiSearchConditions, + nullLastViewedIdAnd10Limit + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일 + ); + }); + } + + @Test + void 조건이_유효하지_않을_경우_예외를_발생시킨다() { + // given + var tripSearchRequest = new TripSearchRequest( + monthsTripSearchConditions(Set.of(Integer.MAX_VALUE)), + nullLastViewedIdAnd10Limit + ); + + // expect + RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .statusCode(BAD_REQUEST.value()); + } + + @Test + void 인증에_실패할_경우_예외를_발생시킨다() { + // given + var tripSearchRequest = new TripSearchRequest( + emptyTripSearchConditions(), + nullLastViewedIdAnd10Limit + ); + + // expect + RestAssured.given().log().all() + .auth().preemptive().oauth2(WRONG_TOKEN) + .contentType(APPLICATION_JSON_VALUE) + .body(tripSearchRequest) + .when().get("/trips") + .then().log().all() + .statusCode(UNAUTHORIZED.value()); + } + } + + private List searchedTripIds(TripsSearchResponse tripsSearchResponse) { + return tripsSearchResponse.trips().stream() + .map(TripSearchResponse::tripId) + .toList(); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index 7c159efcf..4fe6899b9 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -3,24 +3,12 @@ import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.test.fixture.TestFixture.pointCreateRequest; import static dev.tripdraw.test.fixture.TestFixture.tripUpdateRequest; -import static dev.tripdraw.test.fixture.TestFixture.서울_2022_1_2_일; -import static dev.tripdraw.test.fixture.TestFixture.서울_2023_1_1_일; -import static dev.tripdraw.test.fixture.TestFixture.양양_2021_3_2_화; -import static dev.tripdraw.test.fixture.TestFixture.제주_2023_1_1_일; -import static dev.tripdraw.test.fixture.TestFixture.제주_2023_2_1_수; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.addressTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.daysOfWeekTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.emptyTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.monthsTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.yearsTripSearchConditions; -import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; import static dev.tripdraw.test.step.TripStep.addPointAndGetResponse; import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; import static dev.tripdraw.test.step.TripStep.searchTripAndGetResponse; import static dev.tripdraw.test.step.TripStep.updateTrip; import static dev.tripdraw.trip.domain.TripStatus.FINISHED; import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; @@ -28,7 +16,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import dev.tripdraw.auth.application.JwtTokenProvider; -import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; @@ -38,27 +25,18 @@ import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; -import dev.tripdraw.trip.dto.TripSearchConditions; -import dev.tripdraw.trip.dto.TripSearchRequest; -import dev.tripdraw.trip.dto.TripSearchResponse; import dev.tripdraw.trip.dto.TripSearchResponseOfMember; import dev.tripdraw.trip.dto.TripUpdateRequest; -import dev.tripdraw.trip.dto.TripsSearchResponse; import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import java.time.LocalDateTime; import java.util.List; -import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -78,20 +56,13 @@ class TripControllerTest extends ControllerTest { private RouteImageGenerator routeImageGenerator; private String huchuToken; - private String leoToken; - private String herbToken; @BeforeEach public void setUp() { super.setUp(); Member huchu = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - Member leo = memberRepository.save(new Member("리오", "kakaoId", KAKAO)); - Member herb = memberRepository.save(new Member("허브", "kakaoId", KAKAO)); - huchuToken = jwtTokenProvider.generateAccessToken(huchu.id().toString()); - leoToken = jwtTokenProvider.generateAccessToken(leo.id().toString()); - herbToken = jwtTokenProvider.generateAccessToken(herb.id().toString()); } @Test @@ -343,462 +314,4 @@ public void setUp() { .then().log().all() .statusCode(UNAUTHORIZED.value()); } - - @Nested - class 여러_회원이_여행에_감상을_남긴_후 { - - private Long lastViewedId; - private Long 후추_양양_2021_3_2_화; - private Long 후추_서울_2022_1_2_일; - private Long 리오_제주_2023_1_1_일; - private Long 리오_서울_2023_1_1_일; - private Long 허브_제주_2023_2_1_수; - - @BeforeEach - void setUp() { - 후추_양양_2021_3_2_화 = createTripAndGetResponse(huchuToken).tripId(); - createPostAtCurrentPoint(양양_2021_3_2_화(후추_양양_2021_3_2_화), huchuToken); - - 후추_서울_2022_1_2_일 = createTripAndGetResponse(huchuToken).tripId(); - createPostAtCurrentPoint(서울_2022_1_2_일(후추_서울_2022_1_2_일), huchuToken); - - 리오_제주_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); - createPostAtCurrentPoint(제주_2023_1_1_일(리오_제주_2023_1_1_일), leoToken); - - 리오_서울_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); - createPostAtCurrentPoint(서울_2023_1_1_일(리오_서울_2023_1_1_일), leoToken); - - 허브_제주_2023_2_1_수 = createTripAndGetResponse(herbToken).tripId(); - createPostAtCurrentPoint(제주_2023_2_1_수(허브_제주_2023_2_1_수), herbToken); - - lastViewedId = 허브_제주_2023_2_1_수; - } - - @Nested - class 감상이_있는_모든_여행을_페이지네이션으로_조회할_때 { - - @Nested - class 조회할_수_있는_여행_수_미만으로_개수_제한을_입력하면 { - - @ParameterizedTest - @CsvSource({"1, 1", "4, 4"}) - void 해당_개수만큼_여행이_조회된다(int limit, int expectedSize) { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(null, limit) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); - }); - } - - @ParameterizedTest - @ValueSource(ints = {1, 4}) - void 다음_페이지가_존재한다(int limit) { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(null, limit) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(tripsSearchResponse.hasNextPage()).isTrue(); - }); - } - } - - @Nested - class 조회할_수_있는_여행_수_이상으로_개수_제한을_입력하면 { - - @ParameterizedTest - @CsvSource({"5, 5", "6, 5"}) - void 모든_여행이_조회된다(int limit, int expectedSize) { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(null, limit) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(tripsSearchResponse.trips()).hasSize(expectedSize); - }); - } - - @ParameterizedTest - @ValueSource(ints = {5, 6}) - void 다음_페이지가_존재하지_않는다(int limit) { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(null, limit) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(tripsSearchResponse.hasNextPage()).isFalse(); - }); - } - } - - @Nested - class 마지막으로_조회한_여행_ID를 { - - private static final int LIMIT = 10; - - @Test - void 입력하지_않으면_최신_여행부터_내림차순으로_조회된다() { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(null, LIMIT) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 허브_제주_2023_2_1_수, - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일, - 후추_서울_2022_1_2_일, - 후추_양양_2021_3_2_화 - ); - }); - } - - @Test - void 입력하면_해당_여행_이하로_최신_여행을_내림차순으로_조회된다() { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new SearchPaging(lastViewedId, LIMIT) - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일, - 후추_서울_2022_1_2_일, - 후추_양양_2021_3_2_화 - ); - }); - } - - } - } - - private List searchedTripIds(TripsSearchResponse tripsSearchResponse) { - return tripsSearchResponse.trips().stream() - .map(TripSearchResponse::tripId) - .toList(); - } - - @Nested - class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { - - private final SearchPaging nullLastViewedIdAnd10Limit = new SearchPaging(null, 10); - - @Test - void 조건없이_조회할_수_있다() { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 허브_제주_2023_2_1_수, - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일, - 후추_서울_2022_1_2_일, - 후추_양양_2021_3_2_화 - ); - }); - } - - @Test - void 연도를_조건으로_조회할_수_있다() { - // given - var tripSearchRequest = new TripSearchRequest( - yearsTripSearchConditions(Set.of(2023)), - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 허브_제주_2023_2_1_수, - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일 - ); - }); - } - - @Test - void 월을_조건으로_조회할_수_있다() { - // given - var tripSearchRequest = new TripSearchRequest( - monthsTripSearchConditions(Set.of(1, 2)), - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 허브_제주_2023_2_1_수, - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일, - 후추_서울_2022_1_2_일 - ); - }); - } - - @Test - void 요일을_조건으로_조회할_수_있다() { - // given - var tripSearchRequest = new TripSearchRequest( - daysOfWeekTripSearchConditions(Set.of(1, 3)), - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 리오_서울_2023_1_1_일, - 리오_제주_2023_1_1_일, - 후추_서울_2022_1_2_일, - 후추_양양_2021_3_2_화 - ); - }); - } - - @Test - void 주소를_조건으로_조회할_수_있다() { - // given - var tripSearchRequest = new TripSearchRequest( - addressTripSearchConditions("seoul_songpa"), - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 리오_서울_2023_1_1_일, - 후추_서울_2022_1_2_일 - ); - }); - } - - @Test - void 여러_조건으로_조회할_수_있다() { - // given - var multiSearchConditions = new TripSearchConditions( - Set.of(2023, 2021), - Set.of(), - Set.of(1), - Set.of(), - Set.of(), - "seoul" - ); - var tripSearchRequest = new TripSearchRequest( - multiSearchConditions, - nullLastViewedIdAnd10Limit - ); - - // when - ExtractableResponse response = RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .extract(); - - // then - TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); - - assertSoftly(softly -> { - softly.assertThat(response.statusCode()).isEqualTo(OK.value()); - softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( - 리오_서울_2023_1_1_일 - ); - }); - } - - @Test - void 조건이_유효하지_않을_경우_예외를_발생시킨다() { - // given - var tripSearchRequest = new TripSearchRequest( - monthsTripSearchConditions(Set.of(Integer.MAX_VALUE)), - nullLastViewedIdAnd10Limit - ); - - // expect - RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .statusCode(BAD_REQUEST.value()); - } - - @Test - void 인증에_실패할_경우_예외를_발생시킨다() { - // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - nullLastViewedIdAnd10Limit - ); - - // expect - RestAssured.given().log().all() - .auth().preemptive().oauth2(WRONG_TOKEN) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .statusCode(UNAUTHORIZED.value()); - } - } - } } From fedfeb30f1399fe4dc0ee6d77b12dd1281cf1ae2 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 17:46:17 +0900 Subject: [PATCH 104/119] =?UTF-8?q?[chore]=20.gitignore=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index be58d40a8..e7a649a6c 100644 --- a/.gitignore +++ b/.gitignore @@ -192,3 +192,4 @@ fabric.properties !/gradle/wrapper/gradle-wrapper.jar # End of https://www.toptal.com/developers/gitignore/api/android,androidstudio,kotlin +/backend/src/main/generated/ From b8e28b312cfd2cf417a7cf06069ec7d9dd261d0b Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 17:46:44 +0900 Subject: [PATCH 105/119] =?UTF-8?q?[refactor]=20TripCustomRepositoryImpl?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/domain/TripCustomRepositoryImpl.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java index 7778a9ef9..9ddb28eb9 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java @@ -7,10 +7,12 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import dev.tripdraw.common.domain.Paging; +import io.micrometer.common.util.StringUtils; import java.util.List; import java.util.Set; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; +import org.springframework.util.CollectionUtils; @RequiredArgsConstructor @Repository @@ -32,7 +34,7 @@ public List findAllByConditions(SearchConditions searchConditions, Paging addressLike(searchConditions.address()) ) .orderBy(trip.id.desc()) - .limit(paging.limit() + 1) + .limit(paging.limit().longValue() + 1L) .fetch(); } @@ -44,28 +46,28 @@ private BooleanExpression tripIdLt(Long lastViewedId) { } private BooleanExpression yearIn(Set years) { - if (years.isEmpty()) { + if (CollectionUtils.isEmpty(years)) { return null; } return point.recordedAt.year().in(years); } private BooleanExpression monthIn(Set months) { - if (months.isEmpty()) { + if (CollectionUtils.isEmpty(months)) { return null; } return point.recordedAt.month().in(months); } private BooleanExpression dayOfWeekIn(Set daysOfWeek) { - if (daysOfWeek.isEmpty()) { + if (CollectionUtils.isEmpty(daysOfWeek)) { return null; } return point.recordedAt.dayOfWeek().in(daysOfWeek); } private BooleanExpression addressLike(String address) { - if (address.isEmpty()) { + if (StringUtils.isBlank(address)) { return null; } return post.address.like(address + "%"); From 395f8ff2c13f49879d2d8287f32d0b94ebcef0f3 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Mon, 18 Sep 2023 19:58:00 +0900 Subject: [PATCH 106/119] =?UTF-8?q?[refactor]=20TripQueryService=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=9D=98=EC=A1=B4=20=EB=B0=A9?= =?UTF-8?q?=ED=96=A5=20=EC=88=98=EC=A0=95=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/tripdraw/common/dto/SearchPaging.java | 9 - .../trip/application/TripQueryService.java | 27 + .../trip/application/TripService.java | 21 +- .../trip/domain/TripCustomRepository.java | 9 - .../tripdraw/trip/domain/TripRepository.java | 2 +- .../trip/dto/TripSearchConditions.java | 15 +- .../tripdraw/trip/dto/TripSearchPaging.java | 9 + .../tripdraw/trip/dto/TripSearchRequest.java | 13 +- .../trip/presentation/TripController.java | 6 +- .../trip/query/TripCustomRepository.java | 9 + .../TripCustomRepositoryImpl.java | 18 +- .../query/TripPaging.java} | 8 +- .../TripQueryConditions.java} | 6 +- .../{PagingTest.java => TripPagingTest.java} | 13 +- ...e.java => TripQueryConditionsFixture.java} | 32 +- .../acceptance/TripSearchAcceptanceTest.java | 18 +- .../application/TripQueryServiceTest.java | 59 ++ .../trip/application/TripServiceTest.java | 8 +- ...Test.java => TripQueryConditionsTest.java} | 13 +- .../trip/domain/TripRepositoryTest.java | 782 +++++++++--------- .../trip/presentation/TripControllerTest.java | 2 +- .../query/TripCustomRepositoryImplTest.java | 454 ++++++++++ 22 files changed, 1033 insertions(+), 500 deletions(-) delete mode 100644 backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java delete mode 100644 backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/dto/TripSearchPaging.java create mode 100644 backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java rename backend/src/main/java/dev/tripdraw/trip/{domain => query}/TripCustomRepositoryImpl.java (77%) rename backend/src/main/java/dev/tripdraw/{common/domain/Paging.java => trip/query/TripPaging.java} (60%) rename backend/src/main/java/dev/tripdraw/trip/{domain/SearchConditions.java => query/TripQueryConditions.java} (95%) rename backend/src/test/java/dev/tripdraw/common/domain/{PagingTest.java => TripPagingTest.java} (74%) rename backend/src/test/java/dev/tripdraw/test/fixture/{SearchConditionsFixture.java => TripQueryConditionsFixture.java} (56%) create mode 100644 backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java rename backend/src/test/java/dev/tripdraw/trip/domain/{SearchConditionsTest.java => TripQueryConditionsTest.java} (80%) create mode 100644 backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java diff --git a/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java b/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java deleted file mode 100644 index 989ce5da8..000000000 --- a/backend/src/main/java/dev/tripdraw/common/dto/SearchPaging.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.tripdraw.common.dto; - -import dev.tripdraw.common.domain.Paging; - -public record SearchPaging(Long lastViewedId, Integer limit) { - public Paging toPaging() { - return new Paging(lastViewedId, limit); - } -} diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java new file mode 100644 index 000000000..d572e45df --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java @@ -0,0 +1,27 @@ +package dev.tripdraw.trip.application; + +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.query.TripCustomRepository; +import dev.tripdraw.trip.query.TripPaging; +import dev.tripdraw.trip.query.TripQueryConditions; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Transactional +@Service +public class TripQueryService { + + private final TripCustomRepository tripCustomRepository; + + @Transactional(readOnly = true) + public List readAllByQueryConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging) { + return tripCustomRepository.findAllByConditions( + tripQueryConditions, + tripPaging + ); + } +} + diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index f9a79b3d7..e2a924725 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -1,12 +1,10 @@ package dev.tripdraw.trip.application; import dev.tripdraw.common.auth.LoginUser; -import dev.tripdraw.common.domain.Paging; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.PointRepository; -import dev.tripdraw.trip.domain.SearchConditions; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.domain.TripUpdateEvent; @@ -19,6 +17,8 @@ import dev.tripdraw.trip.dto.TripUpdateRequest; import dev.tripdraw.trip.dto.TripsSearchResponse; import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; +import dev.tripdraw.trip.query.TripPaging; +import dev.tripdraw.trip.query.TripQueryConditions; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; @@ -30,9 +30,11 @@ @Service public class TripService { + private static final int FIRST_INDEX = 0; private final TripRepository tripRepository; private final PointRepository pointRepository; private final MemberRepository memberRepository; + private final TripQueryService tripQueryService; private final ApplicationEventPublisher applicationEventPublisher; public TripCreateResponse create(LoginUser loginUser) { @@ -79,17 +81,14 @@ public TripsSearchResponseOfMember readAllTripsOf(LoginUser loginUser) { } @Transactional(readOnly = true) - public TripsSearchResponse readAllTrips(TripSearchRequest tripSearchRequest) { - SearchConditions searchConditions = tripSearchRequest.condition().toSearchConditions(); - Paging paging = tripSearchRequest.paging().toPaging(); + public TripsSearchResponse readAll(TripSearchRequest tripSearchRequest) { + TripQueryConditions tripQueryConditions = tripSearchRequest.toTripQueryConditions(); + TripPaging tripPaging = tripSearchRequest.toTripPaging(); - List trips = tripRepository.findAllByConditions( - searchConditions, - paging - ); + List trips = tripQueryService.readAllByQueryConditions(tripQueryConditions, tripPaging); - if (paging.hasNextPage(trips.size())) { - return TripsSearchResponse.of(trips.subList(0, paging.limit()), true); + if (tripPaging.hasNextPage(trips.size())) { + return TripsSearchResponse.of(trips.subList(FIRST_INDEX, tripPaging.limit()), true); } return TripsSearchResponse.of(trips, false); } diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java deleted file mode 100644 index 4f99ea52d..000000000 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.tripdraw.trip.domain; - -import dev.tripdraw.common.domain.Paging; -import java.util.List; - -public interface TripCustomRepository { - - List findAllByConditions(SearchConditions searchConditions, Paging paging); -} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java b/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java index 5dab56ecd..edb45c393 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java @@ -9,7 +9,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -public interface TripRepository extends JpaRepository, TripCustomRepository { +public interface TripRepository extends JpaRepository { List findAllByMemberId(Long memberId); diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java index 2bce1ca89..df81efeeb 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java @@ -1,8 +1,10 @@ package dev.tripdraw.trip.dto; -import dev.tripdraw.trip.domain.SearchConditions; +import dev.tripdraw.trip.query.TripQueryConditions; import java.util.Set; +import lombok.Builder; +@Builder public record TripSearchConditions( Set years, Set months, @@ -12,14 +14,7 @@ public record TripSearchConditions( String address ) { - public SearchConditions toSearchConditions() { - return new SearchConditions( - years, - months, - daysOfWeek, - ageRanges, - genders, - address - ); + public TripQueryConditions toTripQueryConditions() { + return new TripQueryConditions(years(), months(), daysOfWeek(), ageRanges(), genders(), address()); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchPaging.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchPaging.java new file mode 100644 index 000000000..da83f1bdd --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchPaging.java @@ -0,0 +1,9 @@ +package dev.tripdraw.trip.dto; + +import dev.tripdraw.trip.query.TripPaging; + +public record TripSearchPaging(Long lastViewedId, Integer limit) { + public TripPaging toTripPaging() { + return new TripPaging(lastViewedId, limit); + } +} diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java index 842ee87e1..0289a16c3 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java @@ -1,9 +1,18 @@ package dev.tripdraw.trip.dto; -import dev.tripdraw.common.dto.SearchPaging; +import dev.tripdraw.trip.query.TripPaging; +import dev.tripdraw.trip.query.TripQueryConditions; public record TripSearchRequest( TripSearchConditions condition, - SearchPaging paging + TripSearchPaging paging ) { + + public TripQueryConditions toTripQueryConditions() { + return condition.toTripQueryConditions(); + } + + public TripPaging toTripPaging() { + return paging.toTripPaging(); + } } diff --git a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java index 08a9f8f7d..7492f0b09 100644 --- a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java +++ b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java @@ -109,7 +109,7 @@ public ResponseEntity deletePoint( responseCode = "200", description = "나의 여행 전체 조회 성공." ) - @GetMapping("/trips/mine") + @GetMapping("/trips/me") public ResponseEntity readAllOf(@Auth LoginUser loginUser) { TripsSearchResponseOfMember response = tripService.readAllTripsOf(loginUser); return ResponseEntity.ok(response); @@ -125,8 +125,8 @@ public ResponseEntity readAll( @Auth LoginUser loginUser, @RequestBody TripSearchRequest tripSearchRequest ) { - TripsSearchResponse tripsSearchResponse = tripService.readAllTrips(tripSearchRequest); - return ResponseEntity.ok(tripsSearchResponse); + TripsSearchResponse response = tripService.readAll(tripSearchRequest); + return ResponseEntity.ok(response); } @Operation(summary = "여행 이름 수정 및 종료 API", description = "여행 이름을 수정하고, 여행을 종료합니다.") diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java new file mode 100644 index 000000000..9d8ace9f6 --- /dev/null +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java @@ -0,0 +1,9 @@ +package dev.tripdraw.trip.query; + +import dev.tripdraw.trip.domain.Trip; +import java.util.List; + +public interface TripCustomRepository { + + List findAllByConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging); +} diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java similarity index 77% rename from backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java rename to backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java index 9ddb28eb9..86066939f 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java @@ -1,4 +1,4 @@ -package dev.tripdraw.trip.domain; +package dev.tripdraw.trip.query; import static dev.tripdraw.post.domain.QPost.post; import static dev.tripdraw.trip.domain.QPoint.point; @@ -6,7 +6,7 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; -import dev.tripdraw.common.domain.Paging; +import dev.tripdraw.trip.domain.Trip; import io.micrometer.common.util.StringUtils; import java.util.List; import java.util.Set; @@ -21,20 +21,20 @@ public class TripCustomRepositoryImpl implements TripCustomRepository { private final JPAQueryFactory query; @Override - public List findAllByConditions(SearchConditions searchConditions, Paging paging) { + public List findAllByConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging) { return query .selectFrom(trip) .join(post).on(trip.id.eq(post.tripId)) .join(point).on(post.point.id.eq(point.id)) .where( - tripIdLt(paging.lastViewedId()), - yearIn(searchConditions.years()), - monthIn(searchConditions.months()), - dayOfWeekIn(searchConditions.daysOfWeek()), - addressLike(searchConditions.address()) + tripIdLt(tripPaging.lastViewedId()), + yearIn(tripQueryConditions.years()), + monthIn(tripQueryConditions.months()), + dayOfWeekIn(tripQueryConditions.daysOfWeek()), + addressLike(tripQueryConditions.address()) ) .orderBy(trip.id.desc()) - .limit(paging.limit().longValue() + 1L) + .limit(tripPaging.limit().longValue() + 1L) .fetch(); } diff --git a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java b/backend/src/main/java/dev/tripdraw/trip/query/TripPaging.java similarity index 60% rename from backend/src/main/java/dev/tripdraw/common/domain/Paging.java rename to backend/src/main/java/dev/tripdraw/trip/query/TripPaging.java index 36b72a8de..650c8c3e7 100644 --- a/backend/src/main/java/dev/tripdraw/common/domain/Paging.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripPaging.java @@ -1,9 +1,9 @@ -package dev.tripdraw.common.domain; +package dev.tripdraw.trip.query; -public record Paging(Long lastViewedId, Integer limit) { +public record TripPaging(Long lastViewedId, Integer limit) { private static final int LIMIT_MAXIMUM = 100; - public Paging(Long lastViewedId, Integer limit) { + public TripPaging(Long lastViewedId, Integer limit) { this.lastViewedId = lastViewedId; this.limit = ceil(limit); } @@ -13,6 +13,6 @@ private int ceil(Integer limit) { } public boolean hasNextPage(int size) { - return size > limit; + return limit < size; } } diff --git a/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java similarity index 95% rename from backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java rename to backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java index fee25962e..c856633bd 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/SearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java @@ -1,4 +1,4 @@ -package dev.tripdraw.trip.domain; +package dev.tripdraw.trip.query; import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; @@ -6,7 +6,7 @@ import java.util.HashSet; import java.util.Set; -public record SearchConditions( +public record TripQueryConditions( Set years, Set months, Set daysOfWeek, @@ -26,7 +26,7 @@ public record SearchConditions( private static final int GENDER_MINIMUM = 1; private static final int GENDER_MAXIMUM = 2; - public SearchConditions( + public TripQueryConditions( Set years, Set months, Set daysOfWeek, diff --git a/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java b/backend/src/test/java/dev/tripdraw/common/domain/TripPagingTest.java similarity index 74% rename from backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java rename to backend/src/test/java/dev/tripdraw/common/domain/TripPagingTest.java index 4c34fe304..d02967ce2 100644 --- a/backend/src/test/java/dev/tripdraw/common/domain/PagingTest.java +++ b/backend/src/test/java/dev/tripdraw/common/domain/TripPagingTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import dev.tripdraw.trip.query.TripPaging; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -10,16 +11,16 @@ @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class PagingTest { +class TripPagingTest { @ParameterizedTest @CsvSource({"19, false", "20, false", "21, true"}) void 다음_페이지가_있는지_확인한다(int size, boolean expected) { // given - Paging paging = new Paging(1L, 20); + TripPaging tripPaging = new TripPaging(1L, 20); // when - boolean actual = paging.hasNextPage(size); + boolean actual = tripPaging.hasNextPage(size); // then assertThat(actual).isEqualTo(expected); @@ -31,9 +32,9 @@ class PagingTest { int limit = 101; // when - Paging paging = new Paging(1L, limit); - + TripPaging tripPaging = new TripPaging(1L, limit); + // then - assertThat(paging.limit()).isEqualTo(100); + assertThat(tripPaging.limit()).isEqualTo(100); } } diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java similarity index 56% rename from backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java rename to backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java index c5e4c8d91..a99ae9fd3 100644 --- a/backend/src/test/java/dev/tripdraw/test/fixture/SearchConditionsFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java @@ -1,13 +1,13 @@ package dev.tripdraw.test.fixture; -import dev.tripdraw.trip.domain.SearchConditions; +import dev.tripdraw.trip.query.TripQueryConditions; import java.util.Set; -public class SearchConditionsFixture { +public class TripQueryConditionsFixture { - public static SearchConditions emptySearchConditions() { - return new SearchConditions( + public static TripQueryConditions emptySearchConditions() { + return new TripQueryConditions( Set.of(), Set.of(), Set.of(), @@ -17,8 +17,8 @@ public static SearchConditions emptySearchConditions() { ); } - public static SearchConditions yearsSearchConditions(Set years) { - return new SearchConditions( + public static TripQueryConditions yearsSearchConditions(Set years) { + return new TripQueryConditions( years, Set.of(), Set.of(), @@ -28,8 +28,8 @@ public static SearchConditions yearsSearchConditions(Set years) { ); } - public static SearchConditions monthsSearchConditions(Set months) { - return new SearchConditions( + public static TripQueryConditions monthsSearchConditions(Set months) { + return new TripQueryConditions( Set.of(), months, Set.of(), @@ -39,8 +39,8 @@ public static SearchConditions monthsSearchConditions(Set months) { ); } - public static SearchConditions daysOfWeekSearchConditions(Set daysOfWeek) { - return new SearchConditions( + public static TripQueryConditions daysOfWeekSearchConditions(Set daysOfWeek) { + return new TripQueryConditions( Set.of(), Set.of(), daysOfWeek, @@ -50,8 +50,8 @@ public static SearchConditions daysOfWeekSearchConditions(Set daysOfWee ); } - public static SearchConditions ageRangesSearchConditions(Set ageRanges) { - return new SearchConditions( + public static TripQueryConditions ageRangesSearchConditions(Set ageRanges) { + return new TripQueryConditions( Set.of(), Set.of(), Set.of(), @@ -61,8 +61,8 @@ public static SearchConditions ageRangesSearchConditions(Set ageRanges) ); } - public static SearchConditions gendersSearchConditions(Set genders) { - return new SearchConditions( + public static TripQueryConditions gendersSearchConditions(Set genders) { + return new TripQueryConditions( Set.of(), Set.of(), Set.of(), @@ -72,8 +72,8 @@ public static SearchConditions gendersSearchConditions(Set genders) { ); } - public static SearchConditions addressSearchConditions(String address) { - return new SearchConditions( + public static TripQueryConditions addressSearchConditions(String address) { + return new TripQueryConditions( Set.of(), Set.of(), Set.of(), diff --git a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java index 9d77bd2b9..2f7e10c15 100644 --- a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java @@ -20,12 +20,12 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import dev.tripdraw.auth.application.JwtTokenProvider; -import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.test.ControllerTest; import dev.tripdraw.trip.dto.TripSearchConditions; +import dev.tripdraw.trip.dto.TripSearchPaging; import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripSearchResponse; import dev.tripdraw.trip.dto.TripsSearchResponse; @@ -111,7 +111,7 @@ class 개수_제한을 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(null, limit) + new TripSearchPaging(null, limit) ); // when @@ -138,7 +138,7 @@ class 개수_제한을 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(null, limit) + new TripSearchPaging(null, limit) ); // when @@ -165,7 +165,7 @@ class 개수_제한을 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(null, limit) + new TripSearchPaging(null, limit) ); // when @@ -192,7 +192,7 @@ class 개수_제한을 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(null, limit) + new TripSearchPaging(null, limit) ); // when @@ -213,7 +213,7 @@ class 개수_제한을 { }); } } - + @Nested class 마지막으로_조회한_여행_ID를 { @@ -224,7 +224,7 @@ class 마지막으로_조회한_여행_ID를 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(null, LIMIT) + new TripSearchPaging(null, LIMIT) ); // when @@ -256,7 +256,7 @@ class 마지막으로_조회한_여행_ID를 { // given var tripSearchRequest = new TripSearchRequest( emptyTripSearchConditions(), - new SearchPaging(lastViewedId, LIMIT) + new TripSearchPaging(lastViewedId, LIMIT) ); // when @@ -287,7 +287,7 @@ class 마지막으로_조회한_여행_ID를 { @Nested class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { - private final SearchPaging nullLastViewedIdAnd10Limit = new SearchPaging(null, 10); + private final TripSearchPaging nullLastViewedIdAnd10Limit = new TripSearchPaging(null, 10); @Test void 조건없이_조회할_수_있다() { diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java new file mode 100644 index 000000000..d3ec76e13 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java @@ -0,0 +1,59 @@ +package dev.tripdraw.trip.application; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.query.TripCustomRepository; +import dev.tripdraw.trip.query.TripPaging; +import dev.tripdraw.trip.query.TripQueryConditions; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@ExtendWith(MockitoExtension.class) +class TripQueryServiceTest { + + @Mock + private TripCustomRepository tripCustomRepository; + + @InjectMocks + private TripQueryService tripQueryService; + + @Test + void 쿼리_조건에_따라_여행을_조회한다() { + // given + TripQueryConditions tripQueryConditions = new TripQueryConditions( + Set.of(), + Set.of(), + Set.of(), + Set.of(), + Set.of(), + "" + ); + TripPaging tripPaging = new TripPaging(1L, 10); + + given(tripCustomRepository.findAllByConditions(tripQueryConditions, tripPaging)) + .willReturn(new ArrayList<>()); + + // when + List trips = tripQueryService.readAllByQueryConditions(tripQueryConditions, tripPaging); + + // then + assertThat(trips).isEmpty(); + then(tripCustomRepository) + .should(times(1)) + .findAllByConditions(tripQueryConditions, tripPaging); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index 37d13311a..42da32f94 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -9,7 +9,6 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import dev.tripdraw.common.auth.LoginUser; -import dev.tripdraw.common.dto.SearchPaging; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; @@ -26,6 +25,7 @@ import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; import dev.tripdraw.trip.dto.TripSearchConditions; +import dev.tripdraw.trip.dto.TripSearchPaging; import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripSearchResponse; import dev.tripdraw.trip.dto.TripSearchResponseOfMember; @@ -180,11 +180,11 @@ void setUp() { Set.of(), "" ); - SearchPaging searchPaging = new SearchPaging(null, 10); - TripSearchRequest tripSearchRequest = new TripSearchRequest(emptyConditions, searchPaging); + TripSearchPaging tripSearchPaging = new TripSearchPaging(null, 10); + TripSearchRequest tripSearchRequest = new TripSearchRequest(emptyConditions, tripSearchPaging); // when - TripsSearchResponse tripsSearchResponse = tripService.readAllTrips(tripSearchRequest); + TripsSearchResponse tripsSearchResponse = tripService.readAll(tripSearchRequest); // then assertThat(tripsSearchResponse).usingRecursiveComparison().isEqualTo( diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java similarity index 80% rename from backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java rename to backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java index 0a8e16be6..b2b9f99e7 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/SearchConditionsTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import dev.tripdraw.trip.exception.TripException; +import dev.tripdraw.trip.query.TripQueryConditions; import java.util.Set; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -12,7 +13,7 @@ @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class SearchConditionsTest { +class TripQueryConditionsTest { @ParameterizedTest @ValueSource(ints = {2009, 2024}) @@ -21,7 +22,7 @@ class SearchConditionsTest { Set years = of(year); // expect - assertThatThrownBy(() -> new SearchConditions(years, of(), of(), of(), of(), "")) + assertThatThrownBy(() -> new TripQueryConditions(years, of(), of(), of(), of(), "")) .isInstanceOf(TripException.class) .hasMessage("유효하지 않은 여행 조회 조건입니다."); } @@ -33,7 +34,7 @@ class SearchConditionsTest { Set months = of(month); // expect - assertThatThrownBy(() -> new SearchConditions(of(), months, of(), of(), of(), "")) + assertThatThrownBy(() -> new TripQueryConditions(of(), months, of(), of(), of(), "")) .isInstanceOf(TripException.class) .hasMessage("유효하지 않은 여행 조회 조건입니다."); } @@ -45,7 +46,7 @@ class SearchConditionsTest { Set daysOfWeek = of(dayOfWeek); // expect - assertThatThrownBy(() -> new SearchConditions(of(), of(), daysOfWeek, of(), of(), "")) + assertThatThrownBy(() -> new TripQueryConditions(of(), of(), daysOfWeek, of(), of(), "")) .isInstanceOf(TripException.class) .hasMessage("유효하지 않은 여행 조회 조건입니다."); } @@ -57,7 +58,7 @@ class SearchConditionsTest { Set ageRanges = of(ageRange); // expect - assertThatThrownBy(() -> new SearchConditions(of(), of(), of(), ageRanges, of(), "")) + assertThatThrownBy(() -> new TripQueryConditions(of(), of(), of(), ageRanges, of(), "")) .isInstanceOf(TripException.class) .hasMessage("유효하지 않은 여행 조회 조건입니다."); } @@ -69,7 +70,7 @@ class SearchConditionsTest { Set genders = of(gender); // expect - assertThatThrownBy(() -> new SearchConditions(genders, of(), of(), of(), of(), "")) + assertThatThrownBy(() -> new TripQueryConditions(genders, of(), of(), of(), of(), "")) .isInstanceOf(TripException.class) .hasMessage("유효하지 않은 여행 조회 조건입니다."); } diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index dcfbe1ce1..15a691ad0 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -1,12 +1,6 @@ package dev.tripdraw.trip.domain; import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.test.fixture.SearchConditionsFixture.addressSearchConditions; -import static dev.tripdraw.test.fixture.SearchConditionsFixture.daysOfWeekSearchConditions; -import static dev.tripdraw.test.fixture.SearchConditionsFixture.emptySearchConditions; -import static dev.tripdraw.test.fixture.SearchConditionsFixture.monthsSearchConditions; -import static dev.tripdraw.test.fixture.SearchConditionsFixture.yearsSearchConditions; -import static dev.tripdraw.test.fixture.TestFixture.위치정보; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -14,22 +8,16 @@ import dev.tripdraw.common.config.JpaConfig; import dev.tripdraw.common.config.QueryDslConfig; -import dev.tripdraw.common.domain.Paging; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.post.domain.Post; import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; -import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; @@ -137,389 +125,389 @@ void setUp() { .hasMessage(TRIP_NOT_FOUND.message()); } - @Nested - class 조건에_따라_여행을_조회할_때 { - - @Nested - class 개수_제한이 { - - @ParameterizedTest - @CsvSource({"0, 1", "1, 2", "2, 3"}) - void 여행의_개수보다_적으면_개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { - // given - jeju_2023_1_1_Sun(); - jeju_2023_1_1_Sun(); - jeju_2023_1_1_Sun(); - - Paging paging = new Paging(null, limit); - - // when - List trips = tripRepository.findAllByConditions(emptySearchConditions(), paging); - - // then - assertThat(trips).hasSize(expectedSize); - } - - @ParameterizedTest - @CsvSource({"1, 1", "2, 1"}) - void 여행의_개수보다_많거나_같으면_모든_여행을_반환한다(int limit, int expectedSize) { - // given - jeju_2023_1_1_Sun(); - - Paging paging = new Paging(null, limit); - - // when - List trips = tripRepository.findAllByConditions(emptySearchConditions(), paging); - - // then - assertThat(trips).hasSize(expectedSize); - } - } - - @Nested - class 마지막으로_조회한_Id를 { - - @Test - void 입력하지_않으면_가장_최신_여행부터_내림차순으로_반환한다() { - // given - Trip jeju_2023_1_1_sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - - Long lastViewedId = null; - - // when - List trips = tripRepository.findAllByConditions(emptySearchConditions(), - new Paging(lastViewedId, 10)); - - // then - assertThat(trips).containsExactly( - jeju2023_2_1_Wed, - seoul2023_1_1_Sun, - jeju_2023_1_1_sun - ); - } - - @Test - void 입력하면_해당_Id_이하의_최신_여행을_내림차순으로_반환한다() { - // given - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - - Long lastViewedId = jeju2023_2_1_Wed.id(); - - // when - List trips = tripRepository.findAllByConditions(emptySearchConditions(), - new Paging(lastViewedId, 10)); - - // then - assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun); - } - } - - @Nested - class 조건으로_연도를 { - - @Test - void 한_개_설정하면_해당_연도의_여행을_반환한다() { - // given - seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = yearsSearchConditions(Set.of(2023)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(jeju2023_2_1_Wed, seoul2023_1_1_Sun, jeju2023_1_1_Sun); - } - - @Test - void 여러_개_설정하면_해당_연도들의_여행을_반환한다() { - // given - Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); - seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = yearsSearchConditions(Set.of(2023, 2021)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly( - jeju2023_2_1_Wed, - seoul2023_1_1_Sun, - jeju2023_1_1_Sun, - yangyang2021_3_2_Tue - ); - } - } - - @Nested - class 조건으로_월을 { - - @Test - void 한_개_설정하면_해당_월의_여행을_반환한다() { - // given - Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = monthsSearchConditions(Set.of(1)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); - } - - @Test - void 여러_개_설정하면_해당_월들의_여행을_반환한다() { - // given - Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); - Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = monthsSearchConditions(Set.of(1, 3)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly( - seoul2023_1_1_Sun, - jeju2023_1_1_Sun, - seoul2022_1_2_Sun, - yangyang2021_3_2_Tue - ); - } - } - - @Nested - class 조건으로_요일을 { - - @Test - void 한_개_설정하면_해당_요일의_여행을_반환한다() { - // given - Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = daysOfWeekSearchConditions(Set.of(1)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); - } - - @Test - void 여러_개_설정하면_해당_요일들의_여행을_반환한다() { - // given - Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); - Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = daysOfWeekSearchConditions(Set.of(1, 3)); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly( - seoul2023_1_1_Sun, - jeju2023_1_1_Sun, - seoul2022_1_2_Sun, - yangyang2021_3_2_Tue - ); - } - } - - @Nested - class 조건으로_주소를 { - - @Test - void 시도_시군구_읍면동_형식으로_입력하면_해당하는_여행을_반환한다() { - // given - Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); - Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); - Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - - SearchConditions searchConditions = addressSearchConditions("서울특별시 송파구 신천동"); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul_songpa_sincheon); - } - - @Test - void 시도_시군구_형식으로_입력하면_해당하는_여행을_반환한다() { - // given - Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); - Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); - Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - - SearchConditions searchConditions = addressSearchConditions("서울특별시 송파구"); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); - } - - @Test - void 시도_형식으로_입력하면_해당하는_여행을_반환한다() { - // given - Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); - Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); - Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - - SearchConditions searchConditions = addressSearchConditions("서울특별시"); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); - } - } - - @Nested - class 조건을 { - - @Test - void 여러_개_설정하면_해당하는_여행을_반환한다() { - // given - yangyang_2021_3_2_Tue(); - seoul_2022_1_2_Sun(); - jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = new SearchConditions( - Set.of(2023), - Set.of(1), - Set.of(), - Set.of(), - Set.of(), - "서울특별시" - ); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly(seoul2023_1_1_Sun); - } - - @Test - void 설정하지_않으면_모든_여행을_반환한다() { - // given - Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); - Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); - Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); - Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); - Trip jeju_2023_2_1_Wed = jeju_2023_2_1_Wed(); - - SearchConditions searchConditions = emptySearchConditions(); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).containsExactly( - jeju_2023_2_1_Wed, - seoul2023_1_1_Sun, - jeju2023_1_1_Sun, - seoul2022_1_2_Sun, - yangyang2021_3_2_Tue - ); - } - } - - @Test - void 감상이_없는_여행은_조회되지_않는다() { - // given - emptyPostTrip(); - - SearchConditions searchConditions = emptySearchConditions(); - - // when - List trips = tripRepository.findAllByConditions(searchConditions, new Paging(null, 10)); - - // then - assertThat(trips).isEmpty(); - } - - private Trip jeju_2023_2_1_Wed() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2023, 2, 1, 1, 1); - trip.add(point); - tripRepository.save(trip); - postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); - return trip; - } - - private Trip seoul_2023_1_1_Sun() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2023, 1, 1, 10, 1); - trip.add(point); - tripRepository.save(trip); - postRepository.save(new Post("", point, "서울특별시 송파구 신천동", "", member, trip.id())); - return trip; - } - - private Trip jeju_2023_1_1_Sun() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2023, 1, 1, 1, 1); - trip.add(point); - tripRepository.save(trip); - postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); - return trip; - } - - private Trip seoul_2022_1_2_Sun() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2022, 1, 2, 1, 1); - trip.add(point); - tripRepository.save(trip); - postRepository.save(new Post("", point, "서울특별시 송파구 방이동", "", member, trip.id())); - return trip; - } - - private Trip yangyang_2021_3_2_Tue() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2021, 3, 2, 1, 1); - trip.add(point); - tripRepository.save(trip); - postRepository.save(new Post("", point, "강원도 양양군", "", member, trip.id())); - return trip; - } - - private Trip emptyPostTrip() { - Trip trip = new Trip(TripName.from(""), member); - Point point = 위치정보(2021, 3, 2, 1, 1); - trip.add(point); - tripRepository.save(trip); - return trip; - } - } +// @Nested +// class 조건에_따라_여행을_조회할_때 { +// +// @Nested +// class 개수_제한이 { +// +// @ParameterizedTest +// @CsvSource({"0, 1", "1, 2", "2, 3"}) +// void 여행의_개수보다_적으면_개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { +// // given +// jeju_2023_1_1_Sun(); +// jeju_2023_1_1_Sun(); +// jeju_2023_1_1_Sun(); +// +// TripPaging tripPaging = new TripPaging(null, limit); +// +// // when +// List trips = tripRepository.findAllByConditions(emptySearchConditions(), tripPaging); +// +// // then +// assertThat(trips).hasSize(expectedSize); +// } +// +// @ParameterizedTest +// @CsvSource({"1, 1", "2, 1"}) +// void 여행의_개수보다_많거나_같으면_모든_여행을_반환한다(int limit, int expectedSize) { +// // given +// jeju_2023_1_1_Sun(); +// +// TripPaging tripPaging = new TripPaging(null, limit); +// +// // when +// List trips = tripRepository.findAllByConditions(emptySearchConditions(), tripPaging); +// +// // then +// assertThat(trips).hasSize(expectedSize); +// } +// } +// +// @Nested +// class 마지막으로_조회한_Id를 { +// +// @Test +// void 입력하지_않으면_가장_최신_여행부터_내림차순으로_반환한다() { +// // given +// Trip jeju_2023_1_1_sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); +// +// Long lastViewedId = null; +// +// // when +// List trips = tripRepository.findAllByConditions(emptySearchConditions(), +// new TripPaging(lastViewedId, 10)); +// +// // then +// assertThat(trips).containsExactly( +// jeju2023_2_1_Wed, +// seoul2023_1_1_Sun, +// jeju_2023_1_1_sun +// ); +// } +// +// @Test +// void 입력하면_해당_Id_이하의_최신_여행을_내림차순으로_반환한다() { +// // given +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); +// +// Long lastViewedId = jeju2023_2_1_Wed.id(); +// +// // when +// List trips = tripRepository.findAllByConditions(emptySearchConditions(), +// new TripPaging(lastViewedId, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun); +// } +// } +// +// @Nested +// class 조건으로_연도를 { +// +// @Test +// void 한_개_설정하면_해당_연도의_여행을_반환한다() { +// // given +// seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(jeju2023_2_1_Wed, seoul2023_1_1_Sun, jeju2023_1_1_Sun); +// } +// +// @Test +// void 여러_개_설정하면_해당_연도들의_여행을_반환한다() { +// // given +// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); +// seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023, 2021)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly( +// jeju2023_2_1_Wed, +// seoul2023_1_1_Sun, +// jeju2023_1_1_Sun, +// yangyang2021_3_2_Tue +// ); +// } +// } +// +// @Nested +// class 조건으로_월을 { +// +// @Test +// void 한_개_설정하면_해당_월의_여행을_반환한다() { +// // given +// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); +// } +// +// @Test +// void 여러_개_설정하면_해당_월들의_여행을_반환한다() { +// // given +// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); +// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1, 3)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly( +// seoul2023_1_1_Sun, +// jeju2023_1_1_Sun, +// seoul2022_1_2_Sun, +// yangyang2021_3_2_Tue +// ); +// } +// } +// +// @Nested +// class 조건으로_요일을 { +// +// @Test +// void 한_개_설정하면_해당_요일의_여행을_반환한다() { +// // given +// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); +// } +// +// @Test +// void 여러_개_설정하면_해당_요일들의_여행을_반환한다() { +// // given +// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); +// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1, 3)); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly( +// seoul2023_1_1_Sun, +// jeju2023_1_1_Sun, +// seoul2022_1_2_Sun, +// yangyang2021_3_2_Tue +// ); +// } +// } +// +// @Nested +// class 조건으로_주소를 { +// +// @Test +// void 시도_시군구_읍면동_형식으로_입력하면_해당하는_여행을_반환한다() { +// // given +// Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); +// Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); +// Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); +// +// TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구 신천동"); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul_songpa_sincheon); +// } +// +// @Test +// void 시도_시군구_형식으로_입력하면_해당하는_여행을_반환한다() { +// // given +// Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); +// Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); +// Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); +// +// TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구"); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); +// } +// +// @Test +// void 시도_형식으로_입력하면_해당하는_여행을_반환한다() { +// // given +// Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); +// Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); +// Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); +// +// TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시"); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); +// } +// } +// +// @Nested +// class 조건을 { +// +// @Test +// void 여러_개_설정하면_해당하는_여행을_반환한다() { +// // given +// yangyang_2021_3_2_Tue(); +// seoul_2022_1_2_Sun(); +// jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = new TripQueryConditions( +// Set.of(2023), +// Set.of(1), +// Set.of(), +// Set.of(), +// Set.of(), +// "서울특별시" +// ); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly(seoul2023_1_1_Sun); +// } +// +// @Test +// void 설정하지_않으면_모든_여행을_반환한다() { +// // given +// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); +// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); +// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); +// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); +// Trip jeju_2023_2_1_Wed = jeju_2023_2_1_Wed(); +// +// TripQueryConditions tripQueryConditions = emptySearchConditions(); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).containsExactly( +// jeju_2023_2_1_Wed, +// seoul2023_1_1_Sun, +// jeju2023_1_1_Sun, +// seoul2022_1_2_Sun, +// yangyang2021_3_2_Tue +// ); +// } +// } +// +// @Test +// void 감상이_없는_여행은_조회되지_않는다() { +// // given +// emptyPostTrip(); +// +// TripQueryConditions tripQueryConditions = emptySearchConditions(); +// +// // when +// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); +// +// // then +// assertThat(trips).isEmpty(); +// } +// +// private Trip jeju_2023_2_1_Wed() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2023, 2, 1, 1, 1); +// trip.add(point); +// tripRepository.save(trip); +// postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); +// return trip; +// } +// +// private Trip seoul_2023_1_1_Sun() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2023, 1, 1, 10, 1); +// trip.add(point); +// tripRepository.save(trip); +// postRepository.save(new Post("", point, "서울특별시 송파구 신천동", "", member, trip.id())); +// return trip; +// } +// +// private Trip jeju_2023_1_1_Sun() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2023, 1, 1, 1, 1); +// trip.add(point); +// tripRepository.save(trip); +// postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); +// return trip; +// } +// +// private Trip seoul_2022_1_2_Sun() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2022, 1, 2, 1, 1); +// trip.add(point); +// tripRepository.save(trip); +// postRepository.save(new Post("", point, "서울특별시 송파구 방이동", "", member, trip.id())); +// return trip; +// } +// +// private Trip yangyang_2021_3_2_Tue() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2021, 3, 2, 1, 1); +// trip.add(point); +// tripRepository.save(trip); +// postRepository.save(new Post("", point, "강원도 양양군", "", member, trip.id())); +// return trip; +// } +// +// private Trip emptyPostTrip() { +// Trip trip = new Trip(TripName.from(""), member); +// Point point = 위치정보(2021, 3, 2, 1, 1); +// trip.add(point); +// tripRepository.save(trip); +// return trip; +// } +// } } diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index 4fe6899b9..d8759184f 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -208,7 +208,7 @@ public void setUp() { // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .when().get("/trips/mine") + .when().get("/trips/me") .then().log().all() .extract(); diff --git a/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java b/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java new file mode 100644 index 000000000..90b2c94e0 --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java @@ -0,0 +1,454 @@ +package dev.tripdraw.trip.query; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.TestFixture.위치정보; +import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.addressSearchConditions; +import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.daysOfWeekSearchConditions; +import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.emptySearchConditions; +import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.monthsSearchConditions; +import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.yearsSearchConditions; +import static org.assertj.core.api.Assertions.assertThat; + +import dev.tripdraw.member.domain.Member; +import dev.tripdraw.member.domain.MemberRepository; +import dev.tripdraw.post.domain.Post; +import dev.tripdraw.post.domain.PostRepository; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; +import java.util.List; +import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@Transactional +@SpringBootTest +class TripCustomRepositoryImplTest { + + @Autowired + private TripCustomRepository tripCustomRepository; + + @Autowired + private TripRepository tripRepository; + + @Autowired + private PostRepository postRepository; + + @Autowired + private MemberRepository memberRepository; + + private Member member; + + @BeforeEach + void setUp() { + member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + } + + @Nested + class 조건에_따라_여행을_조회할_때 { + + @Nested + class 개수_제한이 { + + @ParameterizedTest + @CsvSource({"0, 1", "1, 2", "2, 3"}) + void 여행의_개수보다_적으면_개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { + // given + jeju_2023_1_1_Sun(); + jeju_2023_1_1_Sun(); + jeju_2023_1_1_Sun(); + + TripPaging tripPaging = new TripPaging(null, limit); + + // when + List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), tripPaging); + + // then + assertThat(trips).hasSize(expectedSize); + } + + @ParameterizedTest + @CsvSource({"1, 1", "2, 1"}) + void 여행의_개수보다_많거나_같으면_모든_여행을_반환한다(int limit, int expectedSize) { + // given + jeju_2023_1_1_Sun(); + + TripPaging tripPaging = new TripPaging(null, limit); + + // when + List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), tripPaging); + + // then + assertThat(trips).hasSize(expectedSize); + } + } + + @Nested + class 마지막으로_조회한_Id를 { + + @Test + void 입력하지_않으면_가장_최신_여행부터_내림차순으로_반환한다() { + // given + Trip jeju_2023_1_1_sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + Long lastViewedId = null; + + // when + List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), + new TripPaging(lastViewedId, 10)); + + // then + assertThat(trips).containsExactly( + jeju2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju_2023_1_1_sun + ); + } + + @Test + void 입력하면_해당_Id_이하의_최신_여행을_내림차순으로_반환한다() { + // given + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + Long lastViewedId = jeju2023_2_1_Wed.id(); + + // when + List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), + new TripPaging(lastViewedId, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun); + } + } + + @Nested + class 조건으로_연도를 { + + @Test + void 한_개_설정하면_해당_연도의_여행을_반환한다() { + // given + seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(jeju2023_2_1_Wed, seoul2023_1_1_Sun, jeju2023_1_1_Sun); + } + + @Test + void 여러_개_설정하면_해당_연도들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023, 2021)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly( + jeju2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_월을 { + + @Test + void 한_개_설정하면_해당_월의_여행을_반환한다() { + // given + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); + } + + @Test + void 여러_개_설정하면_해당_월들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1, 3)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly( + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_요일을 { + + @Test + void 한_개_설정하면_해당_요일의_여행을_반환한다() { + // given + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); + } + + @Test + void 여러_개_설정하면_해당_요일들의_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1, 3)); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly( + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Nested + class 조건으로_주소를 { + + @Test + void 시도_시군구_읍면동_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구 신천동"); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon); + } + + @Test + void 시도_시군구_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구"); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); + } + + @Test + void 시도_형식으로_입력하면_해당하는_여행을_반환한다() { + // given + Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); + Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); + Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); + + TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시"); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); + } + } + + @Nested + class 조건을 { + + @Test + void 여러_개_설정하면_해당하는_여행을_반환한다() { + // given + yangyang_2021_3_2_Tue(); + seoul_2022_1_2_Sun(); + jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = new TripQueryConditions( + Set.of(2023), + Set.of(1), + Set.of(), + Set.of(), + Set.of(), + "서울특별시" + ); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly(seoul2023_1_1_Sun); + } + + @Test + void 설정하지_않으면_모든_여행을_반환한다() { + // given + Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); + Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); + Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); + Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); + Trip jeju_2023_2_1_Wed = jeju_2023_2_1_Wed(); + + TripQueryConditions tripQueryConditions = emptySearchConditions(); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, + new TripPaging(null, 10)); + + // then + assertThat(trips).containsExactly( + jeju_2023_2_1_Wed, + seoul2023_1_1_Sun, + jeju2023_1_1_Sun, + seoul2022_1_2_Sun, + yangyang2021_3_2_Tue + ); + } + } + + @Test + void 감상이_없는_여행은_조회되지_않는다() { + // given + emptyPostTrip(); + + TripQueryConditions tripQueryConditions = emptySearchConditions(); + + // when + List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); + + // then + assertThat(trips).isEmpty(); + } + + private Trip jeju_2023_2_1_Wed() { + Trip trip = Trip.from(member); + Point point = 위치정보(2023, 2, 1, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); + return trip; + } + + private Trip seoul_2023_1_1_Sun() { + Trip trip = Trip.from(member); + Point point = 위치정보(2023, 1, 1, 10, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "서울특별시 송파구 신천동", "", member, trip.id())); + return trip; + } + + private Trip jeju_2023_1_1_Sun() { + Trip trip = Trip.from(member); + Point point = 위치정보(2023, 1, 1, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); + return trip; + } + + private Trip seoul_2022_1_2_Sun() { + Trip trip = Trip.from(member); + Point point = 위치정보(2022, 1, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "서울특별시 송파구 방이동", "", member, trip.id())); + return trip; + } + + private Trip yangyang_2021_3_2_Tue() { + Trip trip = Trip.from(member); + Point point = 위치정보(2021, 3, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + postRepository.save(new Post("", point, "강원도 양양군", "", member, trip.id())); + return trip; + } + + private Trip emptyPostTrip() { + Trip trip = Trip.from(member); + Point point = 위치정보(2021, 3, 2, 1, 1); + trip.add(point); + tripRepository.save(trip); + return trip; + } + } + +} From cac98f11a538d4c3a8b8e4532fd85555f75504fb Mon Sep 17 00:00:00 2001 From: Combi153 Date: Tue, 19 Sep 2023 13:25:37 +0900 Subject: [PATCH 107/119] =?UTF-8?q?[refactor]=20validate=20=EC=9D=BC?= =?UTF-8?q?=EB=8B=A8=20=EB=B9=BC=EA=B8=B0=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/trip/application/TripQueryService.java | 5 +---- .../java/dev/tripdraw/trip/query/TripQueryConditions.java | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java index d572e45df..1d41a72a3 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java @@ -18,10 +18,7 @@ public class TripQueryService { @Transactional(readOnly = true) public List readAllByQueryConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging) { - return tripCustomRepository.findAllByConditions( - tripQueryConditions, - tripPaging - ); + return tripCustomRepository.findAllByConditions(tripQueryConditions, tripPaging); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java index c856633bd..91a3291a7 100644 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java @@ -34,7 +34,7 @@ public TripQueryConditions( Set genders, String address ) { - validate(years, months, daysOfWeek, ageRanges, genders); +// validate(years, months, daysOfWeek, ageRanges, genders); this.years = new HashSet<>(years); this.months = new HashSet<>(months); this.daysOfWeek = new HashSet<>(daysOfWeek); From 6e90214a6a0ed4269c0d543b44911a829edfcceb Mon Sep 17 00:00:00 2001 From: Combi153 Date: Tue, 19 Sep 2023 13:33:59 +0900 Subject: [PATCH 108/119] =?UTF-8?q?[refactor]=20validate=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=EB=84=A3=EA=B8=B0=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/application/TripService.java | 20 +++++-------------- .../tripdraw/trip/dto/TripSearchResponse.java | 13 ++++++++++++ .../trip/query/TripQueryConditions.java | 7 ++++--- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index e2a924725..a0fd69ec8 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -3,34 +3,24 @@ import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.trip.domain.Point; -import dev.tripdraw.trip.domain.PointRepository; -import dev.tripdraw.trip.domain.Trip; -import dev.tripdraw.trip.domain.TripRepository; -import dev.tripdraw.trip.domain.TripUpdateEvent; -import dev.tripdraw.trip.dto.PointCreateRequest; -import dev.tripdraw.trip.dto.PointCreateResponse; -import dev.tripdraw.trip.dto.PointResponse; -import dev.tripdraw.trip.dto.TripCreateResponse; -import dev.tripdraw.trip.dto.TripResponse; -import dev.tripdraw.trip.dto.TripSearchRequest; -import dev.tripdraw.trip.dto.TripUpdateRequest; -import dev.tripdraw.trip.dto.TripsSearchResponse; -import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; +import dev.tripdraw.trip.domain.*; +import dev.tripdraw.trip.dto.*; import dev.tripdraw.trip.query.TripPaging; import dev.tripdraw.trip.query.TripQueryConditions; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @RequiredArgsConstructor @Transactional @Service public class TripService { private static final int FIRST_INDEX = 0; + private final TripRepository tripRepository; private final PointRepository pointRepository; private final MemberRepository memberRepository; diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java index 02ac94e1d..b7103ce5d 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java @@ -1,14 +1,27 @@ package dev.tripdraw.trip.dto; import dev.tripdraw.trip.domain.Trip; +import io.swagger.v3.oas.annotations.media.Schema; + import java.time.LocalDateTime; public record TripSearchResponse( + @Schema(description = "여행 Id", example = "1") Long tripId, + + @Schema(description = "여행명", example = "통후추의 여행") String name, + + @Schema(description = "이미지 주소", example = "https://tripdraw.site/post-images/cd678ca2-30d5-11ee-be56-0242ac120002.jpg") String imageUrl, + + @Schema(description = "경로 이미지 주소", example = "https://tripdraw.site/route-images/cd678ca2-30d5-11ee-be56-0242ac120002.png") String routeImageUrl, + + @Schema(description = "여행 시작 시각", example = "2023-07-23T19:48:27") LocalDateTime startTime, + + @Schema(description = "여행 종료 시각", example = "2023-07-23T19:48:27") LocalDateTime endTime ) { diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java index 91a3291a7..03bf64e7a 100644 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java @@ -1,11 +1,12 @@ package dev.tripdraw.trip.query; -import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; - import dev.tripdraw.trip.exception.TripException; + import java.util.HashSet; import java.util.Set; +import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; + public record TripQueryConditions( Set years, Set months, @@ -34,7 +35,7 @@ public TripQueryConditions( Set genders, String address ) { -// validate(years, months, daysOfWeek, ageRanges, genders); + validate(years, months, daysOfWeek, ageRanges, genders); this.years = new HashSet<>(years); this.months = new HashSet<>(months); this.daysOfWeek = new HashSet<>(daysOfWeek); From d483ae4514dda064560d09f114be1811e0023beb Mon Sep 17 00:00:00 2001 From: Combi153 Date: Tue, 19 Sep 2023 14:01:08 +0900 Subject: [PATCH 109/119] =?UTF-8?q?[feat]=20builder=20=EC=A0=81=EC=9A=A9?= =?UTF-8?q?=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/dto/TripSearchConditions.java | 12 +- .../trip/query/TripQueryConditions.java | 2 + .../fixture/TripQueryConditionsFixture.java | 113 +++++++++--------- .../fixture/TripSearchConditionsFixture.java | 113 +++++++++--------- 4 files changed, 126 insertions(+), 114 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java index df81efeeb..de91dc5e7 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java @@ -1,9 +1,10 @@ package dev.tripdraw.trip.dto; import dev.tripdraw.trip.query.TripQueryConditions; -import java.util.Set; import lombok.Builder; +import java.util.Set; + @Builder public record TripSearchConditions( Set years, @@ -15,6 +16,13 @@ public record TripSearchConditions( ) { public TripQueryConditions toTripQueryConditions() { - return new TripQueryConditions(years(), months(), daysOfWeek(), ageRanges(), genders(), address()); + return TripQueryConditions.builder() + .years(years) + .months(months) + .daysOfWeek(daysOfWeek) + .ageRanges(ageRanges) + .genders(genders) + .address(address) + .build(); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java index 03bf64e7a..cd7c12ae4 100644 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java @@ -1,12 +1,14 @@ package dev.tripdraw.trip.query; import dev.tripdraw.trip.exception.TripException; +import lombok.Builder; import java.util.HashSet; import java.util.Set; import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; +@Builder public record TripQueryConditions( Set years, Set months, diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java index a99ae9fd3..f0d9710cd 100644 --- a/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java @@ -1,85 +1,86 @@ package dev.tripdraw.test.fixture; import dev.tripdraw.trip.query.TripQueryConditions; + import java.util.Set; public class TripQueryConditionsFixture { public static TripQueryConditions emptySearchConditions() { - return new TripQueryConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripQueryConditions yearsSearchConditions(Set years) { - return new TripQueryConditions( - years, - Set.of(), - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripQueryConditions.builder() + .years(years) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripQueryConditions monthsSearchConditions(Set months) { - return new TripQueryConditions( - Set.of(), - months, - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(months) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripQueryConditions daysOfWeekSearchConditions(Set daysOfWeek) { - return new TripQueryConditions( - Set.of(), - Set.of(), - daysOfWeek, - Set.of(), - Set.of(), - "" - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(daysOfWeek) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripQueryConditions ageRangesSearchConditions(Set ageRanges) { - return new TripQueryConditions( - Set.of(), - Set.of(), - Set.of(), - ageRanges, - Set.of(), - "" - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(ageRanges) + .genders(Set.of()) + .address("") + .build(); } public static TripQueryConditions gendersSearchConditions(Set genders) { - return new TripQueryConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - genders, - "" - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(genders) + .address("") + .build(); } public static TripQueryConditions addressSearchConditions(String address) { - return new TripQueryConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - Set.of(), - address - ); + return TripQueryConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address(address) + .build(); } } diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java index e4e78c2f5..d3d5e67f8 100644 --- a/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java @@ -1,84 +1,85 @@ package dev.tripdraw.test.fixture; import dev.tripdraw.trip.dto.TripSearchConditions; + import java.util.Set; public class TripSearchConditionsFixture { public static TripSearchConditions emptyTripSearchConditions() { - return new TripSearchConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripSearchConditions yearsTripSearchConditions(Set years) { - return new TripSearchConditions( - years, - Set.of(), - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripSearchConditions.builder() + .years(years) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripSearchConditions monthsTripSearchConditions(Set months) { - return new TripSearchConditions( - Set.of(), - months, - Set.of(), - Set.of(), - Set.of(), - "" - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(months) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripSearchConditions daysOfWeekTripSearchConditions(Set daysOfWeek) { - return new TripSearchConditions( - Set.of(), - Set.of(), - daysOfWeek, - Set.of(), - Set.of(), - "" - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(daysOfWeek) + .ageRanges(Set.of()) + .genders(Set.of()) + .address("") + .build(); } public static TripSearchConditions ageRangesTripSearchConditions(Set ageRanges) { - return new TripSearchConditions( - Set.of(), - Set.of(), - Set.of(), - ageRanges, - Set.of(), - "" - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(ageRanges) + .genders(Set.of()) + .address("") + .build(); } public static TripSearchConditions gendersTripSearchConditions(Set genders) { - return new TripSearchConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - genders, - "" - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(genders) + .address("") + .build(); } public static TripSearchConditions addressTripSearchConditions(String address) { - return new TripSearchConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - Set.of(), - address - ); + return TripSearchConditions.builder() + .years(Set.of()) + .months(Set.of()) + .daysOfWeek(Set.of()) + .ageRanges(Set.of()) + .genders(Set.of()) + .address(address) + .build(); } } From 526c8e33c56af15fc57de6979209acce826373be Mon Sep 17 00:00:00 2001 From: Combi153 Date: Tue, 19 Sep 2023 15:03:14 +0900 Subject: [PATCH 110/119] =?UTF-8?q?[refactor]=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EA=B0=9D=EC=B2=B4=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F?= =?UTF-8?q?=20VO=EB=A1=9C=20=ED=86=B5=EC=9D=BC=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/application/TripQueryService.java | 9 +- .../trip/application/TripService.java | 7 +- .../trip/dto/TripSearchConditions.java | 12 -- .../tripdraw/trip/dto/TripSearchRequest.java | 6 +- .../trip/presentation/TripController.java | 25 +-- .../trip/query/TripCustomRepository.java | 4 +- .../trip/query/TripCustomRepositoryImpl.java | 24 +-- .../trip/query/TripQueryConditions.java | 73 --------- .../fixture/TripQueryConditionsFixture.java | 86 ---------- .../fixture/TripSearchConditionsFixture.java | 36 ----- .../acceptance/TripSearchAcceptanceTest.java | 64 ++------ .../application/TripQueryServiceTest.java | 34 ++-- .../trip/domain/TripQueryConditionsTest.java | 77 --------- .../query/TripCustomRepositoryImplTest.java | 148 ++++++++++-------- 14 files changed, 143 insertions(+), 462 deletions(-) delete mode 100644 backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java delete mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java delete mode 100644 backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java index 1d41a72a3..34edc3b69 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripQueryService.java @@ -1,14 +1,15 @@ package dev.tripdraw.trip.application; import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.dto.TripSearchConditions; import dev.tripdraw.trip.query.TripCustomRepository; import dev.tripdraw.trip.query.TripPaging; -import dev.tripdraw.trip.query.TripQueryConditions; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @RequiredArgsConstructor @Transactional @Service @@ -17,8 +18,8 @@ public class TripQueryService { private final TripCustomRepository tripCustomRepository; @Transactional(readOnly = true) - public List readAllByQueryConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging) { - return tripCustomRepository.findAllByConditions(tripQueryConditions, tripPaging); + public List readAllByQueryConditions(TripSearchConditions tripSearchConditions, TripPaging tripPaging) { + return tripCustomRepository.findAllByConditions(tripSearchConditions, tripPaging); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index a0fd69ec8..b422eb5be 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -6,7 +6,6 @@ import dev.tripdraw.trip.domain.*; import dev.tripdraw.trip.dto.*; import dev.tripdraw.trip.query.TripPaging; -import dev.tripdraw.trip.query.TripQueryConditions; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; @@ -20,7 +19,7 @@ public class TripService { private static final int FIRST_INDEX = 0; - + private final TripRepository tripRepository; private final PointRepository pointRepository; private final MemberRepository memberRepository; @@ -72,10 +71,10 @@ public TripsSearchResponseOfMember readAllTripsOf(LoginUser loginUser) { @Transactional(readOnly = true) public TripsSearchResponse readAll(TripSearchRequest tripSearchRequest) { - TripQueryConditions tripQueryConditions = tripSearchRequest.toTripQueryConditions(); + TripSearchConditions condition = tripSearchRequest.condition(); TripPaging tripPaging = tripSearchRequest.toTripPaging(); - List trips = tripQueryService.readAllByQueryConditions(tripQueryConditions, tripPaging); + List trips = tripQueryService.readAllByQueryConditions(condition, tripPaging); if (tripPaging.hasNextPage(trips.size())) { return TripsSearchResponse.of(trips.subList(FIRST_INDEX, tripPaging.limit()), true); diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java index de91dc5e7..785818f63 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchConditions.java @@ -1,6 +1,5 @@ package dev.tripdraw.trip.dto; -import dev.tripdraw.trip.query.TripQueryConditions; import lombok.Builder; import java.util.Set; @@ -14,15 +13,4 @@ public record TripSearchConditions( Set genders, String address ) { - - public TripQueryConditions toTripQueryConditions() { - return TripQueryConditions.builder() - .years(years) - .months(months) - .daysOfWeek(daysOfWeek) - .ageRanges(ageRanges) - .genders(genders) - .address(address) - .build(); - } } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java index 0289a16c3..867f24c6f 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java @@ -1,17 +1,13 @@ package dev.tripdraw.trip.dto; import dev.tripdraw.trip.query.TripPaging; -import dev.tripdraw.trip.query.TripQueryConditions; public record TripSearchRequest( + TripSearchConditions condition, TripSearchPaging paging ) { - public TripQueryConditions toTripQueryConditions() { - return condition.toTripQueryConditions(); - } - public TripPaging toTripPaging() { return paging.toTripPaging(); } diff --git a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java index 7492f0b09..9c96a9db0 100644 --- a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java +++ b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java @@ -1,34 +1,19 @@ package dev.tripdraw.trip.presentation; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.NO_CONTENT; - import dev.tripdraw.common.auth.Auth; import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.common.swagger.SwaggerAuthorizationRequired; import dev.tripdraw.trip.application.TripService; -import dev.tripdraw.trip.dto.PointCreateRequest; -import dev.tripdraw.trip.dto.PointCreateResponse; -import dev.tripdraw.trip.dto.PointResponse; -import dev.tripdraw.trip.dto.TripCreateResponse; -import dev.tripdraw.trip.dto.TripResponse; -import dev.tripdraw.trip.dto.TripSearchRequest; -import dev.tripdraw.trip.dto.TripUpdateRequest; -import dev.tripdraw.trip.dto.TripsSearchResponse; -import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; +import dev.tripdraw.trip.dto.*; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NO_CONTENT; @Tag(name = "Trip", description = "여행 관련 API 명세") @SwaggerAuthorizationRequired diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java index 9d8ace9f6..8c89d9b70 100644 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepository.java @@ -1,9 +1,11 @@ package dev.tripdraw.trip.query; import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.dto.TripSearchConditions; + import java.util.List; public interface TripCustomRepository { - List findAllByConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging); + List findAllByConditions(TripSearchConditions tripSearchConditions, TripPaging tripPaging); } diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java index 86066939f..cf0888ef9 100644 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java @@ -1,19 +1,21 @@ package dev.tripdraw.trip.query; -import static dev.tripdraw.post.domain.QPost.post; -import static dev.tripdraw.trip.domain.QPoint.point; -import static dev.tripdraw.trip.domain.QTrip.trip; - import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.dto.TripSearchConditions; import io.micrometer.common.util.StringUtils; -import java.util.List; -import java.util.Set; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; import org.springframework.util.CollectionUtils; +import java.util.List; +import java.util.Set; + +import static dev.tripdraw.post.domain.QPost.post; +import static dev.tripdraw.trip.domain.QPoint.point; +import static dev.tripdraw.trip.domain.QTrip.trip; + @RequiredArgsConstructor @Repository public class TripCustomRepositoryImpl implements TripCustomRepository { @@ -21,17 +23,17 @@ public class TripCustomRepositoryImpl implements TripCustomRepository { private final JPAQueryFactory query; @Override - public List findAllByConditions(TripQueryConditions tripQueryConditions, TripPaging tripPaging) { + public List findAllByConditions(TripSearchConditions tripSearchConditions, TripPaging tripPaging) { return query .selectFrom(trip) .join(post).on(trip.id.eq(post.tripId)) .join(point).on(post.point.id.eq(point.id)) .where( tripIdLt(tripPaging.lastViewedId()), - yearIn(tripQueryConditions.years()), - monthIn(tripQueryConditions.months()), - dayOfWeekIn(tripQueryConditions.daysOfWeek()), - addressLike(tripQueryConditions.address()) + yearIn(tripSearchConditions.years()), + monthIn(tripSearchConditions.months()), + dayOfWeekIn(tripSearchConditions.daysOfWeek()), + addressLike(tripSearchConditions.address()) ) .orderBy(trip.id.desc()) .limit(tripPaging.limit().longValue() + 1L) diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java b/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java deleted file mode 100644 index cd7c12ae4..000000000 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripQueryConditions.java +++ /dev/null @@ -1,73 +0,0 @@ -package dev.tripdraw.trip.query; - -import dev.tripdraw.trip.exception.TripException; -import lombok.Builder; - -import java.util.HashSet; -import java.util.Set; - -import static dev.tripdraw.trip.exception.TripExceptionType.INVALID_TRIP_SEARCH; - -@Builder -public record TripQueryConditions( - Set years, - Set months, - Set daysOfWeek, - Set ageRanges, - Set genders, - String address -) { - - private static final int YEAR_MINIMUM = 2010; - private static final int YEAR_MAXIMUM = 2023; - private static final int MONTH_MINIMUM = 1; - private static final int MONTH_MAXIMUM = 12; - private static final int DAYS_OF_WEEK_MINIMUM = 1; - private static final int DAYS_OF_WEEK_MAXIMUM = 7; - private static final int AGE_RANGE_MINIMUM = 1; - private static final int AGE_RANGE_MAXIMUM = 10; - private static final int GENDER_MINIMUM = 1; - private static final int GENDER_MAXIMUM = 2; - - public TripQueryConditions( - Set years, - Set months, - Set daysOfWeek, - Set ageRanges, - Set genders, - String address - ) { - validate(years, months, daysOfWeek, ageRanges, genders); - this.years = new HashSet<>(years); - this.months = new HashSet<>(months); - this.daysOfWeek = new HashSet<>(daysOfWeek); - this.ageRanges = new HashSet<>(ageRanges); - this.genders = new HashSet<>(genders); - this.address = address; - } - - private void validate( - Set years, - Set months, - Set daysOfWeek, - Set ageRanges, - Set genders - ) { - validateRange(years, YEAR_MINIMUM, YEAR_MAXIMUM); - validateRange(months, MONTH_MINIMUM, MONTH_MAXIMUM); - validateRange(daysOfWeek, DAYS_OF_WEEK_MINIMUM, DAYS_OF_WEEK_MAXIMUM); - validateRange(ageRanges, AGE_RANGE_MINIMUM, AGE_RANGE_MAXIMUM); - validateRange(genders, GENDER_MINIMUM, GENDER_MAXIMUM); - } - - private void validateRange(Set conditions, int min, int max) { - if (isOutOfRange(conditions, min, max)) { - throw new TripException(INVALID_TRIP_SEARCH); - } - } - - private boolean isOutOfRange(Set conditions, int min, int max) { - return conditions.stream() - .anyMatch(condition -> condition < min || condition > max); - } -} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java deleted file mode 100644 index f0d9710cd..000000000 --- a/backend/src/test/java/dev/tripdraw/test/fixture/TripQueryConditionsFixture.java +++ /dev/null @@ -1,86 +0,0 @@ -package dev.tripdraw.test.fixture; - -import dev.tripdraw.trip.query.TripQueryConditions; - -import java.util.Set; - - -public class TripQueryConditionsFixture { - - public static TripQueryConditions emptySearchConditions() { - return TripQueryConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") - .build(); - } - - public static TripQueryConditions yearsSearchConditions(Set years) { - return TripQueryConditions.builder() - .years(years) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") - .build(); - } - - public static TripQueryConditions monthsSearchConditions(Set months) { - return TripQueryConditions.builder() - .years(Set.of()) - .months(months) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") - .build(); - } - - public static TripQueryConditions daysOfWeekSearchConditions(Set daysOfWeek) { - return TripQueryConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(daysOfWeek) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") - .build(); - } - - public static TripQueryConditions ageRangesSearchConditions(Set ageRanges) { - return TripQueryConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(ageRanges) - .genders(Set.of()) - .address("") - .build(); - } - - public static TripQueryConditions gendersSearchConditions(Set genders) { - return TripQueryConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(genders) - .address("") - .build(); - } - - public static TripQueryConditions addressSearchConditions(String address) { - return TripQueryConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address(address) - .build(); - } -} diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java index d3d5e67f8..9cbcdf4e7 100644 --- a/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchConditionsFixture.java @@ -8,77 +8,41 @@ public class TripSearchConditionsFixture { public static TripSearchConditions emptyTripSearchConditions() { return TripSearchConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") .build(); } public static TripSearchConditions yearsTripSearchConditions(Set years) { return TripSearchConditions.builder() .years(years) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") .build(); } public static TripSearchConditions monthsTripSearchConditions(Set months) { return TripSearchConditions.builder() - .years(Set.of()) .months(months) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") .build(); } public static TripSearchConditions daysOfWeekTripSearchConditions(Set daysOfWeek) { return TripSearchConditions.builder() - .years(Set.of()) - .months(Set.of()) .daysOfWeek(daysOfWeek) - .ageRanges(Set.of()) - .genders(Set.of()) - .address("") .build(); } public static TripSearchConditions ageRangesTripSearchConditions(Set ageRanges) { return TripSearchConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) .ageRanges(ageRanges) - .genders(Set.of()) - .address("") .build(); } public static TripSearchConditions gendersTripSearchConditions(Set genders) { return TripSearchConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) .genders(genders) - .address("") .build(); } public static TripSearchConditions addressTripSearchConditions(String address) { return TripSearchConditions.builder() - .years(Set.of()) - .months(Set.of()) - .daysOfWeek(Set.of()) - .ageRanges(Set.of()) - .genders(Set.of()) .address(address) .build(); } diff --git a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java index 2f7e10c15..bd133613c 100644 --- a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java @@ -1,50 +1,34 @@ package dev.tripdraw.trip.acceptance; -import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.test.fixture.TestFixture.서울_2022_1_2_일; -import static dev.tripdraw.test.fixture.TestFixture.서울_2023_1_1_일; -import static dev.tripdraw.test.fixture.TestFixture.양양_2021_3_2_화; -import static dev.tripdraw.test.fixture.TestFixture.제주_2023_1_1_일; -import static dev.tripdraw.test.fixture.TestFixture.제주_2023_2_1_수; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.addressTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.daysOfWeekTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.emptyTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.monthsTripSearchConditions; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.yearsTripSearchConditions; -import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; -import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; -import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.springframework.http.HttpStatus.BAD_REQUEST; -import static org.springframework.http.HttpStatus.OK; -import static org.springframework.http.HttpStatus.UNAUTHORIZED; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; - import dev.tripdraw.auth.application.JwtTokenProvider; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.test.ControllerTest; -import dev.tripdraw.trip.dto.TripSearchConditions; -import dev.tripdraw.trip.dto.TripSearchPaging; -import dev.tripdraw.trip.dto.TripSearchRequest; -import dev.tripdraw.trip.dto.TripSearchResponse; -import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.*; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; -import java.util.List; -import java.util.Set; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; +import java.util.List; +import java.util.Set; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.TestFixture.*; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.*; +import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; +import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.UNAUTHORIZED; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class TripSearchAcceptanceTest extends ControllerTest { @@ -478,24 +462,6 @@ class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { }); } - @Test - void 조건이_유효하지_않을_경우_예외를_발생시킨다() { - // given - var tripSearchRequest = new TripSearchRequest( - monthsTripSearchConditions(Set.of(Integer.MAX_VALUE)), - nullLastViewedIdAnd10Limit - ); - - // expect - RestAssured.given().log().all() - .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) - .when().get("/trips") - .then().log().all() - .statusCode(BAD_REQUEST.value()); - } - @Test void 인증에_실패할_경우_예외를_발생시킨다() { // given diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java index d3ec76e13..aea4bbf77 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripQueryServiceTest.java @@ -1,17 +1,10 @@ package dev.tripdraw.trip.application; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.times; - +import dev.tripdraw.test.fixture.TripSearchConditionsFixture; import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.dto.TripSearchConditions; import dev.tripdraw.trip.query.TripCustomRepository; import dev.tripdraw.trip.query.TripPaging; -import dev.tripdraw.trip.query.TripQueryConditions; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -20,6 +13,14 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.times; + @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ExtendWith(MockitoExtension.class) @@ -34,26 +35,19 @@ class TripQueryServiceTest { @Test void 쿼리_조건에_따라_여행을_조회한다() { // given - TripQueryConditions tripQueryConditions = new TripQueryConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - Set.of(), - "" - ); + TripSearchConditions tripSearchConditions = TripSearchConditionsFixture.emptyTripSearchConditions(); TripPaging tripPaging = new TripPaging(1L, 10); - given(tripCustomRepository.findAllByConditions(tripQueryConditions, tripPaging)) + given(tripCustomRepository.findAllByConditions(tripSearchConditions, tripPaging)) .willReturn(new ArrayList<>()); // when - List trips = tripQueryService.readAllByQueryConditions(tripQueryConditions, tripPaging); + List trips = tripQueryService.readAllByQueryConditions(tripSearchConditions, tripPaging); // then assertThat(trips).isEmpty(); then(tripCustomRepository) .should(times(1)) - .findAllByConditions(tripQueryConditions, tripPaging); + .findAllByConditions(tripSearchConditions, tripPaging); } } diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java deleted file mode 100644 index b2b9f99e7..000000000 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripQueryConditionsTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package dev.tripdraw.trip.domain; - -import static java.util.Set.of; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import dev.tripdraw.trip.exception.TripException; -import dev.tripdraw.trip.query.TripQueryConditions; -import java.util.Set; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -@SuppressWarnings("NonAsciiCharacters") -@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class TripQueryConditionsTest { - - @ParameterizedTest - @ValueSource(ints = {2009, 2024}) - void 연도가_2010_미만_2023_초과이면_예외를_던진다(int year) { - // given - Set years = of(year); - - // expect - assertThatThrownBy(() -> new TripQueryConditions(years, of(), of(), of(), of(), "")) - .isInstanceOf(TripException.class) - .hasMessage("유효하지 않은 여행 조회 조건입니다."); - } - - @ParameterizedTest - @ValueSource(ints = {0, 13}) - void 월이_1_미만_12_초과이면_예외를_던진다(int month) { - // given - Set months = of(month); - - // expect - assertThatThrownBy(() -> new TripQueryConditions(of(), months, of(), of(), of(), "")) - .isInstanceOf(TripException.class) - .hasMessage("유효하지 않은 여행 조회 조건입니다."); - } - - @ParameterizedTest - @ValueSource(ints = {0, 8}) - void 요일이_1_미만_7_초과이면_예외를_던진다(int dayOfWeek) { - // given - Set daysOfWeek = of(dayOfWeek); - - // expect - assertThatThrownBy(() -> new TripQueryConditions(of(), of(), daysOfWeek, of(), of(), "")) - .isInstanceOf(TripException.class) - .hasMessage("유효하지 않은 여행 조회 조건입니다."); - } - - @ParameterizedTest - @ValueSource(ints = {0, 11}) - void 연령대가_1_미만_10_초과이면_예외를_던진다(int ageRange) { - // given - Set ageRanges = of(ageRange); - - // expect - assertThatThrownBy(() -> new TripQueryConditions(of(), of(), of(), ageRanges, of(), "")) - .isInstanceOf(TripException.class) - .hasMessage("유효하지 않은 여행 조회 조건입니다."); - } - - @ParameterizedTest - @ValueSource(ints = {0, 3}) - void 성별이_1_미만_2_초과이면_예외를_던진다(int gender) { - // given - Set genders = of(gender); - - // expect - assertThatThrownBy(() -> new TripQueryConditions(genders, of(), of(), of(), of(), "")) - .isInstanceOf(TripException.class) - .hasMessage("유효하지 않은 여행 조회 조건입니다."); - } -} diff --git a/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java b/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java index 90b2c94e0..cc69dde71 100644 --- a/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java @@ -1,14 +1,5 @@ package dev.tripdraw.trip.query; -import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.test.fixture.TestFixture.위치정보; -import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.addressSearchConditions; -import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.daysOfWeekSearchConditions; -import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.emptySearchConditions; -import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.monthsSearchConditions; -import static dev.tripdraw.test.fixture.TripQueryConditionsFixture.yearsSearchConditions; -import static org.assertj.core.api.Assertions.assertThat; - import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.domain.Post; @@ -16,19 +7,22 @@ import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; -import java.util.List; -import java.util.Set; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import dev.tripdraw.trip.dto.TripSearchConditions; +import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.Set; + +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.TestFixture.위치정보; +import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.*; +import static org.assertj.core.api.Assertions.assertThat; + @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @Transactional @@ -71,7 +65,7 @@ class 개수_제한이 { TripPaging tripPaging = new TripPaging(null, limit); // when - List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), tripPaging); + List trips = tripCustomRepository.findAllByConditions(emptyTripSearchConditions(), tripPaging); // then assertThat(trips).hasSize(expectedSize); @@ -86,7 +80,7 @@ class 개수_제한이 { TripPaging tripPaging = new TripPaging(null, limit); // when - List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), tripPaging); + List trips = tripCustomRepository.findAllByConditions(emptyTripSearchConditions(), tripPaging); // then assertThat(trips).hasSize(expectedSize); @@ -106,8 +100,10 @@ class 마지막으로_조회한_Id를 { Long lastViewedId = null; // when - List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), - new TripPaging(lastViewedId, 10)); + List trips = tripCustomRepository.findAllByConditions( + emptyTripSearchConditions(), + new TripPaging(lastViewedId, 10) + ); // then assertThat(trips).containsExactly( @@ -127,8 +123,10 @@ class 마지막으로_조회한_Id를 { Long lastViewedId = jeju2023_2_1_Wed.id(); // when - List trips = tripCustomRepository.findAllByConditions(emptySearchConditions(), - new TripPaging(lastViewedId, 10)); + List trips = tripCustomRepository.findAllByConditions( + emptyTripSearchConditions(), + new TripPaging(lastViewedId, 10) + ); // then assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun); @@ -146,11 +144,13 @@ class 조건으로_연도를 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023)); + TripSearchConditions tripSearchConditions = yearsTripSearchConditions(Set.of(2023)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(jeju2023_2_1_Wed, seoul2023_1_1_Sun, jeju2023_1_1_Sun); @@ -165,11 +165,13 @@ class 조건으로_연도를 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023, 2021)); + TripSearchConditions tripSearchConditions = yearsTripSearchConditions(Set.of(2023, 2021)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly( @@ -192,11 +194,13 @@ class 조건으로_월을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1)); + TripSearchConditions tripSearchConditions = monthsTripSearchConditions(Set.of(1)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); @@ -211,11 +215,13 @@ class 조건으로_월을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1, 3)); + TripSearchConditions tripSearchConditions = monthsTripSearchConditions(Set.of(1, 3)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly( @@ -238,11 +244,13 @@ class 조건으로_요일을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1)); + TripSearchConditions tripSearchConditions = daysOfWeekTripSearchConditions(Set.of(1)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); @@ -257,11 +265,13 @@ class 조건으로_요일을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1, 3)); + TripSearchConditions tripSearchConditions = daysOfWeekTripSearchConditions(Set.of(1, 3)); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly( @@ -283,11 +293,13 @@ class 조건으로_주소를 { Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구 신천동"); + TripSearchConditions tripSearchConditions = addressTripSearchConditions("서울특별시 송파구 신천동"); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul_songpa_sincheon); @@ -300,11 +312,13 @@ class 조건으로_주소를 { Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구"); + TripSearchConditions tripSearchConditions = addressTripSearchConditions("서울특별시 송파구"); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); @@ -317,11 +331,13 @@ class 조건으로_주소를 { Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); - TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시"); + TripSearchConditions tripSearchConditions = addressTripSearchConditions("서울특별시"); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); @@ -340,18 +356,17 @@ class 조건을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = new TripQueryConditions( - Set.of(2023), - Set.of(1), - Set.of(), - Set.of(), - Set.of(), - "서울특별시" - ); + TripSearchConditions tripSearchConditions = TripSearchConditions.builder() + .years(Set.of(2023)) + .months(Set.of(1)) + .address("서울특별시") + .build(); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly(seoul2023_1_1_Sun); @@ -366,11 +381,13 @@ class 조건을 { Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); Trip jeju_2023_2_1_Wed = jeju_2023_2_1_Wed(); - TripQueryConditions tripQueryConditions = emptySearchConditions(); + TripSearchConditions tripSearchConditions = emptyTripSearchConditions(); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, - new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).containsExactly( @@ -388,10 +405,13 @@ class 조건을 { // given emptyPostTrip(); - TripQueryConditions tripQueryConditions = emptySearchConditions(); + TripSearchConditions tripSearchConditions = emptyTripSearchConditions(); // when - List trips = tripCustomRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); + List trips = tripCustomRepository.findAllByConditions( + tripSearchConditions, + new TripPaging(null, 10) + ); // then assertThat(trips).isEmpty(); From 0639641ecb0b202ae2a736e377d15e719a8e11b8 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Tue, 19 Sep 2023 15:17:18 +0900 Subject: [PATCH 111/119] =?UTF-8?q?[chore]=20conflict=20=ED=95=B4=EA=B2=B0?= =?UTF-8?q?=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index a2f472eda..549f20f2c 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -26,7 +26,6 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @Import({JpaConfig.class, QueryDslConfig.class}) @DataJpaTest -@Import({JpaConfig.class, QueryDslConfig.class}) class TripRepositoryTest { @Autowired From 069e7d762ddb9226b7f297d1129ae139c494457f Mon Sep 17 00:00:00 2001 From: Combi153 Date: Tue, 19 Sep 2023 15:19:34 +0900 Subject: [PATCH 112/119] =?UTF-8?q?[chore]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=A3=BC=EC=84=9D=20=EC=82=AD=EC=A0=9C=20(#361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/domain/TripRepositoryTest.java | 390 ------------------ 1 file changed, 390 deletions(-) diff --git a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java index 549f20f2c..f38e26b4c 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripRepositoryTest.java @@ -10,7 +10,6 @@ import dev.tripdraw.common.config.QueryDslConfig; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.post.domain.PostRepository; import dev.tripdraw.trip.exception.TripException; import java.time.LocalDateTime; import java.util.List; @@ -31,9 +30,6 @@ class TripRepositoryTest { @Autowired private TripRepository tripRepository; - @Autowired - private PostRepository postRepository; - @Autowired private MemberRepository memberRepository; @@ -124,390 +120,4 @@ void setUp() { .isInstanceOf(TripException.class) .hasMessage(TRIP_NOT_FOUND.message()); } - -// @Nested -// class 조건에_따라_여행을_조회할_때 { -// -// @Nested -// class 개수_제한이 { -// -// @ParameterizedTest -// @CsvSource({"0, 1", "1, 2", "2, 3"}) -// void 여행의_개수보다_적으면_개수_제한보다_하나_더_반환한다(int limit, int expectedSize) { -// // given -// jeju_2023_1_1_Sun(); -// jeju_2023_1_1_Sun(); -// jeju_2023_1_1_Sun(); -// -// TripPaging tripPaging = new TripPaging(null, limit); -// -// // when -// List trips = tripRepository.findAllByConditions(emptySearchConditions(), tripPaging); -// -// // then -// assertThat(trips).hasSize(expectedSize); -// } -// -// @ParameterizedTest -// @CsvSource({"1, 1", "2, 1"}) -// void 여행의_개수보다_많거나_같으면_모든_여행을_반환한다(int limit, int expectedSize) { -// // given -// jeju_2023_1_1_Sun(); -// -// TripPaging tripPaging = new TripPaging(null, limit); -// -// // when -// List trips = tripRepository.findAllByConditions(emptySearchConditions(), tripPaging); -// -// // then -// assertThat(trips).hasSize(expectedSize); -// } -// } -// -// @Nested -// class 마지막으로_조회한_Id를 { -// -// @Test -// void 입력하지_않으면_가장_최신_여행부터_내림차순으로_반환한다() { -// // given -// Trip jeju_2023_1_1_sun = jeju_2023_1_1_Sun(); -// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); -// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); -// -// Long lastViewedId = null; -// -// // when -// List trips = tripRepository.findAllByConditions(emptySearchConditions(), -// new TripPaging(lastViewedId, 10)); -// -// // then -// assertThat(trips).containsExactly( -// jeju2023_2_1_Wed, -// seoul2023_1_1_Sun, -// jeju_2023_1_1_sun -// ); -// } -// -// @Test -// void 입력하면_해당_Id_이하의_최신_여행을_내림차순으로_반환한다() { -// // given -// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); -// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); -// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); -// -// Long lastViewedId = jeju2023_2_1_Wed.id(); -// -// // when -// List trips = tripRepository.findAllByConditions(emptySearchConditions(), -// new TripPaging(lastViewedId, 10)); -// -// // then -// assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun); -// } -// } -// -// @Nested -// class 조건으로_연도를 { -// -// @Test -// void 한_개_설정하면_해당_연도의_여행을_반환한다() { -// // given -// seoul_2022_1_2_Sun(); -// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); -// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); -// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); -// -// TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023)); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).containsExactly(jeju2023_2_1_Wed, seoul2023_1_1_Sun, jeju2023_1_1_Sun); -// } -// -// @Test -// void 여러_개_설정하면_해당_연도들의_여행을_반환한다() { -// // given -// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); -// seoul_2022_1_2_Sun(); -// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); -// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); -// Trip jeju2023_2_1_Wed = jeju_2023_2_1_Wed(); -// -// TripQueryConditions tripQueryConditions = yearsSearchConditions(Set.of(2023, 2021)); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).containsExactly( -// jeju2023_2_1_Wed, -// seoul2023_1_1_Sun, -// jeju2023_1_1_Sun, -// yangyang2021_3_2_Tue -// ); -// } -// } -// -// @Nested -// class 조건으로_월을 { -// -// @Test -// void 한_개_설정하면_해당_월의_여행을_반환한다() { -// // given -// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); -// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); -// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); -// jeju_2023_2_1_Wed(); -// -// TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1)); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); -// } -// -// @Test -// void 여러_개_설정하면_해당_월들의_여행을_반환한다() { -// // given -// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); -// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); -// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); -// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); -// jeju_2023_2_1_Wed(); -// -// TripQueryConditions tripQueryConditions = monthsSearchConditions(Set.of(1, 3)); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).containsExactly( -// seoul2023_1_1_Sun, -// jeju2023_1_1_Sun, -// seoul2022_1_2_Sun, -// yangyang2021_3_2_Tue -// ); -// } -// } -// -// @Nested -// class 조건으로_요일을 { -// -// @Test -// void 한_개_설정하면_해당_요일의_여행을_반환한다() { -// // given -// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); -// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); -// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); -// jeju_2023_2_1_Wed(); -// -// TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1)); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).containsExactly(seoul2023_1_1_Sun, jeju2023_1_1_Sun, seoul2022_1_2_Sun); -// } -// -// @Test -// void 여러_개_설정하면_해당_요일들의_여행을_반환한다() { -// // given -// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); -// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); -// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); -// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); -// jeju_2023_2_1_Wed(); -// -// TripQueryConditions tripQueryConditions = daysOfWeekSearchConditions(Set.of(1, 3)); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).containsExactly( -// seoul2023_1_1_Sun, -// jeju2023_1_1_Sun, -// seoul2022_1_2_Sun, -// yangyang2021_3_2_Tue -// ); -// } -// } -// -// @Nested -// class 조건으로_주소를 { -// -// @Test -// void 시도_시군구_읍면동_형식으로_입력하면_해당하는_여행을_반환한다() { -// // given -// Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); -// Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); -// Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); -// -// TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구 신천동"); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).containsExactly(seoul_songpa_sincheon); -// } -// -// @Test -// void 시도_시군구_형식으로_입력하면_해당하는_여행을_반환한다() { -// // given -// Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); -// Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); -// Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); -// -// TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시 송파구"); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); -// } -// -// @Test -// void 시도_형식으로_입력하면_해당하는_여행을_반환한다() { -// // given -// Trip seoul_songpa_Bangi = seoul_2022_1_2_Sun(); -// Trip jejuIsland_jeju_aewol = jeju_2023_1_1_Sun(); -// Trip seoul_songpa_sincheon = seoul_2023_1_1_Sun(); -// -// TripQueryConditions tripQueryConditions = addressSearchConditions("서울특별시"); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).containsExactly(seoul_songpa_sincheon, seoul_songpa_Bangi); -// } -// } -// -// @Nested -// class 조건을 { -// -// @Test -// void 여러_개_설정하면_해당하는_여행을_반환한다() { -// // given -// yangyang_2021_3_2_Tue(); -// seoul_2022_1_2_Sun(); -// jeju_2023_1_1_Sun(); -// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); -// jeju_2023_2_1_Wed(); -// -// TripQueryConditions tripQueryConditions = new TripQueryConditions( -// Set.of(2023), -// Set.of(1), -// Set.of(), -// Set.of(), -// Set.of(), -// "서울특별시" -// ); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).containsExactly(seoul2023_1_1_Sun); -// } -// -// @Test -// void 설정하지_않으면_모든_여행을_반환한다() { -// // given -// Trip yangyang2021_3_2_Tue = yangyang_2021_3_2_Tue(); -// Trip seoul2022_1_2_Sun = seoul_2022_1_2_Sun(); -// Trip jeju2023_1_1_Sun = jeju_2023_1_1_Sun(); -// Trip seoul2023_1_1_Sun = seoul_2023_1_1_Sun(); -// Trip jeju_2023_2_1_Wed = jeju_2023_2_1_Wed(); -// -// TripQueryConditions tripQueryConditions = emptySearchConditions(); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).containsExactly( -// jeju_2023_2_1_Wed, -// seoul2023_1_1_Sun, -// jeju2023_1_1_Sun, -// seoul2022_1_2_Sun, -// yangyang2021_3_2_Tue -// ); -// } -// } -// -// @Test -// void 감상이_없는_여행은_조회되지_않는다() { -// // given -// emptyPostTrip(); -// -// TripQueryConditions tripQueryConditions = emptySearchConditions(); -// -// // when -// List trips = tripRepository.findAllByConditions(tripQueryConditions, new TripPaging(null, 10)); -// -// // then -// assertThat(trips).isEmpty(); -// } -// -// private Trip jeju_2023_2_1_Wed() { -// Trip trip = new Trip(TripName.from(""), member); -// Point point = 위치정보(2023, 2, 1, 1, 1); -// trip.add(point); -// tripRepository.save(trip); -// postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); -// return trip; -// } -// -// private Trip seoul_2023_1_1_Sun() { -// Trip trip = new Trip(TripName.from(""), member); -// Point point = 위치정보(2023, 1, 1, 10, 1); -// trip.add(point); -// tripRepository.save(trip); -// postRepository.save(new Post("", point, "서울특별시 송파구 신천동", "", member, trip.id())); -// return trip; -// } -// -// private Trip jeju_2023_1_1_Sun() { -// Trip trip = new Trip(TripName.from(""), member); -// Point point = 위치정보(2023, 1, 1, 1, 1); -// trip.add(point); -// tripRepository.save(trip); -// postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); -// return trip; -// } -// -// private Trip seoul_2022_1_2_Sun() { -// Trip trip = new Trip(TripName.from(""), member); -// Point point = 위치정보(2022, 1, 2, 1, 1); -// trip.add(point); -// tripRepository.save(trip); -// postRepository.save(new Post("", point, "서울특별시 송파구 방이동", "", member, trip.id())); -// return trip; -// } -// -// private Trip yangyang_2021_3_2_Tue() { -// Trip trip = new Trip(TripName.from(""), member); -// Point point = 위치정보(2021, 3, 2, 1, 1); -// trip.add(point); -// tripRepository.save(trip); -// postRepository.save(new Post("", point, "강원도 양양군", "", member, trip.id())); -// return trip; -// } -// -// private Trip emptyPostTrip() { -// Trip trip = new Trip(TripName.from(""), member); -// Point point = 위치정보(2021, 3, 2, 1, 1); -// trip.add(point); -// tripRepository.save(trip); -// return trip; -// } -// } } From 7006c6dc72d0af9567503760619553cb5f5f4098 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Wed, 20 Sep 2023 12:11:28 +0900 Subject: [PATCH 113/119] =?UTF-8?q?[refactor]=20Trip=20=EC=A0=84=EC=B2=B4?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20api=20QueryString=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95=20(#379)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/application/TripService.java | 22 ++- .../tripdraw/trip/dto/TripSearchRequest.java | 27 ++- .../trip/presentation/TripController.java | 27 ++- .../fixture/TripSearchQueryParamsFixture.java | 60 ++++++ .../acceptance/TripSearchAcceptanceTest.java | 172 +++++++----------- .../trip/application/TripServiceTest.java | 16 +- .../trip/presentation/TripControllerTest.java | 55 ++++++ 7 files changed, 244 insertions(+), 135 deletions(-) create mode 100644 backend/src/test/java/dev/tripdraw/test/fixture/TripSearchQueryParamsFixture.java diff --git a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java index b422eb5be..a3910a2e2 100644 --- a/backend/src/main/java/dev/tripdraw/trip/application/TripService.java +++ b/backend/src/main/java/dev/tripdraw/trip/application/TripService.java @@ -3,16 +3,28 @@ import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.trip.domain.*; -import dev.tripdraw.trip.dto.*; +import dev.tripdraw.trip.domain.Point; +import dev.tripdraw.trip.domain.PointRepository; +import dev.tripdraw.trip.domain.Trip; +import dev.tripdraw.trip.domain.TripRepository; +import dev.tripdraw.trip.domain.TripUpdateEvent; +import dev.tripdraw.trip.dto.PointCreateRequest; +import dev.tripdraw.trip.dto.PointCreateResponse; +import dev.tripdraw.trip.dto.PointResponse; +import dev.tripdraw.trip.dto.TripCreateResponse; +import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchConditions; +import dev.tripdraw.trip.dto.TripSearchRequest; +import dev.tripdraw.trip.dto.TripUpdateRequest; +import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import dev.tripdraw.trip.query.TripPaging; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - @RequiredArgsConstructor @Transactional @Service @@ -71,7 +83,7 @@ public TripsSearchResponseOfMember readAllTripsOf(LoginUser loginUser) { @Transactional(readOnly = true) public TripsSearchResponse readAll(TripSearchRequest tripSearchRequest) { - TripSearchConditions condition = tripSearchRequest.condition(); + TripSearchConditions condition = tripSearchRequest.toTripSearchConditions(); TripPaging tripPaging = tripSearchRequest.toTripPaging(); List trips = tripQueryService.readAllByQueryConditions(condition, tripPaging); diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java index 867f24c6f..2688c4b35 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchRequest.java @@ -1,14 +1,33 @@ package dev.tripdraw.trip.dto; import dev.tripdraw.trip.query.TripPaging; +import java.util.Set; +import lombok.Builder; +@Builder public record TripSearchRequest( - - TripSearchConditions condition, - TripSearchPaging paging + Set years, + Set months, + Set daysOfWeek, + Set ageRanges, + Set genders, + String address, + Long lastViewedId, + Integer limit ) { + public TripSearchConditions toTripSearchConditions() { + return TripSearchConditions.builder() + .years(years) + .months(months) + .daysOfWeek(daysOfWeek) + .ageRanges(ageRanges) + .genders(genders) + .address(address) + .build(); + } + public TripPaging toTripPaging() { - return paging.toTripPaging(); + return new TripPaging(lastViewedId, limit); } } diff --git a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java index 9c96a9db0..7e7458330 100644 --- a/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java +++ b/backend/src/main/java/dev/tripdraw/trip/presentation/TripController.java @@ -1,19 +1,34 @@ package dev.tripdraw.trip.presentation; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NO_CONTENT; + import dev.tripdraw.common.auth.Auth; import dev.tripdraw.common.auth.LoginUser; import dev.tripdraw.common.swagger.SwaggerAuthorizationRequired; import dev.tripdraw.trip.application.TripService; -import dev.tripdraw.trip.dto.*; +import dev.tripdraw.trip.dto.PointCreateRequest; +import dev.tripdraw.trip.dto.PointCreateResponse; +import dev.tripdraw.trip.dto.PointResponse; +import dev.tripdraw.trip.dto.TripCreateResponse; +import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchRequest; +import dev.tripdraw.trip.dto.TripUpdateRequest; +import dev.tripdraw.trip.dto.TripsSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.NO_CONTENT; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Tag(name = "Trip", description = "여행 관련 API 명세") @SwaggerAuthorizationRequired @@ -108,7 +123,7 @@ public ResponseEntity readAllOf(@Auth LoginUser log @GetMapping("/trips") public ResponseEntity readAll( @Auth LoginUser loginUser, - @RequestBody TripSearchRequest tripSearchRequest + TripSearchRequest tripSearchRequest ) { TripsSearchResponse response = tripService.readAll(tripSearchRequest); return ResponseEntity.ok(response); diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchQueryParamsFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchQueryParamsFixture.java new file mode 100644 index 000000000..cf849b5cf --- /dev/null +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TripSearchQueryParamsFixture.java @@ -0,0 +1,60 @@ +package dev.tripdraw.test.fixture; + +import java.util.Map; +import java.util.Set; + +public class TripSearchQueryParamsFixture { + + public static Map limitParams(int limit) { + return Map.of("limit", limit); + } + + public static Map lastViewedIdAndLimitParams(Long lastViewedId, int limit) { + return Map.of( + "lastViewedId", lastViewedId, + "limit", limit + ); + } + + public static Map yearsAndLimitParams(Set years, int limit) { + return Map.of( + "years", years, + "limit", limit + ); + } + + public static Map monthsAndLimitParams(Set months, int limit) { + return Map.of( + "months", months, + "limit", limit + ); + } + + public static Map daysOfWeekAndLimitParams(Set daysOfWeek, int limit) { + return Map.of( + "daysOfWeek", daysOfWeek, + "limit", limit + ); + } + + public static Map ageRangesAndLimitParams(Set ageRanges, int limit) { + return Map.of( + "ageRanges", ageRanges, + "limit", limit + ); + } + + public static Map gendersAndLimitParams(Set genders, int limit) { + return Map.of( + "genders", genders, + "limit", limit + ); + } + + public static Map addressAndLimitParams(String address, int limit) { + return Map.of( + "address", address, + "limit", limit + ); + } +} diff --git a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java index bd133613c..1d95b8776 100644 --- a/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/acceptance/TripSearchAcceptanceTest.java @@ -1,34 +1,47 @@ package dev.tripdraw.trip.acceptance; +import static dev.tripdraw.common.auth.OauthType.KAKAO; +import static dev.tripdraw.test.fixture.TestFixture.서울_2022_1_2_일; +import static dev.tripdraw.test.fixture.TestFixture.서울_2023_1_1_일; +import static dev.tripdraw.test.fixture.TestFixture.양양_2021_3_2_화; +import static dev.tripdraw.test.fixture.TestFixture.제주_2023_1_1_일; +import static dev.tripdraw.test.fixture.TestFixture.제주_2023_2_1_수; +import static dev.tripdraw.test.fixture.TripSearchQueryParamsFixture.addressAndLimitParams; +import static dev.tripdraw.test.fixture.TripSearchQueryParamsFixture.daysOfWeekAndLimitParams; +import static dev.tripdraw.test.fixture.TripSearchQueryParamsFixture.lastViewedIdAndLimitParams; +import static dev.tripdraw.test.fixture.TripSearchQueryParamsFixture.limitParams; +import static dev.tripdraw.test.fixture.TripSearchQueryParamsFixture.monthsAndLimitParams; +import static dev.tripdraw.test.fixture.TripSearchQueryParamsFixture.yearsAndLimitParams; +import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; +import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.UNAUTHORIZED; + import dev.tripdraw.auth.application.JwtTokenProvider; import dev.tripdraw.draw.application.RouteImageGenerator; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.test.ControllerTest; -import dev.tripdraw.trip.dto.*; +import dev.tripdraw.trip.dto.TripSearchResponse; +import dev.tripdraw.trip.dto.TripsSearchResponse; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; -import org.junit.jupiter.api.*; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; -import java.util.List; -import java.util.Set; - -import static dev.tripdraw.common.auth.OauthType.KAKAO; -import static dev.tripdraw.test.fixture.TestFixture.*; -import static dev.tripdraw.test.fixture.TripSearchConditionsFixture.*; -import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; -import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; -import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.springframework.http.HttpStatus.OK; -import static org.springframework.http.HttpStatus.UNAUTHORIZED; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; - @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class TripSearchAcceptanceTest extends ControllerTest { @@ -57,11 +70,11 @@ public void setUp() { super.setUp(); Member huchu = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - Member leo = memberRepository.save(new Member("리오", "kakaoId", KAKAO)); + Member reo = memberRepository.save(new Member("리오", "kakaoId", KAKAO)); Member herb = memberRepository.save(new Member("허브", "kakaoId", KAKAO)); huchuToken = jwtTokenProvider.generateAccessToken(huchu.id().toString()); - String leoToken = jwtTokenProvider.generateAccessToken(leo.id().toString()); + String reoToken = jwtTokenProvider.generateAccessToken(reo.id().toString()); String herbToken = jwtTokenProvider.generateAccessToken(herb.id().toString()); 후추_양양_2021_3_2_화 = createTripAndGetResponse(huchuToken).tripId(); @@ -70,11 +83,11 @@ public void setUp() { 후추_서울_2022_1_2_일 = createTripAndGetResponse(huchuToken).tripId(); createPostAtCurrentPoint(서울_2022_1_2_일(후추_서울_2022_1_2_일), huchuToken); - 리오_제주_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); - createPostAtCurrentPoint(제주_2023_1_1_일(리오_제주_2023_1_1_일), leoToken); + 리오_제주_2023_1_1_일 = createTripAndGetResponse(reoToken).tripId(); + createPostAtCurrentPoint(제주_2023_1_1_일(리오_제주_2023_1_1_일), reoToken); - 리오_서울_2023_1_1_일 = createTripAndGetResponse(leoToken).tripId(); - createPostAtCurrentPoint(서울_2023_1_1_일(리오_서울_2023_1_1_일), leoToken); + 리오_서울_2023_1_1_일 = createTripAndGetResponse(reoToken).tripId(); + createPostAtCurrentPoint(서울_2023_1_1_일(리오_서울_2023_1_1_일), reoToken); 허브_제주_2023_2_1_수 = createTripAndGetResponse(herbToken).tripId(); createPostAtCurrentPoint(제주_2023_2_1_수(허브_제주_2023_2_1_수), herbToken); @@ -93,16 +106,12 @@ class 개수_제한을 { @CsvSource({"1, 1", "4, 4"}) void 조회할_수_있는_여행_수_미만으로_입력하면_해당_개수만큼_여행이_조회된다(int limit, int expectedSize) { // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new TripSearchPaging(null, limit) - ); + var tripSearchParams = limitParams(limit); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .extract(); @@ -120,16 +129,12 @@ class 개수_제한을 { @ValueSource(ints = {1, 4}) void 조회할_수_있는_여행_수_미만으로_입력하면_다음_페이지가_존재한다(int limit) { // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new TripSearchPaging(null, limit) - ); + var tripSearchParams = limitParams(limit); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .extract(); @@ -147,16 +152,12 @@ class 개수_제한을 { @CsvSource({"5, 5", "6, 5"}) void 조회할_수_있는_여행_수_이상으로_입력하면_모든_여행이_조회된다(int limit, int expectedSize) { // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new TripSearchPaging(null, limit) - ); + var tripSearchParams = limitParams(limit); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .extract(); @@ -174,16 +175,12 @@ class 개수_제한을 { @ValueSource(ints = {5, 6}) void 조회할_수_있는_여행_수_이상으로_입력하면_다음_페이지가_존재하지_않는다(int limit) { // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new TripSearchPaging(null, limit) - ); + var tripSearchParams = limitParams(limit); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .extract(); @@ -206,16 +203,12 @@ class 마지막으로_조회한_여행_ID를 { @Test void 입력하지_않으면_최신_여행부터_내림차순으로_조회된다() { // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new TripSearchPaging(null, LIMIT) - ); + var tripSearchParams = limitParams(LIMIT); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .extract(); @@ -238,16 +231,12 @@ class 마지막으로_조회한_여행_ID를 { @Test void 입력하면_해당_여행_이하로_최신_여행을_내림차순으로_조회된다() { // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - new TripSearchPaging(lastViewedId, LIMIT) - ); + var tripSearchParams = lastViewedIdAndLimitParams(lastViewedId, LIMIT); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .extract(); @@ -271,21 +260,17 @@ class 마지막으로_조회한_여행_ID를 { @Nested class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { - private final TripSearchPaging nullLastViewedIdAnd10Limit = new TripSearchPaging(null, 10); + private static final int LIMIT = 10; @Test void 조건없이_조회할_수_있다() { // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - nullLastViewedIdAnd10Limit - ); + var tripSearchParams = limitParams(LIMIT); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .extract(); @@ -308,16 +293,12 @@ class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { @Test void 연도를_조건으로_조회할_수_있다() { // given - var tripSearchRequest = new TripSearchRequest( - yearsTripSearchConditions(Set.of(2023)), - nullLastViewedIdAnd10Limit - ); + var tripSearchParams = yearsAndLimitParams(Set.of(2023), LIMIT); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .extract(); @@ -338,16 +319,12 @@ class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { @Test void 월을_조건으로_조회할_수_있다() { // given - var tripSearchRequest = new TripSearchRequest( - monthsTripSearchConditions(Set.of(1, 2)), - nullLastViewedIdAnd10Limit - ); + var tripSearchParams = monthsAndLimitParams(Set.of(1, 2), LIMIT); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .extract(); @@ -369,16 +346,12 @@ class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { @Test void 요일을_조건으로_조회할_수_있다() { // given - var tripSearchRequest = new TripSearchRequest( - daysOfWeekTripSearchConditions(Set.of(1, 3)), - nullLastViewedIdAnd10Limit - ); + var tripSearchParams = daysOfWeekAndLimitParams(Set.of(1, 3), LIMIT); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .extract(); @@ -400,16 +373,12 @@ class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { @Test void 주소를_조건으로_조회할_수_있다() { // given - var tripSearchRequest = new TripSearchRequest( - addressTripSearchConditions("seoul_songpa"), - nullLastViewedIdAnd10Limit - ); + var tripSearchParams = addressAndLimitParams("seoul_songpa", LIMIT); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .extract(); @@ -429,24 +398,17 @@ class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { @Test void 여러_조건으로_조회할_수_있다() { // given - var multiSearchConditions = new TripSearchConditions( - Set.of(2023, 2021), - Set.of(), - Set.of(1), - Set.of(), - Set.of(), - "seoul" - ); - var tripSearchRequest = new TripSearchRequest( - multiSearchConditions, - nullLastViewedIdAnd10Limit + Map params = Map.of( + "years", Set.of(2023, 2021), + "daysOfWeek", Set.of(1), + "address", "seoul", + "limit", LIMIT ); // when ExtractableResponse response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(params) .when().get("/trips") .then().log().all() .extract(); @@ -465,16 +427,12 @@ class 감상이_있는_모든_여행을_조건에_따라_조회할_때 { @Test void 인증에_실패할_경우_예외를_발생시킨다() { // given - var tripSearchRequest = new TripSearchRequest( - emptyTripSearchConditions(), - nullLastViewedIdAnd10Limit - ); + var tripSearchParams = limitParams(LIMIT); // expect RestAssured.given().log().all() .auth().preemptive().oauth2(WRONG_TOKEN) - .contentType(APPLICATION_JSON_VALUE) - .body(tripSearchRequest) + .params(tripSearchParams) .when().get("/trips") .then().log().all() .statusCode(UNAUTHORIZED.value()); diff --git a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java index 42da32f94..24a907a3f 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -24,8 +24,6 @@ import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; -import dev.tripdraw.trip.dto.TripSearchConditions; -import dev.tripdraw.trip.dto.TripSearchPaging; import dev.tripdraw.trip.dto.TripSearchRequest; import dev.tripdraw.trip.dto.TripSearchResponse; import dev.tripdraw.trip.dto.TripSearchResponseOfMember; @@ -36,7 +34,6 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Objects; -import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -172,16 +169,9 @@ void setUp() { @Test void 모든_회원의_감상이_있는_여행_전체를_조회한다() { // given - TripSearchConditions emptyConditions = new TripSearchConditions( - Set.of(), - Set.of(), - Set.of(), - Set.of(), - Set.of(), - "" - ); - TripSearchPaging tripSearchPaging = new TripSearchPaging(null, 10); - TripSearchRequest tripSearchRequest = new TripSearchRequest(emptyConditions, tripSearchPaging); + TripSearchRequest tripSearchRequest = TripSearchRequest.builder() + .limit(10) + .build(); // when TripsSearchResponse tripsSearchResponse = tripService.readAll(tripSearchRequest); diff --git a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java index d8759184f..b19d2c802 100644 --- a/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/presentation/TripControllerTest.java @@ -3,6 +3,10 @@ import static dev.tripdraw.common.auth.OauthType.KAKAO; import static dev.tripdraw.test.fixture.TestFixture.pointCreateRequest; import static dev.tripdraw.test.fixture.TestFixture.tripUpdateRequest; +import static dev.tripdraw.test.fixture.TestFixture.서울_2022_1_2_일; +import static dev.tripdraw.test.fixture.TestFixture.서울_2023_1_1_일; +import static dev.tripdraw.test.fixture.TestFixture.제주_2023_1_1_일; +import static dev.tripdraw.test.step.PostStep.createPostAtCurrentPoint; import static dev.tripdraw.test.step.TripStep.addPointAndGetResponse; import static dev.tripdraw.test.step.TripStep.createTripAndGetResponse; import static dev.tripdraw.test.step.TripStep.searchTripAndGetResponse; @@ -25,14 +29,18 @@ import dev.tripdraw.trip.dto.PointResponse; import dev.tripdraw.trip.dto.TripCreateResponse; import dev.tripdraw.trip.dto.TripResponse; +import dev.tripdraw.trip.dto.TripSearchResponse; import dev.tripdraw.trip.dto.TripSearchResponseOfMember; import dev.tripdraw.trip.dto.TripUpdateRequest; +import dev.tripdraw.trip.dto.TripsSearchResponse; import dev.tripdraw.trip.dto.TripsSearchResponseOfMember; import io.restassured.RestAssured; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import java.time.LocalDateTime; import java.util.List; +import java.util.Map; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -56,13 +64,16 @@ class TripControllerTest extends ControllerTest { private RouteImageGenerator routeImageGenerator; private String huchuToken; + private String reoToken; @BeforeEach public void setUp() { super.setUp(); Member huchu = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + Member reo = memberRepository.save(new Member("리오", "kakaoId", KAKAO)); huchuToken = jwtTokenProvider.generateAccessToken(huchu.id().toString()); + reoToken = jwtTokenProvider.generateAccessToken(reo.id().toString()); } @Test @@ -314,4 +325,48 @@ public void setUp() { .then().log().all() .statusCode(UNAUTHORIZED.value()); } + + @Test + void 감상이_있는_모든_여행을_조건으로_조회할_수_있다() { + // given + Long 후추_서울_2022_1_2_일 = createTripAndGetResponse(huchuToken).tripId(); + createPostAtCurrentPoint(서울_2022_1_2_일(후추_서울_2022_1_2_일), huchuToken); + + Long 리오_제주_2023_1_1_일 = createTripAndGetResponse(reoToken).tripId(); + createPostAtCurrentPoint(제주_2023_1_1_일(리오_제주_2023_1_1_일), reoToken); + + Long 리오_서울_2023_1_1_일 = createTripAndGetResponse(reoToken).tripId(); + createPostAtCurrentPoint(서울_2023_1_1_일(리오_서울_2023_1_1_일), reoToken); + + Map params = Map.of( + "years", Set.of(2023, 2021), + "daysOfWeek", Set.of(1), + "address", "seoul", + "limit", 10 + ); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .auth().preemptive().oauth2(huchuToken) + .params(params) + .when().get("/trips") + .then().log().all() + .extract(); + + // then + TripsSearchResponse tripsSearchResponse = response.as(TripsSearchResponse.class); + + assertSoftly(softly -> { + softly.assertThat(response.statusCode()).isEqualTo(OK.value()); + softly.assertThat(searchedTripIds(tripsSearchResponse)).containsExactly( + 리오_서울_2023_1_1_일 + ); + }); + } + + private List searchedTripIds(TripsSearchResponse tripsSearchResponse) { + return tripsSearchResponse.trips().stream() + .map(TripSearchResponse::tripId) + .toList(); + } } From bde72e595378bfdd84b20c0a628f430efc5c4771 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Wed, 20 Sep 2023 12:30:25 +0900 Subject: [PATCH 114/119] =?UTF-8?q?[refactor]=20Post=20=EC=A0=84=EC=B2=B4?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20api=20QueryString=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95=20(#379)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/application/PostService.java | 15 ++-- .../tripdraw/post/dto/PostSearchRequest.java | 32 +++++++- .../post/presentation/PostController.java | 3 +- .../post/application/PostServiceTest.java | 35 ++++----- .../post/presentation/PostControllerTest.java | 75 +++++++++---------- 5 files changed, 92 insertions(+), 68 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index 0d004002f..ed9bf309f 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -15,6 +15,7 @@ import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; +import dev.tripdraw.post.dto.PostSearchPaging; import dev.tripdraw.post.dto.PostSearchRequest; import dev.tripdraw.post.dto.PostSearchResponse; import dev.tripdraw.post.dto.PostUpdateRequest; @@ -24,14 +25,13 @@ import dev.tripdraw.trip.domain.PointRepository; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; -import java.util.List; - @RequiredArgsConstructor @Transactional @Service @@ -129,15 +129,20 @@ public void delete(LoginUser loginUser, Long postId) { } public PostsSearchResponse readAll(PostSearchRequest postSearchRequest) { - List posts = postQueryService.findAllByConditions(postSearchRequest.conditions(), postSearchRequest.paging()); + PostSearchPaging postSearchPaging = postSearchRequest.toPostSearchPaging(); + + List posts = postQueryService.findAllByConditions( + postSearchRequest.toPostSearchConditions(), + postSearchPaging + ); List postSearchResponses = posts.stream() .map(PostSearchResponse::from) .toList(); - boolean hasNextPage = (posts.size() == postSearchRequest.paging().limit() + 1); + boolean hasNextPage = (posts.size() == postSearchPaging.limit() + 1); if (hasNextPage) { - postSearchResponses = postSearchResponses.subList(0, postSearchRequest.paging().limit()); + postSearchResponses = postSearchResponses.subList(0, postSearchPaging.limit()); } return PostsSearchResponse.of(postSearchResponses, hasNextPage); diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java index 5e8edab4c..1426fba3d 100644 --- a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchRequest.java @@ -1,4 +1,34 @@ package dev.tripdraw.post.dto; -public record PostSearchRequest(PostSearchConditions conditions, PostSearchPaging paging) { +import java.util.Set; +import lombok.Builder; + +@Builder +public record PostSearchRequest( + Set years, + Set months, + Set daysOfWeek, + Set hours, + Set ageRanges, + Set genders, + String address, + Long lastViewedId, + Integer limit +) { + + public PostSearchConditions toPostSearchConditions() { + return PostSearchConditions.builder() + .years(years) + .months(months) + .daysOfWeek(daysOfWeek) + .hours(hours) + .ageRanges(ageRanges) + .genders(genders) + .address(address) + .build(); + } + + public PostSearchPaging toPostSearchPaging() { + return new PostSearchPaging(lastViewedId, limit); + } } diff --git a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java index c563d3394..a84173594 100644 --- a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java +++ b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java @@ -29,7 +29,6 @@ import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; @@ -132,7 +131,7 @@ public ResponseEntity readAllPostsOfTrip( @GetMapping("/posts") public ResponseEntity readAllPosts( @Auth LoginUser loginUser, - @RequestBody PostSearchRequest postSearchRequest + PostSearchRequest postSearchRequest ) { PostsSearchResponse response = postService.readAll(postSearchRequest); return ResponseEntity.ok(response); diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index 740e7e5e8..2ff00c5b8 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -25,8 +25,6 @@ import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; -import dev.tripdraw.post.dto.PostSearchConditions; -import dev.tripdraw.post.dto.PostSearchPaging; import dev.tripdraw.post.dto.PostSearchRequest; import dev.tripdraw.post.dto.PostSearchResponse; import dev.tripdraw.post.dto.PostUpdateRequest; @@ -39,6 +37,9 @@ import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.exception.TripException; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -47,10 +48,6 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.web.multipart.MultipartFile; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Set; - @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ServiceTest @@ -325,27 +322,25 @@ void setUp() { PostCreateResponse jejuJuly = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 12, 15, 30)); PostCreateResponse seoulJuly = createPost("서울특별시 송파구 문정동", LocalDateTime.of(2023, 7, 12, 15, 30)); - PostSearchRequest postSearchRequestJeju = new PostSearchRequest( - PostSearchConditions.builder() - .address("제주특별자치도 제주시 애월읍") - .build(), - new PostSearchPaging(null, 10) - ); + PostSearchRequest postSearchRequestJeju = PostSearchRequest.builder() + .address("제주특별자치도 제주시 애월읍") + .limit(10) + .build(); - PostSearchRequest postSearchRequestJuly = new PostSearchRequest( - PostSearchConditions.builder() - .months(Set.of(7)) - .build(), - new PostSearchPaging(null, 10) - ); + PostSearchRequest postSearchRequestJuly = PostSearchRequest.builder() + .months(Set.of(7)) + .limit(10) + .build(); // when PostsSearchResponse postsSearchJejuResponse = postService.readAll(postSearchRequestJeju); PostsSearchResponse postsSearchJulyResponse = postService.readAll(postSearchRequestJuly); // then - assertThat(postsSearchJejuResponse.posts().stream().map(PostSearchResponse::postId).toList()).containsExactly(jejuJuly.postId(), jejuMay.postId()); - assertThat(postsSearchJulyResponse.posts().stream().map(PostSearchResponse::postId).toList()).containsExactly(seoulJuly.postId(), jejuJuly.postId()); + assertThat(postsSearchJejuResponse.posts().stream().map(PostSearchResponse::postId).toList()).containsExactly( + jejuJuly.postId(), jejuMay.postId()); + assertThat(postsSearchJulyResponse.posts().stream().map(PostSearchResponse::postId).toList()).containsExactly( + seoulJuly.postId(), jejuJuly.postId()); } diff --git a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java index c1f2f03f9..f28b976d3 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -20,9 +20,6 @@ import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; import dev.tripdraw.post.dto.PostResponse; -import dev.tripdraw.post.dto.PostSearchConditions; -import dev.tripdraw.post.dto.PostSearchPaging; -import dev.tripdraw.post.dto.PostSearchRequest; import dev.tripdraw.post.dto.PostUpdateRequest; import dev.tripdraw.post.dto.PostsResponse; import dev.tripdraw.post.dto.PostsSearchResponse; @@ -36,6 +33,9 @@ import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import io.restassured.specification.MultiPartSpecification; +import java.time.LocalDateTime; +import java.util.Map; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -43,9 +43,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; -import java.time.LocalDateTime; -import java.util.Set; - @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class PostControllerTest extends ControllerTest { @@ -594,56 +591,51 @@ public void setUp() { @Test void 다른_사용자들의_감상을_조회한다() { // given - PostCreateResponse jejuJuly20hourPostResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 7, 18, 20, 24)); - PostCreateResponse jejuAugust17hourPostResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 8, 18, 17, 24)); - PostCreateResponse jejuSeptember17hourPostResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.of(2023, 9, 18, 17, 24)); - PostCreateResponse seoulSeptember17hourPostResponse = createPost("서울특별시 송파구 잠실동", LocalDateTime.of(2023, 9, 18, 17, 24)); - - PostSearchRequest jejuRequest = new PostSearchRequest( - PostSearchConditions.builder() - .address("제주특별자치도 제주시 애월읍") - .build(), - new PostSearchPaging(null, 10) + PostCreateResponse jejuJuly20hourPostResponse = createPost("제주특별자치도 제주시 애월읍", + LocalDateTime.of(2023, 7, 18, 20, 24)); + PostCreateResponse jejuAugust17hourPostResponse = createPost("제주특별자치도 제주시 애월읍", + LocalDateTime.of(2023, 8, 18, 17, 24)); + PostCreateResponse jejuSeptember17hourPostResponse = createPost("제주특별자치도 제주시 애월읍", + LocalDateTime.of(2023, 9, 18, 17, 24)); + PostCreateResponse seoulSeptember17hourPostResponse = createPost("서울특별시 송파구 잠실동", + LocalDateTime.of(2023, 9, 18, 17, 24)); + + Map jejuParams = Map.of( + "address", "제주특별자치도 제주시 애월읍", + "limit", 10 ); - PostSearchRequest jeju17hourRequest = new PostSearchRequest( - PostSearchConditions.builder() - .hours(Set.of(17)) - .address("제주특별자치도 제주시 애월읍") - .build(), - new PostSearchPaging(null, 10) + Map jejuHour17Params = Map.of( + "hours", Set.of(17), + "address", "제주특별자치도 제주시 애월읍", + "limit", 10 ); - PostSearchRequest hour17Request = new PostSearchRequest( - PostSearchConditions.builder() - .hours(Set.of(17)) - .build(), - new PostSearchPaging(null, 10) + Map hour17Params = Map.of( + "hours", Set.of(17), + "limit", 10 ); // when ExtractableResponse jejuResponse = RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) .auth().preemptive().oauth2(huchuToken) - .body(jejuRequest) + .params(jejuParams) .when().get("/posts") .then().log().all() .statusCode(OK.value()) .extract(); - ExtractableResponse jeju17hourResponse = RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) + ExtractableResponse jejuhour17Response = RestAssured.given().log().all() .auth().preemptive().oauth2(huchuToken) - .body(jeju17hourRequest) + .params(jejuHour17Params) .when().get("/posts") .then().log().all() .statusCode(OK.value()) .extract(); ExtractableResponse hour17Response = RestAssured.given().log().all() - .contentType(APPLICATION_JSON_VALUE) .auth().preemptive().oauth2(huchuToken) - .body(hour17Request) + .params(hour17Params) .when().get("/posts") .then().log().all() .statusCode(OK.value()) @@ -651,19 +643,22 @@ public void setUp() { // then PostsSearchResponse jejuPostsSearchResponse = jejuResponse.as(PostsSearchResponse.class); - PostsSearchResponse jeju17hourPostsSearchResponse = jeju17hourResponse.as(PostsSearchResponse.class); + PostsSearchResponse jeju17hourPostsSearchResponse = jejuhour17Response.as(PostsSearchResponse.class); PostsSearchResponse hour17PostsSearchResponse = hour17Response.as(PostsSearchResponse.class); assertThat(jejuPostsSearchResponse.posts().get(0).postId()).isEqualTo(jejuSeptember17hourPostResponse.postId()); assertThat(jejuPostsSearchResponse.posts().get(1).postId()).isEqualTo(jejuAugust17hourPostResponse.postId()); assertThat(jejuPostsSearchResponse.posts().get(2).postId()).isEqualTo(jejuJuly20hourPostResponse.postId()); + assertThat(jeju17hourPostsSearchResponse.posts().get(0).postId()).isEqualTo( + jejuSeptember17hourPostResponse.postId()); + assertThat(jeju17hourPostsSearchResponse.posts().get(1).postId()).isEqualTo( + jejuAugust17hourPostResponse.postId()); - assertThat(jeju17hourPostsSearchResponse.posts().get(0).postId()).isEqualTo(jejuSeptember17hourPostResponse.postId()); - assertThat(jeju17hourPostsSearchResponse.posts().get(1).postId()).isEqualTo(jejuAugust17hourPostResponse.postId()); - - assertThat(hour17PostsSearchResponse.posts().get(0).postId()).isEqualTo(seoulSeptember17hourPostResponse.postId()); - assertThat(hour17PostsSearchResponse.posts().get(1).postId()).isEqualTo(jejuSeptember17hourPostResponse.postId()); + assertThat(hour17PostsSearchResponse.posts().get(0).postId()).isEqualTo( + seoulSeptember17hourPostResponse.postId()); + assertThat(hour17PostsSearchResponse.posts().get(1).postId()).isEqualTo( + jejuSeptember17hourPostResponse.postId()); assertThat(hour17PostsSearchResponse.posts().get(2).postId()).isEqualTo(jejuAugust17hourPostResponse.postId()); } From e86fa9bf180b25e6345104c16ec911e485f7ddd5 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Wed, 20 Sep 2023 14:14:47 +0900 Subject: [PATCH 115/119] =?UTF-8?q?[fix]=20=EC=97=AC=ED=96=89=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=EC=A1=B0=ED=9A=8C=20=EC=A0=9C=EA=B1=B0=20(#381)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: greeng00se --- .../trip/query/TripCustomRepositoryImpl.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java index cf0888ef9..557c5ba16 100644 --- a/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/trip/query/TripCustomRepositoryImpl.java @@ -1,21 +1,20 @@ package dev.tripdraw.trip.query; +import static dev.tripdraw.post.domain.QPost.post; +import static dev.tripdraw.trip.domain.QPoint.point; +import static dev.tripdraw.trip.domain.QTrip.trip; + import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.dto.TripSearchConditions; import io.micrometer.common.util.StringUtils; +import java.util.List; +import java.util.Set; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; import org.springframework.util.CollectionUtils; -import java.util.List; -import java.util.Set; - -import static dev.tripdraw.post.domain.QPost.post; -import static dev.tripdraw.trip.domain.QPoint.point; -import static dev.tripdraw.trip.domain.QTrip.trip; - @RequiredArgsConstructor @Repository public class TripCustomRepositoryImpl implements TripCustomRepository { @@ -26,6 +25,7 @@ public class TripCustomRepositoryImpl implements TripCustomRepository { public List findAllByConditions(TripSearchConditions tripSearchConditions, TripPaging tripPaging) { return query .selectFrom(trip) + .distinct() .join(post).on(trip.id.eq(post.tripId)) .join(point).on(post.point.id.eq(point.id)) .where( From eb76e458a0ee6b82d0a89eb3ecc5a0b6e0271312 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Wed, 20 Sep 2023 14:24:07 +0900 Subject: [PATCH 116/119] =?UTF-8?q?[refactor]=20DTO=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=20=EA=B0=92=20=EC=88=98=EC=A0=95=20(#381)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/post/dto/PostSearchResponse.java | 9 ++++++--- .../java/dev/tripdraw/trip/dto/TripSearchResponse.java | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchResponse.java b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchResponse.java index 28e9cf33c..e4ba1a3a7 100644 --- a/backend/src/main/java/dev/tripdraw/post/dto/PostSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostSearchResponse.java @@ -1,8 +1,8 @@ package dev.tripdraw.post.dto; import dev.tripdraw.post.domain.Post; - import java.time.LocalDateTime; +import java.util.Objects; public record PostSearchResponse( Long postId, @@ -14,6 +14,9 @@ public record PostSearchResponse( String routeImageUrl, LocalDateTime recordedAt ) { + + private static final String EMPTY_IMAGE_URL = ""; + public static PostSearchResponse from(Post post) { return new PostSearchResponse( post.id(), @@ -21,8 +24,8 @@ public static PostSearchResponse from(Post post) { post.title(), post.address(), post.writing(), - post.postImageUrl(), - post.routeImageUrl(), + Objects.requireNonNullElse(post.postImageUrl(), EMPTY_IMAGE_URL), + Objects.requireNonNullElse(post.routeImageUrl(), EMPTY_IMAGE_URL), post.pointRecordedAt() ); } diff --git a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java index b7103ce5d..62a527001 100644 --- a/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java +++ b/backend/src/main/java/dev/tripdraw/trip/dto/TripSearchResponse.java @@ -2,8 +2,8 @@ import dev.tripdraw.trip.domain.Trip; import io.swagger.v3.oas.annotations.media.Schema; - import java.time.LocalDateTime; +import java.util.Objects; public record TripSearchResponse( @Schema(description = "여행 Id", example = "1") @@ -25,12 +25,14 @@ public record TripSearchResponse( LocalDateTime endTime ) { + private static final String EMPTY_IMAGE_URL = ""; + public static TripSearchResponse from(Trip trip) { return new TripSearchResponse( trip.id(), trip.nameValue(), - trip.imageUrl(), - trip.routeImageUrl(), + Objects.requireNonNullElse(trip.imageUrl(), EMPTY_IMAGE_URL), + Objects.requireNonNullElse(trip.routeImageUrl(), EMPTY_IMAGE_URL), trip.createdAt(), trip.updatedAt() ); From 1fce51a272097a208ba3014f32a05e7e1d7d0926 Mon Sep 17 00:00:00 2001 From: ReO Date: Thu, 21 Sep 2023 04:43:09 +0900 Subject: [PATCH 117/119] =?UTF-8?q?[feat]=20=EA=B0=90=EC=83=81=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20=EB=8B=A4=EB=A5=B8=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EB=8F=84=20=EA=B0=90=EC=83=81=EC=9D=84=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20(#388)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/application/PostService.java | 18 ++--- .../post/presentation/PostController.java | 4 +- .../post/application/PostServiceTest.java | 66 +++---------------- 3 files changed, 22 insertions(+), 66 deletions(-) diff --git a/backend/src/main/java/dev/tripdraw/post/application/PostService.java b/backend/src/main/java/dev/tripdraw/post/application/PostService.java index ed9bf309f..08557ab54 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -1,5 +1,6 @@ package dev.tripdraw.post.application; +import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static java.util.Comparator.comparing; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; @@ -25,13 +26,15 @@ import dev.tripdraw.trip.domain.PointRepository; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; -import java.util.List; +import dev.tripdraw.trip.exception.TripException; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import java.util.List; + @RequiredArgsConstructor @Transactional @Service @@ -91,18 +94,16 @@ public PostCreateResponse addAtExistingLocation( } @Transactional(readOnly = true) - public PostResponse read(LoginUser loginUser, Long postId) { + public PostResponse read(Long postId) { Post post = postRepository.getByPostId(postId); - Member member = memberRepository.getById(loginUser.memberId()); - post.validateAuthorization(member); return PostResponse.from(post); } @Transactional(readOnly = true) - public PostsResponse readAllByTripId(LoginUser loginUser, Long tripId) { - Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = tripRepository.getById(tripId); - trip.validateAuthorization(member); + public PostsResponse readAllByTripId(Long tripId) { + if (!tripRepository.existsById(tripId)) { + throw new TripException(TRIP_NOT_FOUND); + } return postRepository.findAllByTripId(tripId).stream() .sorted(comparing(Post::pointRecordedAt).reversed()) @@ -128,6 +129,7 @@ public void delete(LoginUser loginUser, Long postId) { postRepository.deleteById(postId); } + @Transactional(readOnly = true) public PostsSearchResponse readAll(PostSearchRequest postSearchRequest) { PostSearchPaging postSearchPaging = postSearchRequest.toPostSearchPaging(); diff --git a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java index a84173594..263ae2c31 100644 --- a/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java +++ b/backend/src/main/java/dev/tripdraw/post/presentation/PostController.java @@ -105,7 +105,7 @@ public ResponseEntity read( @Auth LoginUser loginUser, @PathVariable Long postId ) { - PostResponse response = postService.read(loginUser, postId); + PostResponse response = postService.read(postId); return ResponseEntity.ok(response); } @@ -119,7 +119,7 @@ public ResponseEntity readAllPostsOfTrip( @Auth LoginUser loginUser, @PathVariable Long tripId ) { - PostsResponse response = postService.readAllByTripId(loginUser, tripId); + PostsResponse response = postService.readAllByTripId(tripId); return ResponseEntity.ok(response); } diff --git a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java index 2ff00c5b8..99064cd4e 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -4,7 +4,6 @@ import static dev.tripdraw.member.exception.MemberExceptionType.MEMBER_NOT_FOUND; import static dev.tripdraw.post.exception.PostExceptionType.NOT_AUTHORIZED_TO_POST; import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; -import static dev.tripdraw.trip.exception.TripExceptionType.NOT_AUTHORIZED_TO_TRIP; import static dev.tripdraw.trip.exception.TripExceptionType.POINT_NOT_FOUND; import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; @@ -37,9 +36,6 @@ import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.exception.TripException; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -48,6 +44,10 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.web.multipart.MultipartFile; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; + @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ServiceTest @@ -224,7 +224,7 @@ void setUp() { PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); // when - PostResponse postResponse = postService.read(loginUser, postCreateResponse.postId()); + PostResponse postResponse = postService.read(postCreateResponse.postId()); // then assertSoftly(softly -> { @@ -237,36 +237,11 @@ void setUp() { @Test void 특정_감상을_조회할_때_존재하지_않는_감상_ID이면_예외를_발생시킨다() { // expect - assertThatThrownBy(() -> postService.read(loginUser, Long.MIN_VALUE)) + assertThatThrownBy(() -> postService.read(Long.MIN_VALUE)) .isInstanceOf(PostException.class) .hasMessage(POST_NOT_FOUND.message()); } - @Test - void 특정_감상을_조회할_때_존재하지_않는_사용자_닉네임이면_예외를_발생시킨다() { - // given - PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); - LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); - - // expect - Long postId = postCreateResponse.postId(); - assertThatThrownBy(() -> postService.read(wrongUser, postId)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); - } - - @Test - void 특정_감상을_조회할_때_로그인_한_사용자가_감상의_작성자가_아니면_예외가_발생한다() { - // given - PostCreateResponse postCreateResponse = createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); - - // expect - Long postId = postCreateResponse.postId(); - assertThatThrownBy(() -> postService.read(otherUser, postId)) - .isInstanceOf(PostException.class) - .hasMessage(NOT_AUTHORIZED_TO_POST.message()); - } - @Test void 특정_여행의_모든_감상을_조회한다() { // given @@ -274,7 +249,7 @@ void setUp() { createPost("제주특별자치도 제주시 애월읍", LocalDateTime.now()); // when - PostsResponse postsResponse = postService.readAllByTripId(loginUser, trip.id()); + PostsResponse postsResponse = postService.readAllByTripId(trip.id()); // then List posts = postsResponse.posts(); @@ -286,35 +261,14 @@ void setUp() { }); } - @Test - void 특정_여행의_모든_감상을_조회할_때_존재하지_않는_사용자_닉네임이면_예외를_발생시킨다() { - // given - LoginUser wrongUser = new LoginUser(Long.MIN_VALUE); - - // expect - Long tripId = trip.id(); - assertThatThrownBy(() -> postService.readAllByTripId(wrongUser, tripId)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); - } - @Test void 특정_여행의_모든_감상을_조회할_때_존재하지_않는_여행_ID이면_예외가_발생한다() { // expect - assertThatThrownBy(() -> postService.readAllByTripId(loginUser, Long.MIN_VALUE)) + assertThatThrownBy(() -> postService.readAllByTripId(Long.MIN_VALUE)) .isInstanceOf(TripException.class) .hasMessage(TRIP_NOT_FOUND.message()); } - @Test - void 특정_여행의_모든_감상을_조회할_때_로그인_한_사용자가_여행의_주인이_아니면_예외가_발생한다() { - // expect - Long tripId = trip.id(); - assertThatThrownBy(() -> postService.readAllByTripId(otherUser, tripId)) - .isInstanceOf(TripException.class) - .hasMessage(NOT_AUTHORIZED_TO_TRIP.message()); - } - @Test void 조건에_해당하는_모든_여행을_조회한다() { // given @@ -357,7 +311,7 @@ void setUp() { postService.update(loginUser, postCreateResponse.postId(), postUpdateRequest, null); // then - PostResponse postResponseBeforeUpdate = postService.read(loginUser, postCreateResponse.postId()); + PostResponse postResponseBeforeUpdate = postService.read(postCreateResponse.postId()); assertSoftly(softly -> { softly.assertThat(postResponseBeforeUpdate.postId()).isEqualTo(postCreateResponse.postId()); @@ -422,7 +376,7 @@ void setUp() { Long postId = postCreateResponse.postId(); assertDoesNotThrow(() -> postService.delete(loginUser, postId)); - assertThatThrownBy(() -> postService.read(loginUser, postId)) + assertThatThrownBy(() -> postService.read(postId)) .isInstanceOf(PostException.class) .hasMessage(POST_NOT_FOUND.message()); } From 0e77800badd3d6e276ae6849fb8a897c938578e3 Mon Sep 17 00:00:00 2001 From: ReO Date: Thu, 21 Sep 2023 11:14:54 +0900 Subject: [PATCH 118/119] =?UTF-8?q?[feat]=20fetch=20join=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20(#388)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/dev/tripdraw/post/domain/PostRepository.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java index f8c12c541..7baa16bd7 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java @@ -4,12 +4,15 @@ import dev.tripdraw.post.exception.PostException; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; public interface PostRepository extends JpaRepository { - List findAllByTripId(Long tripId); + @Query("SELECT p FROM Post p JOIN FETCH p.point where p.tripId = :tripId") + List findAllByTripId(@Param("tripId") Long tripId); default Post getByPostId(Long id) { return findById(id) From 92029cb56666c0148630719ea027d265b59c07b4 Mon Sep 17 00:00:00 2001 From: ReO Date: Thu, 21 Sep 2023 11:46:37 +0900 Subject: [PATCH 119/119] =?UTF-8?q?[feat]=20JPQL=20fetch=20join=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20(#388)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java b/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java index 9d713bc80..21a5af420 100644 --- a/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java +++ b/backend/src/main/java/dev/tripdraw/post/query/PostCustomRepositoryImpl.java @@ -23,6 +23,8 @@ public class PostCustomRepositoryImpl implements PostCustomRepository { public List findAllByConditions(PostSearchConditions conditions, PostSearchPaging paging) { // TODO: 2023/09/16 연령대, 성별 추가 return jpaQueryFactory.selectFrom(post) + .leftJoin(post.point).fetchJoin() + .leftJoin(post.point.trip).fetchJoin() .where( postIdLt(paging.lastViewedId()), yearIn(conditions.years()),