-
Notifications
You must be signed in to change notification settings - Fork 1
[FEAT] 홈 화면 게스트하우스 목록 조회 #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9193c7a
34ec856
3a947bb
4db6d26
d9e7548
52cd1b4
3a586a8
55e58ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,17 @@ | ||
| package com.sumte.guesthouse.service; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.domain.Slice; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import com.sumte.apiPayload.code.error.CommonErrorCode; | ||
| import com.sumte.apiPayload.exception.SumteException; | ||
| import com.sumte.guesthouse.converter.GuesthouseConverter; | ||
| import com.sumte.guesthouse.dto.GuesthousePreviewDTO; | ||
| import com.sumte.guesthouse.dto.GuesthouseResponseDTO; | ||
| import com.sumte.guesthouse.dto.GuesthouseSearchRequestDTO; | ||
|
|
@@ -17,17 +20,24 @@ | |
| import com.sumte.guesthouse.repository.GuesthouseRepository; | ||
| import com.sumte.guesthouse.repository.GuesthouseRepositoryCustom; | ||
| import com.sumte.guesthouse.repository.GuesthouseTargetAudienceRepository; | ||
| import com.sumte.review.repository.ReviewRepository; | ||
| import com.sumte.room.dto.RoomResponseDTO; | ||
| import com.sumte.room.repository.RoomRepository; | ||
|
|
||
| import jakarta.transaction.Transactional; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class GuesthouseQueryServiceImpl implements GuesthouseQueryService { | ||
|
|
||
| private final GuesthouseRepository guesthouseRepository; | ||
| private final RoomRepository roomRepository; | ||
| private final ReviewRepository reviewRepository; | ||
| private final GuesthouseConverter guesthouseConverter; | ||
| private final GuesthouseTargetAudienceRepository guesthouseTargetAudienceRepository; | ||
| private final GuesthouseOptionServicesRepository guesthouseOptionServicesRepository; | ||
| private final GuesthouseRepositoryCustom guesthouseRepositoryCustom; | ||
|
|
||
| @Override | ||
| @Transactional | ||
|
|
@@ -67,13 +77,23 @@ public GuesthouseResponseDTO.GetHouseResponse getHouseById(Long id) { | |
| .build(); | ||
| } | ||
|
|
||
| private final GuesthouseRepositoryCustom guesthouseRepositoryCustom; | ||
| @Override | ||
| @Transactional | ||
| public Slice<GuesthouseResponseDTO.HomeSummary> getGuesthousesForHome(Pageable pageable) { | ||
| Slice<Guesthouse> guesthouses = guesthouseRepository.findAllOrderedForHome(pageable); | ||
|
|
||
| return guesthouses.map(gh -> guesthouseConverter.toHomeSummary( | ||
| gh, | ||
| Optional.ofNullable(reviewRepository.findAverageScoreByGuesthouseId(gh.getId())).orElse(0.0), | ||
| reviewRepository.countByGuesthouseId(gh.getId()), | ||
| Optional.ofNullable(roomRepository.findEarliestCheckinByGuesthouseId(gh.getId())).orElse("00:00"), | ||
| Optional.ofNullable(roomRepository.findMinPriceByGuesthouseId(gh.getId())).orElse(0L) | ||
| )); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 체크인 시간과, 가격 같은 경우 0으로 제공되는 것보단 null이나 -1같은 특별한 값으로 프론트에서 처리할 수 있도록 하는 것이 좋아 보입니다. (관련 설명을 스웨거에도 기입해주면 좋겠죠?) |
||
|
|
||
| @Override | ||
| @Transactional | ||
| public Page<GuesthousePreviewDTO> getFilteredGuesthouse(GuesthouseSearchRequestDTO dto, Pageable pageable) { | ||
|
|
||
| return guesthouseRepositoryCustom.searchFiltered(dto, pageable); | ||
| } | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| 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.data.repository.query.Param; | ||
|
|
||
| import com.sumte.review.entity.Review; | ||
|
|
||
|
|
@@ -19,5 +21,13 @@ public interface ReviewRepository extends JpaRepository<Review, Long> { | |
| //내가 작성한 리뷰 조회 (단순 내가 작성한 리뷰만 조회하는거라 넣었는데 다시 확인(중복) ) | ||
| Page<Review> findAllByUserId(Long userId, Pageable pageable); | ||
|
|
||
| //홈화면 | ||
| @Query("SELECT AVG(r.score) FROM Review r WHERE r.room.guesthouse.id = :guesthouseId") | ||
| Double findAverageScoreByGuesthouseId(@Param("guesthouseId") Long guesthouseId); | ||
|
|
||
| @Query("SELECT COUNT(r) FROM Review r WHERE r.room.guesthouse.id = :guesthouseId") | ||
| int countByGuesthouseId(@Param("guesthouseId") Long guesthouseId); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. int countByRoomGuesthouseId(Long guesthouseId); 처럼 |
||
| // int countByRoomGuesthouseId(Long guesthouseId); | ||
|
|
||
| boolean existsByUserIdAndRoomGuesthouseId(Long userId, Long roomGuesthouseId); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
게스트하우스 전용 예외처리를 사용하면 더 좋을 것 같습니다!