게시판 백 수정
This commit is contained in:
parent
135d0a9a7f
commit
36f2559232
@ -131,3 +131,4 @@ tasks.javadoc {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
|
||||
@ -76,7 +76,7 @@ public class SecurityConfig {
|
||||
http
|
||||
.securityMatcher("/api/**") // '/api/**' 경로에 대해서만 보안 적용
|
||||
.authorizeHttpRequests(auth ->
|
||||
auth.requestMatchers("/api/board/general").permitAll() // 특정 엔드포인트 허용
|
||||
auth.requestMatchers("/api/**").permitAll() // 특정 엔드포인트 허용
|
||||
.anyRequest().authenticated() // 나머지 요청은 인증 필요
|
||||
//auth.anyRequest().access(authorizationManager) // 모든 요청에 대해 권한 관리
|
||||
)
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package io.company.localhost.controller.api;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Blob;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -15,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import io.company.localhost.common.annotation.ReqMap;
|
||||
import io.company.localhost.common.dto.ApiResponse;
|
||||
@ -32,13 +36,13 @@ public class BoardController {
|
||||
|
||||
//공지사항
|
||||
@GetMapping("/notices")
|
||||
public ApiResponse<List<Map<String, Object>>> getNotices() {
|
||||
public ApiResponse<List<MapDto>> getNotices() {
|
||||
return ApiResponse.ok(boardService.getNotices());
|
||||
}
|
||||
//비밀,자유게시판
|
||||
@GetMapping("/general")
|
||||
public ApiResponse<List<Map<String, Object>>> getGeneralPosts() {
|
||||
List<Map<String, Object>> posts = boardService.getGeneralPosts();
|
||||
public ApiResponse<List<MapDto>> getGeneralPosts() {
|
||||
List<MapDto> posts = boardService.getGeneralPosts();
|
||||
for (Map<String, Object> post : posts) {
|
||||
Object content = post.get("content");
|
||||
if (content instanceof Blob) {
|
||||
@ -50,23 +54,48 @@ public class BoardController {
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println(posts);
|
||||
return ApiResponse.ok(posts);
|
||||
}
|
||||
//게시물 작성
|
||||
@PostMapping
|
||||
public ApiResponse<String> createBoard(@ReqMap MapDto map) {
|
||||
boardService.createBoard(map);
|
||||
return ApiResponse.ok("게시물이 작성되었습니다.");
|
||||
public ApiResponse<?> createBoard(@ReqMap MapDto map) {
|
||||
BigInteger createdIdx = boardService.createBoard(map); // 작성된 게시물의 idx를 반환
|
||||
Map<String, Object> responseData = new HashMap<>();
|
||||
responseData.put("boardId", createdIdx);
|
||||
responseData.put("message", "게시물이 작성되었습니다.");
|
||||
return ApiResponse.ok(responseData);
|
||||
}
|
||||
// 첨부파일 추가
|
||||
@PostMapping("/{boardId}/attachments")
|
||||
public ApiResponse<String> uploadAttachment(@PathVariable Long boardId, @ReqMap MapDto map) {
|
||||
map.put("LOCBRDSEQ", boardId);
|
||||
public ApiResponse<String> uploadAttachment(
|
||||
@PathVariable("boardId") Long boardId,
|
||||
@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("CMNFLEPAT") String filePath,
|
||||
@RequestParam("CMNFLEORG") String originalFileName,
|
||||
@RequestParam("CMNFLEEXT") String fileExtension,
|
||||
@RequestParam("CMNFLESIZ") Long fileSize,
|
||||
@RequestParam("CMNFLEREG") Long registrantId,
|
||||
@RequestParam("CMNFLENAM") String fileName
|
||||
) {
|
||||
// 데이터 준비
|
||||
MapDto fileData = new MapDto();
|
||||
fileData.put("CMNBRDSEQ", boardId);
|
||||
fileData.put("CMNFLENAM", fileName); // 업로드된 파일 이름
|
||||
fileData.put("CMNFLEORG", originalFileName);
|
||||
fileData.put("CMNFLEPAT", filePath);
|
||||
fileData.put("CMNFLEEXT", fileExtension);
|
||||
fileData.put("CMNFLESIZ", fileSize);
|
||||
fileData.put("CMNFLEREG", registrantId);
|
||||
fileData.put("CMNFLERDT", new Date()); // 등록일 현재 시간
|
||||
|
||||
log.info("Uploading attachment for board ID: {}", boardId);
|
||||
boardService.addAttachment(map);
|
||||
|
||||
// 파일 데이터 저장
|
||||
boardService.addAttachment(fileData);
|
||||
|
||||
return ApiResponse.ok("첨부파일이 저장되었습니다.");
|
||||
}
|
||||
|
||||
// 게시물 삭제
|
||||
@DeleteMapping("/{boardId}")
|
||||
public ApiResponse<String> deleteBoard(@PathVariable Long boardId, @ReqMap MapDto map) {
|
||||
@ -90,7 +119,7 @@ public class BoardController {
|
||||
}
|
||||
//댓글/대댓글 조회
|
||||
@GetMapping("/{boardId}/comments")
|
||||
public ApiResponse<List<Map<String, Object>>> getComments(@PathVariable int boardId) {
|
||||
public ApiResponse<List<MapDto>> getComments(@PathVariable int boardId) {
|
||||
return ApiResponse.ok(boardService.getComments(boardId));
|
||||
}
|
||||
//댓글/대댓글 작성
|
||||
|
||||
@ -11,10 +11,10 @@ import io.company.localhost.common.dto.MapDto;
|
||||
@Mapper
|
||||
public interface LocalBordMapper {
|
||||
// 공지사항 조회
|
||||
List<Map<String, Object>> getNotices();
|
||||
List<MapDto> getNotices();
|
||||
|
||||
// 자유/비밀 게시판 조회
|
||||
List<Map<String, Object>> getGeneralPosts();
|
||||
List<MapDto> getGeneralPosts();
|
||||
|
||||
// 게시물 작성
|
||||
void createBoard(MapDto map);
|
||||
@ -32,7 +32,7 @@ public interface LocalBordMapper {
|
||||
void reactToBoard(MapDto map);
|
||||
|
||||
// 댓글 조회
|
||||
List<Map<String, Object>> getComments(int boardSeq);
|
||||
List<MapDto> getComments(int boardSeq);
|
||||
|
||||
// 댓글/대댓글 작성
|
||||
void addCommentOrReply(MapDto map);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package io.company.localhost.service;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -14,16 +15,17 @@ import lombok.RequiredArgsConstructor;
|
||||
public class LocalBordService {
|
||||
private final LocalBordMapper boardMapper;
|
||||
|
||||
public List<Map<String, Object>> getNotices() {
|
||||
public List<MapDto> getNotices() {
|
||||
return boardMapper.getNotices();
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getGeneralPosts() {
|
||||
public List<MapDto> getGeneralPosts() {
|
||||
return boardMapper.getGeneralPosts();
|
||||
}
|
||||
|
||||
public void createBoard(MapDto map) {
|
||||
boardMapper.createBoard(map);
|
||||
public BigInteger createBoard(MapDto map) {
|
||||
boardMapper.createBoard(map); // 게시물 작성
|
||||
return (BigInteger) map.get("LOCBRDSEQ"); // Mapper에서 자동 생성된 key를 가져옴
|
||||
}
|
||||
|
||||
public void addAttachment(MapDto map) {
|
||||
@ -42,7 +44,7 @@ public class LocalBordService {
|
||||
boardMapper.reactToBoard(map);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getComments(int boardSeq) {
|
||||
public List<MapDto> getComments(int boardSeq) {
|
||||
return boardMapper.getComments(boardSeq);
|
||||
}
|
||||
|
||||
|
||||
@ -5,16 +5,12 @@
|
||||
<!-- 공지사항 조회 -->
|
||||
<select id="getNotices" resultType="java.util.Map">
|
||||
SELECT
|
||||
b.LOCBRDSEQ,
|
||||
b.LOCBRDTTL,
|
||||
b.LOCBRDCON,
|
||||
b.LOCBRDRDT,
|
||||
b.LOCBRDTYP,
|
||||
a.FILE_PATH,
|
||||
a.FILE_NAME,
|
||||
a.FILE_TYPE
|
||||
FROM localbord b
|
||||
LEFT JOIN attachments a ON b.LOCBRDSEQ = a.LOCBRDSEQ
|
||||
LOCBRDSEQ,
|
||||
LOCBRDTTL,
|
||||
LOCBRDCON,
|
||||
LOCBRDRDT,
|
||||
LOCBRDTYP,
|
||||
FROM localbord
|
||||
WHERE b.LOCBRDTYP = 'N'
|
||||
ORDER BY b.LOCBRDRDT DESC
|
||||
</select>
|
||||
@ -32,17 +28,24 @@
|
||||
</select>
|
||||
|
||||
<!-- 게시물 작성 -->
|
||||
<insert id="createBoard">
|
||||
INSERT INTO localbord (LOCBRDTTL, LOCBRDCON, LOCBRDCAT, MEMBERSEQ, LOCBRDCNT, LOCBRDRDT, LOCBRDUDT, LOCBRDPWD, LOCBRDTYP)
|
||||
VALUES (#{LOCBRDTTL}, #{LOCBRDCON}, #{LOCBRDCAT}, #{MEMBERSEQ}, 0, NOW(), NOW(), #{LOCBRDPWD}, #{LOCBRDTYP})
|
||||
</insert>
|
||||
<insert id="createBoard" parameterType="map" useGeneratedKeys="true" keyProperty="LOCBRDSEQ">
|
||||
INSERT INTO localbord (LOCBRDTTL, LOCBRDCON, LOCBRDCAT, MEMBERSEQ, LOCBRDCNT, LOCBRDRDT, LOCBRDUDT, LOCBRDPWD, LOCBRDTYP)
|
||||
VALUES (#{LOCBRDTTL}, #{LOCBRDCON}, #{LOCBRDCAT}, #{MEMBERSEQ}, 0, NOW(), NOW(), #{LOCBRDPWD}, #{LOCBRDTYP})
|
||||
</insert>
|
||||
|
||||
|
||||
<!-- 첨부파일 저장 -->
|
||||
<insert id="addAttachment">
|
||||
INSERT INTO commonfil (CMNBRDSEQ, CMNFLEPAT, CMNFLENAM, CMNFLEORG, CMNFLEEXT, CMNFLESIZ, CMNFLEREG, CMNFLERDT)
|
||||
VALUES (#{CMNBRDSEQ}, #{CMNFLEPAT}, #{CMNFLENAM}, #{CMNFLEORG}, #{CMNFLEEXT}, #{CMNFLESIZ}, #{CMNFLEREG}, NOW())
|
||||
<insert id="addAttachment" parameterType="map">
|
||||
INSERT INTO commonfil (
|
||||
CMNBRDSEQ,CMNFLENAM,CMNFLEORG,CMNFLEPAT,
|
||||
CMNFLEEXT,CMNFLESIZ,CMNFLEREG,CMNFLERDT
|
||||
) VALUES (
|
||||
#{CMNBRDSEQ},#{CMNFLENAM},#{CMNFLEORG},#{CMNFLEPAT},
|
||||
#{CMNFLEEXT},#{CMNFLESIZ},#{CMNFLEREG},#{CMNFLERDT}
|
||||
)
|
||||
</insert>
|
||||
|
||||
|
||||
<!-- 게시물 삭제 -->
|
||||
<delete id="deleteBoard">
|
||||
DELETE FROM localbord WHERE LOCBRDSEQ = #{LOCBRDSEQ}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user