diff --git a/src/main/java/io/company/localhost/controller/api/BoardController.java b/src/main/java/io/company/localhost/controller/api/BoardController.java index 3bfd031..b67a73a 100644 --- a/src/main/java/io/company/localhost/controller/api/BoardController.java +++ b/src/main/java/io/company/localhost/controller/api/BoardController.java @@ -72,6 +72,12 @@ public class BoardController { Blob blob = (Blob) content; post.put("content", safeBlobToString(blob)); } + + // "id" 값을 Number로 받고 longValue()로 변환 + Object idObject = post.get("id"); + long postId = ((Number) idObject).longValue(); + post.put("hasAttachment", boardService.hasAttachments(postId)); + } return ApiResponse.ok(posts); @@ -93,6 +99,19 @@ public class BoardController { Blob blob = (Blob) content; post.put("content", safeBlobToString(blob)); } + + // "id" 값을 Number로 받고 longValue()로 변환 + Object idObject = post.get("id"); + if (idObject instanceof Number) { + long postId = ((Number) idObject).longValue(); + post.put("commentCount", boardService.getCommentCount(postId)); + post.put("hasAttachment", boardService.hasAttachments(postId)); + MapDto reactions = boardService.getBoardReactions(postId); + post.put("likeCount", reactions.getOrDefault("likeCount", 0)); + post.put("dislikeCount", reactions.getOrDefault("dislikeCount", 0)); + } else { + post.put("commentCount", 0); // id가 없거나 잘못된 경우 기본값 설정 + } } return ApiResponse.ok(posts); @@ -182,16 +201,32 @@ public class BoardController { throw new RuntimeException("Failed to process Blob content", e); } } + + MapDto reactions = boardService.getBoardReactions(boardId); + boardDetail.put("likeCount", reactions.getOrDefault("likeCount", 0)); + boardDetail.put("dislikeCount", reactions.getOrDefault("dislikeCount", 0)); - // 첨부파일 및 댓글 조회 List attachments = boardService.getAttachments(boardId); List comments = boardService.getComments(boardId.intValue()); + List commentReactions = boardService.getCommentReactions(boardId); + for (MapDto comment : comments) { + Integer commentId = (Integer) comment.get("LOCCMTSEQ"); + for (MapDto reaction : commentReactions) { + if (reaction.get("LOCCMTSEQ").equals(commentId)) { + comment.put("likeCount", reaction.getOrDefault("likeCount", 0)); + comment.put("dislikeCount", reaction.getOrDefault("dislikeCount", 0)); + } + } + } + // 결과 조합 MapDto result = new MapDto(); result.put("boardDetail", boardDetail); result.put("attachments", attachments); result.put("comments", comments); + result.put("commentCount", boardService.getCommentCount(boardId)); + result.put("hasAttachment", boardService.hasAttachments(boardId)); return ApiResponse.ok(result); } diff --git a/src/main/java/io/company/localhost/mapper/localbordMapper.java b/src/main/java/io/company/localhost/mapper/localbordMapper.java index 0bf37d3..cc40a1f 100644 --- a/src/main/java/io/company/localhost/mapper/localbordMapper.java +++ b/src/main/java/io/company/localhost/mapper/localbordMapper.java @@ -55,13 +55,24 @@ public interface localbordMapper { // 게시물 상세보기 MapDto selectBoardDetail(Long boardId); + // 댓글 갯수 + int countComments(Long boardId); + + // 첨부파일 유무 + int countAttachments(Long boardId); + + // 게시물 좋아요/싫어요 개수 + MapDto getBoardReactions(Long boardId); + + // 댓글 좋아요/싫어요 개수 + List getCommentReactions(Long boardId); + // 첨부파일 가져오기 List selectAttachments(Long boardId); - //댓글 좋아요/싫어요추가 - void reactToComment(MapDto map); - //댓글id 확인 MapDto getCommentById(int commentId); + + } diff --git a/src/main/java/io/company/localhost/service/localbordService.java b/src/main/java/io/company/localhost/service/localbordService.java index c8225cd..11de3a1 100644 --- a/src/main/java/io/company/localhost/service/localbordService.java +++ b/src/main/java/io/company/localhost/service/localbordService.java @@ -92,6 +92,24 @@ public class localbordService { public MapDto getCommentById(int commentId) { return boardMapper.getCommentById(commentId); } + + public int getCommentCount(Long boardId) { + return boardMapper.countComments(boardId); + } + + public boolean hasAttachments(Long boardId) { + int count = boardMapper.countAttachments(boardId); + return count > 0; // 첨부파일 개수가 0보다 크면 true 반환 + } + + public MapDto getBoardReactions(Long boardId) { + return boardMapper.getBoardReactions(boardId); + } + + public List getCommentReactions(Long boardId) { + return boardMapper.getCommentReactions(boardId); + } + } diff --git a/src/main/resources/mapper/localbordMapper.xml b/src/main/resources/mapper/localbordMapper.xml index eb2ac08..8abc715 100644 --- a/src/main/resources/mapper/localbordMapper.xml +++ b/src/main/resources/mapper/localbordMapper.xml @@ -146,5 +146,40 @@ WHERE LOCCMTSEQ = #{commentId} + + + + + + + + + + + +