모델 수정/삭제 API 커밋

This commit is contained in:
2025-11-25 15:37:09 +09:00
parent 2547907e52
commit e4ca6ab6ea
6 changed files with 75 additions and 22 deletions

View File

@@ -36,24 +36,24 @@ public class GlobalExceptionHandler {
this.errorLogRepository = errorLogRepository; this.errorLogRepository = errorLogRepository;
} }
@ResponseStatus(HttpStatus.NOT_FOUND) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ExceptionHandler(EntityNotFoundException.class) @ExceptionHandler(EntityNotFoundException.class)
public ApiResponseDto<String> handlerEntityNotFoundException( public ApiResponseDto<String> handlerEntityNotFoundException(
EntityNotFoundException e, HttpServletRequest request) { EntityNotFoundException e, HttpServletRequest request) {
log.warn("[EntityNotFoundException] resource :{} ", e.getMessage()); log.warn("[EntityNotFoundException] resource :{} ", e.getMessage());
String codeName = "NOT_FOUND"; String codeName = "NOT_FOUND_DATA";
ErrorLogEntity errorLog = ErrorLogEntity errorLog =
saveErrerLogData( saveErrerLogData(
request, request,
ApiResponseCode.getCode(codeName), ApiResponseCode.getCode(codeName),
HttpStatus.valueOf(codeName), HttpStatus.valueOf("UNPROCESSABLE_ENTITY"),
ErrorLogDto.LogErrorLevel.ERROR, ErrorLogDto.LogErrorLevel.WARNING,
e.getStackTrace()); e.getStackTrace());
return ApiResponseDto.createException( return ApiResponseDto.createException(
ApiResponseCode.getCode(codeName), ApiResponseCode.getCode(codeName),
ApiResponseCode.getMessage(codeName), ApiResponseCode.getMessage(codeName),
HttpStatus.valueOf(codeName), HttpStatus.valueOf("UNPROCESSABLE_ENTITY"),
errorLog.getId()); errorLog.getId());
} }
@@ -130,7 +130,7 @@ public class GlobalExceptionHandler {
saveErrerLogData( saveErrerLogData(
request, request,
ApiResponseCode.getCode(codeName), ApiResponseCode.getCode(codeName),
HttpStatus.valueOf(codeName), HttpStatus.valueOf("UNPROCESSABLE_ENTITY"),
ErrorLogDto.LogErrorLevel.CRITICAL, ErrorLogDto.LogErrorLevel.CRITICAL,
e.getStackTrace()); e.getStackTrace());
@@ -204,6 +204,28 @@ public class GlobalExceptionHandler {
errorLog.getId()); 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) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(RuntimeException.class) @ExceptionHandler(RuntimeException.class)
public ApiResponseDto<String> handlerRuntimeException( public ApiResponseDto<String> handlerRuntimeException(

View File

@@ -142,6 +142,7 @@ public class ApiResponseDto<T> {
DUPLICATE_EMPLOYEEID("이미 가입된 사번입니다."), DUPLICATE_EMPLOYEEID("이미 가입된 사번입니다."),
NOT_FOUND_USER_FOR_EMAIL("이메일로 유저를 찾을 수 없습니다."), NOT_FOUND_USER_FOR_EMAIL("이메일로 유저를 찾을 수 없습니다."),
NOT_FOUND_USER("사용자를 찾을 수 없습니다."), NOT_FOUND_USER("사용자를 찾을 수 없습니다."),
UNPROCESSABLE_ENTITY("이 데이터는 삭제할 수 없습니다."),
INVALID_EMAIL_TOKEN( INVALID_EMAIL_TOKEN(
"You can only reset your password within 24 hours from when the email was sent.\n" "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" + "To reset your password again, please submit a new request through \"Forgot"

View File

@@ -138,4 +138,14 @@ public class ModelMngDto {
private String deployState; private String deployState;
private String strDeployDttm; private String strDeployDttm;
} }
@Schema(name = "ModelDmlReturn", description = "모델 등록/수정/삭제 리턴")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class ModelDmlReturn {
private String execStatus;
private String message;
}
} }

View File

@@ -43,21 +43,25 @@ public class ModelMngCoreService {
public Long update(Long id, ModelMngDto.AddReq addReq) { public Long update(Long id, ModelMngDto.AddReq addReq) {
//조회 //조회
ModelVerEntity existData = modelVerRepository.findModelVerById(id) ModelVerEntity existData = modelVerRepository.findModelVerById(id)
.orElseThrow(() -> new EntityNotFoundException("버전 id 에 대한 정보를 찾을 수 없습니다. id : " + id)); .orElseThrow(EntityNotFoundException::new); //데이터 없는 경우 exception
existData.update(addReq);
ModelVerEntity modelVerEntity = new ModelVerEntity(existData.getId(), addReq.getModelCate(), addReq.getModelVer(), "NONE", "NONE", //TODO: 추후 수정 단계에서 도커파일 업로드하면 버전 업데이트 하는 로직 필요
0.0, "NONE", addReq.getModelPath(), 1L, 1L); return existData.getId();
return modelVerRepository.save(modelVerEntity).getId();
} }
public Long delete(Long id) { public Long delete(Long id) {
//조회 //조회
// ModelVerEntity entity = modelVerRepository.findModelVerById(id) ModelVerEntity verEntity = modelVerRepository.findModelVerById(id)
// .orElseThrow(() -> new EntityNotFoundException("버전 id 에 대한 정보를 찾을 수 없습니다. id : " + id)); .orElseThrow(() -> new EntityNotFoundException("버전 id 에 대한 정보를 찾을 수 없습니다. id : " + id));
//
// // id 코드 deleted = false 업데이트 //usedState가 USED 이거나 이미 삭제된 상태이면 삭제 불가
// entity.deleted(); if (verEntity.getUsedState().equals("USED") || verEntity.isDeleted().equals(true)) {
return null; 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) { public Page<ModelMngDto.ModelRegHistory> getRegHistoryList(ModelMngDto.searchReq searchReq, LocalDate startDate, LocalDate endDate, String searchVal) {

View File

@@ -1,17 +1,20 @@
package com.kamco.cd.kamcoback.postgres.entity; 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.model.dto.ModelVerDto;
import com.kamco.cd.kamcoback.postgres.CommonDateEntity; import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@Getter @Getter
@Setter @Setter
@Entity @Entity
@Table(name = "tb_model_ver") @Table(name = "tb_model_ver")
@NoArgsConstructor
public class ModelVerEntity extends CommonDateEntity { public class ModelVerEntity extends CommonDateEntity {
@Id @Id
@@ -57,8 +60,10 @@ public class ModelVerEntity extends CommonDateEntity {
@Column(name = "updated_uid") @Column(name = "updated_uid")
private Long updatedUid; private Long updatedUid;
private Boolean deleted = false;
public ModelVerEntity(Long id, Long modelUid, String modelCate, String modelVer, String usedState, String modelState, 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.id = id;
this.modelUid = modelUid; this.modelUid = modelUid;
this.modelCate = modelCate; this.modelCate = modelCate;
@@ -70,6 +75,7 @@ public class ModelVerEntity extends CommonDateEntity {
this.modelPath = modelPath; this.modelPath = modelPath;
this.createdUid = createdUid; this.createdUid = createdUid;
this.updatedUid = updatedUid; this.updatedUid = updatedUid;
this.deleted = deleted;
} }
public ModelVerEntity(Long modelUid, String modelCate, String modelVer, String usedState, String modelState, public ModelVerEntity(Long modelUid, String modelCate, String modelVer, String usedState, String modelState,
@@ -102,4 +108,18 @@ public class ModelVerEntity extends CommonDateEntity {
super.getModifiedDate(), super.getModifiedDate(),
this.updatedUid); 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;
}
} }

View File

@@ -1,18 +1,14 @@
package com.kamco.cd.kamcoback.postgres.repository.model; 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.ModelMngEntity;
import com.kamco.cd.kamcoback.postgres.entity.ModelVerEntity; 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.Expressions;
import com.querydsl.core.types.dsl.StringExpression; import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.impl.JPAQueryFactory; import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport; import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import static com.kamco.cd.kamcoback.postgres.entity.QModelMngEntity.modelMngEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QModelVerEntity.modelVerEntity; import static com.kamco.cd.kamcoback.postgres.entity.QModelVerEntity.modelVerEntity;
public class ModelVerRepositoryImpl extends QuerydslRepositorySupport public class ModelVerRepositoryImpl extends QuerydslRepositorySupport