diff --git a/backend/src/main/java/com/staccato/member/repository/MemberRepository.java b/backend/src/main/java/com/staccato/member/repository/MemberRepository.java index 841f2caa4..1991679db 100644 --- a/backend/src/main/java/com/staccato/member/repository/MemberRepository.java +++ b/backend/src/main/java/com/staccato/member/repository/MemberRepository.java @@ -1,8 +1,11 @@ package com.staccato.member.repository; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import com.staccato.member.domain.Member; public interface MemberRepository extends JpaRepository { + Optional findByIdAndIsDeletedIsFalse(long memberId); } diff --git a/backend/src/main/java/com/staccato/travel/domain/TravelMember.java b/backend/src/main/java/com/staccato/travel/domain/TravelMember.java index 47bdde374..fff512c12 100644 --- a/backend/src/main/java/com/staccato/travel/domain/TravelMember.java +++ b/backend/src/main/java/com/staccato/travel/domain/TravelMember.java @@ -22,7 +22,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -@SQLDelete(sql = "UPDATE mate SET is_deleted = true WHERE id = ?") +@SQLDelete(sql = "UPDATE travel_member SET is_deleted = true WHERE id = ?") public class TravelMember extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/backend/src/main/java/com/staccato/travel/repository/TravelMemberRepository.java b/backend/src/main/java/com/staccato/travel/repository/TravelMemberRepository.java index 9274a4968..8cddf776f 100644 --- a/backend/src/main/java/com/staccato/travel/repository/TravelMemberRepository.java +++ b/backend/src/main/java/com/staccato/travel/repository/TravelMemberRepository.java @@ -9,8 +9,8 @@ import com.staccato.travel.domain.TravelMember; public interface TravelMemberRepository extends JpaRepository { - List findAllByMemberId(long memberId); + List findAllByMemberIdAndIsDeletedIsFalse(long memberId); - @Query("SELECT tm FROM TravelMember tm WHERE tm.member.id = :memberId AND YEAR(tm.travel.startAt) = :year") + @Query("SELECT tm FROM TravelMember tm WHERE tm.member.id = :memberId AND YEAR(tm.travel.startAt) = :year AND tm.isDeleted IS FALSE") List findAllByMemberIdAndTravelStartAtYear(@Param("memberId") long memberId, @Param("year") int year); } diff --git a/backend/src/main/java/com/staccato/travel/service/TravelService.java b/backend/src/main/java/com/staccato/travel/service/TravelService.java index 964437cd1..1c2a54f50 100644 --- a/backend/src/main/java/com/staccato/travel/service/TravelService.java +++ b/backend/src/main/java/com/staccato/travel/service/TravelService.java @@ -46,7 +46,7 @@ private void saveTravelMember(Long memberId, Travel travel) { } private Member getMemberById(long memberId) { - return memberRepository.findById(memberId) + return memberRepository.findByIdAndIsDeletedIsFalse(memberId) .orElseThrow(() -> new IllegalArgumentException("Invalid Operation")); } @@ -70,7 +70,7 @@ public TravelResponses readAllTravels(long memberId, Integer year) { } private TravelResponses readAll(long memberId) { - List travelMembers = travelMemberRepository.findAllByMemberId(memberId); + List travelMembers = travelMemberRepository.findAllByMemberIdAndIsDeletedIsFalse(memberId); return getTravelDetailResponses(travelMembers); } diff --git a/backend/src/test/java/com/staccato/travel/repository/TravelMemberRepositoryTest.java b/backend/src/test/java/com/staccato/travel/repository/TravelMemberRepositoryTest.java index 2001bdeec..7cb59bd21 100644 --- a/backend/src/test/java/com/staccato/travel/repository/TravelMemberRepositoryTest.java +++ b/backend/src/test/java/com/staccato/travel/repository/TravelMemberRepositoryTest.java @@ -43,6 +43,24 @@ void findAllByMemberIdAndTravelStartAtYear() { assertThat(result).hasSize(2); } + @DisplayName("사용자 식별자와 년도로 삭제 되지 않은 여행 상세 목록만 조회한다.") + @Test + void findAllByMemberIdAndTravelStartAtYearWithoutDeleted() { + // given + Member member = memberRepository.save(Member.builder().nickname("staccato").build()); + Travel travel = travelRepository.save(createTravel(LocalDate.of(2023, 7, 1), LocalDate.of(2023, 7, 10))); + Travel travel2 = travelRepository.save(createTravel(LocalDate.of(2023, 12, 31), LocalDate.of(2024, 1, 10))); + TravelMember target = travelMemberRepository.save(new TravelMember(member, travel)); + travelMemberRepository.save(new TravelMember(member, travel2)); + travelMemberRepository.deleteById(target.getId()); + + // when + List result = travelMemberRepository.findAllByMemberIdAndTravelStartAtYear(member.getId(), 2023); + + // then + assertThat(result).hasSize(1); + } + private static Travel createTravel(LocalDate startAt, LocalDate endAt) { return Travel.builder() .title("여행") diff --git a/backend/src/test/java/com/staccato/travel/service/TravelServiceTest.java b/backend/src/test/java/com/staccato/travel/service/TravelServiceTest.java index 6815fcc64..51871b857 100644 --- a/backend/src/test/java/com/staccato/travel/service/TravelServiceTest.java +++ b/backend/src/test/java/com/staccato/travel/service/TravelServiceTest.java @@ -51,7 +51,7 @@ void createTravel() { // when long travelId = travelService.createTravel(travelRequest, member.getId()); - TravelMember travelMember = travelMemberRepository.findAll().get(0); + TravelMember travelMember = travelMemberRepository.findAllByMemberIdAndIsDeletedIsFalse(member.getId()).get(0); // then assertAll(