123 lines
5.1 KiB
Java
123 lines
5.1 KiB
Java
package io.company.localhost.controller.api;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
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 io.company.localhost.common.annotation.ReqMap;
|
|
import io.company.localhost.common.dto.ApiResponse;
|
|
import io.company.localhost.common.dto.MapDto;
|
|
import io.company.localhost.service.LocalBordService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/board")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
public class BoardController {
|
|
private final LocalBordService boardService;
|
|
|
|
//공지사항
|
|
@GetMapping("/notices")
|
|
public ApiResponse<List<Map<String, Object>>> getNotices() {
|
|
return ApiResponse.ok(boardService.getNotices());
|
|
}
|
|
//비밀,자유게시판
|
|
@GetMapping("/general")
|
|
public ApiResponse<List<Map<String, Object>>> getGeneralPosts() {
|
|
List<Map<String, Object>> posts = boardService.getGeneralPosts();
|
|
System.out.println(posts);
|
|
return ApiResponse.ok(posts);
|
|
}
|
|
//게시물 작성
|
|
@PostMapping
|
|
public ApiResponse<String> createBoard(@ReqMap MapDto map) {
|
|
boardService.createBoard(map);
|
|
return ApiResponse.ok("게시물이 작성되었습니다.");
|
|
}
|
|
// 첨부파일 추가
|
|
@PostMapping("/{boardId}/attachments")
|
|
public ApiResponse<String> uploadAttachment(@PathVariable Long boardId, @ReqMap MapDto map) {
|
|
map.put("LOCBRDSEQ", boardId);
|
|
log.info("Uploading attachment for board ID: {}", boardId);
|
|
boardService.addAttachment(map);
|
|
return ApiResponse.ok("첨부파일이 저장되었습니다.");
|
|
}
|
|
// 게시물 삭제
|
|
@DeleteMapping("/{boardId}")
|
|
public ApiResponse<String> deleteBoard(@PathVariable Long boardId, @ReqMap MapDto map) {
|
|
map.put("LOCBRDSEQ", boardId);
|
|
log.info("Deleting board with ID: {}", boardId);
|
|
boardService.deleteBoard(map);
|
|
return ApiResponse.ok("게시물이 삭제되었습니다.");
|
|
}
|
|
//게시물 수정
|
|
@PutMapping
|
|
public ApiResponse<String> updateBoard(@ReqMap MapDto map) {
|
|
boardService.updateBoard(map);
|
|
return ApiResponse.ok("게시물이 수정되었습니다.");
|
|
}
|
|
//게시물과 댓글에 좋아요/싫어요 추가
|
|
@PostMapping("/{boardId}/reaction")
|
|
public ApiResponse<String> reactToBoard(@PathVariable Long boardId, @ReqMap MapDto map) {
|
|
map.put("LOCBRDSEQ", boardId);
|
|
boardService.reactToBoard(map);
|
|
return ApiResponse.ok("반응이 추가되었습니다.");
|
|
}
|
|
//댓글/대댓글 조회
|
|
@GetMapping("/{boardId}/comments")
|
|
public ApiResponse<List<Map<String, Object>>> getComments(@PathVariable int boardId) {
|
|
return ApiResponse.ok(boardService.getComments(boardId));
|
|
}
|
|
//댓글/대댓글 작성
|
|
@PostMapping("/{boardId}/comment")
|
|
public ApiResponse<String> addCommentOrReply(@PathVariable int boardId, @ReqMap MapDto map) {
|
|
map.put("LOCBRDSEQ", boardId);
|
|
boardService.addCommentOrReply(map);
|
|
return ApiResponse.ok("댓글 또는 대댓글이 작성되었습니다.");
|
|
}
|
|
//댓글/대댓글 수정
|
|
@PutMapping("/comment/{commentId}")
|
|
public ApiResponse<String> updateComment(@PathVariable int commentId, @ReqMap MapDto map) {
|
|
map.put("LOCCMTSEQ", commentId);
|
|
boardService.updateComment(map);
|
|
return ApiResponse.ok("댓글이 수정되었습니다.");
|
|
}
|
|
//댓글/대댓글 삭제
|
|
@DeleteMapping("/comment/{commentId}")
|
|
public ApiResponse<String> deleteComment(@PathVariable int commentId, @ReqMap MapDto map) {
|
|
map.put("LOCCMTSEQ", commentId);
|
|
boardService.deleteComment(map);
|
|
return ApiResponse.ok("댓글이 삭제되었습니다.");
|
|
}
|
|
//비밀번호 확인 (게시물)
|
|
@PostMapping("/comment/{commentId}/password")
|
|
public ApiResponse<Boolean> checkCommentPassword(@PathVariable int commentId, @ReqMap MapDto map) {
|
|
map.put("LOCCMTSEQ", commentId);
|
|
return ApiResponse.ok(boardService.checkCommentPassword(map));
|
|
}
|
|
//비밀번호 확인 (댓글)
|
|
@PostMapping("/{boardId}/password")
|
|
public ApiResponse<Boolean> checkBoardPassword(@PathVariable int boardId, @ReqMap MapDto map) {
|
|
map.put("LOCBRDSEQ", boardId);
|
|
return ApiResponse.ok(boardService.checkBoardPassword(map));
|
|
}
|
|
// 비밀게시판 여부 확인
|
|
@GetMapping("/{boardId}/isSecret")
|
|
public ApiResponse<Boolean> isSecretBoard(@PathVariable Long boardId) {
|
|
log.info("Checking if board ID {} is secret", boardId);
|
|
return ApiResponse.ok(boardService.isSecretBoard(boardId));
|
|
}
|
|
}
|