diff --git a/common/core/src/main/java/kr/co/palnet/kac/core/code/ErrorCode.java b/common/core/src/main/java/kr/co/palnet/kac/core/code/ErrorCode.java new file mode 100644 index 0000000..21ca466 --- /dev/null +++ b/common/core/src/main/java/kr/co/palnet/kac/core/code/ErrorCode.java @@ -0,0 +1,60 @@ +package kr.co.palnet.kac.core.code; + +import com.fasterxml.jackson.annotation.JsonCreator; + +public enum ErrorCode { + SUCCESS("1", "성공"), + FAIL("-1", "실패"), + NON_VALID_PARAMETER("VP001", "파라미터가 유효하지 않습니다."), + INTERNAL_SERVER_ERROR("ER500", "내부 시스템 오류"), + NOT_REGIST_ERROR_CODE("ER501", "등록되지 않은 오류 코드"), + DATA_NOTFIND("DT001", "데이터 를 찾을수 없습니다."), + DATA_DUPLICATE("DT002", "중복 데이터가 존재합니다."), + DATA_NOT_CHANGE("DT003", "아직 갱신되지 않았습니다."), + DATA_NO("DT003", "데이터 미존재"), + DB_ERROR("DB001", "디비 처리중 오류"), + PLAN_DATA_DUPLICATE("FT500", "이미 등록된 비행계획서의 비행구역과 비행시간이 일치합니다.\n비행시간 또는 비행구역을 수정하여 주십시오."), + ARCRFT_DATA_DUPLICATE("FT501", "해당 기체는 다른 비행계획서에서 이미 등록된 기체입니다.\n비행시간 또는 기체 정보를 확인하여 주십시오."), + PLAN_LAANC_NOT_VALID("FT502", "LAANC를 통과하지 못한 비행계획서입니다."), + EXTERNAL_API_ERROR("EA500", "외부서버 호출에 실패하였습니다."), + AUTH_NAUTHORIZED("AU001", "권한이 없습니다."), + + // TS 연동 ERROR CODE + TS_SUCCESS("TS200", "정상적으로 수신되었습니다."), + TS_PARAM("TS300", "메시지 규격이 다릅니다."), // Json 포멧이 틀린 경우 + TS_PARAM_REQUIRED("TS301", "필수 항목이 누락되었습니다."), // 필수 항목이 누락된 경우 + TS_TYPE("TS302", "메시지 타입이 맞지 않습니다."), // 메시지내 파라미터의 타입이 잘못된 경우 + TS_SERVER_ERROR("TS500", "서버 연결이 되지 않습니다."), // call측 network exception 처리 + TS_NT_LAZY("TS501", "네트워크 연결이 지연 됩니다."), // call측 network exception 처리 + TS_AUTH_KEY("TS600", "인증키가 유효하지 않습니다."), + TS_ETC("TS700", "기타 오류"), // 기 정의된 내용이 아닌 기타 오류인 경우 + + // QR 관련 ERROR CODE + QR_EXPIRED("QR001", "QR코드 유효기간이 만료되었습니다"); + private final String code; + + private final String message; + + private ErrorCode(String code, String message) { + this.code = code; + this.message = message; + } + + public String code() { + return code; + } + + public String message() { + return message; + } + + @JsonCreator + public static ErrorCode fromCode(String code) { + for (ErrorCode errorCode : ErrorCode.values()) { + if (errorCode.code().equals(code)) { + return errorCode; + } + } + return null; + } +} diff --git a/common/core/src/main/java/kr/co/palnet/kac/core/response/ErrorResponse.java b/common/core/src/main/java/kr/co/palnet/kac/core/response/ErrorResponse.java index 9f33deb..e89c6dd 100644 --- a/common/core/src/main/java/kr/co/palnet/kac/core/response/ErrorResponse.java +++ b/common/core/src/main/java/kr/co/palnet/kac/core/response/ErrorResponse.java @@ -1,6 +1,7 @@ package kr.co.palnet.kac.core.response; -import com.palnet.comn.code.RSErrorCode; + +import kr.co.palnet.kac.core.code.RSErrorCode; import lombok.Data; import lombok.EqualsAndHashCode; diff --git a/common/core/src/main/java/kr/co/palnet/kac/core/response/SuccessResponse.java b/common/core/src/main/java/kr/co/palnet/kac/core/response/SuccessResponse.java index a8ff29f..d5b4ce1 100644 --- a/common/core/src/main/java/kr/co/palnet/kac/core/response/SuccessResponse.java +++ b/common/core/src/main/java/kr/co/palnet/kac/core/response/SuccessResponse.java @@ -1,30 +1,30 @@ -package kr.co.palnet.kac.core.response; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - - -@Data -@EqualsAndHashCode(callSuper=false) -public class SuccessResponse extends BasicResponse { - - @Schema(description = "응답 데이터 건수") - private int count; - - @Schema(description = "응답 데이터") - private T data; - - public SuccessResponse(T data) { - this.data = data; - if(data instanceof List) { - this.count = ((List)data).size(); - } else { - this.count = 1; - } - } - - -} +//package kr.co.palnet.kac.core.response; +// +//import io.swagger.v3.oas.annotations.media.Schema; +//import lombok.Data; +//import lombok.EqualsAndHashCode; +// +//import java.util.List; +// +// +//@Data +//@EqualsAndHashCode(callSuper=false) +//public class SuccessResponse extends BasicResponse { +// +// @Schema(description = "응답 데이터 건수") +// private int count; +// +// @Schema(description = "응답 데이터") +// private T data; +// +// public SuccessResponse(T data) { +// this.data = data; +// if(data instanceof List) { +// this.count = ((List)data).size(); +// } else { +// this.count = 1; +// } +// } +// +// +//} diff --git a/web/api-cns/src/main/java/kr/co/palnet/kac/api/v1/cns/faq/controller/CnsFaqController.java b/web/api-cns/src/main/java/kr/co/palnet/kac/api/v1/cns/faq/controller/CnsFaqController.java index c9f2fcf..3a07050 100644 --- a/web/api-cns/src/main/java/kr/co/palnet/kac/api/v1/cns/faq/controller/CnsFaqController.java +++ b/web/api-cns/src/main/java/kr/co/palnet/kac/api/v1/cns/faq/controller/CnsFaqController.java @@ -1,278 +1,279 @@ -package kr.co.palnet.kac.api.v1.cns.faq.controller; - - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; -import kr.co.palnet.kac.api.v1.cns.faq.model.FaqListDto; -import kr.co.palnet.kac.api.v1.cns.faq.model.FaqListRq; -import kr.co.palnet.kac.api.v1.cns.faq.model.FaqListRs; -import kr.co.palnet.kac.api.v1.cns.faq.model.FaqUpdateDto; -import kr.co.palnet.kac.api.v1.cns.faq.service.CnsFaqService; -import kr.co.palnet.kac.core.exception.BaseException; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.ErrorResponse; -import org.springframework.web.bind.annotation.*; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@RestController -@Slf4j -@RequiredArgsConstructor -@RequestMapping(value = "/v1/cns/faq") -@Tag(name = "FAQ", description = "FAQ 관련 API") -public class CnsFaqController { - - private final CnsFaqService service; - - /** - * FAQ 목록 조회하는 기능, - * FaqListRQModel 값에 있는 조건값으로 조회함. - * @param model - * @return - */ - @GetMapping - @Operation(summary = "FAQ 조회", description = "FAQ를 조회하는 API 입니다.") - public ResponseEntity getFaqList(FaqListRq model) { - List result = null; - try { - result = service.getFaqList(model); // FaQ 항목들 조회하는 기능 - } catch (BaseException e) { - /** - * try{ - ... - } - * try 영역 안 코드들중 문제가 생기면 오는 곳. - * CustomException은 개발자가 "의도적으로" 낸 예외처리, - * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 - */ - Map resultMap = new HashMap<>(); - log.error("IGNORE : ", e); - resultMap.put("result", false); - resultMap.put("errorCode", e.getErrorCode()); - resultMap.put("errorMessage", e.getMessage()); - return ResponseEntity.ok().body(new SuccessResponse<>(resultMap)); - } catch (Exception e) { - /** - * try{ - ... - } - * try 영역 안 코드들중 문제가 생기면 오는 곳. - * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 - */ - log.error("IGNORE : ", e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(new ErrorResponse("Server Error", "-1")); - - } - return ResponseEntity.ok().body(new SuccessResponse<>(result)); - } - - /** - * FAQ 상세 조회하는 기능, - * 일련번호[sno]로 조회함. - * @param sno - * @return - */ - @GetMapping("/{sno}") - @Operation(summary = "FAQ 상세 조회", description = "특정 FAQ만 조회하는 API 입니다. sno 값 : 1, 2, 등 ....") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "성공", - content = { - @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", - array = @io.swagger.v3.oas.annotations.media.ArraySchema( - schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = FaqListDto.class))) - }) - }) - public ResponseEntity getFaqDetail( - @Parameter(name="sno", description = "FAQ 시리얼 넘버", in = ParameterIn.PATH, example = "17")@PathVariable int sno) { - FaqListRs result = null; - try { - result = service.getFaqDetail(sno); // 일련번호[sno]로 상세정보를 조회하는 기능 - } catch (CustomException e) { - /** - * try{ - ... - } - * try 영역 안 코드들중 문제가 생기면 오는 곳. - * CustomException은 개발자가 "의도적으로" 낸 예외처리, - * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 - */ - Map resultMap = new HashMap<>(); - log.error("IGNORE : ", e); - resultMap.put("result", false); - resultMap.put("errorCode", e.getErrorCode()); - resultMap.put("errorMessage", e.getMessage()); - return ResponseEntity.ok().body(new SuccessResponse<>(resultMap)); - } catch (Exception e) { - /** - * try{ - ... - } - * try 영역 안 코드들중 문제가 생기면 오는 곳. - * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 - */ - log.error("IGNORE : ", e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(new ErrorResponse("Server Error", "-1")); - - } - return ResponseEntity.ok().body(new SuccessResponse<>(result)); - } - - /** - * FAQ 작성하는 기능, - * FaqListModel모델에 있는 값으로 작성하는 기능. - * @param model - * @return - */ - @PostMapping - @Operation(summary = "FAQ 작성", description = "FAQ를 작성하는 API 입니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "성공", - content = { - @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", - array = @io.swagger.v3.oas.annotations.media.ArraySchema( - schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = SuccessResponse.class))) - }) - }) - public ResponseEntity insertFaq(@RequestBody FaqListDto model) { - boolean result = false; - try { - result = service.insertFaq(model); // FaQ 추가하는 기능 - } catch (CustomException e) { - /** - * try{ - ... - } - * try 영역 안 코드들중 문제가 생기면 오는 곳. - * CustomException은 개발자가 "의도적으로" 낸 예외처리, - * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 - */ - Map resultMap = new HashMap<>(); - log.error("IGNORE : ", e); - resultMap.put("result", false); - resultMap.put("errorCode", e.getErrorCode()); - resultMap.put("errorMessage", e.getMessage()); - return ResponseEntity.ok().body(new SuccessResponse<>(resultMap)); - } catch (Exception e) { - /** - * try{ - ... - } - * try 영역 안 코드들중 문제가 생기면 오는 곳. - * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 - */ - log.error("IGNORE : ", e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(new ErrorResponse("Server Error", "-1")); - - } - return ResponseEntity.ok().body(new SuccessResponse<>(result)); - - - } - - /** - * FAQ 업데이트 기능, - * FaqListModel 모델에 있는 값으로 업데이트함. - * @param model - * @return - */ - @PutMapping - @Operation(summary = "FAQ 수정", description = "FAQ를 수정하는 API 입니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "성공", - content = { - @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", - array = @io.swagger.v3.oas.annotations.media.ArraySchema( - schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = SuccessResponse.class))) - }) - }) - public ResponseEntity updateFaq(@RequestBody FaqUpdateDto model) { - boolean result = false; - try { - result = service.updateFaq(model); // FaQ 수정하는 기능 - } catch (CustomException e) { - /** - * try{ - ... - } - * try 영역 안 코드들중 문제가 생기면 오는 곳. - * CustomException은 개발자가 "의도적으로" 낸 예외처리, - * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 - */ - Map resultMap = new HashMap<>(); - log.error("IGNORE : ", e); - resultMap.put("result", false); - resultMap.put("errorCode", e.getErrorCode()); - resultMap.put("errorMessage", e.getMessage()); - return ResponseEntity.ok().body(new SuccessResponse<>(resultMap)); - } catch (Exception e) { - /** - * try{ - ... - } - * try 영역 안 코드들중 문제가 생기면 오는 곳. - * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 - */ - log.error("IGNORE : ", e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(new ErrorResponse("Server Error", "-1")); - - } - return ResponseEntity.ok().body(new SuccessResponse<>(result)); - - } - - /** - * FAQ 삭제하는 기능, - * 일련번호[sno]로 삭제하는 기능. - * @param sno - * @return - */ - @DeleteMapping("/{sno}") - @Operation(summary = "FAQ 삭제", description = "특정 FAQ를 논리 삭제하는 API 입니다. sno 예시 : 1, 2, 등 ...") - public ResponseEntity deleteFaq(@PathVariable("sno") int sno) { - // TODO 성공/실패 상태값 전송 - try { - service.deleteFaq(sno); // 일련번호[sno]로 삭제하는 기능 - } catch (CustomException e) { - /** - * try{ - ... - } - * try 영역 안 코드들중 문제가 생기면 오는 곳. - * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 - */ - Map resultMap = new HashMap<>(); - log.error("IGNORE : ", e); - resultMap.put("result", false); - resultMap.put("errorCode", e.getErrorCode()); - resultMap.put("errorMessage", e.getMessage()); - return ResponseEntity.ok().body(new SuccessResponse<>(resultMap)); - } catch (Exception e) { - /** - * try{ - ... - } - * try 영역 안 코드들중 문제가 생기면 오는 곳. - * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 - */ - log.error("IGNORE : ", e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(new ErrorResponse("Server Error", "-1")); - - } - return ResponseEntity.ok().build(); - - } -} \ No newline at end of file +//package kr.co.palnet.kac.api.v1.cns.faq.controller; +// +// +//import io.swagger.v3.oas.annotations.Operation; +//import io.swagger.v3.oas.annotations.Parameter; +//import io.swagger.v3.oas.annotations.enums.ParameterIn; +//import io.swagger.v3.oas.annotations.responses.ApiResponse; +//import io.swagger.v3.oas.annotations.responses.ApiResponses; +//import io.swagger.v3.oas.annotations.tags.Tag; +//import kr.co.palnet.kac.api.v1.cns.faq.model.FaqListDto; +//import kr.co.palnet.kac.api.v1.cns.faq.model.FaqListRq; +//import kr.co.palnet.kac.api.v1.cns.faq.model.FaqListRs; +//import kr.co.palnet.kac.api.v1.cns.faq.model.FaqUpdateDto; +//import kr.co.palnet.kac.api.v1.cns.faq.service.CnsFaqService; +//import kr.co.palnet.kac.core.exception.BaseException; +//import kr.co.palnet.kac.core.response.BasicResponse; +//import lombok.RequiredArgsConstructor; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.http.HttpStatus; +//import org.springframework.http.ResponseEntity; +//import org.springframework.web.ErrorResponse; +//import org.springframework.web.bind.annotation.*; +// +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map; +// +//@RestController +//@Slf4j +//@RequiredArgsConstructor +//@RequestMapping(value = "/v1/cns/faq") +//@Tag(name = "FAQ", description = "FAQ 관련 API") +//public class CnsFaqController { +// +// private final CnsFaqService service; +// +// /** +// * FAQ 목록 조회하는 기능, +// * FaqListRQModel 값에 있는 조건값으로 조회함. +// * @param model +// * @return +// */ +// @GetMapping +// @Operation(summary = "FAQ 조회", description = "FAQ를 조회하는 API 입니다.") +// public ResponseEntity getFaqList(FaqListRq model) { +// List result = null; +// try { +// result = service.getFaqList(model); // FaQ 항목들 조회하는 기능 +// } catch (BaseException e) { +// /** +// * try{ +// ... +// } +// * try 영역 안 코드들중 문제가 생기면 오는 곳. +// * CustomException은 개발자가 "의도적으로" 낸 예외처리, +// * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 +// */ +// Map resultMap = new HashMap<>(); +// log.error("IGNORE : ", e); +// resultMap.put("result", false); +// resultMap.put("errorCode", e.getErrorCode()); +// resultMap.put("errorMessage", e.getMessage()); +// return ResponseEntity.ok().body(new SuccessResponse<>(resultMap)); +// } catch (Exception e) { +// /** +// * try{ +// ... +// } +// * try 영역 안 코드들중 문제가 생기면 오는 곳. +// * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 +// */ +// log.error("IGNORE : ", e); +// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) +// .body(new ErrorResponse("Server Error", "-1")); +// +// } +// return ResponseEntity.ok().body(new SuccessResponse<>(result)); +// } +// +// /** +// * FAQ 상세 조회하는 기능, +// * 일련번호[sno]로 조회함. +// * @param sno +// * @return +// */ +// @GetMapping("/{sno}") +// @Operation(summary = "FAQ 상세 조회", description = "특정 FAQ만 조회하는 API 입니다. sno 값 : 1, 2, 등 ....") +// @ApiResponses(value = { +// @ApiResponse(responseCode = "200", description = "성공", +// content = { +// @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", +// array = @io.swagger.v3.oas.annotations.media.ArraySchema( +// schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = FaqListDto.class))) +// }) +// }) +// public ResponseEntity getFaqDetail( +// @Parameter(name="sno", description = "FAQ 시리얼 넘버", in = ParameterIn.PATH, example = "17")@PathVariable int sno) { +// FaqListRs result = null; +// try { +// result = service.getFaqDetail(sno); // 일련번호[sno]로 상세정보를 조회하는 기능 +// } catch (CustomException e) { +// /** +// * try{ +// ... +// } +// * try 영역 안 코드들중 문제가 생기면 오는 곳. +// * CustomException은 개발자가 "의도적으로" 낸 예외처리, +// * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 +// */ +// Map resultMap = new HashMap<>(); +// log.error("IGNORE : ", e); +// resultMap.put("result", false); +// resultMap.put("errorCode", e.getErrorCode()); +// resultMap.put("errorMessage", e.getMessage()); +// return ResponseEntity.ok().body(new SuccessResponse<>(resultMap)); +// } catch (Exception e) { +// /** +// * try{ +// ... +// } +// * try 영역 안 코드들중 문제가 생기면 오는 곳. +// * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 +// */ +// log.error("IGNORE : ", e); +// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) +// .body(new ErrorResponse("Server Error", "-1")); +// +// } +// return ResponseEntity.ok().body(new SuccessResponse<>(result)); +// } +// +// /** +// * FAQ 작성하는 기능, +// * FaqListModel모델에 있는 값으로 작성하는 기능. +// * @param model +// * @return +// */ +// @PostMapping +// @Operation(summary = "FAQ 작성", description = "FAQ를 작성하는 API 입니다.") +// @ApiResponses(value = { +// @ApiResponse(responseCode = "200", description = "성공", +// content = { +// @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", +// array = @io.swagger.v3.oas.annotations.media.ArraySchema( +// schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = SuccessResponse.class))) +// }) +// }) +// public ResponseEntity insertFaq(@RequestBody FaqListDto model) { +// boolean result = false; +// try { +// result = service.insertFaq(model); // FaQ 추가하는 기능 +// } catch (CustomException e) { +// /** +// * try{ +// ... +// } +// * try 영역 안 코드들중 문제가 생기면 오는 곳. +// * CustomException은 개발자가 "의도적으로" 낸 예외처리, +// * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 +// */ +// Map resultMap = new HashMap<>(); +// log.error("IGNORE : ", e); +// resultMap.put("result", false); +// resultMap.put("errorCode", e.getErrorCode()); +// resultMap.put("errorMessage", e.getMessage()); +// return ResponseEntity.ok().body(new SuccessResponse<>(resultMap)); +// } catch (Exception e) { +// /** +// * try{ +// ... +// } +// * try 영역 안 코드들중 문제가 생기면 오는 곳. +// * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 +// */ +// log.error("IGNORE : ", e); +// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) +// .body(new ErrorResponse("Server Error", "-1")); +// +// } +// return ResponseEntity.ok().body(new SuccessResponse<>(result)); +// +// +// } +// +// /** +// * FAQ 업데이트 기능, +// * FaqListModel 모델에 있는 값으로 업데이트함. +// * @param model +// * @return +// */ +// @PutMapping +// @Operation(summary = "FAQ 수정", description = "FAQ를 수정하는 API 입니다.") +// @ApiResponses(value = { +// @ApiResponse(responseCode = "200", description = "성공", +// content = { +// @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", +// array = @io.swagger.v3.oas.annotations.media.ArraySchema( +// schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = SuccessResponse.class))) +// }) +// }) +// public ResponseEntity updateFaq(@RequestBody FaqUpdateDto model) { +// boolean result = false; +// try { +// result = service.updateFaq(model); // FaQ 수정하는 기능 +// } catch (CustomException e) { +// /** +// * try{ +// ... +// } +// * try 영역 안 코드들중 문제가 생기면 오는 곳. +// * CustomException은 개발자가 "의도적으로" 낸 예외처리, +// * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 +// */ +// Map resultMap = new HashMap<>(); +// log.error("IGNORE : ", e); +// resultMap.put("result", false); +// resultMap.put("errorCode", e.getErrorCode()); +// resultMap.put("errorMessage", e.getMessage()); +// return ResponseEntity.ok().body(new SuccessResponse<>(resultMap)); +// } catch (Exception e) { +// /** +// * try{ +// ... +// } +// * try 영역 안 코드들중 문제가 생기면 오는 곳. +// * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 +// */ +// log.error("IGNORE : ", e); +// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) +// .body(new ErrorResponse("Server Error", "-1")); +// +// } +// return ResponseEntity.ok().body(new SuccessResponse<>(result)); +// +// } +// +// /** +// * FAQ 삭제하는 기능, +// * 일련번호[sno]로 삭제하는 기능. +// * @param sno +// * @return +// */ +// @DeleteMapping("/{sno}") +// @Operation(summary = "FAQ 삭제", description = "특정 FAQ를 논리 삭제하는 API 입니다. sno 예시 : 1, 2, 등 ...") +// public ResponseEntity deleteFaq(@PathVariable("sno") int sno) { +// // TODO 성공/실패 상태값 전송 +// try { +// service.deleteFaq(sno); // 일련번호[sno]로 삭제하는 기능 +// } catch (CustomException e) { +// /** +// * try{ +// ... +// } +// * try 영역 안 코드들중 문제가 생기면 오는 곳. +// * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 +// */ +// Map resultMap = new HashMap<>(); +// log.error("IGNORE : ", e); +// resultMap.put("result", false); +// resultMap.put("errorCode", e.getErrorCode()); +// resultMap.put("errorMessage", e.getMessage()); +// return ResponseEntity.ok().body(new SuccessResponse<>(resultMap)); +// } catch (Exception e) { +// /** +// * try{ +// ... +// } +// * try 영역 안 코드들중 문제가 생기면 오는 곳. +// * log.error 로그로 원인 파악과 함께 API를 호출한 곳에 서버에러 내려줌 +// */ +// log.error("IGNORE : ", e); +// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) +// .body(new ErrorResponse("Server Error", "-1")); +// +// } +// return ResponseEntity.ok().build(); +// +// } +//} \ No newline at end of file diff --git a/web/api-cns/src/main/java/kr/co/palnet/kac/api/v1/cns/faq/service/CnsFaqService.java b/web/api-cns/src/main/java/kr/co/palnet/kac/api/v1/cns/faq/service/CnsFaqService.java index ddccbc5..7a9b57c 100644 --- a/web/api-cns/src/main/java/kr/co/palnet/kac/api/v1/cns/faq/service/CnsFaqService.java +++ b/web/api-cns/src/main/java/kr/co/palnet/kac/api/v1/cns/faq/service/CnsFaqService.java @@ -1,129 +1,126 @@ -package kr.co.palnet.kac.api.v1.cns.faq.service; - -import com.palnet.biz.api.acnt.jwt.utils.JwtTokenUtil; -import com.palnet.biz.api.cns.faq.model.FaqListModel; -import com.palnet.biz.api.cns.faq.model.FaqListRQModel; -import com.palnet.biz.api.cns.faq.model.FaqListRSModel; -import com.palnet.biz.api.cns.faq.model.FaqUpdateModel; -import com.palnet.biz.jpa.entity.CnsFaqBas; -import com.palnet.biz.jpa.repository.cns.CnsFaqBasRepository; -import com.palnet.biz.jpa.repository.cns.CnsFaqQueryRepository; -import com.palnet.comn.code.ErrorCode; -import com.palnet.comn.exception.CustomException; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import javax.transaction.Transactional; -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Service -@RequiredArgsConstructor -public class CnsFaqService { - - private final CnsFaqQueryRepository query; - private final CnsFaqBasRepository cnsFaqBasRepository; - private final JwtTokenUtil jwtTokenUtil; - - /** - * FaQ 항목들 조회하는 기능. - * @param model - * @return - */ - public List getFaqList(FaqListRQModel model){ - - List result = query.getFaqList(model.getCategory(), model.getWord()); - - if(result == null) result = new ArrayList<>(); - - return result; - - } - - /** - * 일련번호[sno]로 상세정보를 조회하는 기능. - * @param sno - * @return - */ - public FaqListRSModel getFaqDetail(int sno){ - cnsFaqBasRepository.updateViewCnt(sno); - FaqListRSModel result = query.getFaqDetail(sno); - if(result == null) throw new CustomException(ErrorCode.DATA_NO); - return result; - } - - /** - * FaQ 추가하는 기능. - * @param model - * @return - */ - @Transactional - public boolean insertFaq(FaqListModel model){ - String userId = jwtTokenUtil.getUserIdByToken(); - - CnsFaqBas bas = new CnsFaqBas(); - - bas.setCreateUserId(userId); - bas.setUpdateUserId(userId); - - bas.setCategory(model.getCategory()); - bas.setContent(model.getContent()); - bas.setExpsrYn(model.getExpsrYn()); - bas.setTitle(model.getTitle()); - - bas.setDelYn("N"); - bas.setViewCnt(0); - - try { - CnsFaqBas saveEntity = cnsFaqBasRepository.save(bas); - if(saveEntity != null) return true; - else return false; - } catch(Exception e) { - // TODO parameter validate...?? - throw new CustomException(ErrorCode.NON_VALID_PARAMETER); - } - } - - /** - * FaQ 수정하는 기능. - * @param model - * @return - */ - @Transactional - public boolean updateFaq(FaqUpdateModel model) { - String userId = jwtTokenUtil.getUserIdByToken(); - - CnsFaqBas prevData = cnsFaqBasRepository.findById(model.getFaqSno()).orElseThrow(() -> new CustomException(ErrorCode.DATA_NO)); - - if(model.getCategory() != null) prevData.setCategory(model.getCategory()); - if(model.getTitle() != null) prevData.setTitle(model.getTitle()); - if(model.getContent() != null) prevData.setContent(model.getContent()); - if(model.getExpsrYn() != null) prevData.setExpsrYn(model.getExpsrYn()); - prevData.setUpdateUserId(userId); - - - try { - CnsFaqBas saveEntity = cnsFaqBasRepository.save(prevData); - if(saveEntity != null) return true; - else return false; - } catch(Exception e) { - // TODO parameter validate...?? - throw new CustomException(ErrorCode.NON_VALID_PARAMETER); - } - } - - /** - * 일련번호[sno]로 삭제하는 기능. - * @param sno - */ - public void deleteFaq(int sno) { - - // TODO 반환값이 실행한 갯수인지 확인 필요 - int delCnt = cnsFaqBasRepository.deleteFaq(sno); - - if(delCnt == 0) throw new CustomException(ErrorCode.DATA_NO); - - } -} \ No newline at end of file +//package kr.co.palnet.kac.api.v1.cns.faq.service; +// +// +//import jakarta.transaction.Transactional; +//import kr.co.palnet.kac.api.v1.cns.faq.model.FaqListRq; +//import kr.co.palnet.kac.api.v1.cns.faq.model.FaqListRs; +//import kr.co.palnet.kac.core.code.ErrorCode; +//import kr.co.palnet.kac.core.exception.BaseException; +//import kr.co.palnet.kac.data.cns.model.CnsFaqBas; +//import kr.co.palnet.kac.data.cns.repository.CnsFaqBasRepository; +//import lombok.RequiredArgsConstructor; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.stereotype.Service; +// +//import java.util.ArrayList; +//import java.util.List; +// +//@Slf4j +//@Service +//@RequiredArgsConstructor +//public class CnsFaqService { +// +// private final CnsFaqQueryRepository query; +// private final CnsFaqBasRepository cnsFaqBasRepository; +// private final JwtTokenUtil jwtTokenUtil; +// +// /** +// * FaQ 항목들 조회하는 기능. +// * @param model +// * @return +// */ +// public List getFaqList(FaqListRq model){ +// +// List result = query.getFaqList(model.getCategory(), model.getWord()); +// +// if(result == null) result = new ArrayList<>(); +// +// return result; +// +// } +// +// /** +// * 일련번호[sno]로 상세정보를 조회하는 기능. +// * @param sno +// * @return +// */ +// public FaqListRs getFaqDetail(int sno){ +// cnsFaqBasRepository.updateViewCnt(sno); +// FaqListRs result = query.getFaqDetail(sno); +// if(result == null) throw new BaseException(ErrorCode.DATA_NO); +// return result; +// } +// +// /** +// * FaQ 추가하는 기능. +// * @param model +// * @return +// */ +// @Transactional +// public boolean insertFaq(FaqListModel model){ +// String userId = jwtTokenUtil.getUserIdByToken(); +// +// CnsFaqBas bas = new CnsFaqBas(); +// +// bas.setCreateUserId(userId); +// bas.setUpdateUserId(userId); +// +// bas.setCategory(model.getCategory()); +// bas.setContent(model.getContent()); +// bas.setExpsrYn(model.getExpsrYn()); +// bas.setTitle(model.getTitle()); +// +// bas.setDelYn("N"); +// bas.setViewCnt(0); +// +// try { +// CnsFaqBas saveEntity = cnsFaqBasRepository.save(bas); +// if(saveEntity != null) return true; +// else return false; +// } catch(Exception e) { +// // TODO parameter validate...?? +// throw new CustomException(ErrorCode.NON_VALID_PARAMETER); +// } +// } +// +// /** +// * FaQ 수정하는 기능. +// * @param model +// * @return +// */ +// @Transactional +// public boolean updateFaq(FaqUpdateModel model) { +// String userId = jwtTokenUtil.getUserIdByToken(); +// +// CnsFaqBas prevData = cnsFaqBasRepository.findById(model.getFaqSno()).orElseThrow(() -> new CustomException(ErrorCode.DATA_NO)); +// +// if(model.getCategory() != null) prevData.setCategory(model.getCategory()); +// if(model.getTitle() != null) prevData.setTitle(model.getTitle()); +// if(model.getContent() != null) prevData.setContent(model.getContent()); +// if(model.getExpsrYn() != null) prevData.setExpsrYn(model.getExpsrYn()); +// prevData.setUpdateUserId(userId); +// +// +// try { +// CnsFaqBas saveEntity = cnsFaqBasRepository.save(prevData); +// if(saveEntity != null) return true; +// else return false; +// } catch(Exception e) { +// // TODO parameter validate...?? +// throw new CustomException(ErrorCode.NON_VALID_PARAMETER); +// } +// } +// +// /** +// * 일련번호[sno]로 삭제하는 기능. +// * @param sno +// */ +// public void deleteFaq(int sno) { +// +// // TODO 반환값이 실행한 갯수인지 확인 필요 +// int delCnt = cnsFaqBasRepository.deleteFaq(sno); +// +// if(delCnt == 0) throw new CustomException(ErrorCode.DATA_NO); +// +// } +//} \ No newline at end of file