댓글 좋아요/싫어요 수정

This commit is contained in:
dyhj625 2025-02-20 10:36:05 +09:00
parent b09f4cda2f
commit b4c49fbe58
5 changed files with 29 additions and 9 deletions

View File

@ -165,7 +165,7 @@ public class BoardController {
} }
/** /**
* 댓글/대댓글 조회 * 댓글 조회
* @ReqMap map 수정 데이터 (LOCBRDSEQ) * @ReqMap map 수정 데이터 (LOCBRDSEQ)
* @return 댓글 * @return 댓글
*/ */

View File

@ -5,6 +5,7 @@ import java.util.Map;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import io.company.localhost.common.dto.MapDto; import io.company.localhost.common.dto.MapDto;
@ -89,7 +90,8 @@ public interface localbordMapper {
MapDto selectCountBoardReactions(Long boardId); MapDto selectCountBoardReactions(Long boardId);
// 댓글 좋아요/싫어요 개수 // 댓글 좋아요/싫어요 개수
List<MapDto> selectCountCommentReactions(Long boardId); @ResultType(MapDto.class)
MapDto selectCountCommentReactions(Long commentId);
// 첨부파일 가져오기 // 첨부파일 가져오기
List<MapDto> selectAttachments(Long boardId); List<MapDto> selectAttachments(Long boardId);
@ -97,5 +99,6 @@ public interface localbordMapper {
//댓글id 확인 //댓글id 확인
MapDto selectCommentById(int commentId); MapDto selectCommentById(int commentId);
} }

View File

@ -116,7 +116,7 @@ public class localbordService {
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
List<MapDto> result = boardMapper.selectComments(map); List<MapDto> result = boardMapper.selectComments(map);
enrichCommentsWithAdditionalData(result); // 댓글 데이터 보강
return PageUtil.redefineNavigation(new PageInfo<>(result, size)); return PageUtil.redefineNavigation(new PageInfo<>(result, size));
} }
@ -177,7 +177,7 @@ public class localbordService {
return boardMapper.selectCountBoardReactions(boardId); return boardMapper.selectCountBoardReactions(boardId);
} }
public List<MapDto> selectCountCommentReactions(Long boardId) { public MapDto selectCountCommentReactions(Long boardId) {
return boardMapper.selectCountCommentReactions(boardId); return boardMapper.selectCountCommentReactions(boardId);
} }
@ -306,4 +306,20 @@ public class localbordService {
} }
} }
private void enrichCommentsWithAdditionalData(List<MapDto> comments) {
for (MapDto comment : comments) {
Object idObject = comment.get("LOCCMTSEQ");
if (idObject instanceof Number) {
long commentId = ((Number) idObject).longValue();
MapDto reactions = boardMapper.selectCountCommentReactions(commentId);
comment.put("likeCount", reactions != null ? reactions.getOrDefault("likeCount", 0) : 0);
comment.put("dislikeCount", reactions != null ? reactions.getOrDefault("dislikeCount", 0) : 0);
Object content = comment.get("content");
comment.put("content", content);
}
}
}
} }

View File

@ -252,14 +252,15 @@
</select> </select>
<!-- 댓글별 좋아요/싫어요 개수 조회 --> <!-- 댓글별 좋아요/싫어요 개수 조회 -->
<select id="selectCountCommentReactions" resultType="io.company.localhost.common.dto.MapDto"> <select id="selectCountCommentReactions" parameterType="long" resultType="io.company.localhost.common.dto.MapDto">
SELECT SELECT
LOCCMTSEQ, LOCCMTSEQ,
COALESCE(SUM(CASE WHEN LOCGOBGOD = 'T' THEN 1 ELSE 0 END), 0) AS likeCount, 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 COALESCE(SUM(CASE WHEN LOCGOBBAD = 'T' THEN 1 ELSE 0 END), 0) AS dislikeCount
FROM localgorb FROM localgorb
WHERE LOCBRDSEQ = #{boardId} WHERE LOCCMTSEQ = #{commentId}
GROUP BY LOCCMTSEQ LIMIT 1
</select> </select>
</mapper> </mapper>

View File

@ -10,7 +10,7 @@
<!-- 휴가 정보 조회 --> <!-- 휴가 정보 조회 -->
<select id="findVacations" parameterType="map" resultType="io.company.localhost.common.dto.MapDto"> <select id="findVacations" parameterType="map" resultType="io.company.localhost.common.dto.MapDto">
SELECT MEMBERSEQ, LOCVACUDT, LOCVACTYP SELECT MEMBERSEQ, LOCVACUDT, LOCVACTYP, LOCVACRMM
FROM localvaca FROM localvaca
WHERE DATE_FORMAT(LOCVACUDT, '%Y-%m') = CONCAT(#{year}, '-', LPAD(#{month}, 2, '0')) WHERE DATE_FORMAT(LOCVACUDT, '%Y-%m') = CONCAT(#{year}, '-', LPAD(#{month}, 2, '0'))
</select> </select>