From 46a8344b0a97ad4db3c061355383b18daad2c08b Mon Sep 17 00:00:00 2001 From: LEEYONGJAE Date: Fri, 6 Sep 2024 16:13:49 +0900 Subject: [PATCH] =?UTF-8?q?[community]=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qcast/biz/community/BoardController.java | 49 +++++++ .../qcast/biz/community/BoardService.java | 122 ++++++++++++++++++ .../qcast/biz/community/dto/BoardRequest.java | 28 ++++ .../biz/community/dto/BoardResponse.java | 15 +++ 4 files changed, 214 insertions(+) create mode 100644 src/main/java/com/interplug/qcast/biz/community/BoardController.java create mode 100644 src/main/java/com/interplug/qcast/biz/community/BoardService.java create mode 100644 src/main/java/com/interplug/qcast/biz/community/dto/BoardRequest.java create mode 100644 src/main/java/com/interplug/qcast/biz/community/dto/BoardResponse.java diff --git a/src/main/java/com/interplug/qcast/biz/community/BoardController.java b/src/main/java/com/interplug/qcast/biz/community/BoardController.java new file mode 100644 index 00000000..c2b980e2 --- /dev/null +++ b/src/main/java/com/interplug/qcast/biz/community/BoardController.java @@ -0,0 +1,49 @@ +package com.interplug.qcast.biz.community; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import com.interplug.qcast.biz.community.dto.BoardRequest; +import com.interplug.qcast.biz.community.dto.BoardResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestController +@RequestMapping("/api/board") +@RequiredArgsConstructor +@Tag(name = "BoardController", description = "Community Board API") +public class BoardController { + + private final BoardService boardService; + + @Operation(description = "커뮤니티(공지사항, FAQ, 자료다운로드) 게시글 목록을 조회한다.") + @GetMapping("/list") + @ResponseStatus(HttpStatus.OK) + public BoardResponse getBoardList(@ModelAttribute BoardRequest boardRequest) throws Exception { + return boardService.getBoardList(boardRequest); + } + + @Operation(description = "커뮤니티(공지사항, FAQ, 자료다운로드) 게시글 상세 정보를 조회한다.") + @GetMapping("/detail") + @ResponseStatus(HttpStatus.OK) + public BoardResponse getBoardDetail(@ModelAttribute BoardRequest boardRequest) throws Exception { + return boardService.getBoardDetail(boardRequest); + } + + @Operation(description = "커뮤니티(공지사항, FAQ, 자료다운로드) 파일 다운로드를 진행한다.") + @GetMapping("/file/download") + @ResponseStatus(HttpStatus.OK) + public void getFileDownload(HttpServletResponse response, + @RequestParam(required = true) String encodeFileNo) throws Exception { + boardService.getFileDownload(response, encodeFileNo); + } + +} diff --git a/src/main/java/com/interplug/qcast/biz/community/BoardService.java b/src/main/java/com/interplug/qcast/biz/community/BoardService.java new file mode 100644 index 00000000..4efc3ab3 --- /dev/null +++ b/src/main/java/com/interplug/qcast/biz/community/BoardService.java @@ -0,0 +1,122 @@ +package com.interplug.qcast.biz.community; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +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; +import com.interplug.qcast.biz.community.dto.BoardResponse; +import com.interplug.qcast.util.InterfaceQsp; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +@RequiredArgsConstructor +public class BoardService { + + @Value("${qsp.url}") + private String QSP_API_URL; + + private final InterfaceQsp interfaceQsp; + + /** + * ※ 게시판 목록 조회 QSP -> Q.CAST3 + * + * @param boardRequest + * @return + * @throws Exception + */ + public BoardResponse getBoardList(BoardRequest boardRequest) throws Exception { + + BoardResponse response = null; + + /* [0]. QSP API (url + param) Setting */ + String url = QSP_API_URL + "/api/board/list"; + String apiUrl = + UriComponentsBuilder.fromHttpUrl(url).queryParam("noticeNo", boardRequest.getNoticeNo()) + .queryParam("schTitle", boardRequest.getSchTitle()) + .queryParam("schNoticeTpCd", boardRequest.getSchNoticeTpCd()) + .queryParam("schNoticeClsCd", boardRequest.getSchNoticeClsCd()) + .queryParam("startRow", boardRequest.getStartRow()) + .queryParam("endRow", boardRequest.getEndRow()).build().toUriString(); + + /* [1]. QSP API CALL -> Response */ + String strResponse = interfaceQsp.callApi(HttpMethod.GET, apiUrl, null); + + if (!"".equals(strResponse)) { + ObjectMapper om = + new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + response = om.readValue(strResponse, BoardResponse.class); + } + + return response; + + } + + /** + * ※ 게시판 상세 조회 QSP -> Q.CAST3 + * + * @param boardRequest + * @return + * @throws Exception + */ + public BoardResponse getBoardDetail(BoardRequest boardRequest) throws Exception { + + BoardResponse response = null; + + /* [0]. QSP API (url + param) Setting */ + String url = QSP_API_URL + "/api/board/detail"; + String apiUrl = UriComponentsBuilder.fromHttpUrl(url) + .queryParam("noticeNo", boardRequest.getNoticeNo()).build().toUriString(); + + /* [1]. QSP API CALL -> Response */ + String strResponse = interfaceQsp.callApi(HttpMethod.GET, apiUrl, null); + + if (!"".equals(strResponse)) { + ObjectMapper om = + new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + response = om.readValue(strResponse, BoardResponse.class); + } + + return response; + } + + /** + * ※ 게시판 파일 다운로드 QSP -> Q.CAST3 + * + * @param response + * @param encodeFileNo + * @throws Exception + */ + public void getFileDownload(HttpServletResponse response, String encodeFileNo) throws Exception { + + /* [0]. QSP API (url + fileNo) Setting */ + String url = QSP_API_URL + "/api/file/downloadFile" + "?encodeFileNo=" + encodeFileNo; + + /* [1]. QSP API CALL -> Response */ + String strResponse = interfaceQsp.callApi(HttpMethod.GET, url, null); + + if (!"".equals(strResponse)) { + /* [2]. API 응답 파일 처리 */ + response.setContentType("application/octet-stream"); + response.setHeader("Content-Disposition", "attachment;"); + + InputStream inputStream = new ByteArrayInputStream(strResponse.getBytes()); + StreamUtils.copy(inputStream, response.getOutputStream()); + + response.flushBuffer(); + } + + } + + +} diff --git a/src/main/java/com/interplug/qcast/biz/community/dto/BoardRequest.java b/src/main/java/com/interplug/qcast/biz/community/dto/BoardRequest.java new file mode 100644 index 00000000..b690b521 --- /dev/null +++ b/src/main/java/com/interplug/qcast/biz/community/dto/BoardRequest.java @@ -0,0 +1,28 @@ +package com.interplug.qcast.biz.community.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class BoardRequest { + + /** NOTICE_NO */ + private Integer noticeNo; + + /** 제목 검색조건 */ + private String schTitle; + + /** Notice Type Code 검색조건 */ + private String schNoticeTpCd; + + /** Notice Type Code 검색조건 */ + private String schNoticeClsCd; + + /** 시작 행 */ + private Integer startRow; + + /** 종료 행 */ + private int endRow; + +} diff --git a/src/main/java/com/interplug/qcast/biz/community/dto/BoardResponse.java b/src/main/java/com/interplug/qcast/biz/community/dto/BoardResponse.java new file mode 100644 index 00000000..de367a09 --- /dev/null +++ b/src/main/java/com/interplug/qcast/biz/community/dto/BoardResponse.java @@ -0,0 +1,15 @@ +package com.interplug.qcast.biz.community.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class BoardResponse { + + /** API response result */ + private Object result; + + /** API response data */ + private Object data; +}