2525import java.util.Map;
2626
2727/**
28- * 코드 작성자:
29- * - 서진영(jin2304)
30- *
31- * 코드 설명:
32- * - BoardController는 게시판 및 게시글 관련 기능을 처리하는 컨트롤러
33- *
34- * 코드 주요 기능:
35- * - 게시글 등록, 게시글 목록 조회(검색어, 최신순/인기순), 게시글 단일(상세) 조회, 게시글 수정, 게시글 삭제
36- * - 게시글 좋아요/북마크 추가 및 취소
37- *
38- * 코드 작성일:
39- * - 2024.08.24 ~ 2024.09.05
28+ * BoardController (Legacy - PostgreSQL)
29+ *
30+ * 게시판 및 게시글 관련 기능을 처리하는 컨트롤러
4031 */
4132@Controller
4233public class BoardController {
@@ -55,15 +46,6 @@ public BoardController(BoardService boardservice, MemberService memberservice, L
5546 }
5647
5748
58- /**
59- * 게시글 생성
60- */
61- @PostMapping("/board/{memberId}/post")
62- public String insertBoard(@PathVariable int memberId, BoardDto boardDto){
63- int result = boardservice.insertBoard(memberId, boardDto);
64- return "redirect:/board";
65- }
66-
6749
6850
6951 /**
@@ -76,27 +58,20 @@ public String boardPage() {
7658
7759
7860 /**
79- * 페이징된 게시글 목록 조회
80- * - 검색어, 최신순/인기순, 게시글타입
81- * - 스크롤 방식으로 페이징 지원
82- * - 클라이언트(JS)에서 스크롤 이벤트 발생 시 요청
61+ * 게시글 생성
8362 */
84- @ResponseBody
85- @GetMapping("api/boards")
86- public Map<String, Object> getBoards(@RequestParam(defaultValue = "0") int page,
87- @RequestParam(defaultValue = "10") int size,
88- @RequestParam(defaultValue = "newest") String sort,
89- @RequestParam(required = false) String query,
90- @RequestParam(defaultValue = "all") String postType) {
91- return boardservice.selectBoardPage(page, size, sort, query, postType);
63+ @PostMapping("/board/{memberId}/post")
64+ public String insertBoard(@PathVariable Long memberId, BoardDto boardDto){
65+ int result = boardservice.insertBoard(memberId, boardDto);
66+ return "redirect:/board";
9267 }
9368
9469
9570 /**
9671 * 게시글 단일 조회
9772 */
9873 @GetMapping("/board/{boardId}")
99- public String boardDetail(@PathVariable int boardId,@AuthenticationPrincipal Object currentUser, Model model){
74+ public String boardDetail(@PathVariable Long boardId, @AuthenticationPrincipal Object currentUser, Model model){
10075 Map<String, Object> boardData = boardservice.selectBoard(boardId);
10176 Board board = (Board) boardData.get("board");
10277 String[] hashtagsList = (String[]) boardData.get("hashtagsList");
@@ -106,7 +81,7 @@ public String boardDetail(@PathVariable int boardId,@AuthenticationPrincipal Obj
10681
10782 // 사용자가 로그인된 상태라면, 좋아요 여부를 확인하여 모델에 추가
10883 if (currentUser != null && !"anonymousUser".equals(currentUser)) {
109- int memberId;
84+ Long memberId;
11085 if(currentUser instanceof UserDetails) {
11186 // 일반 로그인 사용자 처리
11287 memberId = ((CustomUserDetails) currentUser).getMemberId();
@@ -129,12 +104,29 @@ else if(currentUser instanceof OAuth2User) {
129104 }
130105
131106
107+ /**
108+ * 페이징된 게시글 목록 조회
109+ * - 검색어, 최신순/인기순, 게시글타입
110+ * - 스크롤 방식으로 페이징 지원
111+ * - 클라이언트(JS)에서 스크롤 이벤트 발생 시 요청
112+ */
113+ @ResponseBody
114+ @GetMapping("api/boards")
115+ public Map<String, Object> getBoards(@RequestParam(defaultValue = "0") int page,
116+ @RequestParam(defaultValue = "10") int size,
117+ @RequestParam(defaultValue = "newest") String sort,
118+ @RequestParam(required = false) String query,
119+ @RequestParam(defaultValue = "all") String postType) {
120+ return boardservice.selectBoardPage(page, size, sort, query, postType);
121+ }
122+
123+
132124 /**
133125 * 게시글 수정
134126 */
135127 @PostMapping("/board/{boardId}/update")
136128 @OwnerCheck(idParam = "boardId", service = "boardService")
137- public String updateBoard(@PathVariable int boardId, BoardDto boardDto){
129+ public String updateBoard(@PathVariable Long boardId, BoardDto boardDto){
138130 boardservice.updateBoard(boardId, boardDto);
139131 return "redirect:/board/{boardId}";
140132 }
@@ -145,7 +137,7 @@ public String updateBoard(@PathVariable int boardId, BoardDto boardDto){
145137 */
146138 @PostMapping("/board/{boardId}/delete")
147139 @OwnerCheck(idParam = "boardId", service = "boardService")
148- public String deleteBoard(@PathVariable int boardId) {
140+ public String deleteBoard(@PathVariable Long boardId) {
149141 boardservice.deleteBoard(boardId);
150142 return "redirect:/board";
151143 }
@@ -156,7 +148,7 @@ public String deleteBoard(@PathVariable int boardId) {
156148 */
157149 @PostMapping("/board/{boardId}/like")
158150 @ResponseBody
159- public Map<String, Object> toggleLike(@PathVariable int boardId, @AuthenticationPrincipal Object currentUser) {
151+ public Map<String, Object> toggleLike(@PathVariable Long boardId, @AuthenticationPrincipal Object currentUser) {
160152
161153 Map<String, Object> response = new HashMap<>();
162154
@@ -168,7 +160,7 @@ public Map<String, Object> toggleLike(@PathVariable int boardId, @Authentication
168160 }
169161
170162 // 로그인 된 경우
171- int memberId;
163+ Long memberId;
172164 if(currentUser instanceof UserDetails) {
173165 // 일반 로그인 사용자 처리
174166 memberId = ((CustomUserDetails) currentUser).getMemberId();
@@ -192,8 +184,8 @@ else if(currentUser instanceof OAuth2User) {
192184 */
193185 @PostMapping(value ="/board/{boardId}/bookmark/{memberId}")
194186 public ResponseEntity<Map<String, Object>> toggleBookmark(
195- @PathVariable final int boardId,
196- @PathVariable final int memberId,
187+ @PathVariable final Long boardId,
188+ @PathVariable final Long memberId,
197189 @RequestBody BookmarkDto bookmarkDto,
198190 @AuthenticationPrincipal Object currentUser){
199191 Map<String, Object> response = new HashMap<>();
@@ -211,7 +203,7 @@ public ResponseEntity<Map<String, Object>> toggleBookmark(
211203
212204 if (bookmarkExists == 0) {
213205 // 북마크가 안 되어 있으면 북마크 추가
214- bookmarkService.insertBookmarkForBoard(bookmarkDto);
206+ bookmarkService.insertBookmarkForBoard(boardId, bookmarkDto);
215207 boardservice.incrementBookmarkCount(boardId); // 북마크 추가 시 게시글의 북마크 수 증가
216208 response.put("action", "bookmarked");
217209 } else {
0 commit comments