|
|
|
|
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;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.data.domain.*;
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
// 프론트가 0-based page 전달 (0=첫페이지, 1=두번째페이지)
|
|
|
|
|
int pageIndex = Math.max(0, request.getPage());
|
|
|
|
|
|
|
|
|
|
Pageable pageable = PageRequest.of(
|
|
|
|
|
pageIndex,
|
|
|
|
|
request.getSize(),
|
|
|
|
|
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(),
|
|
|
|
|
request.getSearchType(),
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|