리스트 첨부파일유무,댓글갯수,좋아요/싫어요 갯수 추가
This commit is contained in:
parent
cd81956d7c
commit
77730be07f
@ -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);
|
||||
@ -183,15 +202,31 @@ public class BoardController {
|
||||
}
|
||||
}
|
||||
|
||||
// 첨부파일 및 댓글 조회
|
||||
MapDto reactions = boardService.getBoardReactions(boardId);
|
||||
boardDetail.put("likeCount", reactions.getOrDefault("likeCount", 0));
|
||||
boardDetail.put("dislikeCount", reactions.getOrDefault("dislikeCount", 0));
|
||||
|
||||
List<MapDto> attachments = boardService.getAttachments(boardId);
|
||||
List<MapDto> comments = boardService.getComments(boardId.intValue());
|
||||
|
||||
List<MapDto> 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);
|
||||
}
|
||||
|
||||
@ -55,13 +55,24 @@ public interface localbordMapper {
|
||||
// 게시물 상세보기
|
||||
MapDto selectBoardDetail(Long boardId);
|
||||
|
||||
// 댓글 갯수
|
||||
int countComments(Long boardId);
|
||||
|
||||
// 첨부파일 유무
|
||||
int countAttachments(Long boardId);
|
||||
|
||||
// 게시물 좋아요/싫어요 개수
|
||||
MapDto getBoardReactions(Long boardId);
|
||||
|
||||
// 댓글 좋아요/싫어요 개수
|
||||
List<MapDto> getCommentReactions(Long boardId);
|
||||
|
||||
// 첨부파일 가져오기
|
||||
List<MapDto> selectAttachments(Long boardId);
|
||||
|
||||
//댓글 좋아요/싫어요추가
|
||||
void reactToComment(MapDto map);
|
||||
|
||||
//댓글id 확인
|
||||
MapDto getCommentById(int commentId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -93,6 +93,24 @@ public class localbordService {
|
||||
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<MapDto> getCommentReactions(Long boardId) {
|
||||
return boardMapper.getCommentReactions(boardId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -146,5 +146,40 @@
|
||||
WHERE LOCCMTSEQ = #{commentId}
|
||||
</select>
|
||||
|
||||
<!-- 댓글 개수 조회 -->
|
||||
<select id="countComments" parameterType="long" resultType="int">
|
||||
SELECT COUNT(*)
|
||||
FROM localcomt
|
||||
WHERE LOCBRDSEQ = #{boardId}
|
||||
</select>
|
||||
|
||||
<!-- 첨부파일 유무 -->
|
||||
<select id="countAttachments" resultType="int">
|
||||
SELECT COUNT(*)
|
||||
FROM commonfil
|
||||
WHERE CMNBRDSEQ = #{boardId}
|
||||
</select>
|
||||
|
||||
<!-- 게시물 좋아요/싫어요 개수 조회 -->
|
||||
<select id="getBoardReactions" resultType="io.company.localhost.common.dto.MapDto">
|
||||
SELECT
|
||||
COALESCE(SUM(CASE WHEN LOCGOBGOD = 'T' THEN 1 ELSE 0 END), 0) AS likeCount,
|
||||
COALESCE(SUM(CASE WHEN LOCGOBBAD = 'T' THEN 1 ELSE 0 END), 0) AS dislikeCount
|
||||
FROM localgorb
|
||||
WHERE LOCBRDSEQ = #{boardId};
|
||||
|
||||
</select>
|
||||
|
||||
<!-- 댓글별 좋아요/싫어요 개수 조회 -->
|
||||
<select id="getCommentReactions" resultType="io.company.localhost.common.dto.MapDto">
|
||||
SELECT
|
||||
LOCCMTSEQ,
|
||||
SUM(CASE WHEN LOCGOBGOD = 'T' THEN 1 ELSE 0 END) AS likeCount,
|
||||
SUM(CASE WHEN LOCGOBBAD = 'T' THEN 1 ELSE 0 END) AS dislikeCount
|
||||
FROM localgorb
|
||||
WHERE LOCBRDSEQ = #{boardId}
|
||||
GROUP BY LOCCMTSEQ
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user