-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from LIKELION-TEAM4-HACKATHON/feature/review-d…
…etail 전체 후기 간단 조회 기능 추가함
- Loading branch information
Showing
9 changed files
with
145 additions
and
40 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/likelion/MZConnent/api/review/ReviewController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/likelion/MZConnent/dto/paging/response/PageContentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
src/main/java/likelion/MZConnent/dto/review/ReviewDto.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/main/java/likelion/MZConnent/dto/review/response/ReviewsSimpleResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/likelion/MZConnent/repository/review/ReviewRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
src/main/java/likelion/MZConnent/service/review/ReviewService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
} |