Skip to content

Commit

Permalink
Merge pull request #55 from LIKELION-TEAM4-HACKATHON/feature/review-d…
Browse files Browse the repository at this point in the history
…etail

전체 후기 간단 조회 기능 추가함
  • Loading branch information
oosedus authored Jul 26, 2024
2 parents bfb6916 + 6b49cb7 commit ae3dd75
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 40 deletions.
26 changes: 26 additions & 0 deletions src/main/java/likelion/MZConnent/api/review/ReviewController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package likelion.MZConnent.api.review;

import likelion.MZConnent.dto.paging.response.PageContentResponse;
import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse;
import likelion.MZConnent.service.review.ReviewService;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@Slf4j
public class ReviewController {
private final ReviewService reviewService;
@GetMapping("/api/reviews")
ResponseEntity<PageContentResponse> getReviewSimpleList(@RequestParam(required = false, defaultValue = "", value = "keyword") String keyword, @RequestParam(required = false, defaultValue = "0", value = "page") int page ) {

PageContentResponse<ReviewsSimpleResponse> response = reviewService.getReviewsSimpleList(keyword, page);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class SecurityConfig {
"/api/auth/login", "/api/auth/logout", // 회원
"/api/categories/culture", "/api/cultures", // 문화
"/api/clubs", "/api/clubs/*/join", // 동아리
"/api/reviews", // 후기
"/api/clubs/*",
"/swagger", "/swagger-ui.html", "/swagger-ui/**", "/api-docs", "/api-docs/**", "/v3/api-docs/**", //swagger
};
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/likelion/MZConnent/domain/review/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Review {
private String reviewImageUrl4;

@Column(nullable = false)
private LocalDateTime createDate;
private LocalDateTime createdDate;

@Column(nullable = false)
private int likeCount;
Expand All @@ -60,14 +60,14 @@ public class Review {
private List<ReviewLike> reviewLikes;

@Builder
public Review(String title, String content, String reviewImageUrl1, String reviewImageUrl2, String reviewImageUrl3, String reviewImageUrl4, LocalDateTime createDate, int likeCount, int commentCount, Culture culture, Member member) {
public Review(String title, String content, String reviewImageUrl1, String reviewImageUrl2, String reviewImageUrl3, String reviewImageUrl4, LocalDateTime createdDate, int likeCount, int commentCount, Culture culture, Member member) {
this.title = title;
this.content = content;
this.reviewImageUrl1 = reviewImageUrl1 != null ? reviewImageUrl1 : ""; // 나중에 기본 이미지 URL 추가
this.reviewImageUrl2 = reviewImageUrl2 != null ? reviewImageUrl2 : "";
this.reviewImageUrl3 = reviewImageUrl3 != null ? reviewImageUrl3 : "";
this.reviewImageUrl4 = reviewImageUrl4 != null ? reviewImageUrl4 : "";
this.createDate = createDate;
this.createdDate = createdDate;
this.likeCount = likeCount;
this.commentCount = commentCount;
this.culture = culture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import likelion.MZConnent.domain.member.Age;
import likelion.MZConnent.domain.member.Gender;
import likelion.MZConnent.domain.member.Member;
import likelion.MZConnent.domain.member.Role;
import likelion.MZConnent.dto.culture.CultureCategoryDto;
import likelion.MZConnent.dto.review.ReviewDto;
import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse;
import lombok.*;

import java.math.BigDecimal;
Expand All @@ -27,7 +26,7 @@ public class MemberInfoResponse {
private String profileImageUrl;
private BigDecimal averageMannersScore;
private List<CultureCategoryDto> selfIntroductions = new ArrayList<>();
private List<ReviewDto> reviews = new ArrayList<>();
private List<ReviewsSimpleResponse> reviews = new ArrayList<>();


public MemberInfoResponse(Member member) {
Expand All @@ -44,7 +43,7 @@ public MemberInfoResponse(Member member) {
.map((selfIntroduction)-> new CultureCategoryDto(selfIntroduction.getCultureCategory()))
.collect(Collectors.toList());
this.reviews = member.getReviews().stream()
.map(ReviewDto::new)
.map(ReviewsSimpleResponse::new)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package likelion.MZConnent.dto.paging.response;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;

import java.util.List;

@Getter
@NoArgsConstructor
public class PageContentResponse<T> {
private List<T> content;
private int totalPages;
private long totalElements;
private int size;

@Builder
public PageContentResponse(List<T> content, int totalPages, long totalElements, int size) {
this.content = content;
this.totalPages = totalPages;
this.totalElements = totalElements;
this.size = size;
}
}
33 changes: 0 additions & 33 deletions src/main/java/likelion/MZConnent/dto/review/ReviewDto.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package likelion.MZConnent.dto.review.response;


import likelion.MZConnent.domain.review.Review;
import likelion.MZConnent.dto.member.MemberProfileDto;
import lombok.*;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
public class ReviewsSimpleResponse {
private Long reviewId;
private MemberProfileDto reviewer;
private String title;
private String reviewImageUrl;
private String cultureName;
private LocalDateTime createdDate;
private int likeCount;
private int commentCount;

@Builder
public ReviewsSimpleResponse(Review review) {
this.reviewId = review.getReviewId();
this.reviewer = new MemberProfileDto(review.getMember());
this.title = review.getTitle();
this.reviewImageUrl = review.getReviewImageUrl1();
this.cultureName = review.getCulture().getName();
this.createdDate = review.getCreatedDate();
this.likeCount = review.getLikeCount();
this.commentCount = review.getCommentCount();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package likelion.MZConnent.repository.review;

import io.lettuce.core.dynamic.annotation.Param;
import likelion.MZConnent.domain.review.Review;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ReviewRepository extends JpaRepository<Review, Long> {
@Query("SELECT r FROM Review r WHERE r.title LIKE %:keyword%")
Page<Review> findByKeyword(@Param("keyword") String keyword, Pageable pageable);
}
46 changes: 46 additions & 0 deletions src/main/java/likelion/MZConnent/service/review/ReviewService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package likelion.MZConnent.service.review;

import likelion.MZConnent.domain.review.Review;
import likelion.MZConnent.dto.paging.response.PageContentResponse;
import likelion.MZConnent.dto.review.response.ReviewsSimpleResponse;
import likelion.MZConnent.repository.review.ReviewRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
@Slf4j
@RequiredArgsConstructor
public class ReviewService {
private final ReviewRepository reviewRepository;
private final int PAGE_SIZE = 6;

public PageContentResponse<ReviewsSimpleResponse> getReviewsSimpleList(String keyword, int page) {
Pageable pageable = PageRequest.of(page, PAGE_SIZE, Sort.by("createdDate").descending());

log.info(keyword);

Page<Review> reviews = reviewRepository.findByKeyword(keyword, pageable);

List<ReviewsSimpleResponse> reviewsResponse = reviews.stream().map(review -> ReviewsSimpleResponse.builder()
.review(review).build()
).collect(Collectors.toList());

return PageContentResponse.<ReviewsSimpleResponse>builder()
.content(reviewsResponse)
.totalPages(reviews.getTotalPages())
.totalElements(reviews.getTotalElements())
.size(pageable.getPageSize())
.build();

}
}

0 comments on commit ae3dd75

Please sign in to comment.