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 7828bd7c1..871d9e7d6 100644 --- a/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java +++ b/backend/src/main/java/dev/tripdraw/member/domain/MemberRepository.java @@ -6,6 +6,8 @@ import dev.tripdraw.member.exception.MemberException; 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 MemberRepository extends JpaRepository { @@ -13,6 +15,9 @@ public interface MemberRepository extends JpaRepository { boolean existsByNickname(String nickname); + @Query("SELECT m.nickname FROM Member m WHERE m.id = :id") + String getNicknameById(@Param("id") 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/member/exception/MemberExceptionType.java b/backend/src/main/java/dev/tripdraw/member/exception/MemberExceptionType.java index e6a7b31f8..47bfa5779 100644 --- a/backend/src/main/java/dev/tripdraw/member/exception/MemberExceptionType.java +++ b/backend/src/main/java/dev/tripdraw/member/exception/MemberExceptionType.java @@ -1,6 +1,7 @@ package dev.tripdraw.member.exception; import static org.springframework.http.HttpStatus.CONFLICT; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import static org.springframework.http.HttpStatus.NOT_FOUND; import dev.tripdraw.common.exception.ExceptionType; @@ -9,6 +10,7 @@ public enum MemberExceptionType implements ExceptionType { DUPLICATE_NICKNAME(CONFLICT, "이미 존재하는 닉네임입니다."), MEMBER_NOT_FOUND(NOT_FOUND, "존재하지 않는 회원입니다."), + MEMBER_NOT_REGISTERED(INTERNAL_SERVER_ERROR, "가입이 완료되지 않은 회원이 존재합니다."), ; private final HttpStatus httpStatus; 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 08557ab54..7afc33875 100644 --- a/backend/src/main/java/dev/tripdraw/post/application/PostService.java +++ b/backend/src/main/java/dev/tripdraw/post/application/PostService.java @@ -7,8 +7,6 @@ import dev.tripdraw.common.auth.LoginUser; 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; @@ -27,14 +25,13 @@ import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.exception.TripException; +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 @@ -44,7 +41,6 @@ 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; @@ -53,12 +49,13 @@ public PostCreateResponse addAtCurrentPoint( PostAndPointCreateRequest postAndPointCreateRequest, MultipartFile file ) { - Member member = memberRepository.getById(loginUser.memberId()); + Long memberId = loginUser.memberId(); + Trip trip = tripRepository.getById(postAndPointCreateRequest.tripId()); - trip.validateAuthorization(member); + trip.validateAuthorization(memberId); Point point = pointRepository.save(postAndPointCreateRequest.toPoint(trip)); - Post post = postAndPointCreateRequest.toPost(member, point); + Post post = postAndPointCreateRequest.toPost(memberId, point); uploadImage(file, post, trip); Post savedPost = postRepository.save(post); @@ -80,12 +77,13 @@ public PostCreateResponse addAtExistingLocation( PostRequest postRequest, MultipartFile file ) { - Member member = memberRepository.getById(loginUser.memberId()); + Long memberId = loginUser.memberId(); + Trip trip = tripRepository.getById(postRequest.tripId()); - trip.validateAuthorization(member); + trip.validateAuthorization(memberId); Point point = pointRepository.getById(postRequest.pointId()); - Post post = postRequest.toPost(member, point); + Post post = postRequest.toPost(memberId, point); uploadImage(file, post, trip); Post savedPost = postRepository.save(post); @@ -111,11 +109,12 @@ public PostsResponse readAllByTripId(Long tripId) { } public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdateRequest, MultipartFile file) { + Long memberId = loginUser.memberId(); + Post post = postRepository.getByPostId(postId); - Member member = memberRepository.getById(loginUser.memberId()); - post.validateAuthorization(member); + post.validateAuthorization(memberId); Trip trip = tripRepository.getById(post.tripId()); - trip.validateAuthorization(member); + trip.validateAuthorization(memberId); post.changeTitle(postUpdateRequest.title()); post.changeWriting(postUpdateRequest.writing()); @@ -124,8 +123,7 @@ public void update(LoginUser loginUser, Long postId, PostUpdateRequest postUpdat public void delete(LoginUser loginUser, Long postId) { Post post = postRepository.getByPostId(postId); - Member member = memberRepository.getById(loginUser.memberId()); - post.validateAuthorization(member); + post.validateAuthorization(loginUser.memberId()); postRepository.deleteById(postId); } 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 da6cead66..13a2608df 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/Post.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/Post.java @@ -1,12 +1,10 @@ package dev.tripdraw.post.domain; 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; import dev.tripdraw.common.entity.BaseEntity; -import dev.tripdraw.member.domain.Member; import dev.tripdraw.post.exception.PostException; import dev.tripdraw.trip.domain.Point; import jakarta.persistence.Column; @@ -14,7 +12,6 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToOne; import java.time.LocalDateTime; import lombok.Getter; @@ -48,31 +45,29 @@ public class Post extends BaseEntity { @JoinColumn(name = "point_id") private Point point; - @ManyToOne(fetch = LAZY) - @JoinColumn(name = "member_id") - private Member member; + private Long memberId; private String postImageUrl; private String routeImageUrl; - public Post(String title, Point point, String address, String writing, Member member, Long tripId) { - this(null, title, point, address, writing, member, tripId); + public Post(String title, Point point, String address, String writing, Long memberId, Long tripId) { + this(null, title, point, address, writing, memberId, tripId); } - public Post(Long id, String title, Point point, String address, String writing, Member member, Long tripId) { + public Post(Long id, String title, Point point, String address, String writing, Long memberId, Long tripId) { point.registerPost(); this.id = id; this.title = title; this.point = point; this.address = address; this.writing = writing; - this.member = member; + this.memberId = memberId; this.tripId = tripId; } - public void validateAuthorization(Member member) { - if (!this.member.equals(member)) { + public void validateAuthorization(Long memberId) { + if (!this.memberId.equals(memberId)) { throw new PostException(NOT_AUTHORIZED_TO_POST); } } 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 b239b6db8..3ef64913c 100644 --- a/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java +++ b/backend/src/main/java/dev/tripdraw/post/domain/PostRepository.java @@ -1,7 +1,5 @@ package dev.tripdraw.post.domain; -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; @@ -9,6 +7,8 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import static dev.tripdraw.post.exception.PostExceptionType.POST_NOT_FOUND; + public interface PostRepository extends JpaRepository { @Query("SELECT p FROM Post p JOIN FETCH p.point where p.tripId = :tripId") @@ -20,6 +20,6 @@ default Post getByPostId(Long id) { } @Modifying - @Query("DELETE FROM Post p WHERE p.member.id = :memberId") - void deleteByMemberId(@Param(value = "memberId") Long memberId); + @Query("DELETE FROM Post p WHERE p.memberId = :memberId") + void deleteByMemberId(@Param("memberId") Long memberId); } 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 1f368b674..88e77a2a7 100644 --- a/backend/src/main/java/dev/tripdraw/post/dto/PostAndPointCreateRequest.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostAndPointCreateRequest.java @@ -3,7 +3,6 @@ import static com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING; import com.fasterxml.jackson.annotation.JsonFormat; -import dev.tripdraw.member.domain.Member; import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; @@ -53,7 +52,7 @@ 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); + public Post toPost(Long memberId, Point point) { + return new Post(title, point, address, writing, memberId, tripId); } } diff --git a/backend/src/main/java/dev/tripdraw/post/dto/PostRequest.java b/backend/src/main/java/dev/tripdraw/post/dto/PostRequest.java index e09e8a430..24cbf720b 100644 --- a/backend/src/main/java/dev/tripdraw/post/dto/PostRequest.java +++ b/backend/src/main/java/dev/tripdraw/post/dto/PostRequest.java @@ -1,6 +1,5 @@ package dev.tripdraw.post.dto; -import dev.tripdraw.member.domain.Member; import dev.tripdraw.post.domain.Post; import dev.tripdraw.trip.domain.Point; import io.swagger.v3.oas.annotations.media.Schema; @@ -30,7 +29,7 @@ public record PostRequest( String writing ) { - public Post toPost(Member member, Point point) { - return new Post(title, point, address, writing, member, tripId); + public Post toPost(Long memberId, Point point) { + return new Post(title, point, address, writing, memberId, tripId); } } 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 a3910a2e2..a1fafe93d 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,6 @@ package dev.tripdraw.trip.application; 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; @@ -39,16 +38,16 @@ public class TripService { private final ApplicationEventPublisher applicationEventPublisher; public TripCreateResponse create(LoginUser loginUser) { - Member member = memberRepository.getById(loginUser.memberId()); - Trip trip = Trip.from(member); + Long memberId = loginUser.memberId(); + + Trip trip = Trip.of(memberId, memberRepository.getNicknameById(memberId)); Trip savedTrip = tripRepository.save(trip); return TripCreateResponse.from(savedTrip); } public PointCreateResponse addPoint(LoginUser loginUser, PointCreateRequest pointCreateRequest) { - Member member = memberRepository.getById(loginUser.memberId()); Trip trip = tripRepository.getById(pointCreateRequest.tripId()); - trip.validateAuthorization(member); + trip.validateAuthorization(loginUser.memberId()); Point point = pointCreateRequest.toPoint(); point.setTrip(trip); @@ -58,9 +57,8 @@ public PointCreateResponse addPoint(LoginUser loginUser, PointCreateRequest poin } public void deletePoint(LoginUser loginUser, Long pointId, Long tripId) { - Member member = memberRepository.getById(loginUser.memberId()); Trip trip = tripRepository.getById(tripId); - trip.validateAuthorization(member); + trip.validateAuthorization(loginUser.memberId()); Point point = pointRepository.getById(pointId); pointRepository.delete(point); @@ -68,16 +66,14 @@ public void deletePoint(LoginUser loginUser, Long pointId, Long tripId) { @Transactional(readOnly = true) public TripResponse readTripById(LoginUser loginUser, Long id) { - Member member = memberRepository.getById(loginUser.memberId()); Trip trip = tripRepository.getById(id); - trip.validateAuthorization(member); + trip.validateAuthorization(loginUser.memberId()); return TripResponse.from(trip); } @Transactional(readOnly = true) public TripsSearchResponseOfMember readAllTripsOf(LoginUser loginUser) { - Member member = memberRepository.getById(loginUser.memberId()); - List trips = tripRepository.findAllByMemberId(member.id()); + List trips = tripRepository.findAllByMemberId(loginUser.memberId()); return TripsSearchResponseOfMember.from(trips); } @@ -95,9 +91,8 @@ public TripsSearchResponse readAll(TripSearchRequest tripSearchRequest) { } public void updateTripById(LoginUser loginUser, Long tripId, TripUpdateRequest tripUpdateRequest) { - Member member = memberRepository.getById(loginUser.memberId()); Trip trip = tripRepository.getById(tripId); - trip.validateAuthorization(member); + trip.validateAuthorization(loginUser.memberId()); trip.changeName(tripUpdateRequest.name()); trip.changeStatus(tripUpdateRequest.status()); @@ -107,18 +102,16 @@ 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 = tripRepository.getById(tripId); - trip.validateAuthorization(member); + trip.validateAuthorization(loginUser.memberId()); Point point = pointRepository.getById(pointId); return PointResponse.from(point); } public void delete(LoginUser loginUser, Long tripId) { - Member member = memberRepository.getById(loginUser.memberId()); Trip trip = tripRepository.getById(tripId); - trip.validateAuthorization(member); + trip.validateAuthorization(loginUser.memberId()); tripRepository.delete(trip); } 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 44b49fd9c..b0a715a9e 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/Trip.java @@ -3,20 +3,16 @@ 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.common.entity.BaseEntity; -import dev.tripdraw.member.domain.Member; import dev.tripdraw.trip.exception.TripException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import java.util.List; import lombok.Getter; import lombok.NoArgsConstructor; @@ -38,9 +34,7 @@ public class Trip extends BaseEntity { @Embedded private TripName name; - @ManyToOne(fetch = LAZY) - @JoinColumn(name = "member_id") - private Member member; + private Long memberId; @Embedded private Route route = new Route(); @@ -52,22 +46,22 @@ public class Trip extends BaseEntity { private String routeImageUrl; - public Trip(TripName name, Member member) { - this(null, name, member, ONGOING, EMPTY_IMAGE_URL, EMPTY_IMAGE_URL); + public Trip(TripName name, Long memberId) { + this(null, name, memberId, ONGOING, EMPTY_IMAGE_URL, EMPTY_IMAGE_URL); } - public Trip(Long id, TripName name, Member member, TripStatus status, String imageUrl, String routeImageUrl) { + public Trip(Long id, TripName name, Long memberId, TripStatus status, String imageUrl, String routeImageUrl) { this.id = id; this.name = name; - this.member = member; + this.memberId = memberId; this.status = status; this.imageUrl = imageUrl; this.routeImageUrl = routeImageUrl; } - public static Trip from(Member member) { - TripName tripName = TripName.from(member.nickname()); - return new Trip(tripName, member); + public static Trip of(Long memberId, String nickname) { + TripName tripName = TripName.from(nickname); + return new Trip(tripName, memberId); } public void add(Point point) { @@ -81,8 +75,8 @@ public boolean contains(Point point) { return route.contains(point); } - public void validateAuthorization(Member member) { - if (!this.member.equals(member)) { + public void validateAuthorization(Long memberId) { + if (!this.memberId.equals(memberId)) { throw new TripException(NOT_AUTHORIZED_TO_TRIP); } } 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 86446588f..339c8438b 100644 --- a/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java +++ b/backend/src/main/java/dev/tripdraw/trip/domain/TripRepository.java @@ -1,22 +1,23 @@ package dev.tripdraw.trip.domain; -import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; - import dev.tripdraw.trip.exception.TripException; -import java.util.List; -import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import java.util.List; +import java.util.Optional; + +import static dev.tripdraw.trip.exception.TripExceptionType.TRIP_NOT_FOUND; + public interface TripRepository extends JpaRepository { List findAllByMemberId(Long memberId); @Modifying - @Query("DELETE FROM Trip t WHERE t.member.id = :memberId") - void deleteByMemberId(@Param(value = "memberId") Long memberId); + @Query("DELETE FROM Trip t WHERE t.memberId = :memberId") + void deleteByMemberId(@Param("memberId") Long memberId); default Trip getById(Long id) { return findById(id) @@ -31,6 +32,6 @@ default Trip getTripWithPoints(Long tripId) { .orElseThrow(() -> new TripException(TRIP_NOT_FOUND)); } - @Query("SELECT t.id FROM Trip t WHERE t.member.id = :memberId") - List findAllTripIdsByMemberId(@Param(value = "memberId") Long memberId); + @Query("SELECT t.id FROM Trip t WHERE t.memberId = :memberId") + List findAllTripIdsByMemberId(@Param("memberId") Long 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 220bbc7f6..f5b458815 100644 --- a/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/member/application/MemberServiceTest.java @@ -48,7 +48,7 @@ class MemberServiceTest { @BeforeEach void setUp() { member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - trip = tripRepository.save(new Trip(TripName.from("통후추의 여행"), member)); + trip = tripRepository.save(new Trip(TripName.from("통후추의 여행"), member.id())); Point point = new Point(3.14, 5.25, LocalDateTime.now()); point.setTrip(trip); postRepository.save(new Post( @@ -56,7 +56,7 @@ void setUp() { point, "위치", "오늘은 날씨가 좋네요.", - member, + member.id(), trip.id() )); } 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 a2083f2f3..73d6aa655 100644 --- a/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/member/domain/MemberRepositoryTest.java @@ -72,4 +72,16 @@ class MemberRepositoryTest { .isInstanceOf(MemberException.class) .hasMessage(MEMBER_NOT_FOUND.message()); } + + @Test + void 회원_ID로_회원_닉네임을_얻는다() { + // given + Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); + + // when + String nickname = memberRepository.getNicknameById(member.id()); + + // then + assertThat(nickname).isEqualTo("통후추"); + } } 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 03a5d11ee..3afa57b89 100644 --- a/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/member/presentation/MemberControllerTest.java @@ -82,7 +82,7 @@ public void setUp() { Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); String huchuToken = jwtTokenProvider.generateAccessToken(member.id().toString()); - Trip trip = new Trip(TripName.from("통후추의 여행"), member); + Trip trip = new Trip(TripName.from("통후추의 여행"), member.id()); Point point = new Point(3.14, 5.25, LocalDateTime.now()); trip.add(point); tripRepository.save(trip); @@ -91,7 +91,7 @@ public void setUp() { point, "위치", "오늘은 날씨가 좋네요.", - member, + member.id(), trip.id() )); 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 99064cd4e..30cb890f8 100644 --- a/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/post/application/PostServiceTest.java @@ -1,9 +1,9 @@ package dev.tripdraw.post.application; 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; +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; @@ -19,7 +19,6 @@ import dev.tripdraw.file.application.FileUploader; import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; -import dev.tripdraw.member.exception.MemberException; import dev.tripdraw.post.dto.PostAndPointCreateRequest; import dev.tripdraw.post.dto.PostCreateResponse; import dev.tripdraw.post.dto.PostRequest; @@ -36,6 +35,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; @@ -44,10 +46,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 @@ -80,7 +78,7 @@ class PostServiceTest { void setUp() { Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); Member otherMember = memberRepository.save(new Member("순후추", "kakaoId", KAKAO)); - trip = tripRepository.save(Trip.from(member)); + trip = tripRepository.save(Trip.of(member.id(), member.nickname())); point = new Point(1.1, 2.1, LocalDateTime.now()); point.setTrip(trip); pointRepository.save(point); @@ -124,8 +122,8 @@ void setUp() { // expect assertThatThrownBy(() -> postService.addAtCurrentPoint(wrongUser, postAndPointCreateRequest, null)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); + .isInstanceOf(TripException.class) + .hasMessage(NOT_AUTHORIZED_TO_TRIP.message()); } @Test @@ -180,8 +178,8 @@ void setUp() { // expect assertThatThrownBy(() -> postService.addAtExistingLocation(wrongUser, postRequest, null)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); + .isInstanceOf(TripException.class) + .hasMessage(NOT_AUTHORIZED_TO_TRIP.message()); } @Test @@ -347,8 +345,8 @@ void setUp() { // expect Long postId = postCreateResponse.postId(); assertThatThrownBy(() -> postService.update(wrongUser, postId, postUpdateRequest, null)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); + .isInstanceOf(PostException.class) + .hasMessage(NOT_AUTHORIZED_TO_POST.message()); } @Test @@ -398,8 +396,8 @@ void setUp() { // expect Long postId = postCreateResponse.postId(); assertThatThrownBy(() -> postService.delete(wrongUser, postId)) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); + .isInstanceOf(PostException.class) + .hasMessage(NOT_AUTHORIZED_TO_POST.message()); } @Test 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 2e7533668..6999f2c3a 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostCustomRepositoryImplTest.java @@ -13,6 +13,9 @@ import dev.tripdraw.trip.domain.Point; import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; +import java.time.LocalDateTime; +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; @@ -21,10 +24,6 @@ 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 @@ -48,7 +47,7 @@ class PostCustomRepositoryImplTest { void 조건에_해당하는_감상을_조회한다() { // given Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); 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)); @@ -60,9 +59,9 @@ class PostCustomRepositoryImplTest { 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()); + Post firstPost = new Post("제목", firstPoint, "위치", "오늘은 날씨가 좋네요.", member.id(), trip.id()); + Post secondPost = new Post("제목", secondPoint, "위치", "오늘은 날씨가 좋네요.", member.id(), trip.id()); + Post thirdPost = new Post("제목", thirdPoint, "위치", "오늘은 날씨가 좋네요.", member.id(), trip.id()); postRepository.save(firstPost); postRepository.save(secondPost); 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 e6dc7dddb..d65b4e11b 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostRepositoryTest.java @@ -49,7 +49,7 @@ class PostRepositoryTest { @BeforeEach void setUp() { member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - trip = tripRepository.save(new Trip(TripName.from("통후추의 여행"), member)); + trip = tripRepository.save(new Trip(TripName.from("통후추의 여행"), member.id())); point = new Point(3.14, 5.25, LocalDateTime.now()); trip.add(point); } @@ -57,7 +57,7 @@ void setUp() { @Test void 여행_ID로_감상_목록을_조회한다() { // given - Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, trip.id()); + Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), trip.id()); postRepository.save(post); // when @@ -70,7 +70,8 @@ void setUp() { @Test void 회원_ID로_감상을_삭제한다() { // given - Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, trip.id()); + Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), trip.id()); + Long postId = postRepository.save(post).id(); // when @@ -83,7 +84,7 @@ void setUp() { @Test void 감상_ID로_감상을_조회한다() { // given - Post post = postRepository.save(new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, trip.id())); + Post post = postRepository.save(new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), trip.id())); // when Post foundPost = postRepository.getByPostId(post.id()); 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 5e8f673a0..5e384f3e1 100644 --- a/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java +++ b/backend/src/test/java/dev/tripdraw/post/domain/PostTest.java @@ -26,7 +26,7 @@ class PostTest { LocalDateTime recordedAt = LocalDateTime.now(); Point point = new Point(3.14, 5.25, recordedAt); Member member = new Member("통후추", "kakaoId", KAKAO); - Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, 1L); + Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), 1L); // expect assertThat(post.pointRecordedAt()).isEqualTo(recordedAt); @@ -37,11 +37,11 @@ class PostTest { // given LocalDateTime recordedAt = LocalDateTime.now(); Point point = new Point(3.14, 5.25, recordedAt); - Member member = new Member("통후추", "kakaoId", KAKAO); - Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, 1L); + Member member = new Member(1L, "통후추", "kakaoId", KAKAO); + Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), 1L); // expect - assertThatNoException().isThrownBy(() -> post.validateAuthorization(member)); + assertThatNoException().isThrownBy(() -> post.validateAuthorization(member.id())); } @Test @@ -49,11 +49,11 @@ class PostTest { // given LocalDateTime recordedAt = LocalDateTime.now(); Point point = new Point(3.14, 5.25, recordedAt); - Member member = new Member("통후추", "kakaoId", KAKAO); - Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, 1L); + Member member = new Member(1L, "통후추", "kakaoId", KAKAO); + Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), 1L); // expect - assertThatThrownBy(() -> post.validateAuthorization(new Member("순후추", "kakaoId", KAKAO))) + assertThatThrownBy(() -> post.validateAuthorization(new Member(2L, "순후추", "kakaoId", KAKAO).id())) .isInstanceOf(PostException.class) .hasMessage(NOT_AUTHORIZED_TO_POST.message()); } @@ -66,7 +66,7 @@ class PostTest { Member member = new Member("통후추", "kakaoId", KAKAO); // when - new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, 1L); + new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), 1L); // then assertThat(point.hasPost()).isTrue(); @@ -81,7 +81,7 @@ class PostTest { Member member = new Member("통후추", "kakaoId", KAKAO); // expect - assertThatThrownBy(() -> new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, 1L)) + assertThatThrownBy(() -> new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), 1L)) .isInstanceOf(TripException.class) .hasMessage(POINT_ALREADY_HAS_POST.message()); } @@ -92,7 +92,7 @@ class PostTest { LocalDateTime recordedAt = LocalDateTime.now(); Point point = new Point(3.14, 5.25, recordedAt); Member member = new Member("통후추", "kakaoId", KAKAO); - Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, 1L); + Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), 1L); // when post.changeTitle("바뀐 제목"); @@ -107,7 +107,7 @@ class PostTest { LocalDateTime recordedAt = LocalDateTime.now(); Point point = new Point(3.14, 5.25, recordedAt); Member member = new Member("통후추", "kakaoId", KAKAO); - Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, 1L); + Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), 1L); // when post.changeWriting("내일은 바람이 많네요."); @@ -122,7 +122,7 @@ class PostTest { LocalDateTime recordedAt = LocalDateTime.now(); Point point = new Point(3.14, 5.25, recordedAt); Member member = new Member("통후추", "kakaoId", KAKAO); - Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, 1L); + Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), 1L); // when post.changePostImageUrl("/통후추셀카.jpg"); @@ -137,7 +137,7 @@ class PostTest { LocalDateTime recordedAt = LocalDateTime.now(); Point point = new Point(3.14, 5.25, recordedAt); Member member = new Member("통후추", "kakaoId", KAKAO); - Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, 1L); + Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), 1L); // when post.changeRouteImageUrl("/통후추여행경로.png"); @@ -152,7 +152,7 @@ class PostTest { LocalDateTime recordedAt = LocalDateTime.now(); Point point = new Point(3.14, 5.25, recordedAt); Member member = new Member("통후추", "kakaoId", KAKAO); - Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, 1L); + Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member.id(), 1L); post.changePostImageUrl("example.url"); // when 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 f28b976d3..b62907a4d 100644 --- a/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java +++ b/backend/src/test/java/dev/tripdraw/post/presentation/PostControllerTest.java @@ -70,7 +70,7 @@ public void setUp() { super.setUp(); Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - trip = tripRepository.save(Trip.from(member)); + trip = tripRepository.save(Trip.of(member.id(), member.nickname())); huchuToken = jwtTokenProvider.generateAccessToken(member.id().toString()); } diff --git a/backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java b/backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java index 8f5c37aed..747d12dc8 100644 --- a/backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java +++ b/backend/src/test/java/dev/tripdraw/test/fixture/TestFixture.java @@ -30,11 +30,11 @@ public class TestFixture { } public static Trip 여행() { - return new Trip(1L, TripName.from("통후추"), 사용자(), TripStatus.ONGOING, "", ""); + return new Trip(1L, TripName.from("통후추"), 사용자().id(), TripStatus.ONGOING, "", ""); } public static Post 감상() { - return new Post("감상 제목", 위치정보(), "주소", "감상", 사용자(), 1L); + return new Post("감상 제목", 위치정보(), "주소", "감상", 사용자().id(), 1L); } public static PointCreateRequest pointCreateRequest(Long tripId) { 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 24a907a3f..2cf5bab6c 100644 --- a/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/application/TripServiceTest.java @@ -1,8 +1,8 @@ package dev.tripdraw.trip.application; 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.NOT_AUTHORIZED_TO_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; @@ -12,7 +12,6 @@ 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; @@ -63,12 +62,12 @@ class TripServiceTest { @BeforeEach void setUp() { Member member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO)); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); 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())); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member.id(), trip.id())); } @Test @@ -144,8 +143,8 @@ void setUp() { // expect assertThatThrownBy(() -> tripService.deletePoint(otherUser, response.pointId(), trip.id())) - .isInstanceOf(MemberException.class) - .hasMessage(MEMBER_NOT_FOUND.message()); + .isInstanceOf(TripException.class) + .hasMessage(NOT_AUTHORIZED_TO_TRIP.message()); } @Test 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 5fff89f8b..25fbc23c0 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointRepositoryTest.java @@ -46,8 +46,9 @@ class PointRepositoryTest { void setUp() { Member huchu = memberRepository.save(new Member("후추", "kakaoId", KAKAO)); Member herb = memberRepository.save(new Member("허브", "kakaoId", KAKAO)); - huchuTrip = tripRepository.save(Trip.from(huchu)); - herbTrip = tripRepository.save(Trip.from(herb)); + + huchuTrip = tripRepository.save(Trip.of(huchu.id(), huchu.nickname())); + herbTrip = tripRepository.save(Trip.of(herb.id(), herb.nickname())); } @Test @@ -97,7 +98,7 @@ void setUp() { // when pointRepository.deleteByTripIds(tripIds); - + // then assertSoftly(softly -> { softly.assertThat(pointRepository.existsById(huchuFirstPoint.id())).isFalse(); 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 ac22e44ff..4d47eb07c 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/PointTest.java @@ -46,7 +46,7 @@ class PointTest { // given Point point = new Point(3.14, 5.25, LocalDateTime.now()); Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); // when point.setTrip(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 0428aa357..bfd325093 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,5 @@ package dev.tripdraw.trip.domain; -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; -import static org.assertj.core.api.SoftAssertions.assertSoftly; -import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; - import dev.tripdraw.common.config.JpaConfig; import dev.tripdraw.common.config.QueryDslConfig; import dev.tripdraw.member.domain.Member; @@ -24,6 +17,17 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.IntStream; + +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; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; + @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @Import({JpaConfig.class, QueryDslConfig.class}) @@ -47,7 +51,7 @@ void setUp() { @Test void 회원_ID로_여행_목록을_조회한다() { // given - Trip trip = new Trip(TripName.from("제주도 여행"), member); + Trip trip = new Trip(TripName.from("제주도 여행"), member.id()); tripRepository.save(trip); // when @@ -72,7 +76,7 @@ void setUp() { @Test void 여행_ID를_입력받아_여행_목록과_위치_정보까지_조회한다() { // given - Trip trip = new Trip(TripName.from("제주도 여행"), member); + Trip trip = new Trip(TripName.from("제주도 여행"), member.id()); Point point1 = new Point(1.1, 2.2, LocalDateTime.now()); Point point2 = new Point(3.3, 4.4, LocalDateTime.now()); trip.add(point1); @@ -92,7 +96,7 @@ void setUp() { @Test void 회원_ID로_여행을_삭제한다() { // given - Trip trip = new Trip(TripName.from("제주도 여행"), member); + Trip trip = new Trip(TripName.from("제주도 여행"), member.id()); tripRepository.save(trip); // when @@ -105,7 +109,7 @@ void setUp() { @Test void 여행_ID로_여행을_조회한다() { // given - Trip trip = tripRepository.save(new Trip(TripName.from("제주도 여행"), member)); + Trip trip = tripRepository.save(new Trip(TripName.from("제주도 여행"), member.id())); // when Trip foundTrip = tripRepository.getById(trip.id()); @@ -129,7 +133,7 @@ void setUp() { void 회원_ID를_갖는_모든_여행_ID를_조회한다() { // given List tripIds = IntStream.range(0, 5) - .mapToObj(value -> tripRepository.save(Trip.from(member)).id()) + .mapToObj(value -> tripRepository.save(Trip.of(member.id(), member.nickname())).id()) .toList(); // when 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 5bfa29998..f6a25cfbf 100644 --- a/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/domain/TripTest.java @@ -27,7 +27,7 @@ class TripTest { void 여행_경로에_좌표를_추가한다() { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); Point point = new Point(1.1, 2.2, LocalDateTime.now()); // when @@ -48,7 +48,7 @@ class 위치정보_포함_여부를_확인할_때 { void 위치정보를_포함하는_여행이면_참값을_반환한다() { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); Point point = new Point(1.1, 2.2, LocalDateTime.now()); trip.add(point); @@ -60,7 +60,7 @@ class 위치정보_포함_여부를_확인할_때 { void 위치정보를_포함하지_않는_여행이면_참값을_반환하지_않는다() { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); Point point = new Point(1.1, 2.2, LocalDateTime.now()); // expect @@ -71,21 +71,21 @@ class 위치정보_포함_여부를_확인할_때 { @Test void 인가된_사용자는_예외가_발생하지_않는다() { // given - Member member = new Member("tonghuchu", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Member member = new Member(1L, "tonghuchu", "kakaoId", KAKAO); + Trip trip = Trip.of(member.id(), member.nickname()); // expect - assertThatNoException().isThrownBy(() -> trip.validateAuthorization(member)); + assertThatNoException().isThrownBy(() -> trip.validateAuthorization(member.id())); } @Test void 인가되지_않은_사용자는_예외가_발생한다() { // given - Member member = new Member("tonghuchu", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Member member = new Member(1L, "tonghuchu", "kakaoId", KAKAO); + Trip trip = Trip.of(member.id(), member.nickname()); // expect - assertThatThrownBy(() -> trip.validateAuthorization(new Member("other", "kakaoId", KAKAO))) + assertThatThrownBy(() -> trip.validateAuthorization(new Member(2L, "other", "kakaoId", KAKAO).id())) .isInstanceOf(TripException.class) .hasMessage(NOT_AUTHORIZED_TO_TRIP.message()); } @@ -94,7 +94,7 @@ class 위치정보_포함_여부를_확인할_때 { void 이름을_반환한다() { // given Member member = new Member("tonghuchu", "kakaoId", KAKAO); - Trip trip = new Trip(TripName.from("통후추"), member); + Trip trip = new Trip(TripName.from("통후추"), member.id()); // expect assertThat(trip.nameValue()).isEqualTo("통후추의 여행"); @@ -104,7 +104,7 @@ class 위치정보_포함_여부를_확인할_때 { void 이름을_변경한다() { // given Member member = new Member("tonghuchu", "kakaoId", KAKAO); - Trip trip = new Trip(TripName.from("통후추"), member); + Trip trip = new Trip(TripName.from("통후추"), member.id()); // when trip.changeName("제주도 여행"); @@ -117,7 +117,7 @@ class 위치정보_포함_여부를_확인할_때 { void 경로에_해당하는_모든_위치를_반환한다() { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); Point point1 = new Point(1.1, 2.2, LocalDateTime.now()); Point point2 = new Point(3.3, 4.4, LocalDateTime.now()); trip.add(point1); @@ -135,7 +135,7 @@ class 위치정보_포함_여부를_확인할_때 { void 여행_상태를_변경한다(TripStatus target, TripStatus expected) { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); // when trip.changeStatus(target); @@ -148,7 +148,7 @@ class 위치정보_포함_여부를_확인할_때 { void 여행_상태를_null로_변경하려할_경우_예외를_발생시킨다() { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); // expect assertThatThrownBy(() -> trip.changeStatus(null)) @@ -160,7 +160,7 @@ class 위치정보_포함_여부를_확인할_때 { void 감상_사진_URL을_변경한다() { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); // when trip.changeImageUrl("/통후추셀카.jpg"); @@ -173,7 +173,7 @@ class 위치정보_포함_여부를_확인할_때 { void 경로_이미지_URL을_변경한다() { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); // when trip.changeRouteImageUrl("/통후추여행경로.png"); @@ -186,7 +186,7 @@ class 위치정보_포함_여부를_확인할_때 { void 위도를_반환한다() { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); trip.add(new Point(1.1, 2.2, LocalDateTime.now())); trip.add(new Point(3.3, 4.4, LocalDateTime.now())); trip.add(new Point(5.5, 6.6, LocalDateTime.now())); @@ -202,7 +202,7 @@ class 위치정보_포함_여부를_확인할_때 { void 경도를_반환한다() { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); trip.add(new Point(1.1, 2.2, LocalDateTime.now())); trip.add(new Point(3.3, 4.4, LocalDateTime.now())); trip.add(new Point(5.5, 6.6, LocalDateTime.now())); @@ -218,7 +218,7 @@ class 위치정보_포함_여부를_확인할_때 { void 감상을_남긴_위치_정보의_위도를_반환한다() { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); 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())); @@ -234,7 +234,7 @@ class 위치정보_포함_여부를_확인할_때 { void 감상을_남긴_위치_정보의_경도를_반환한다() { // given Member member = new Member("통후추", "kakaoId", KAKAO); - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); 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())); diff --git a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseOfMemberTest.java b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseOfMemberTest.java index 8f273eee4..2c4585689 100644 --- a/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseOfMemberTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/dto/TripSearchResponseOfMemberTest.java @@ -20,14 +20,14 @@ class TripSearchResponseOfMemberTest { // given Member member = new Member("통후추", "kakaoId", KAKAO); TripName tripName = TripName.from("통후추의 여행"); - Trip trip = new Trip(1L, tripName, member, ONGOING, null, null); + Trip trip = new Trip(1L, tripName, member.id(), ONGOING, null, null); // when TripSearchResponseOfMember response = TripSearchResponseOfMember.from(trip); // then assertThat(response).usingRecursiveComparison().isEqualTo( - TripSearchResponseOfMember.from(new Trip(1L, tripName, member, ONGOING, "", "")) + TripSearchResponseOfMember.from(new Trip(1L, tripName, member.id(), ONGOING, "", "")) ); } } 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 cc69dde71..65a303d4b 100644 --- a/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java +++ b/backend/src/test/java/dev/tripdraw/trip/query/TripCustomRepositoryImplTest.java @@ -1,5 +1,14 @@ 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.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 org.assertj.core.api.Assertions.assertThat; + import dev.tripdraw.member.domain.Member; import dev.tripdraw.member.domain.MemberRepository; import dev.tripdraw.post.domain.Post; @@ -8,21 +17,19 @@ import dev.tripdraw.trip.domain.Trip; import dev.tripdraw.trip.domain.TripRepository; import dev.tripdraw.trip.dto.TripSearchConditions; -import org.junit.jupiter.api.*; +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; -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 @@ -418,52 +425,52 @@ class 조건을 { } private Trip jeju_2023_2_1_Wed() { - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); Point point = 위치정보(2023, 2, 1, 1, 1); trip.add(point); tripRepository.save(trip); - postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member.id(), trip.id())); return trip; } private Trip seoul_2023_1_1_Sun() { - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); Point point = 위치정보(2023, 1, 1, 10, 1); trip.add(point); tripRepository.save(trip); - postRepository.save(new Post("", point, "서울특별시 송파구 신천동", "", member, trip.id())); + postRepository.save(new Post("", point, "서울특별시 송파구 신천동", "", member.id(), trip.id())); return trip; } private Trip jeju_2023_1_1_Sun() { - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); Point point = 위치정보(2023, 1, 1, 1, 1); trip.add(point); tripRepository.save(trip); - postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member, trip.id())); + postRepository.save(new Post("", point, "제주특별자치도 제주시 애월읍", "", member.id(), trip.id())); return trip; } private Trip seoul_2022_1_2_Sun() { - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); Point point = 위치정보(2022, 1, 2, 1, 1); trip.add(point); tripRepository.save(trip); - postRepository.save(new Post("", point, "서울특별시 송파구 방이동", "", member, trip.id())); + postRepository.save(new Post("", point, "서울특별시 송파구 방이동", "", member.id(), trip.id())); return trip; } private Trip yangyang_2021_3_2_Tue() { - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); Point point = 위치정보(2021, 3, 2, 1, 1); trip.add(point); tripRepository.save(trip); - postRepository.save(new Post("", point, "강원도 양양군", "", member, trip.id())); + postRepository.save(new Post("", point, "강원도 양양군", "", member.id(), trip.id())); return trip; } private Trip emptyPostTrip() { - Trip trip = Trip.from(member); + Trip trip = Trip.of(member.id(), member.nickname()); Point point = 위치정보(2021, 3, 2, 1, 1); trip.add(point); tripRepository.save(trip);