[API 응답 개선] ApiResponseDto에 success 필드 추가로 성공/실패 여부 명확화. ApiResponseCode에 COMMON_CODE_DUPLICATE 추가 및 관련 메시지 수정. CommonCodeServiceImpl에서 중복 코드 예외 처리 개선.
This commit is contained in:
		@@ -8,6 +8,7 @@ import com.bio.bio_backend.domain.admin.common_code.mapper.CommonCodeMapper;
 | 
			
		||||
import com.bio.bio_backend.domain.admin.common_code.mapper.CommonGroupCodeMapper;
 | 
			
		||||
import com.bio.bio_backend.domain.admin.common_code.repository.CommonCodeRepository;
 | 
			
		||||
import com.bio.bio_backend.domain.admin.common_code.repository.CommonGroupCodeRepository;
 | 
			
		||||
import com.bio.bio_backend.global.constants.AppConstants;
 | 
			
		||||
import com.bio.bio_backend.global.exception.ApiException;
 | 
			
		||||
import com.bio.bio_backend.global.constants.ApiResponseCode;
 | 
			
		||||
import lombok.RequiredArgsConstructor;
 | 
			
		||||
@@ -33,7 +34,7 @@ public class CommonCodeServiceImpl implements CommonCodeService {
 | 
			
		||||
    @Transactional
 | 
			
		||||
    public CommonGroupCodeDto createGroupCode(CommonGroupCodeDto groupCodeDto) {
 | 
			
		||||
        if (commonGroupCodeRepository.existsByCode(groupCodeDto.getCode())) {
 | 
			
		||||
            throw new ApiException(ApiResponseCode.USER_ID_DUPLICATE, "이미 존재하는 그룹 코드입니다: " + groupCodeDto.getCode());
 | 
			
		||||
            throw new ApiException(ApiResponseCode.COMMON_CODE_DUPLICATE);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        CommonGroupCode groupCode = commonGroupCodeMapper.toCommonGroupCode(groupCodeDto);
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@ public enum ApiResponseCode {
 | 
			
		||||
    
 | 
			
		||||
    /*공통 Code*/
 | 
			
		||||
    // 200 OK
 | 
			
		||||
    COMMON_SUCCESS(HttpStatus.OK.value(), "요청 성공"),
 | 
			
		||||
    COMMON_SUCCESS(HttpStatus.OK.value(), "요청을 성공하였습니다"),
 | 
			
		||||
    COMMON_SUCCESS_CREATED(HttpStatus.CREATED.value(), "성공적으로 생성되었습니다"),
 | 
			
		||||
    COMMON_SUCCESS_UPDATED(HttpStatus.OK.value(), "성공적으로 수정되었습니다"),
 | 
			
		||||
    COMMON_SUCCESS_DELETED(HttpStatus.OK.value(), "성공적으로 삭제되었습니다"),
 | 
			
		||||
@@ -39,6 +39,7 @@ public enum ApiResponseCode {
 | 
			
		||||
 | 
			
		||||
    // 409 Conflict
 | 
			
		||||
    COMMON_CONFLICT(HttpStatus.CONFLICT.value(), "충돌이 발생했습니다"),
 | 
			
		||||
    COMMON_CODE_DUPLICATE(HttpStatus.CONFLICT.value(), "동일한 코드가 존재합니다"),
 | 
			
		||||
 | 
			
		||||
    // 500 Internal Server Error
 | 
			
		||||
    COMMON_INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버에서 오류가 발생했습니다"),
 | 
			
		||||
 
 | 
			
		||||
@@ -12,12 +12,17 @@ import lombok.RequiredArgsConstructor;
 | 
			
		||||
@JsonInclude(JsonInclude.Include.NON_NULL)
 | 
			
		||||
public class ApiResponseDto<T> {
 | 
			
		||||
 | 
			
		||||
    private static final boolean SUCCESS = true;
 | 
			
		||||
    private static final boolean FAIL = false;
 | 
			
		||||
 | 
			
		||||
    private boolean success;
 | 
			
		||||
    private int code;
 | 
			
		||||
    private String message;
 | 
			
		||||
    private String description;
 | 
			
		||||
    private T data;
 | 
			
		||||
 | 
			
		||||
    private ApiResponseDto(int code, String message, String description, T data){
 | 
			
		||||
    private ApiResponseDto(boolean success, int code, String message, String description, T data){
 | 
			
		||||
        this.success = success;
 | 
			
		||||
        this.code = code;
 | 
			
		||||
        this.message = message;
 | 
			
		||||
        this.description = description;
 | 
			
		||||
@@ -25,19 +30,19 @@ public class ApiResponseDto<T> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static <T> ApiResponseDto<T> success(ApiResponseCode responseCode, T data) {
 | 
			
		||||
        return new ApiResponseDto<T>(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data);
 | 
			
		||||
        return new ApiResponseDto<T>(SUCCESS, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static <T> ApiResponseDto<T> success(ApiResponseCode responseCode) {
 | 
			
		||||
        return new ApiResponseDto<T>(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null);
 | 
			
		||||
        return new ApiResponseDto<T>(SUCCESS, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static <T> ApiResponseDto<T> fail(ApiResponseCode responseCode, T data) {
 | 
			
		||||
        return new ApiResponseDto<T>(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data);
 | 
			
		||||
        return new ApiResponseDto<T>(FAIL, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static <T> ApiResponseDto<T> fail(ApiResponseCode responseCode) {
 | 
			
		||||
        return new ApiResponseDto<T>(responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null);
 | 
			
		||||
        return new ApiResponseDto<T>(FAIL, responseCode.getStatusCode(), responseCode.name(), responseCode.getDescription(), null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user