diff --git a/src/main/java/org/prography/kagongsillok/image/application/ImageService.java b/src/main/java/org/prography/kagongsillok/image/application/ImageService.java index 73c1b8a..63ebb5e 100644 --- a/src/main/java/org/prography/kagongsillok/image/application/ImageService.java +++ b/src/main/java/org/prography/kagongsillok/image/application/ImageService.java @@ -1,6 +1,5 @@ package org.prography.kagongsillok.image.application; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @@ -43,11 +42,11 @@ public List getImages(final List imageIds) { private List toImages(List commands) { return commands.stream() - .map(command -> command.toEntity()) + .map(ImageCreateCommand::toEntity) .collect(Collectors.toList()); } - private List saveImages(List images) { + private List saveImages(List images) { // todo: 개선포인트 bulkInsert 필요 return images.stream() .map(imageRepository::save) .collect(Collectors.toList()); diff --git a/src/main/java/org/prography/kagongsillok/image/domain/Image.java b/src/main/java/org/prography/kagongsillok/image/domain/Image.java index ad1ea7e..4707a1e 100644 --- a/src/main/java/org/prography/kagongsillok/image/domain/Image.java +++ b/src/main/java/org/prography/kagongsillok/image/domain/Image.java @@ -9,11 +9,15 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import org.prography.kagongsillok.common.entity.AbstractRootEntity; @Getter @Entity @Table(name = "image") +@Where(clause = "is_deleted = false") +@SQLDelete(sql = "update image set is_deleted = true, updated_at = now() where id = ?") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Image extends AbstractRootEntity { diff --git a/src/main/java/org/prography/kagongsillok/member/application/MemberService.java b/src/main/java/org/prography/kagongsillok/member/application/MemberService.java index 7fb1205..f94d976 100644 --- a/src/main/java/org/prography/kagongsillok/member/application/MemberService.java +++ b/src/main/java/org/prography/kagongsillok/member/application/MemberService.java @@ -20,9 +20,6 @@ public MemberDto getMember(final LoginMemberDto loginMemberDto) { final Long memberId = loginMemberDto.getMemberId(); final Member member = memberRepository.findById(memberId) .orElseThrow(() -> new NotFoundMemberException(memberId)); - if (member.getIsDeleted()) { - throw new NotFoundMemberException(memberId); - } return MemberDto.from(member); } diff --git a/src/main/java/org/prography/kagongsillok/member/domain/Member.java b/src/main/java/org/prography/kagongsillok/member/domain/Member.java index 0f6d6bd..3745290 100644 --- a/src/main/java/org/prography/kagongsillok/member/domain/Member.java +++ b/src/main/java/org/prography/kagongsillok/member/domain/Member.java @@ -12,11 +12,15 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import org.prography.kagongsillok.common.entity.AbstractRootEntity; @Getter @Entity @Table(name = "member") +@Where(clause = "is_deleted = false") +@SQLDelete(sql = "update member set is_deleted = true, updated_at = now() where id = ?") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Member extends AbstractRootEntity { diff --git a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java index 22b188c..f714c82 100644 --- a/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java +++ b/src/main/java/org/prography/kagongsillok/place/application/PlaceService.java @@ -48,9 +48,6 @@ public PlaceDto createPlace(final PlaceCreateCommand placeCreateCommand) { public PlaceDto getPlace(final Long id) { final Place place = placeRepository.findById(id) .orElseThrow(() -> new NotFoundPlaceException(id)); - if (place.getIsDeleted()) { - throw new NotFoundPlaceException(id); - } return PlaceDto.of(place, getImages(place)); } @@ -59,9 +56,7 @@ public PlaceDto getPlace(final Long id) { public PlaceDto getPlaceWithTags(final Long placeId) { final Place place = placeRepository.findById(placeId) .orElseThrow(() -> new NotFoundPlaceException(placeId)); - if (place.getIsDeleted()) { - throw new NotFoundPlaceException(placeId); - } + final List reviews = reviewRepository.findAllByPlaceId(placeId); return PlaceDto.of( diff --git a/src/main/java/org/prography/kagongsillok/place/domain/Place.java b/src/main/java/org/prography/kagongsillok/place/domain/Place.java index 5dd4eb0..b5081f6 100644 --- a/src/main/java/org/prography/kagongsillok/place/domain/Place.java +++ b/src/main/java/org/prography/kagongsillok/place/domain/Place.java @@ -11,6 +11,8 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import org.prography.kagongsillok.common.entity.AbstractRootEntity; import org.prography.kagongsillok.common.utils.CustomListUtils; import org.prography.kagongsillok.common.utils.CustomStringUtils; @@ -18,6 +20,8 @@ @Getter @Entity @Table(name = "place") +@Where(clause = "is_deleted = false") +@SQLDelete(sql = "update place set is_deleted = true, updated_at = now() where id = ?") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Place extends AbstractRootEntity { diff --git a/src/main/java/org/prography/kagongsillok/record/domain/StudyRecord.java b/src/main/java/org/prography/kagongsillok/record/domain/StudyRecord.java index b8e1466..9ef4253 100644 --- a/src/main/java/org/prography/kagongsillok/record/domain/StudyRecord.java +++ b/src/main/java/org/prography/kagongsillok/record/domain/StudyRecord.java @@ -13,6 +13,8 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import org.prography.kagongsillok.common.entity.AbstractRootEntity; import org.prography.kagongsillok.common.utils.CustomListUtils; import org.prography.kagongsillok.common.utils.CustomStringUtils; @@ -23,6 +25,8 @@ @Getter @Entity @Table(name = "study_record") +@Where(clause = "is_deleted = false") +@SQLDelete(sql = "update study_record set is_deleted = true, updated_at = now() where id = ?") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class StudyRecord extends AbstractRootEntity { diff --git a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java index e5c87fc..b7da0e1 100644 --- a/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java +++ b/src/main/java/org/prography/kagongsillok/review/application/ReviewService.java @@ -67,9 +67,6 @@ public ReviewDto getReview(final Long id) { final Long memberId = review.getMemberId(); final Member member = memberRepository.findById(memberId) .orElseThrow(() -> new NotFoundMemberException(memberId)); - if (review.getIsDeleted()) { - throw new NotFoundReviewException(id); - } final List images = imageRepository.findByIdIn(review.getImageIds()); @@ -183,7 +180,7 @@ private List getMappedImage(final Review review, final Map i return review .getImageIds() .stream() - .filter(imageId -> images.containsKey(imageId)) + .filter(images::containsKey) .map(images::get) .collect(Collectors.toList()); } @@ -204,7 +201,7 @@ private List getReviewImageDtos(final Review review, final Map getReviewedMemberIds(final List reviews) { return reviews.stream() - .map(review -> review.getMemberId()) + .map(Review::getMemberId) .collect(Collectors.toList()); } @@ -227,7 +224,7 @@ private void checkExistImage(final List imageIds) { private List getMappedImages(final List imageIds, final Map imageMap) { return imageIds.stream() - .map(imageId -> imageMap.get(imageId)) + .map(imageMap::get) .collect(Collectors.toList()); } diff --git a/src/main/java/org/prography/kagongsillok/review/domain/Review.java b/src/main/java/org/prography/kagongsillok/review/domain/Review.java index f5eaa17..5e6cce4 100644 --- a/src/main/java/org/prography/kagongsillok/review/domain/Review.java +++ b/src/main/java/org/prography/kagongsillok/review/domain/Review.java @@ -13,6 +13,8 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import org.prography.kagongsillok.common.entity.AbstractRootEntity; import org.prography.kagongsillok.common.utils.CustomListUtils; import org.prography.kagongsillok.common.utils.CustomStringUtils; @@ -22,6 +24,8 @@ @Getter @Entity @Table(name = "review") +@Where(clause = "is_deleted = false") +@SQLDelete(sql = "update review set is_deleted = true, updated_at = now() where id = ?") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Review extends AbstractRootEntity { diff --git a/src/main/java/org/prography/kagongsillok/review/domain/ReviewTag.java b/src/main/java/org/prography/kagongsillok/review/domain/ReviewTag.java index f62f76d..269ec7a 100644 --- a/src/main/java/org/prography/kagongsillok/review/domain/ReviewTag.java +++ b/src/main/java/org/prography/kagongsillok/review/domain/ReviewTag.java @@ -8,11 +8,15 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import org.prography.kagongsillok.common.entity.AbstractRootEntity; @Getter @Entity @Table(name = "review_tag") +@Where(clause = "is_deleted = false") +@SQLDelete(sql = "update review_tag set is_deleted = true, updated_at = now() where id = ?") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class ReviewTag extends AbstractRootEntity { diff --git a/src/test/java/org/prography/kagongsillok/place/application/PlaceServiceTest.java b/src/test/java/org/prography/kagongsillok/place/application/PlaceServiceTest.java index 48492fc..8cf28e0 100644 --- a/src/test/java/org/prography/kagongsillok/place/application/PlaceServiceTest.java +++ b/src/test/java/org/prography/kagongsillok/place/application/PlaceServiceTest.java @@ -6,6 +6,7 @@ import java.time.LocalTime; import java.util.List; +import javax.persistence.EntityManager; import org.junit.jupiter.api.Test; import org.prography.kagongsillok.image.domain.Image; import org.prography.kagongsillok.image.domain.ImageRepository; @@ -34,6 +35,9 @@ class PlaceServiceTest { @Autowired private ImageRepository imageRepository; + @Autowired + private EntityManager em; + private final List linkCreateCommands = List.of( new LinkCreateCommand(LinkType.INSTAGRAM.name(), "testInstagramUrl"), new LinkCreateCommand(LinkType.BLOG.name(), "testBlogUrl"), @@ -251,6 +255,8 @@ class PlaceServiceTest { final Long placeId = placeService.createPlace(placeCreateCommand).getId(); placeService.deletePlace(placeId); + em.flush(); + em.clear(); assertThatThrownBy(() -> placeService.getPlace(placeId)) .isInstanceOf(NotFoundPlaceException.class) diff --git a/src/test/java/org/prography/kagongsillok/review/application/ReviewServiceTest.java b/src/test/java/org/prography/kagongsillok/review/application/ReviewServiceTest.java index ff9f847..1768fb5 100644 --- a/src/test/java/org/prography/kagongsillok/review/application/ReviewServiceTest.java +++ b/src/test/java/org/prography/kagongsillok/review/application/ReviewServiceTest.java @@ -6,6 +6,7 @@ import java.time.LocalTime; import java.util.List; +import javax.persistence.EntityManager; import org.junit.jupiter.api.Test; import org.prography.kagongsillok.image.domain.Image; import org.prography.kagongsillok.image.domain.ImageRepository; @@ -48,6 +49,9 @@ public class ReviewServiceTest { @Autowired private PlaceRepository placeRepository; + @Autowired + private EntityManager em; + @Test void 리뷰를_생성한다() { final Long memberId = saveMemberAndGetMemberId(); @@ -147,6 +151,8 @@ public class ReviewServiceTest { .build(); final Long createdReviewId = reviewService.createReview(reviewCreateCommand).getId(); reviewService.deleteReview(createdReviewId); + em.flush(); + em.clear(); assertThatThrownBy(() -> reviewService.getReview(createdReviewId)) .isInstanceOf(NotFoundReviewException.class)