-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 발주처 목록 조회 기능 구현 #43
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
05cd580
6acd255
5a67280
2ea2762
6015522
cddae03
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.almang.inventory.global.util; | ||
|
|
||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Sort; | ||
| import org.springframework.data.domain.Sort.Direction; | ||
|
|
||
| public class PaginationUtil { | ||
|
|
||
| private PaginationUtil() {} // 인스턴스 생성 방지 | ||
|
|
||
| public static PageRequest createPageRequest(Integer page, Integer size, String sortBy) { | ||
| int pageIndex = (page == null || page < 1) ? 0 : page - 1; | ||
| int pageSize = (size == null || size < 1) ? 20 : size; | ||
|
|
||
| return PageRequest.of(pageIndex, pageSize, Sort.by(Direction.ASC, sortBy)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,23 @@ | ||
| package com.almang.inventory.vendor.repository; | ||
|
|
||
| import com.almang.inventory.vendor.domain.Vendor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface VendorRepository extends JpaRepository<Vendor, Long> { | ||
|
|
||
| Page<Vendor> findAllByStoreId(Long storeId, Pageable pageable); | ||
|
|
||
| Page<Vendor> findAllByStoreIdAndActivatedTrue( | ||
| Long storeId, Pageable pageable | ||
| ); | ||
|
|
||
| Page<Vendor> findAllByStoreIdAndNameContainingIgnoreCase( | ||
| Long storeId, String name, Pageable pageable | ||
| ); | ||
|
|
||
| Page<Vendor> findAllByStoreIdAndActivatedTrueAndNameContainingIgnoreCase( | ||
| Long storeId, String name, Pageable pageable | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| package com.almang.inventory.vendor.service; | ||
|
|
||
| import com.almang.inventory.global.api.PageResponse; | ||
| import com.almang.inventory.global.exception.BaseException; | ||
| import com.almang.inventory.global.exception.ErrorCode; | ||
| import com.almang.inventory.global.util.PaginationUtil; | ||
| import com.almang.inventory.store.domain.Store; | ||
| import com.almang.inventory.user.domain.User; | ||
| import com.almang.inventory.user.repository.UserRepository; | ||
| import com.almang.inventory.vendor.domain.Vendor; | ||
|
|
@@ -11,6 +14,8 @@ | |
| import com.almang.inventory.vendor.repository.VendorRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
|
|
@@ -57,6 +62,22 @@ public VendorResponse getVendorDetail(Long vendorId, Long userId) { | |
| return VendorResponse.from(vendor); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public PageResponse<VendorResponse> getVendorList( | ||
| Long userId, Integer page, Integer size, Boolean isActivate, String nameKeyword | ||
| ) { | ||
| User user = findUserById(userId); | ||
| Store store = user.getStore(); | ||
|
|
||
| log.info("[VendorService] 발주처 목록 조회 요청 - userId: {}, storeId: {}", userId, store.getId()); | ||
| PageRequest pageable = PaginationUtil.createPageRequest(page, size, "name"); | ||
| Page<Vendor> vendorPage = findVendorsByFilter(store.getId(), isActivate, nameKeyword, pageable); | ||
| Page<VendorResponse> mapped = vendorPage.map(VendorResponse::from); | ||
|
|
||
| log.info("[VendorService] 발주처 목록 조회 성공 - userId: {}, storeId: {}", userId, store.getId()); | ||
| return PageResponse.from(mapped); | ||
| } | ||
|
|
||
| private Vendor toEntity(CreateVendorRequest request, User user) { | ||
| return Vendor.builder() | ||
| .store(user.getStore()) | ||
|
|
@@ -83,4 +104,32 @@ private Vendor findVendorByIdAndValidateAccess(Long vendorId, User user) { | |
|
|
||
| return vendor; | ||
| } | ||
|
|
||
| private Page<Vendor> findVendorsByFilter( | ||
| Long storeId, Boolean isActivate, String nameKeyword, PageRequest pageable | ||
| ) { | ||
| boolean hasName = nameKeyword != null && !nameKeyword.isBlank(); | ||
|
|
||
| // 필터 없음 | ||
| if (isActivate == null && !hasName) { | ||
| return vendorRepository.findAllByStoreId(storeId, pageable); | ||
| } | ||
|
|
||
| // 활성 여부 | ||
| if (isActivate != null && !hasName) { | ||
| return vendorRepository.findAllByStoreIdAndActivatedTrue(storeId, pageable); | ||
| } | ||
|
Comment on lines
+118
to
+121
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. 🧩 Analysis chain🚨 필터 로직에 버그가 있습니다 Line 119에서 다음과 같이 수정이 필요합니다: // 활성 여부
- if (isActivate != null && !hasName) {
- return vendorRepository.findAllByStoreIdAndActivatedTrue(storeId, pageable);
+ if (isActivate != null && isActivate && !hasName) {
+ return vendorRepository.findAllByStoreIdAndActivatedTrue(storeId, pageable);
}또한 Line 130의 결합 필터 로직도 동일하게 수정해야 합니다: // 활성 여부 + 이름 검색
- return vendorRepository.findAllByStoreIdAndActivatedTrueAndNameContainingIgnoreCase(
- storeId, nameKeyword, pageable
- );
+ if (isActivate) {
+ return vendorRepository.findAllByStoreIdAndActivatedTrueAndNameContainingIgnoreCase(
+ storeId, nameKeyword, pageable
+ );
+ } else {
+ return vendorRepository.findAllByStoreIdAndNameContainingIgnoreCase(
+ storeId, nameKeyword, pageable
+ );
+ }동일한 버그가 ProductService에도 존재하는지 확인이 필요합니다. 🏁 Script executed: #!/bin/bash
# ProductService의 필터 로직 확인
echo "=== ProductService filter logic ==="
rg -n -A5 "if \(isActivate != null" --type=java src/main/java/com/almang/inventory/product/service/ProductService.javaLength of output: 257 VendorService의 설계 의도를 확인하기 위해 추가 검증이 필요합니다. 추가 검증을 위해 VendorService 컨트롤러 레이어와 메서드 문서를 확인해야 합니다. VendorService의 컨트롤러 엔드포인트를 확인해야 합니다. 현재까지의 분석으로는 Length of output: 10730 VendorController 엔드포인트를 확인하여 API 계약을 명확히 하겠습니다. Length of output: 166 Length of output: 1236 VendorRepository의 쿼리 메서드를 확인하여 false 케이스 처리 가능성을 검증하겠습니다. Length of output: 510 필터 로직에 실제 버그가 있습니다 - 원본 리뷰가 정확합니다. VendorRepository에 사용 가능한 메서드를 확인한 결과:
문제점:
설계 의도: 수정 방안:
원본 리뷰 코멘트의 수정 제안이 타당합니다. 🤖 Prompt for AI Agents |
||
|
|
||
| // 이름 검색 | ||
| if (isActivate == null) { | ||
| return vendorRepository.findAllByStoreIdAndNameContainingIgnoreCase( | ||
| storeId, nameKeyword, pageable | ||
| ); | ||
| } | ||
|
|
||
| // 활성 여부 + 이름 검색 | ||
| return vendorRepository.findAllByStoreIdAndActivatedTrueAndNameContainingIgnoreCase( | ||
| storeId, nameKeyword, pageable | ||
| ); | ||
| } | ||
| } | ||
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.
🛠️ Refactor suggestion | 🟠 Major
Repository 메서드가 불완전합니다
현재
activated=true인 경우만 필터링하는 메서드가 있지만,activated=false를 조회하는 메서드가 없습니다. VendorService의 필터 로직 버그와 연관된 이슈입니다.완전한 필터링 지원을 위해 다음 메서드들을 추가하세요:
또는, Spring Data JPA Specification을 사용하여 동적 쿼리를 구성하는 것도 좋은 대안입니다:
참고: Spring Data JPA Specifications
🤖 Prompt for AI Agents