[ADD] Add search by date range(createdAt) to Kubeflow Run search API

main
bjkim 9 months ago
parent a03a5ab6d7
commit 9483299400

@ -1,6 +1,7 @@
package kr.re.etri.autoflow.service;
import kr.re.etri.autoflow.entity.KubeflowRunEntity;
import kr.re.etri.autoflow.entity.ProjectEntity;
import kr.re.etri.autoflow.payload.request.KubeflowRunSearchRequest;
import kr.re.etri.autoflow.repository.KubeflowRunRepository;
import kr.re.etri.autoflow.specification.KubeflowRunSpecification;
@ -10,6 +11,10 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
@Service
@RequiredArgsConstructor
public class KubeflowRunService {
@ -17,6 +22,8 @@ public class KubeflowRunService {
private final KubeflowRunRepository runRepository;
private final KubeflowRunSpecification runSpecification;
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@Transactional(readOnly = true)
public Page<KubeflowRunEntity> search(KubeflowRunSearchRequest request) {
int pageIndex = request.getPage() > 0 ? request.getPage() - 1 : 0;
@ -27,12 +34,28 @@ public class KubeflowRunService {
Sort.by(Sort.Direction.fromString(request.getSortDirection()), request.getSortField())
);
LocalDate startDate = parseDate(request.getStartDate());
LocalDate endDate = parseDate(request.getEndDate());
Specification<KubeflowRunEntity> spec = runSpecification.searchByConditions(
request.getExperimentId(), // experimentId는 필수
request.getSearchType(),
request.getKeyword()
request.getKeyword(),
startDate,
endDate
);
return runRepository.findAll(spec, pageable);
}
}
private LocalDate parseDate(String dateStr) {
if (dateStr == null || dateStr.isBlank()) return null;
try {
return LocalDate.parse(dateStr, formatter);
} catch (DateTimeParseException e) {
throw new IllegalArgumentException("날짜 형식이 잘못되었습니다. yyyy-MM-dd 형식이어야 합니다: " + dateStr);
}
}
}

@ -117,7 +117,7 @@ public class KubeflowRunSpecification {
}
public Specification<KubeflowRunEntity> searchByConditions(
String experimentId, String searchType, String keyword) {
String experimentId, String searchType, String keyword, LocalDate startDate, LocalDate endDate) {
return (root, query, cb) -> {
Predicate predicate = cb.conjunction();
@ -140,6 +140,16 @@ public class KubeflowRunSpecification {
}
}
if (startDate != null) {
predicate = cb.and(predicate,
cb.greaterThanOrEqualTo(root.get("createdAt"), startDate));
}
if (endDate != null) {
predicate = cb.and(predicate,
cb.lessThanOrEqualTo(root.get("createdAt"), endDate));
}
return predicate;
};
}

Loading…
Cancel
Save