모델관리 목록,삭제 API 수정
This commit is contained in:
@@ -4,15 +4,17 @@ import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
|
||||
import com.kamco.cd.kamcoback.model.service.ModelMngService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.time.LocalDate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Tag(name = "모델 관리", description = "모델 관리 API")
|
||||
@RequiredArgsConstructor
|
||||
@@ -40,4 +42,28 @@ public class ModelMngApiController {
|
||||
|
||||
return ApiResponseDto.ok(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "삭제", description = "모델을 삭제 합니다.")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "204",
|
||||
description = "모델 삭제 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Long.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@DeleteMapping("/{modelVer}")
|
||||
public ApiResponseDto<ApiResponseDto.ResponseObj> removeModel(
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "모델 삭제 요청 정보",
|
||||
required = true)
|
||||
@PathVariable
|
||||
String modelVer) {
|
||||
return ApiResponseDto.okObject(modelMngService.removeModel(modelVer));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import com.kamco.cd.kamcoback.common.utils.enums.CodeExpose;
|
||||
import com.kamco.cd.kamcoback.common.utils.enums.EnumType;
|
||||
import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.ZonedDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -14,6 +12,9 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public class ModelMngDto {
|
||||
|
||||
@Schema(name = "ModelMgmtDto Basic", description = "모델관리 엔티티 기본 정보")
|
||||
@@ -69,10 +70,10 @@ public class ModelMngDto {
|
||||
public static class ModelList {
|
||||
private Integer rowNum;
|
||||
private String modelVer;
|
||||
private String dockerFileNm;
|
||||
private String fileName;
|
||||
private String modelType;
|
||||
private String createCompleteDttm;
|
||||
private String recentUseDttm; // TODO: 추론관리 테이블 나오면 분석진행중일 때 사용중으로 리턴하기
|
||||
private String recentUseDttm;
|
||||
private BigDecimal f1Score;
|
||||
private BigDecimal precision;
|
||||
private BigDecimal recall;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.kamco.cd.kamcoback.model.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
|
||||
import com.kamco.cd.kamcoback.postgres.core.ModelMngCoreService;
|
||||
import java.time.LocalDate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ModelMngService {
|
||||
@@ -22,4 +24,8 @@ public class ModelMngService {
|
||||
return modelMngCoreService.findModelMgmtList(
|
||||
searchReq, startDate, endDate, modelType, searchVal);
|
||||
}
|
||||
|
||||
public ApiResponseDto.ResponseObj removeModel(String modelVer) {
|
||||
return modelMngCoreService.removeModel(modelVer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.ModelMngEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.model.ModelMngRepository;
|
||||
import java.time.LocalDate;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ModelMngCoreService {
|
||||
@@ -22,4 +26,15 @@ public class ModelMngCoreService {
|
||||
return modelMngRepository.findModelMgmtList(
|
||||
searchReq, startDate, endDate, modelType, searchVal);
|
||||
}
|
||||
|
||||
public ApiResponseDto.ResponseObj removeModel(String modelVer) {
|
||||
ModelMngEntity entity =
|
||||
modelMngRepository
|
||||
.findByModelUid(modelVer)
|
||||
.orElseThrow(() -> new EntityNotFoundException("model을 찾을 수 없습니다. ver: " + modelVer));
|
||||
|
||||
// id 코드 deleted = true 업데이트
|
||||
entity.deleted();
|
||||
return new ApiResponseDto.ResponseObj(ApiResponseDto.ApiResponseCode.OK, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
|
||||
import jakarta.persistence.*;
|
||||
import java.time.ZonedDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@@ -19,15 +20,6 @@ public class ModelMngEntity extends CommonDateEntity {
|
||||
@Column(name = "model_ver")
|
||||
private String modelVer;
|
||||
|
||||
@Column(name = "hyper_ver")
|
||||
private String hyperVer;
|
||||
|
||||
@Column(name = "epoch_ver")
|
||||
private String epochVer;
|
||||
|
||||
@Column(name = "docker_file_nm")
|
||||
private String dockerFileNm;
|
||||
|
||||
@Column(name = "create_complete_dttm")
|
||||
private ZonedDateTime createCompleteDttm;
|
||||
|
||||
@@ -42,4 +34,17 @@ public class ModelMngEntity extends CommonDateEntity {
|
||||
|
||||
@Column(name = "updated_uid")
|
||||
private Long updatedUid;
|
||||
|
||||
@Column(name = "model_type")
|
||||
private String modelType;
|
||||
|
||||
@Column(name = "file_path")
|
||||
private String filePath;
|
||||
|
||||
@Column(name = "file_name")
|
||||
private String fileName;
|
||||
|
||||
public void deleted() {
|
||||
this.deleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.model;
|
||||
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
|
||||
import java.time.LocalDate;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.ModelMngEntity;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ModelMngRepositoryCustom {
|
||||
|
||||
Page<ModelMngDto.ModelList> findModelMgmtList(
|
||||
@@ -12,4 +15,6 @@ public interface ModelMngRepositoryCustom {
|
||||
LocalDate endDate,
|
||||
String modelType,
|
||||
String searchVal);
|
||||
|
||||
Optional<ModelMngEntity> findByModelUid(String modelVer);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.model;
|
||||
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QModelMngEntity.modelMngEntity;
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QModelResultMetricEntity.modelResultMetricEntity;
|
||||
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
|
||||
import com.kamco.cd.kamcoback.postgres.QuerydslOrderUtil;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.ModelMngEntity;
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
import com.querydsl.core.types.Expression;
|
||||
import com.querydsl.core.types.Projections;
|
||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||
import com.querydsl.core.types.dsl.Expressions;
|
||||
import com.querydsl.core.types.dsl.NumberPath;
|
||||
import com.querydsl.core.types.dsl.StringExpression;
|
||||
import com.querydsl.core.types.dsl.*;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -21,11 +21,10 @@ import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QModelMngEntity.modelMngEntity;
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QModelResultMetricEntity.modelResultMetricEntity;
|
||||
|
||||
public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
|
||||
implements ModelMngRepositoryCustom {
|
||||
@@ -68,16 +67,9 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
|
||||
ModelMngDto.ModelList.class,
|
||||
Expressions.numberTemplate(
|
||||
Integer.class, "row_number() over(order by {0} desc)", sortColumn),
|
||||
Expressions.stringTemplate(
|
||||
"concat({0}, {1}, {2}, {3}, {4})",
|
||||
modelMngEntity.modelVer,
|
||||
".",
|
||||
modelMngEntity.hyperVer,
|
||||
".",
|
||||
modelMngEntity.epochVer)
|
||||
.as("modelVer"),
|
||||
modelMngEntity.dockerFileNm,
|
||||
modelMngEntity.modelVer.as("modelType"),
|
||||
modelMngEntity.modelVer,
|
||||
modelMngEntity.fileName,
|
||||
modelMngEntity.modelType,
|
||||
Expressions.stringTemplate(
|
||||
"to_char({0}, 'YYYY-MM-DD')", modelMngEntity.createCompleteDttm),
|
||||
Expressions.stringTemplate(
|
||||
@@ -93,7 +85,8 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
|
||||
.on(modelMngEntity.modelUid.eq(modelResultMetricEntity.modelUid))
|
||||
.where(
|
||||
eventEndedAtBetween(startDate, endDate, property),
|
||||
searchModelVersion(modelType, searchVal))
|
||||
searchModelVersion(modelType, searchVal),
|
||||
modelMngEntity.deleted.isFalse().or(modelMngEntity.deleted.isNull()))
|
||||
.offset(pageable.getOffset())
|
||||
.limit(pageable.getPageSize())
|
||||
.orderBy(
|
||||
@@ -113,6 +106,14 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
|
||||
return new PageImpl<>(foundContent, pageable, countQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ModelMngEntity> findByModelUid(String modelVer) {
|
||||
return Optional.ofNullable(queryFactory
|
||||
.selectFrom(modelMngEntity)
|
||||
.where(modelMngEntity.modelVer.eq(modelVer))
|
||||
.fetchOne());
|
||||
}
|
||||
|
||||
private BooleanExpression eventEndedAtBetween(
|
||||
LocalDate startDate, LocalDate endDate, String sortColumn) {
|
||||
if (Objects.isNull(startDate) || Objects.isNull(endDate)) {
|
||||
@@ -139,11 +140,11 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
|
||||
BooleanBuilder builder = new BooleanBuilder();
|
||||
|
||||
if (Objects.nonNull(modelType)) {
|
||||
builder.and(modelMngEntity.modelVer.eq(modelType));
|
||||
builder.and(modelMngEntity.modelType.eq(modelType));
|
||||
}
|
||||
|
||||
if (Objects.nonNull(searchVal)) {
|
||||
builder.and(modelMngEntity.dockerFileNm.likeIgnoreCase("%" + searchVal + "%"));
|
||||
builder.and(modelMngEntity.modelVer.likeIgnoreCase("%" + searchVal + "%"));
|
||||
}
|
||||
|
||||
return builder;
|
||||
|
||||
Reference in New Issue
Block a user