-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT]: 마이페이지에서의 내 가게 리스트 조회 API 추가 #135
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
bfdbca3
9a208fc
0bf305b
4f568f6
20588d5
11b5c04
b442361
c3a7c4e
1451dda
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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import com.eatsfine.eatsfine.domain.booking.entity.Booking; | ||
| import com.eatsfine.eatsfine.domain.booking.enums.BookingStatus; | ||
| import com.eatsfine.eatsfine.domain.store.entity.Store; | ||
| import com.eatsfine.eatsfine.domain.user.entity.User; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
|
|
@@ -114,4 +115,18 @@ List<Long> findTableIdsWithFutureBookings( | |
| @Param("currentDate") LocalDate currentDate, | ||
| @Param("currentTime") LocalTime currentTime | ||
| ); | ||
| @Query("select count(b) from Booking b " + | ||
| "where b.store = :store " + | ||
| "and b.status in (com.eatsfine.eatsfine.domain.booking.enums.BookingStatus.CONFIRMED, " + | ||
| "com.eatsfine.eatsfine.domain.booking.enums.BookingStatus.PENDING, " + | ||
| "com.eatsfine.eatsfine.domain.booking.enums.BookingStatus.COMPLETED)") | ||
| Long countActiveBookings(@Param("store") Store store); | ||
|
|
||
| @Query("select b.store.id, count(b) from Booking b " + | ||
| "where b.store in :stores " + | ||
| "and b.status in (com.eatsfine.eatsfine.domain.booking.enums.BookingStatus.CONFIRMED, " + | ||
| "com.eatsfine.eatsfine.domain.booking.enums.BookingStatus.PENDING, " + | ||
| "com.eatsfine.eatsfine.domain.booking.enums.BookingStatus.COMPLETED) " + | ||
| "group by b.store.id") | ||
| List<Object[]> countActiveBookingsByStores(@Param("stores") List<Store> stores); | ||
|
Comment on lines
+118
to
+131
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. 🧹 Nitpick | 🔵 Trivial 상태 필터 조건의 중복 및 쿼리 스타일 불일치 두 가지 개선 포인트가 있습니다:
🤖 Prompt for AI Agents
Comment on lines
+125
to
+131
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. 🧹 Nitpick | 🔵 Trivial
♻️ 인터페이스 프로젝션 예시public interface StoreBookingCount {
Long getStoreId();
Long getBookingCount();
}- `@Query`("select b.store.id, count(b) from Booking b " +
+ `@Query`("select b.store.id as storeId, count(b) as bookingCount from Booking b " +
"where b.store in :stores " +
"and b.status in (com.eatsfine.eatsfine.domain.booking.enums.BookingStatus.CONFIRMED, " +
"com.eatsfine.eatsfine.domain.booking.enums.BookingStatus.PENDING, " +
"com.eatsfine.eatsfine.domain.booking.enums.BookingStatus.COMPLETED) " +
"group by b.store.id")
- List<Object[]> countActiveBookingsByStores(`@Param`("stores") List<Store> stores);
+ List<StoreBookingCount> countActiveBookingsByStores(`@Param`("stores") List<Store> stores);🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| package com.eatsfine.eatsfine.domain.store.enums; | ||
|
|
||
| public enum Category { | ||
| KOREAN, CHINESE, JAPANESE, WESTERN, CAFE | ||
| KOREAN, CHINESE, JAPANESE, WESTERN, ITALIAN, CAFE | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package com.eatsfine.eatsfine.domain.store.service; | ||
|
|
||
| import com.eatsfine.eatsfine.domain.businesshours.entity.BusinessHours; | ||
| import com.eatsfine.eatsfine.domain.booking.repository.BookingRepository; | ||
| import com.eatsfine.eatsfine.domain.store.condition.StoreSearchCondition; | ||
| import com.eatsfine.eatsfine.domain.store.converter.StoreConverter; | ||
| import com.eatsfine.eatsfine.domain.store.dto.StoreResDto; | ||
|
|
@@ -9,6 +10,10 @@ | |
| import com.eatsfine.eatsfine.domain.store.exception.StoreException; | ||
| import com.eatsfine.eatsfine.domain.store.repository.StoreRepository; | ||
| import com.eatsfine.eatsfine.domain.store.status.StoreErrorStatus; | ||
| import com.eatsfine.eatsfine.domain.user.entity.User; | ||
| import com.eatsfine.eatsfine.domain.user.exception.UserException; | ||
| import com.eatsfine.eatsfine.domain.user.repository.UserRepository; | ||
| import com.eatsfine.eatsfine.domain.user.status.UserErrorStatus; | ||
| import com.eatsfine.eatsfine.global.s3.S3Service; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
|
|
@@ -21,13 +26,17 @@ | |
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class StoreQueryServiceImpl implements StoreQueryService { | ||
|
|
||
| private final StoreRepository storeRepository; | ||
| private final BookingRepository bookingRepository; | ||
| private final UserRepository userRepository; | ||
| private final S3Service s3Service; | ||
|
|
||
| // 식당 검색 | ||
|
|
@@ -142,4 +151,37 @@ private boolean isEffectiveOpen(BusinessHours bh, LocalTime time, boolean isToda | |
|
|
||
| return false; // 영업 시간 자체가 아님 | ||
| } | ||
|
|
||
| // 내 가게 리스트 조회 | ||
| @Override | ||
| public StoreResDto.MyStoreListDto getMyStores(String email) { | ||
| User user = userRepository.findByEmail(email) | ||
| .orElseThrow(() -> new UserException(UserErrorStatus.MEMBER_NOT_FOUND)); | ||
|
|
||
| List<Store> myStores = storeRepository.findAllByOwner(user); | ||
|
|
||
| if(myStores.isEmpty()) { | ||
| return StoreConverter.toMyStoreListDto(List.of()); | ||
| } | ||
| // N+1 문제 해결을 위한 Bulk Query 실행 | ||
| List<Object[]> bookingCounts = bookingRepository.countActiveBookingsByStores(myStores); | ||
| Map<Long, Long> bookingCountMap = bookingCounts.stream() | ||
| .collect(Collectors.toMap( | ||
| row -> (Long) row[0], | ||
| row -> (Long) row[1] | ||
| )); | ||
|
Comment on lines
+167
to
+172
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. 🧹 Nitpick | 🔵 Trivial
♻️ 타입 안전한 projection 예시BookingRepository에서: public record StoreBookingCount(Long storeId, Long count) {}
`@Query`("select new com.eatsfine.eatsfine.domain.booking.repository.BookingRepository.StoreBookingCount(" +
"b.store.id, count(b)) from Booking b " +
"where b.store in :stores " +
"and b.status in (...) " +
"group by b.store.id")
List<StoreBookingCount> countActiveBookingsByStores(`@Param`("stores") List<Store> stores);서비스에서: Map<Long, Long> bookingCountMap = bookingCounts.stream()
.collect(Collectors.toMap(StoreBookingCount::storeId, StoreBookingCount::count));🤖 Prompt for AI Agents |
||
|
|
||
| LocalDateTime now = LocalDateTime.now(); | ||
|
|
||
| List<StoreResDto.MyStoreDto> storeDtos = myStores.stream() | ||
| .map(store -> { | ||
| boolean isOpen = isOpenNow(store, now); | ||
| Long totalBookingCount = bookingCountMap.getOrDefault(store.getId(), 0L); | ||
| String mainImageUrl = s3Service.toUrl(store.getMainImageKey()); | ||
| return StoreConverter.toMyStoreDto(store, isOpen, mainImageUrl, totalBookingCount); | ||
| }) | ||
| .toList(); | ||
|
|
||
| return StoreConverter.toMyStoreListDto(storeDtos); | ||
| } | ||
| } | ||
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.
🧹 Nitpick | 🔵 Trivial
🧩 Analysis chain
🏁 Script executed:
rg -nP '\bcountActiveBookings\b' --type=java -C2Repository: Eatsfine/BE
Length of output: 784
🏁 Script executed:
rg -nP '\bcountActiveBookingsByStores\b' --type=java -C2Repository: Eatsfine/BE
Length of output: 1312
countActiveBookings메서드는 사용되지 않으므로 제거해주세요.코드베이스에서 이 메서드가 호출되는 곳이 없으며,
StoreQueryServiceImpl에서는countActiveBookingsByStoresbulk 쿼리만 사용 중입니다. N+1 문제를 해결하기 위한 bulk 쿼리만 필요하므로 단건 메서드는 삭제하는 것이 좋습니다.🤖 Prompt for AI Agents