diff --git a/src/main/java/kr/re/etri/autoflow/service/KubeflowRunService.java b/src/main/java/kr/re/etri/autoflow/service/KubeflowRunService.java index effe70c..dd95df8 100644 --- a/src/main/java/kr/re/etri/autoflow/service/KubeflowRunService.java +++ b/src/main/java/kr/re/etri/autoflow/service/KubeflowRunService.java @@ -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 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 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); + } + } + +} \ No newline at end of file diff --git a/src/main/java/kr/re/etri/autoflow/specification/KubeflowRunSpecification.java b/src/main/java/kr/re/etri/autoflow/specification/KubeflowRunSpecification.java index 0c2a7eb..5a75c2f 100644 --- a/src/main/java/kr/re/etri/autoflow/specification/KubeflowRunSpecification.java +++ b/src/main/java/kr/re/etri/autoflow/specification/KubeflowRunSpecification.java @@ -117,7 +117,7 @@ public class KubeflowRunSpecification { } public Specification 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; }; }