QCAST -> QSP 게시판 관련 api 수정

This commit is contained in:
LEEYONGJAE 2024-10-10 11:29:07 +09:00
parent eb7e947728
commit 4dadc7ed92

View File

@ -1,5 +1,15 @@
package com.interplug.qcast.biz.community;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import org.springframework.util.StreamUtils;
import org.springframework.web.util.UriComponentsBuilder;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.interplug.qcast.biz.community.dto.BoardRequest;
@ -9,18 +19,8 @@ import com.interplug.qcast.config.Exception.QcastException;
import com.interplug.qcast.config.message.Messages;
import com.interplug.qcast.util.InterfaceQsp;
import jakarta.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import org.springframework.util.StreamUtils;
import org.springframework.web.util.UriComponentsBuilder;
@Slf4j
@Service
@ -28,7 +28,8 @@ import org.springframework.web.util.UriComponentsBuilder;
public class BoardService {
private final InterfaceQsp interfaceQsp;
@Autowired Messages message;
@Autowired
Messages message;
@Value("${qsp.url}")
private String QSP_API_URL;
@ -47,31 +48,28 @@ public class BoardService {
/* [0]. Validation Check */
if ("".equals(boardRequest.getSchNoticeClsCd())) {
// [msg] {0} is required input value.
throw new QcastException(
ErrorCode.INVALID_INPUT_VALUE,
throw new QcastException(ErrorCode.INVALID_INPUT_VALUE,
message.getMessage("common.message.required.data", "Notice Cls Code"));
}
if ("".equals(boardRequest.getSchNoticeTpCd())) {
// [msg] {0} is required input value.
throw new QcastException(
ErrorCode.INVALID_INPUT_VALUE,
throw new QcastException(ErrorCode.INVALID_INPUT_VALUE,
message.getMessage("common.message.required.data", "Notice Type Code"));
}
/* [1]. QSP API (url + param) Setting */
String encodedSchTitle = URLEncoder.encode(boardRequest.getSchTitle(), StandardCharsets.UTF_8);
String encodedSchTitle = "";
if (!"".equals(boardRequest.getSchTitle()) && boardRequest.getSchTitle() != null) {
encodedSchTitle = URLEncoder.encode(boardRequest.getSchTitle(), StandardCharsets.UTF_8);
}
String url = QSP_API_URL + "/api/board/list";
String apiUrl =
UriComponentsBuilder.fromHttpUrl(url)
.queryParam("noticeNo", boardRequest.getNoticeNo())
.queryParam("schTitle", encodedSchTitle)
.queryParam("schNoticeTpCd", boardRequest.getSchNoticeTpCd())
.queryParam("schNoticeClsCd", boardRequest.getSchNoticeClsCd())
.queryParam("startRow", boardRequest.getStartRow())
.queryParam("endRow", boardRequest.getEndRow())
.build()
.toUriString();
String apiUrl = UriComponentsBuilder.fromHttpUrl(url)
.queryParam("noticeNo", boardRequest.getNoticeNo()).queryParam("schTitle", encodedSchTitle)
.queryParam("schNoticeTpCd", boardRequest.getSchNoticeTpCd())
.queryParam("schNoticeClsCd", boardRequest.getSchNoticeClsCd())
.queryParam("startRow", boardRequest.getStartRow())
.queryParam("endRow", boardRequest.getEndRow()).build().toUriString();
/* [2]. QSP API CALL -> Response */
String strResponse = interfaceQsp.callApi(HttpMethod.GET, apiUrl, null);
@ -103,18 +101,14 @@ public class BoardService {
/* [0]. Validation Check */
if (boardRequest.getNoticeNo() == null) {
// [msg] {0} is required input value.
throw new QcastException(
ErrorCode.INVALID_INPUT_VALUE,
throw new QcastException(ErrorCode.INVALID_INPUT_VALUE,
message.getMessage("common.message.required.data", "Notice No"));
}
/* [1]. QSP API (url + param) Setting */
String url = QSP_API_URL + "/api/board/detail";
String apiUrl =
UriComponentsBuilder.fromHttpUrl(url)
.queryParam("noticeNo", boardRequest.getNoticeNo())
.build()
.toUriString();
String apiUrl = UriComponentsBuilder.fromHttpUrl(url)
.queryParam("noticeNo", boardRequest.getNoticeNo()).build().toUriString();
/* [2]. QSP API CALL -> Response */
String strResponse = interfaceQsp.callApi(HttpMethod.GET, apiUrl, null);
@ -144,8 +138,7 @@ public class BoardService {
/* [0]. Validation Check */
if ("".equals(encodeFileNo)) {
// [msg] {0} is required input value.
throw new QcastException(
ErrorCode.INVALID_INPUT_VALUE,
throw new QcastException(ErrorCode.INVALID_INPUT_VALUE,
message.getMessage("common.message.required.data", "File No"));
}
@ -169,15 +162,14 @@ public class BoardService {
} catch (Exception e) {
// [msg] File download error
throw new QcastException(
ErrorCode.INTERNAL_SERVER_ERROR,
throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR,
message.getMessage("common.message.file.download.error"));
}
} else {
// [msg] File does not exist.
throw new QcastException(
ErrorCode.NOT_FOUND, message.getMessage("common.message.file.download.exists"));
throw new QcastException(ErrorCode.NOT_FOUND,
message.getMessage("common.message.file.download.exists"));
}
}
}