
중간 발표가 있는 주차였기 때문에, MVP를 최대한 완료하려고 노력해서 80%이상은 구현 완료
public Page<ProductResponseDto> searchProduct(String companyName, String productName, Long categoryCode, Pageable pageable){
if(!categoryCode.equals(0L)){ // category 0은 전체
try{
categoryRepository.findById(categoryCode).orElseThrow();
}catch (Exception e){
throw new ApiException(HttpStatus.BAD_REQUEST, "잘못된 Category 입니다", e.getMessage());
}
}
try{
if(!(companyName ==null)){
Page<ProductResponseDto> productResponseDtos = productRepository.searchByCompanyName(companyName, categoryCode, pageable).map(ProductResponseDto::from);
return productResponseDtos;
}else{
Page<ProductResponseDto> productResponseDtos = productRepository.searchByProductName(productName, categoryCode, pageable).map(ProductResponseDto::from);
return productResponseDtos;
}
}catch (Exception e){
throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR, "Product Search에 실패했습니다.", e.getMessage());
}
}
@RequiredArgsConstructor
public class ProductCustomRepositoryImpl implements ProductCustomRepository{
private final JPAQueryFactory jpaQueryFactory;
@Override
public Page<Product> searchByCompanyName(String companyName, Long categoryCode, Pageable pageable) {
List<OrderSpecifier> orders = getAllOrderSpecifiers(pageable);
List<Product> query;
JPAQuery<Long> countQuery;
if(categoryCode.equals(0L)){
query = jpaQueryFactory
.selectFrom(product)
.distinct()
.where(
product.isDeleted.isFalse(),
product.company.companyName.contains(companyName)
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(orders.stream().toArray(OrderSpecifier[]::new))
.fetch();
countQuery = jpaQueryFactory
.select(product.count())
.from(product)
.where(
product.isDeleted.isFalse(),
product.company.companyName.contains(companyName)
);
return PageableExecutionUtils.getPage(query, pageable, () -> countQuery.fetchOne());
}
query = jpaQueryFactory
.selectFrom(product)
.distinct()
.where(
product.isDeleted.isFalse(),
product.company.companyName.contains(companyName),
product.category.categoryCode.eq(categoryCode)
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(orders.stream().toArray(OrderSpecifier[]::new))
.fetch();
countQuery = jpaQueryFactory
.select(product.count())
.from(product)
.where(
product.isDeleted.isFalse(),
product.company.companyName.contains(companyName),
product.category.categoryCode.eq(categoryCode)
);
return PageableExecutionUtils.getPage(query, pageable, () -> countQuery.fetchOne());
}
@Override
public Page<Product> searchByProductName(String productName, Long categoryCode, Pageable pageable) {
List<OrderSpecifier> orders = getAllOrderSpecifiers(pageable);
List<Product> query;
JPAQuery<Long> countQuery;
if(categoryCode.equals(0L)){
query = jpaQueryFactory
.selectFrom(product)
.distinct()
.where(
product.isDeleted.isFalse(),
product.productName.contains(productName)
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(orders.stream().toArray(OrderSpecifier[]::new))
.fetch();
countQuery = jpaQueryFactory
.select(product.count())
.from(product)
.where(
product.isDeleted.isFalse(),
product.productName.contains(productName)
);
return PageableExecutionUtils.getPage(query, pageable, () -> countQuery.fetchOne());
}
query = jpaQueryFactory
.selectFrom(product)
.distinct()
.where(
product.isDeleted.isFalse(),
product.productName.contains(productName),
product.category.categoryCode.eq(categoryCode)
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(orders.stream().toArray(OrderSpecifier[]::new))
.fetch();
countQuery = jpaQueryFactory
.select(product.count())
.from(product)
.where(
product.isDeleted.isFalse(),
product.productName.contains(productName),
product.category.categoryCode.eq(categoryCode)
);
return PageableExecutionUtils.getPage(query, pageable, () -> countQuery.fetchOne());
}
}
IF NOT EXISTS 조건을 추가해서 Create Table sql도 추가함{{ if gt (len .Alerts.Firing) 0 }}
[DOWN] {{ (index .Alerts.Firing 0).Labels.alertname }} ({{ (index .Alerts.Firing 0).Labels.job }}
*DOWN*
{{ else if gt (len .Alerts.Resolved) 0 }}
[OK] {{ (index .Alerts.Resolved 0).Labels.alertname }} ({{ (index .Alerts.Resolved 0).Labels.job }}
*OK*
{{ end }}
