Skip to content

Commit

Permalink
Merge pull request #68 from MEME-UMC/add/#65
Browse files Browse the repository at this point in the history
[Feat] 별점 현황 map 구현
  • Loading branch information
yeopyeop-82 authored Jan 29, 2024
2 parents 47678c1 + 9385c9f commit 3a47307
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package umc.meme.shop.domain.review.dto.response;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReviewListResponseDto {
private List<ReviewResponseDto> reviewResponseDtoList;
private Map<Integer, Integer> starStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import umc.meme.shop.domain.reservation.repository.ReservationRepository;
import umc.meme.shop.domain.review.dto.request.DeleteReviewDto;
import umc.meme.shop.domain.review.dto.request.ReviewDto;
import umc.meme.shop.domain.review.dto.response.ReviewListResponseDto;
import umc.meme.shop.domain.review.dto.response.ReviewResponseDto;
import umc.meme.shop.domain.review.entity.Review;
import umc.meme.shop.domain.review.repository.ReviewRepository;
import umc.meme.shop.global.ErrorStatus;
import umc.meme.shop.global.exception.GlobalException;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -72,13 +75,26 @@ public List<ReviewResponseDto> getMyReview(Long modelId){
}

//리뷰 리스트 조회
public List<ReviewResponseDto> getReviewList(Long portfolioId){
public ReviewListResponseDto getReviewList(Long portfolioId){
Portfolio portfolio = portfolioRepository.findById(portfolioId)
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_PORTFOLIO));

//review List
List<Review> reviewList = portfolio.getReviewList();
return reviewList.stream()
List<ReviewResponseDto> responseDtoList = reviewList.stream()
.map(ReviewResponseDto::from)
.toList();

//별점 현황
Map<Integer, Integer> starStatus = new HashMap<>(Map.of(5, 0, 4, 0, 3, 0, 2, 0, 1, 0));
for(ReviewResponseDto review : responseDtoList){
starStatus.put(review.getStar(), starStatus.get(review.getStar())+1 );
}

return ReviewListResponseDto.builder()
.reviewResponseDtoList(responseDtoList)
.starStatus(starStatus)
.build();
}

//리뷰 삭제
Expand Down

0 comments on commit 3a47307

Please sign in to comment.