[community] 게시판 관련 API 추가

This commit is contained in:
LEEYONGJAE 2024-09-06 16:13:49 +09:00
parent 0cc3baf6aa
commit 46a8344b0a
4 changed files with 214 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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();
}
}
}

View File

@ -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;
}

View File

@ -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;
}