모델 수정/삭제 API 커밋
This commit is contained in:
@@ -36,24 +36,24 @@ public class GlobalExceptionHandler {
|
||||
this.errorLogRepository = errorLogRepository;
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
@ExceptionHandler(EntityNotFoundException.class)
|
||||
public ApiResponseDto<String> handlerEntityNotFoundException(
|
||||
EntityNotFoundException e, HttpServletRequest request) {
|
||||
log.warn("[EntityNotFoundException] resource :{} ", e.getMessage());
|
||||
String codeName = "NOT_FOUND";
|
||||
String codeName = "NOT_FOUND_DATA";
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrerLogData(
|
||||
request,
|
||||
ApiResponseCode.getCode(codeName),
|
||||
HttpStatus.valueOf(codeName),
|
||||
ErrorLogDto.LogErrorLevel.ERROR,
|
||||
HttpStatus.valueOf("UNPROCESSABLE_ENTITY"),
|
||||
ErrorLogDto.LogErrorLevel.WARNING,
|
||||
e.getStackTrace());
|
||||
|
||||
return ApiResponseDto.createException(
|
||||
ApiResponseCode.getCode(codeName),
|
||||
ApiResponseCode.getMessage(codeName),
|
||||
HttpStatus.valueOf(codeName),
|
||||
HttpStatus.valueOf("UNPROCESSABLE_ENTITY"),
|
||||
errorLog.getId());
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class GlobalExceptionHandler {
|
||||
saveErrerLogData(
|
||||
request,
|
||||
ApiResponseCode.getCode(codeName),
|
||||
HttpStatus.valueOf(codeName),
|
||||
HttpStatus.valueOf("UNPROCESSABLE_ENTITY"),
|
||||
ErrorLogDto.LogErrorLevel.CRITICAL,
|
||||
e.getStackTrace());
|
||||
|
||||
@@ -204,6 +204,28 @@ public class GlobalExceptionHandler {
|
||||
errorLog.getId());
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
@ExceptionHandler(IllegalStateException.class)
|
||||
public ApiResponseDto<String> handlerIllegalStateException(
|
||||
IllegalStateException e, HttpServletRequest request) {
|
||||
log.warn("[IllegalStateException] resource :{} ", e.getMessage());
|
||||
|
||||
String codeName = "UNPROCESSABLE_ENTITY";
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrerLogData(
|
||||
request,
|
||||
ApiResponseCode.getCode(codeName),
|
||||
HttpStatus.valueOf(codeName),
|
||||
ErrorLogDto.LogErrorLevel.WARNING,
|
||||
e.getStackTrace());
|
||||
|
||||
return ApiResponseDto.createException(
|
||||
ApiResponseCode.getCode(codeName),
|
||||
ApiResponseCode.getMessage(codeName),
|
||||
HttpStatus.valueOf(codeName),
|
||||
errorLog.getId());
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public ApiResponseDto<String> handlerRuntimeException(
|
||||
|
||||
@@ -142,6 +142,7 @@ public class ApiResponseDto<T> {
|
||||
DUPLICATE_EMPLOYEEID("이미 가입된 사번입니다."),
|
||||
NOT_FOUND_USER_FOR_EMAIL("이메일로 유저를 찾을 수 없습니다."),
|
||||
NOT_FOUND_USER("사용자를 찾을 수 없습니다."),
|
||||
UNPROCESSABLE_ENTITY("이 데이터는 삭제할 수 없습니다."),
|
||||
INVALID_EMAIL_TOKEN(
|
||||
"You can only reset your password within 24 hours from when the email was sent.\n"
|
||||
+ "To reset your password again, please submit a new request through \"Forgot"
|
||||
|
||||
@@ -138,4 +138,14 @@ public class ModelMngDto {
|
||||
private String deployState;
|
||||
private String strDeployDttm;
|
||||
}
|
||||
|
||||
@Schema(name = "ModelDmlReturn", description = "모델 등록/수정/삭제 리턴")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class ModelDmlReturn {
|
||||
private String execStatus;
|
||||
private String message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,21 +43,25 @@ public class ModelMngCoreService {
|
||||
public Long update(Long id, ModelMngDto.AddReq addReq) {
|
||||
//조회
|
||||
ModelVerEntity existData = modelVerRepository.findModelVerById(id)
|
||||
.orElseThrow(() -> new EntityNotFoundException("버전 id 에 대한 정보를 찾을 수 없습니다. id : " + id));
|
||||
|
||||
ModelVerEntity modelVerEntity = new ModelVerEntity(existData.getId(), addReq.getModelCate(), addReq.getModelVer(), "NONE", "NONE",
|
||||
0.0, "NONE", addReq.getModelPath(), 1L, 1L);
|
||||
return modelVerRepository.save(modelVerEntity).getId();
|
||||
.orElseThrow(EntityNotFoundException::new); //데이터 없는 경우 exception
|
||||
existData.update(addReq);
|
||||
//TODO: 추후 수정 단계에서 도커파일 업로드하면 버전 업데이트 하는 로직 필요
|
||||
return existData.getId();
|
||||
}
|
||||
|
||||
public Long delete(Long id) {
|
||||
//조회
|
||||
// ModelVerEntity entity = modelVerRepository.findModelVerById(id)
|
||||
// .orElseThrow(() -> new EntityNotFoundException("버전 id 에 대한 정보를 찾을 수 없습니다. id : " + id));
|
||||
//
|
||||
// // id 코드 deleted = false 업데이트
|
||||
// entity.deleted();
|
||||
return null;
|
||||
ModelVerEntity verEntity = modelVerRepository.findModelVerById(id)
|
||||
.orElseThrow(() -> new EntityNotFoundException("버전 id 에 대한 정보를 찾을 수 없습니다. id : " + id));
|
||||
|
||||
//usedState가 USED 이거나 이미 삭제된 상태이면 삭제 불가
|
||||
if (verEntity.getUsedState().equals("USED") || verEntity.isDeleted().equals(true)) {
|
||||
throw new IllegalStateException("해당 모델이 사용중이라 삭제 불가"); //TODO: 추후 규칙 정의되면 수정 필요
|
||||
}
|
||||
|
||||
// id 코드 deleted = true 업데이트
|
||||
verEntity.deleted();
|
||||
return verEntity.getId();
|
||||
}
|
||||
|
||||
public Page<ModelMngDto.ModelRegHistory> getRegHistoryList(ModelMngDto.searchReq searchReq, LocalDate startDate, LocalDate endDate, String searchVal) {
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelVerDto;
|
||||
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "tb_model_ver")
|
||||
@NoArgsConstructor
|
||||
public class ModelVerEntity extends CommonDateEntity {
|
||||
|
||||
@Id
|
||||
@@ -57,8 +60,10 @@ public class ModelVerEntity extends CommonDateEntity {
|
||||
@Column(name = "updated_uid")
|
||||
private Long updatedUid;
|
||||
|
||||
private Boolean deleted = false;
|
||||
|
||||
public ModelVerEntity(Long id, Long modelUid, String modelCate, String modelVer, String usedState, String modelState,
|
||||
Double qualityProb, String deployState, String modelPath, Long createdUid, Long updatedUid) {
|
||||
Double qualityProb, String deployState, String modelPath, Long createdUid, Long updatedUid, Boolean deleted) {
|
||||
this.id = id;
|
||||
this.modelUid = modelUid;
|
||||
this.modelCate = modelCate;
|
||||
@@ -70,6 +75,7 @@ public class ModelVerEntity extends CommonDateEntity {
|
||||
this.modelPath = modelPath;
|
||||
this.createdUid = createdUid;
|
||||
this.updatedUid = updatedUid;
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
public ModelVerEntity(Long modelUid, String modelCate, String modelVer, String usedState, String modelState,
|
||||
@@ -102,4 +108,18 @@ public class ModelVerEntity extends CommonDateEntity {
|
||||
super.getModifiedDate(),
|
||||
this.updatedUid);
|
||||
}
|
||||
|
||||
public void update(ModelMngDto.AddReq addReq) {
|
||||
this.modelCate = addReq.getModelCate();
|
||||
this.modelVer = addReq.getModelVer();
|
||||
this.modelPath = addReq.getModelPath();
|
||||
}
|
||||
|
||||
public Boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void deleted(){
|
||||
this.deleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.model;
|
||||
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.ModelMngEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.ModelVerEntity;
|
||||
import com.querydsl.core.types.Projections;
|
||||
import com.querydsl.core.types.dsl.Expressions;
|
||||
import com.querydsl.core.types.dsl.StringExpression;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QModelMngEntity.modelMngEntity;
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QModelVerEntity.modelVerEntity;
|
||||
|
||||
public class ModelVerRepositoryImpl extends QuerydslRepositorySupport
|
||||
|
||||
Reference in New Issue
Block a user