Skip to content

Commit

Permalink
[refactor] 감상, 여행 삭제 로직 변경 (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
Combi153 committed Sep 23, 2023
1 parent 5f60cca commit 6cc528e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
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;
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;

public interface PostRepository extends JpaRepository<Post, Long> {

@Query("SELECT p FROM Post p JOIN FETCH p.point where p.tripId = :tripId")
Expand All @@ -19,5 +19,7 @@ default Post getByPostId(Long id) {
.orElseThrow(() -> new PostException(POST_NOT_FOUND));
}

void deleteByMemberId(Long memberId);
@Modifying
@Query("DELETE FROM Post p WHERE p.member.id = :memberId")
void deleteByMemberId(@Param(value = "memberId") Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
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;

public interface TripRepository extends JpaRepository<Trip, Long> {

List<Trip> findAllByMemberId(Long memberId);

void deleteByMemberId(Long memberId);
@Modifying
@Query("DELETE FROM Trip t WHERE t.member.id = :memberId")
void deleteByMemberId(@Param(value = "memberId") Long memberId);

default Trip getById(Long id) {
return findById(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void setUp() {
member = memberRepository.save(new Member("통후추", "kakaoId", KAKAO));
trip = tripRepository.save(new Trip(TripName.from("통후추의 여행"), member));
Point point = new Point(3.14, 5.25, LocalDateTime.now());
trip.add(point);
point.setTrip(trip);
postRepository.save(new Post(
"제목",
point,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ void setUp() {
void 회원_ID로_감상을_삭제한다() {
// given
Post post = new Post("제목", point, "위치", "오늘은 날씨가 좋네요.", member, trip.id());
postRepository.save(post);
Long postId = postRepository.save(post).id();

// when
postRepository.deleteByMemberId(member.id());

// then
assertThat(postRepository.findById(post.id())).isEmpty();
assertThat(postRepository.existsById(postId)).isFalse();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void setUp() {
tripRepository.deleteByMemberId(member.id());

// then
assertThat(tripRepository.findById(trip.id())).isEmpty();
assertThat(tripRepository.existsById(trip.id())).isFalse();
}

@Test
Expand Down

0 comments on commit 6cc528e

Please sign in to comment.