diff --git a/src/main/java/likelion/MZConnent/api/main/MainInfoController.java b/src/main/java/likelion/MZConnent/api/main/MainInfoController.java new file mode 100644 index 0000000..4526bd3 --- /dev/null +++ b/src/main/java/likelion/MZConnent/api/main/MainInfoController.java @@ -0,0 +1,25 @@ +package likelion.MZConnent.api.main; + +import likelion.MZConnent.dto.main.response.MainInfoResponse; +import likelion.MZConnent.service.main.MainInfoService; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Slf4j +@RequiredArgsConstructor +public class MainInfoController { + private final MainInfoService mainInfoService; + + @GetMapping("/api/main") + public ResponseEntity getMainInfo() { + MainInfoResponse mainInfo = mainInfoService.getMainInfo(); + log.info("메인 정보 조회: {}", mainInfo); + + return ResponseEntity.ok(mainInfo); + } +} diff --git a/src/main/java/likelion/MZConnent/api/review/ReviewController.java b/src/main/java/likelion/MZConnent/api/review/ReviewController.java index 140cd9a..a9abd9c 100644 --- a/src/main/java/likelion/MZConnent/api/review/ReviewController.java +++ b/src/main/java/likelion/MZConnent/api/review/ReviewController.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import likelion.MZConnent.dto.paging.response.PageContentResponse; import likelion.MZConnent.dto.review.request.SaveReviewRequest; +import likelion.MZConnent.dto.review.response.ReviewDetailResponse; import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse; import likelion.MZConnent.dto.review.response.SaveReviewResponse; import likelion.MZConnent.jwt.principle.UserPrinciple; @@ -71,4 +72,19 @@ public ResponseEntity> toggleReviewLike(@PathVariable("revie return ResponseEntity.ok(Map.of("message", "후기 좋아요 삭제 성공")); } } + + + // 후기 상세 정보 조회 + @GetMapping("/api/reviews/{reviewId}") + public ResponseEntity getReviewDetailInfo(@PathVariable("reviewId") Long reviewId) { + ReviewDetailResponse response = reviewService.getReviewDetailInfo(reviewId); + log.info("후기 상세 정보: {}", response); + return ResponseEntity.ok(response); + } + + @DeleteMapping("/api/reviews/{reviewId}") + public ResponseEntity> deleteReview(@PathVariable("reviewId") Long reviewId) { + reviewService.deleteReview(reviewId); + return ResponseEntity.ok(Map.of("message", "후기 삭제 성공")); + } } diff --git a/src/main/java/likelion/MZConnent/config/SecurityConfig.java b/src/main/java/likelion/MZConnent/config/SecurityConfig.java index 1efeef8..57ff576 100644 --- a/src/main/java/likelion/MZConnent/config/SecurityConfig.java +++ b/src/main/java/likelion/MZConnent/config/SecurityConfig.java @@ -46,7 +46,7 @@ public class SecurityConfig { private final String[] permitAllUrl = {"/error", "/api/auth/login", "/api/auth/email", "/api/auth/username", // 회원 "/api/categories/culture", "/api/cultures", "/api/cultures/**", // 문화 - "/api/reviews", // 후기 + "/api/reviews/**", // 후기 "/api/categories/region", "/api/clubs/list", "/api/main", "/api/clubs/**", "/swagger", "/swagger-ui.html", "/swagger-ui/**", "/api-docs", "/api-docs/**", "/v3/api-docs/**", //swagger @@ -86,7 +86,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration config = new CorsConfiguration(); - config.setAllowedOrigins(Arrays.asList("http://localhost:3000")); // frontend url + config.setAllowedOrigins(Arrays.asList("http://mzconnect.site", "http://localhost:3000")); // frontend url config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS")); config.setAllowedHeaders(Collections.singletonList("*")); config.setAllowCredentials(true); diff --git a/src/main/java/likelion/MZConnent/domain/member/Member.java b/src/main/java/likelion/MZConnent/domain/member/Member.java index ada766a..d9dc928 100644 --- a/src/main/java/likelion/MZConnent/domain/member/Member.java +++ b/src/main/java/likelion/MZConnent/domain/member/Member.java @@ -22,7 +22,7 @@ @ToString @NoArgsConstructor public class Member { - public static final String DEFAULT_PROFILE_IMAGE_URL = "https://mzconnect-bucket.s3.ap-northeast-2.amazonaws.com/default_image.jpeg"; + public static final String DEFAULT_PROFILE_IMAGE_URL = "https://mzconnect-bucket.s3.ap-northeast-2.amazonaws.com/default_image.png"; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/likelion/MZConnent/dto/club/response/ClubSimpleResponse.java b/src/main/java/likelion/MZConnent/dto/club/response/ClubSimpleResponse.java index 451a7d1..35c8a16 100644 --- a/src/main/java/likelion/MZConnent/dto/club/response/ClubSimpleResponse.java +++ b/src/main/java/likelion/MZConnent/dto/club/response/ClubSimpleResponse.java @@ -1,13 +1,21 @@ package likelion.MZConnent.dto.club.response; +import likelion.MZConnent.domain.club.AgeRestriction; +import likelion.MZConnent.domain.club.Club; +import likelion.MZConnent.domain.club.ClubRole; +import likelion.MZConnent.domain.club.GenderRestriction; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; import java.time.LocalDate; import java.time.LocalDateTime; @Getter +@Slf4j +@ToString @NoArgsConstructor public class ClubSimpleResponse { private Long clubId; @@ -19,15 +27,15 @@ public class ClubSimpleResponse { private String leaderProfileImage; private LocalDate meetingDate; private LocalDateTime createdDate; - private String genderRestriction; - private String ageRestriction; + private GenderRestriction genderRestriction; + private AgeRestriction ageRestriction; private int currentParticipant; private int maxParticipant; @Builder public ClubSimpleResponse(Long clubId, String title, Long regionId, String regionName, Long cultureCategoryId, String cultureName, String leaderProfileImage, LocalDate meetingDate, - LocalDateTime createdDate, String genderRestriction, String ageRestriction, + LocalDateTime createdDate, GenderRestriction genderRestriction, AgeRestriction ageRestriction, int currentParticipant, int maxParticipant) { this.clubId = clubId; this.title = title; @@ -43,4 +51,23 @@ public ClubSimpleResponse(Long clubId, String title, Long regionId, String regio this.currentParticipant = currentParticipant; this.maxParticipant = maxParticipant; } + + public ClubSimpleResponse(Club club) { + this.clubId = club.getClubId(); + this.title = club.getTitle(); + this.regionId = club.getRegion().getRegionId(); + this.regionName = club.getRegion().getName(); + this.cultureCategoryId = club.getCulture().getCultureId(); + this.cultureName = club.getCulture().getName(); + this.leaderProfileImage = club.getClubMembers().stream().filter(clubMember -> clubMember.getClubRole().equals(ClubRole.LEADER)).findFirst().orElseThrow(()-> { + log.info("모임장이 존재하지 않음."); + return new IllegalArgumentException("모임장이 존재하지 않습니다."); + }).getMember().getProfileImageUrl(); + this.meetingDate = club.getMeetingDate(); + this.createdDate = club.getCreatedDate(); + this.genderRestriction = club.getGenderRestriction(); + this.ageRestriction = club.getAgeRestriction(); + this.currentParticipant = club.getCurrentParticipant(); + this.maxParticipant = club.getMaxParticipant(); + } } diff --git a/src/main/java/likelion/MZConnent/dto/culture/response/CultureDetailResponse.java b/src/main/java/likelion/MZConnent/dto/culture/response/CultureDetailResponse.java index ebbb7d8..db491f6 100644 --- a/src/main/java/likelion/MZConnent/dto/culture/response/CultureDetailResponse.java +++ b/src/main/java/likelion/MZConnent/dto/culture/response/CultureDetailResponse.java @@ -5,6 +5,7 @@ import likelion.MZConnent.domain.club.ClubRole; import likelion.MZConnent.domain.club.GenderRestriction; import likelion.MZConnent.domain.culture.Culture; +import likelion.MZConnent.dto.club.response.ClubSimpleResponse; import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse; import lombok.*; import lombok.extern.slf4j.Slf4j; @@ -27,7 +28,7 @@ public class CultureDetailResponse { private int interestCount; private String recommendedMember; private String content; - private List clubs; + private List clubs; private List reviews; @Builder @@ -40,51 +41,11 @@ public CultureDetailResponse(Culture culture) { this.recommendedMember = culture.getRecommendedMember(); this.content = culture.getContent(); this.clubs = culture.getClubs().stream().filter(club -> - (club.getStatus().equals("OPEN") - )).map(club -> - ClubsSimpleResponse.builder() - .club(club).build()).collect(Collectors.toList()); + (club.getStatus().equals("OPEN") + )).map(ClubSimpleResponse::new).collect(Collectors.toList()); this.reviews = culture.getReviews().stream().map( review -> ReviewsSimpleResponse.builder() .review(review).build() ).collect(Collectors.toList()); } - - - @Getter - @ToString - @NoArgsConstructor(access = AccessLevel.PROTECTED) - static private class ClubsSimpleResponse { - private Long clubId; - private String title; - private String regionName; - private String cultureName; - private String leaderProfileImage; - private LocalDate meetingDate; - private LocalDateTime createdDate; - private GenderRestriction genderRestriction; - private AgeRestriction ageRestriction; - private int currentParticipant; - private int maxParticipant; - - @Builder - public ClubsSimpleResponse(Club club) { - this.clubId = club.getClubId(); - this.title = club.getTitle(); - this.regionName = club.getRegion().getName(); - this.cultureName = club.getCulture().getName(); - this.leaderProfileImage = club.getClubMembers().stream().filter((member) -> - member.getClubRole() == ClubRole.LEADER - ).findFirst().orElseThrow(() -> { - log.info("모임장이 존재하지 않음."); - return new IllegalArgumentException("모임장이 존재하지 않습니다."); - }).getMember().getProfileImageUrl(); - this.meetingDate = club.getMeetingDate(); - this.createdDate = club.getCreatedDate(); - this.genderRestriction = club.getGenderRestriction(); - this.ageRestriction = club.getAgeRestriction(); - this.currentParticipant = club.getCurrentParticipant(); - this.maxParticipant = club.getMaxParticipant(); - } - } } diff --git a/src/main/java/likelion/MZConnent/dto/main/response/MainInfoResponse.java b/src/main/java/likelion/MZConnent/dto/main/response/MainInfoResponse.java new file mode 100644 index 0000000..4e1b106 --- /dev/null +++ b/src/main/java/likelion/MZConnent/dto/main/response/MainInfoResponse.java @@ -0,0 +1,30 @@ +package likelion.MZConnent.dto.main.response; + +import likelion.MZConnent.domain.club.Club; +import likelion.MZConnent.domain.culture.Culture; +import likelion.MZConnent.domain.review.Review; +import likelion.MZConnent.dto.club.response.ClubSimpleResponse; +import likelion.MZConnent.dto.culture.response.CulturesSimpleResponse; +import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.stream.Collectors; + +@Data +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class MainInfoResponse { + private List popularCultures; + private List popularReviews; + private List recentClubs; + + @Builder + public MainInfoResponse(List popularCultures, List popularReviews, List recentClubs) { + this.popularCultures = popularCultures.stream().map(culture -> CulturesSimpleResponse.builder().culture(culture).build()).collect(Collectors.toList()); + this.popularReviews = popularReviews.stream().map(review -> ReviewsSimpleResponse.builder().review(review).build()).collect(Collectors.toList()); + this.recentClubs = recentClubs.stream().map(ClubSimpleResponse::new).collect(Collectors.toList()); + } +} diff --git a/src/main/java/likelion/MZConnent/dto/review/response/ReviewDetailResponse.java b/src/main/java/likelion/MZConnent/dto/review/response/ReviewDetailResponse.java new file mode 100644 index 0000000..84cbcc0 --- /dev/null +++ b/src/main/java/likelion/MZConnent/dto/review/response/ReviewDetailResponse.java @@ -0,0 +1,78 @@ +package likelion.MZConnent.dto.review.response; + +import likelion.MZConnent.domain.culture.Culture; +import likelion.MZConnent.domain.review.Review; +import likelion.MZConnent.domain.review.ReviewComment; +import likelion.MZConnent.dto.member.MemberProfileDto; +import lombok.*; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@Getter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class ReviewDetailResponse { + private Long reviewId; + private MemberProfileDto reviewer; + private CultureSimpleDto culture; + private String title; + private String reviewImageUrl1; + private String reviewImageUrl2; + private String reviewImageUrl3; + private String reviewImageUrl4; + private String content; + private LocalDateTime createdDate; + private int likeCount; + private List comments = new ArrayList(); + + @Builder + public ReviewDetailResponse(Review review) { + this.reviewId = review.getReviewId(); + this.reviewer = MemberProfileDto.builder().member(review.getMember()).build(); + this.culture = CultureSimpleDto.builder().culture(review.getCulture()).build(); + this.title = review.getTitle(); + this.reviewImageUrl1 = review.getReviewImageUrl1(); + this.reviewImageUrl2 = review.getReviewImageUrl2(); + this.reviewImageUrl3 = review.getReviewImageUrl3(); + this.reviewImageUrl4 = review.getReviewImageUrl4(); + this.content = review.getContent(); + this.createdDate = review.getCreatedDate(); + this.likeCount = review.getLikeCount(); + this.comments = review.getReviewComments().stream() + .map(CommentSimpleDto::new).collect(Collectors.toList()); + } + + @Getter + @ToString + @NoArgsConstructor(access = AccessLevel.PROTECTED) + private static class CultureSimpleDto { + private Long cultureId; + private String name; + + @Builder + public CultureSimpleDto(Culture culture) { + this.cultureId = culture.getCultureId(); + this.name = culture.getName(); + } + } + + @Getter + @ToString + @NoArgsConstructor(access = AccessLevel.PROTECTED) + private static class CommentSimpleDto { + private Long commentId; + private MemberProfileDto commenter; + private String content; + + @Builder + public CommentSimpleDto(ReviewComment comment) { + this.commentId = comment.getCommentId(); + this.commenter = MemberProfileDto.builder().member(comment.getMember()).build(); + this.content = comment.getContent(); + } + } + +} diff --git a/src/main/java/likelion/MZConnent/repository/club/ClubRepository.java b/src/main/java/likelion/MZConnent/repository/club/ClubRepository.java index 354fa72..cc035f6 100644 --- a/src/main/java/likelion/MZConnent/repository/club/ClubRepository.java +++ b/src/main/java/likelion/MZConnent/repository/club/ClubRepository.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Repository; import java.util.Collection; +import java.util.List; @Repository public interface ClubRepository extends JpaRepository { @@ -27,5 +28,8 @@ Page findAllByFilters(@Param("cultureCategoryId") Long cultureCategoryId, Pageable pageable); Collection findAllByStatus(String status); + + @Query("SELECT c FROM Club c WHERE c.status = 'OPEN' ORDER BY c.createdDate DESC") + List findTop6OrderByCreatedDateDesc(Pageable pageable); } diff --git a/src/main/java/likelion/MZConnent/repository/culture/CultureRepository.java b/src/main/java/likelion/MZConnent/repository/culture/CultureRepository.java index 66fb886..8436830 100644 --- a/src/main/java/likelion/MZConnent/repository/culture/CultureRepository.java +++ b/src/main/java/likelion/MZConnent/repository/culture/CultureRepository.java @@ -8,6 +8,8 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface CultureRepository extends JpaRepository { @Query("SELECT c FROM Culture c WHERE :category = 0 OR c.cultureCategory.id = :category") @@ -15,4 +17,8 @@ public interface CultureRepository extends JpaRepository { @Query("SELECT c FROM Culture c JOIN c.cultureInterests ci JOIN ci.member m WHERE (:category = 0 OR c.cultureCategory.id = :category) AND m.email = :email") Page findByMemberAndCategory(@Param("email") String email, @Param("category") Long category, Pageable pageable); + + @Query("SELECT c FROM Culture c ORDER BY c.interestCount DESC") + List findTop4ByInterestCount(Pageable pageable); + } diff --git a/src/main/java/likelion/MZConnent/repository/review/ReviewCommentRepository.java b/src/main/java/likelion/MZConnent/repository/review/ReviewCommentRepository.java index d0ffc9a..53555a2 100644 --- a/src/main/java/likelion/MZConnent/repository/review/ReviewCommentRepository.java +++ b/src/main/java/likelion/MZConnent/repository/review/ReviewCommentRepository.java @@ -1,10 +1,15 @@ package likelion.MZConnent.repository.review; +import likelion.MZConnent.domain.review.Review; import likelion.MZConnent.domain.review.ReviewComment; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; + @Repository public interface ReviewCommentRepository extends JpaRepository { + List findAllByReview(Review review); } diff --git a/src/main/java/likelion/MZConnent/repository/review/ReviewLikeRepository.java b/src/main/java/likelion/MZConnent/repository/review/ReviewLikeRepository.java index d83a486..ab29a58 100644 --- a/src/main/java/likelion/MZConnent/repository/review/ReviewLikeRepository.java +++ b/src/main/java/likelion/MZConnent/repository/review/ReviewLikeRepository.java @@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository @@ -16,4 +17,6 @@ public interface ReviewLikeRepository extends JpaRepository { boolean existsByMemberAndReview(Member member, Review review); Optional findByMemberAndReview(Member member, Review review); + + List findAllByReview(Review review); } diff --git a/src/main/java/likelion/MZConnent/repository/review/ReviewRepository.java b/src/main/java/likelion/MZConnent/repository/review/ReviewRepository.java index 48d3799..0bd0384 100644 --- a/src/main/java/likelion/MZConnent/repository/review/ReviewRepository.java +++ b/src/main/java/likelion/MZConnent/repository/review/ReviewRepository.java @@ -1,6 +1,7 @@ package likelion.MZConnent.repository.review; import io.lettuce.core.dynamic.annotation.Param; +import likelion.MZConnent.domain.culture.Culture; import likelion.MZConnent.domain.review.Review; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -14,4 +15,7 @@ public interface ReviewRepository extends JpaRepository { @Query("SELECT r FROM Review r WHERE r.title LIKE %:keyword%") Page findByKeyword(@Param("keyword") String keyword, Pageable pageable); + + @Query("SELECT r FROM Review r ORDER BY r.likeCount DESC") + List findTop6ByLikeCount(Pageable pageable); } diff --git a/src/main/java/likelion/MZConnent/service/club/ClubInfoService.java b/src/main/java/likelion/MZConnent/service/club/ClubInfoService.java index 10dee03..8c8a85f 100644 --- a/src/main/java/likelion/MZConnent/service/club/ClubInfoService.java +++ b/src/main/java/likelion/MZConnent/service/club/ClubInfoService.java @@ -104,8 +104,8 @@ public PageContentResponse getClubList(long cultureCategoryI .leaderProfileImage(getLeaderProfileImage(club)) .meetingDate(club.getMeetingDate()) .createdDate(club.getCreatedDate()) - .genderRestriction(club.getGenderRestriction().name()) - .ageRestriction(club.getAgeRestriction().name()) + .genderRestriction(club.getGenderRestriction()) + .ageRestriction(club.getAgeRestriction()) .currentParticipant(club.getCurrentParticipant()) .maxParticipant(club.getMaxParticipant()) .build()) diff --git a/src/main/java/likelion/MZConnent/service/main/MainInfoService.java b/src/main/java/likelion/MZConnent/service/main/MainInfoService.java new file mode 100644 index 0000000..b6d7f4d --- /dev/null +++ b/src/main/java/likelion/MZConnent/service/main/MainInfoService.java @@ -0,0 +1,41 @@ +package likelion.MZConnent.service.main; + +import likelion.MZConnent.domain.club.Club; +import likelion.MZConnent.domain.culture.Culture; +import likelion.MZConnent.domain.review.Review; +import likelion.MZConnent.dto.main.response.MainInfoResponse; +import likelion.MZConnent.repository.club.ClubRepository; +import likelion.MZConnent.repository.culture.CultureRepository; +import likelion.MZConnent.repository.review.ReviewRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Slf4j +public class MainInfoService { + private final ReviewRepository reviewRepository; + private final CultureRepository cultureRepository; + private final ClubRepository clubRepository; + public MainInfoResponse + getMainInfo() { + Pageable top4 = PageRequest.of(0, 4); + Pageable top6 = PageRequest.of(0, 3); + + List popularCultures = cultureRepository.findTop4ByInterestCount(top4); + List popularReviews = reviewRepository.findTop6ByLikeCount(top6); + List recentClubs = clubRepository.findTop6OrderByCreatedDateDesc(top6); + + + return MainInfoResponse.builder() + .popularCultures(popularCultures) + .popularReviews(popularReviews) + .recentClubs(recentClubs) + .build(); + } +} diff --git a/src/main/java/likelion/MZConnent/service/review/ReviewService.java b/src/main/java/likelion/MZConnent/service/review/ReviewService.java index e8587d3..82323b7 100644 --- a/src/main/java/likelion/MZConnent/service/review/ReviewService.java +++ b/src/main/java/likelion/MZConnent/service/review/ReviewService.java @@ -5,13 +5,16 @@ import likelion.MZConnent.domain.culture.CultureInterest; import likelion.MZConnent.domain.member.Member; import likelion.MZConnent.domain.review.Review; +import likelion.MZConnent.domain.review.ReviewComment; import likelion.MZConnent.domain.review.ReviewLike; import likelion.MZConnent.dto.paging.response.PageContentResponse; import likelion.MZConnent.dto.review.request.SaveReviewRequest; +import likelion.MZConnent.dto.review.response.ReviewDetailResponse; import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse; import likelion.MZConnent.dto.review.response.SaveReviewResponse; import likelion.MZConnent.repository.culture.CultureRepository; import likelion.MZConnent.repository.member.MemberRepository; +import likelion.MZConnent.repository.review.ReviewCommentRepository; import likelion.MZConnent.repository.review.ReviewLikeRepository; import likelion.MZConnent.repository.review.ReviewRepository; import likelion.MZConnent.service.image.S3ImageService; @@ -28,6 +31,7 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Service @@ -40,6 +44,8 @@ public class ReviewService { private final MemberRepository memberRepository; private final CultureRepository cultureRepository; private final ReviewLikeRepository reviewLikeRepository; + private final ReviewCommentRepository reviewCommentRepository; + private final int PAGE_SIZE = 6; public PageContentResponse getReviewsSimpleList(String keyword, int page) { @@ -151,6 +157,11 @@ public boolean toggleReviewLike(String email, Long reviewId) { } } + // 후기 상세 정보 조회 + public ReviewDetailResponse getReviewDetailInfo(Long reviewId) { + return ReviewDetailResponse.builder().review(findReviewById(reviewId)).build(); + } + private Review findReviewById(Long reviewId) { return reviewRepository.findById(reviewId).orElseThrow(() -> { log.info("후기 정보를 찾을 수 없음."); @@ -170,4 +181,21 @@ private Member findMemberByEmail(String email) { return new IllegalArgumentException("회원 정보를 찾을 수 없습니다."); }); } + + public void deleteReview(Long reviewId) { + Review review = findReviewById(reviewId); + // 후기 댓글 삭제 + List comments = reviewCommentRepository.findAllByReview(review); + comments.forEach(comment -> review.getMember().getReviewComments().remove(comment)); + reviewCommentRepository.deleteAll(comments); + + // 후기 좋아요 삭제 + List likes = reviewLikeRepository.findAllByReview(review); + likes.forEach(like -> like.getMember().getReviewLikes().remove(like)); + reviewLikeRepository.deleteAll(likes); + + // 후기 삭제 + review.getCulture().getReviews().remove(review); + reviewRepository.delete(review); + } } diff --git a/src/test/java/likelion/MZConnent/service/main/MainInfoServiceTest.java b/src/test/java/likelion/MZConnent/service/main/MainInfoServiceTest.java new file mode 100644 index 0000000..9c43cd2 --- /dev/null +++ b/src/test/java/likelion/MZConnent/service/main/MainInfoServiceTest.java @@ -0,0 +1,4 @@ +import static org.junit.jupiter.api.Assertions.*; +class MainInfoServiceTest { + +} \ No newline at end of file