공통코드 API 리턴 형식 수정 SuccFail 삭제
This commit is contained in:
@@ -139,8 +139,8 @@ public class CommonCodeUtil {
|
|||||||
try {
|
try {
|
||||||
ApiResponseDto.ResponseObj response = commonCodeService.getCodeCheckDuplicate(parentId, code);
|
ApiResponseDto.ResponseObj response = commonCodeService.getCodeCheckDuplicate(parentId, code);
|
||||||
// ResponseObj의 flag 필드를 통해 SUCCESS/FAIL 확인
|
// ResponseObj의 flag 필드를 통해 SUCCESS/FAIL 확인
|
||||||
return response.getFlag() != null
|
return response.getCode() != null
|
||||||
&& response.getFlag().equals(ApiResponseDto.SuccFailCode.SUCCESS);
|
&& response.getCode().equals(ApiResponseDto.ApiResponseCode.OK);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("코드 중복 확인 중 오류 발생: parentId={}, code={}", parentId, code, e);
|
log.error("코드 중복 확인 중 오류 발생: parentId={}, code={}", parentId, code, e);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -68,10 +68,10 @@ public class ApiResponseDto<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> ApiResponseDto<ResponseObj> okObject(ResponseObj data) {
|
public static <T> ApiResponseDto<ResponseObj> okObject(ResponseObj data) {
|
||||||
if (data.getFlag().equals(SuccFailCode.SUCCESS)) {
|
if (data.getCode().equals(ApiResponseCode.OK)) {
|
||||||
return new ApiResponseDto<>(data, HttpStatus.OK);
|
return new ApiResponseDto<>(data, HttpStatus.NO_CONTENT);
|
||||||
} else {
|
} else {
|
||||||
return new ApiResponseDto<>(data.getCode(), data.getMessage(), HttpStatus.OK);
|
return new ApiResponseDto<>(data.getCode(), data.getMessage(), HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,36 +118,15 @@ public class ApiResponseDto<T> {
|
|||||||
@Getter
|
@Getter
|
||||||
public static class ResponseObj {
|
public static class ResponseObj {
|
||||||
|
|
||||||
private final SuccFailCode flag;
|
|
||||||
private final ApiResponseCode code;
|
private final ApiResponseCode code;
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
public ResponseObj(SuccFailCode flag, ApiResponseCode code, String message) {
|
public ResponseObj(ApiResponseCode code, String message) {
|
||||||
this.flag = flag;
|
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public enum SuccFailCode implements EnumType {
|
|
||||||
SUCCESS("성공"),
|
|
||||||
FAIL("실패");
|
|
||||||
|
|
||||||
private final String desc;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return name();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getText() {
|
|
||||||
return desc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public enum ApiResponseCode implements EnumType {
|
public enum ApiResponseCode implements EnumType {
|
||||||
|
|||||||
@@ -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.common.service.BaseCoreService;
|
||||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.ApiResponseCode;
|
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.ResponseObj;
|
||||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.SuccFailCode;
|
|
||||||
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
|
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
|
||||||
import com.kamco.cd.kamcoback.postgres.repository.code.CommonCodeRepository;
|
import com.kamco.cd.kamcoback.postgres.repository.code.CommonCodeRepository;
|
||||||
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.SearchReq;
|
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.SearchReq;
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CommonCodeCoreService
|
public class CommonCodeCoreService
|
||||||
@@ -44,18 +44,18 @@ public class CommonCodeCoreService
|
|||||||
@CacheEvict(value = "commonCodes", allEntries = true)
|
@CacheEvict(value = "commonCodes", allEntries = true)
|
||||||
public ResponseObj save(CommonCodeDto.AddReq req) {
|
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);
|
boolean isValid = req.getCode().matches(regex);
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
return new ResponseObj(
|
return new ResponseObj(
|
||||||
SuccFailCode.FAIL, ApiResponseCode.CONFLICT, "공통코드에 영문 대문자, 숫자, 언더바(_)만 입력 가능합니다.");
|
ApiResponseCode.CONFLICT, "공통코드에 영문 대문자, 숫자, 언더바(_)만 입력 가능합니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Long existsCount =
|
Long existsCount =
|
||||||
commonCodeRepository.findByParentIdCodeExists(req.getParentId(), req.getCode());
|
commonCodeRepository.findByParentIdCodeExists(req.getParentId(), req.getCode());
|
||||||
if (existsCount > 0) {
|
if (existsCount > 0) {
|
||||||
return new ResponseObj(
|
return new ResponseObj(
|
||||||
SuccFailCode.FAIL, ApiResponseCode.DUPLICATE_DATA, "이미 사용중인 공통코드ID 입니다.");
|
ApiResponseCode.DUPLICATE_DATA, "이미 사용중인 공통코드ID 입니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonCodeEntity entity =
|
CommonCodeEntity entity =
|
||||||
@@ -82,7 +82,7 @@ public class CommonCodeCoreService
|
|||||||
}
|
}
|
||||||
|
|
||||||
commonCodeRepository.save(entity).toDto();
|
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.getProps2(),
|
||||||
req.getProps3());
|
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());
|
found.updateOrder(req.getOrder());
|
||||||
|
|
||||||
return new ResponseObj(SuccFailCode.SUCCESS, ApiResponseCode.OK, "수정되었습니다.");
|
return new ResponseObj(ApiResponseCode.OK, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CommonCodeDto.Basic> findByCode(String code) {
|
public List<CommonCodeDto.Basic> findByCode(String code) {
|
||||||
@@ -161,14 +161,13 @@ public class CommonCodeCoreService
|
|||||||
// 하위코드가 있으면 삭제 불가
|
// 하위코드가 있으면 삭제 불가
|
||||||
if (!entity.getChildren().isEmpty()) {
|
if (!entity.getChildren().isEmpty()) {
|
||||||
return new ResponseObj(
|
return new ResponseObj(
|
||||||
SuccFailCode.FAIL,
|
|
||||||
ApiResponseCode.UNPROCESSABLE_ENTITY,
|
ApiResponseCode.UNPROCESSABLE_ENTITY,
|
||||||
"하위에 다른 공통코드를 가지고 있습니다.<br/>하위공통 코드를 이동한 후 삭제할 수 있습니다.");
|
"하위에 다른 공통코드를 가지고 있습니다.<br/>하위공통 코드를 이동한 후 삭제할 수 있습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// id 코드 deleted = false 업데이트
|
// id 코드 deleted = false 업데이트
|
||||||
entity.deleted();
|
entity.deleted();
|
||||||
return new ResponseObj(SuccFailCode.SUCCESS, ApiResponseCode.OK, "삭제되었습니다.");
|
return new ResponseObj(ApiResponseCode.OK, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -206,18 +205,18 @@ public class CommonCodeCoreService
|
|||||||
public ResponseObj getCodeCheckDuplicate(Long parentId, String code) {
|
public ResponseObj getCodeCheckDuplicate(Long parentId, String code) {
|
||||||
Long existsCount = commonCodeRepository.findByParentIdCodeExists(parentId, 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);
|
boolean isValid = code.matches(regex);
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
return new ResponseObj(
|
return new ResponseObj(
|
||||||
SuccFailCode.FAIL, ApiResponseCode.CONFLICT, "공통코드에 영문 대문자, 숫자, 언더바(_)만 입력 가능합니다.");
|
ApiResponseCode.CONFLICT, "공통코드에 영문 대문자, 숫자, 언더바(_)만 입력 가능합니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existsCount > 0) {
|
if (existsCount > 0) {
|
||||||
return new ResponseObj(
|
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