-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
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
...a/com/skhuthon/skhuthon_0th_team9/app/dto/review/responseDto/ReviewSearchResponseDto.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 com.skhuthon.skhuthon_0th_team9.app.dto.review.responseDto; | ||
|
||
import com.skhuthon.skhuthon_0th_team9.app.domain.category.DepartmentCategory; | ||
import com.skhuthon.skhuthon_0th_team9.app.domain.category.DetailCategory; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
public class ReviewSearchResponseDto { | ||
|
||
private Long id; | ||
private String title; | ||
private String description; | ||
private List<String> imageUrls; | ||
private LocalDateTime createAt; | ||
private LocalDateTime modifiedAt; | ||
private Long userId; | ||
private DepartmentCategory departmentCategory; | ||
private DetailCategory detailCategory; | ||
|
||
} |
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
72 changes: 72 additions & 0 deletions
72
...src/main/java/com/skhuthon/skhuthon_0th_team9/app/service/review/ReviewSearchService.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,72 @@ | ||
package com.skhuthon.skhuthon_0th_team9.app.service.review; | ||
|
||
import com.skhuthon.skhuthon_0th_team9.app.domain.review.Review; | ||
import com.skhuthon.skhuthon_0th_team9.app.dto.review.responseDto.ReviewCreateResponseDto; | ||
import com.skhuthon.skhuthon_0th_team9.app.repository.ReviewRepository; | ||
import com.skhuthon.skhuthon_0th_team9.global.common.dto.ApiResponseTemplate; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.security.Principal; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReviewSearchService { | ||
|
||
private final ReviewRepository reviewRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public ApiResponseTemplate<List<ReviewCreateResponseDto>> getAllReviews(Principal principal) { | ||
List<Review> reviews = reviewRepository.findAll(); | ||
|
||
List<ReviewCreateResponseDto> reviewCreateResponseDtos = reviews.stream() | ||
.map(review -> ReviewCreateResponseDto.builder() | ||
.id(review.getId()) | ||
.title(review.getTitle()) | ||
.description(review.getDescription()) | ||
.imageUrls(review.getImageUrls()) | ||
.createAt(review.getCreateAt()) | ||
.modifiedAt(review.getModifiedAt()) | ||
.userId(review.getUser().getId()) | ||
.departmentCategory(review.getDepartmentCategory()) | ||
.detailCategory(review.getDetailCategory()) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
|
||
return ApiResponseTemplate.<List<ReviewCreateResponseDto>>builder() | ||
.status(200) | ||
.success(true) | ||
.message("리뷰 조회 성공") | ||
.data(reviewCreateResponseDtos) | ||
.build(); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public ApiResponseTemplate<List<ReviewCreateResponseDto>> getReviewsByDepartmentCategory(Long departmentCategoryId){ | ||
List<Review> reviews = reviewRepository.findByDepartmentCategoryId(departmentCategoryId); | ||
|
||
List<ReviewCreateResponseDto> reviewCreateResponseDtos = reviews.stream() | ||
.map(review -> ReviewCreateResponseDto.builder() | ||
.id(review.getId()) | ||
.title(review.getTitle()) | ||
.description(review.getDescription()) | ||
.imageUrls(review.getImageUrls()) | ||
.createAt(review.getCreateAt()) | ||
.modifiedAt(review.getModifiedAt()) | ||
.userId(review.getUser().getId()) | ||
.departmentCategory(review.getDepartmentCategory()) | ||
.detailCategory(review.getDetailCategory()) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
|
||
return ApiResponseTemplate.<List<ReviewCreateResponseDto>>builder() | ||
.status(200) | ||
.success(true) | ||
.message("리뷰 조회 성공") | ||
.data(reviewCreateResponseDtos) | ||
.build(); | ||
} | ||
} |
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