공통코드 API 리턴 형식 수정 SuccFail 삭제
This commit is contained in:
@@ -5,19 +5,19 @@ import com.kamco.cd.kamcoback.code.dto.CommonCodeDto.Basic;
|
||||
import com.kamco.cd.kamcoback.common.service.BaseCoreService;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.ApiResponseCode;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.ResponseObj;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.SuccFailCode;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.code.CommonCodeRepository;
|
||||
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.SearchReq;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CommonCodeCoreService
|
||||
@@ -44,18 +44,18 @@ public class CommonCodeCoreService
|
||||
@CacheEvict(value = "commonCodes", allEntries = true)
|
||||
public ResponseObj save(CommonCodeDto.AddReq req) {
|
||||
|
||||
String regex = "^[A-Z0-9_]+$";
|
||||
String regex = "^([A-Z]+|[0-9]+|[A-Z0-9]+(_[A-Z0-9]+)+)$";
|
||||
boolean isValid = req.getCode().matches(regex);
|
||||
if (!isValid) {
|
||||
return new ResponseObj(
|
||||
SuccFailCode.FAIL, ApiResponseCode.CONFLICT, "공통코드에 영문 대문자, 숫자, 언더바(_)만 입력 가능합니다.");
|
||||
ApiResponseCode.CONFLICT, "공통코드에 영문 대문자, 숫자, 언더바(_)만 입력 가능합니다.");
|
||||
}
|
||||
|
||||
Long existsCount =
|
||||
commonCodeRepository.findByParentIdCodeExists(req.getParentId(), req.getCode());
|
||||
if (existsCount > 0) {
|
||||
return new ResponseObj(
|
||||
SuccFailCode.FAIL, ApiResponseCode.DUPLICATE_DATA, "이미 사용중인 공통코드ID 입니다.");
|
||||
ApiResponseCode.DUPLICATE_DATA, "이미 사용중인 공통코드ID 입니다.");
|
||||
}
|
||||
|
||||
CommonCodeEntity entity =
|
||||
@@ -82,7 +82,7 @@ public class CommonCodeCoreService
|
||||
}
|
||||
|
||||
commonCodeRepository.save(entity).toDto();
|
||||
return new ResponseObj(SuccFailCode.SUCCESS, ApiResponseCode.OK, "등록되었습니다.");
|
||||
return new ResponseObj(ApiResponseCode.OK, "");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +107,7 @@ public class CommonCodeCoreService
|
||||
req.getProps2(),
|
||||
req.getProps3());
|
||||
|
||||
return new ResponseObj(SuccFailCode.SUCCESS, ApiResponseCode.OK, "수정되었습니다.");
|
||||
return new ResponseObj(ApiResponseCode.OK, "");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +127,7 @@ public class CommonCodeCoreService
|
||||
|
||||
found.updateOrder(req.getOrder());
|
||||
|
||||
return new ResponseObj(SuccFailCode.SUCCESS, ApiResponseCode.OK, "수정되었습니다.");
|
||||
return new ResponseObj(ApiResponseCode.OK, "");
|
||||
}
|
||||
|
||||
public List<CommonCodeDto.Basic> findByCode(String code) {
|
||||
@@ -161,14 +161,13 @@ public class CommonCodeCoreService
|
||||
// 하위코드가 있으면 삭제 불가
|
||||
if (!entity.getChildren().isEmpty()) {
|
||||
return new ResponseObj(
|
||||
SuccFailCode.FAIL,
|
||||
ApiResponseCode.UNPROCESSABLE_ENTITY,
|
||||
"하위에 다른 공통코드를 가지고 있습니다.<br/>하위공통 코드를 이동한 후 삭제할 수 있습니다.");
|
||||
}
|
||||
|
||||
// id 코드 deleted = false 업데이트
|
||||
entity.deleted();
|
||||
return new ResponseObj(SuccFailCode.SUCCESS, ApiResponseCode.OK, "삭제되었습니다.");
|
||||
return new ResponseObj(ApiResponseCode.OK, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -206,18 +205,18 @@ public class CommonCodeCoreService
|
||||
public ResponseObj getCodeCheckDuplicate(Long parentId, String code) {
|
||||
Long existsCount = commonCodeRepository.findByParentIdCodeExists(parentId, code);
|
||||
|
||||
String regex = "^[A-Z0-9_]+$";
|
||||
String regex = "^([A-Z]+|[0-9]+|[A-Z0-9]+(_[A-Z0-9]+)+)$";
|
||||
boolean isValid = code.matches(regex);
|
||||
if (!isValid) {
|
||||
return new ResponseObj(
|
||||
SuccFailCode.FAIL, ApiResponseCode.CONFLICT, "공통코드에 영문 대문자, 숫자, 언더바(_)만 입력 가능합니다.");
|
||||
ApiResponseCode.CONFLICT, "공통코드에 영문 대문자, 숫자, 언더바(_)만 입력 가능합니다.");
|
||||
}
|
||||
|
||||
if (existsCount > 0) {
|
||||
return new ResponseObj(
|
||||
SuccFailCode.FAIL, ApiResponseCode.DUPLICATE_DATA, "이미 사용중인 공통코드ID 입니다.");
|
||||
ApiResponseCode.DUPLICATE_DATA, "이미 사용중인 공통코드ID 입니다.");
|
||||
}
|
||||
|
||||
return new ResponseObj(SuccFailCode.SUCCESS, ApiResponseCode.OK, "사용할 수 있는 공통코드ID 입니다.");
|
||||
return new ResponseObj(ApiResponseCode.OK, "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user