Skip to content

Commit

Permalink
Merge pull request #76 from SWM-WeLike2Coding/feat/searchIssueNumber
Browse files Browse the repository at this point in the history
feat: 회차 번호를 통한 상품 검색 기능
  • Loading branch information
kjungw1025 authored Oct 1, 2024
2 parents bfa31ea + 5dbe8a2 commit b79619f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ public ResponsePage<SummarizedProductDto> searchProduct(@Valid @RequestBody Requ
return new ResponsePage<>(result);
}

/**
* 회차 번호에 해당하는 상품 검색
* <p>
* 각 발행사에서 회차는 유니크하지만, 다른 발행사끼리 회차 번호가 겹칠 수 있기때문에 리스트로 반환합니다.
* </p>
*
* @param number 회차 번호
* @return 검색 조건에 맞는 상품 리스트
*/
@GetMapping("/search/{number}")
public List<SummarizedProductDto> searchProductByIssueNumber(@PathVariable Integer number) {
return productService.searchProductByIssueNumber(number);
}

/**
* 오늘 받아온 상품들의 id 리스트 조회
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class Product extends BaseEntity {
@NotNull
private String name;

private Integer issueNumber;

@NotNull
private String equities;

Expand Down Expand Up @@ -100,6 +102,7 @@ public class Product extends BaseEntity {
@Builder
private Product (@NonNull String issuer,
@NonNull String name,
Integer issueNumber,
@NonNull String equities,
int equityCount,
@NonNull LocalDate issuedDate,
Expand All @@ -123,6 +126,7 @@ private Product (@NonNull String issuer,
ProductState productState) {
this.issuer = issuer;
this.name = name;
this.issueNumber = issueNumber;
this.equities = equities;
this.equityCount = equityCount;
this.knockIn = knockIn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.dsl.*;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.JPQLQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.wl2c.elswhereproductservice.domain.product.model.ProductState;
Expand All @@ -12,7 +11,7 @@
import com.wl2c.elswhereproductservice.domain.product.model.dto.list.QSummarizedProductDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.list.SummarizedProductDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.request.RequestProductSearchDto;
import com.wl2c.elswhereproductservice.domain.product.model.entity.QProductTickerSymbol;
import com.wl2c.elswhereproductservice.domain.product.model.entity.Product;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -36,6 +35,16 @@ public class ProductSearchRepository {

private final JPAQueryFactory queryFactory;

public List<Product> searchByIssueNumber(Integer issueNumber) {
return queryFactory.selectFrom(product)
.where(
issueNumberEq(issueNumber),
product.productState.eq(ProductState.ACTIVE)
)
.orderBy(product.id.desc())
.fetch();
}

public Page<SummarizedProductDto> search(RequestProductSearchDto requestDto,
Pageable pageable) {
List<SummarizedProductDto> content = queryFactory
Expand Down Expand Up @@ -325,4 +334,9 @@ private BooleanExpression periodBetween(LocalDate subscriptionStartDate, LocalDa
}
return null;
}

// 회차 번호
private BooleanExpression issueNumberEq(Integer issueNumber) {
return issueNumber != null ? product.issueNumber.eq(issueNumber) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ public Page<SummarizedProductDto> searchProduct(RequestProductSearchDto requestP
return productSearchRepository.search(requestProductSearchDto, pageable);
}

public List<SummarizedProductDto> searchProductByIssueNumber(Integer IssueNumber) {
// 각 발행사에서 회차는 유니크하지만, 다른 발행사끼리 회차 번호가 겹칠 수 있기때문에 리스트로 반환
List<Product> productList = productSearchRepository.searchByIssueNumber(IssueNumber);

return productList.stream()
.map(SummarizedProductDto::new)
.collect(Collectors.toList());
}

public ResponseTodayReceivedProductIdsDto findTodayReceivedProductIds() {
List<Product> productList = productRepository.listByCreatedAtToday();
if (productList.isEmpty()) {
Expand Down

0 comments on commit b79619f

Please sign in to comment.