좋아요기능 좋아요 버튼으로만 구현
<script>
function ArticleDetail__doIncreaseLikeCount() {
const localStorageKey = 'article__' + params.id + '__alreadyLike';
if (localStorage.getItem(localStorageKey)) {
return;
}
localStorage.setItem(localStorageKey, true);
$.get('../article/doIncreaseLikeCountRd', {
id : params.id,
ajaxMode : 'Y'
}, function(data) {
$('.article-detail__like-count').empty().html(data.data1);
}, 'json');
}
</script>
이건 사용하지 않기로..
SELECT A.*, M.nickname AS extra__writer,
IFNULL(SUM(RP.point),0) AS extra__sumReactionPoint,
IFNULL(SUM(IF(RP.point > 0, RP.point, 0)),0) AS extra__goodReactionPoint,
IFNULL(SUM(IF(RP.point < 0, RP.point, 0)),0) AS extra__badReactionPoint
FROM article AS A
INNER JOIN `member` AS M
ON A.memberId = M.id
LEFT JOIN reactionPoint AS RP
ON A.id = RP.relId AND RP.relTypeCode = 'article'
GROUP BY A.id
ORDER BY A.id DESC;
# reactionPoint 테스트 데이터 생성
# 1번 회원이 1번 글에 싫어요
INSERT INTO reactionPoint
SET regDate = NOW(),
updateDate = NOW(),
memberId = 1,
relTypeCode = 'article',
relId = 1,
`point` = -1;
.
.
# 이하 생략
@Select("""
SELECT A.*, M.nickname AS extra__writer,
IFNULL(SUM(RP.point),0) AS extra__sumReactionPoint,
IFNULL(SUM(IF(RP.point > 0, RP.point, 0)),0) AS extra__goodReactionPoint,
IFNULL(SUM(IF(RP.point < 0, RP.point, 0)),0) AS extra__badReactionPoint
FROM article AS A
INNER JOIN `member` AS M
ON A.memberId = M.id
LEFT JOIN reactionPoint AS RP
ON A.id = RP.relId AND RP.relTypeCode = 'article'
WHERE A.id = #{id}
GROUP BY A.id
""")
public Article getForPrintArticle(int id);
IFNULL (SUM(RP.point), 0)
# 만약 nulll이 아니라면 RP.point의 sum을 보여주고, null이라면 0을 보여줘.
테이블 2개에 JOIN을 걸어서 UPDATE를 해야 할 경우도 있음
#SELECT JOIN
SELECT columnA
FROM tableA AS A
INNER JOIN tableB AS B
ON A.id = B.id
WHERE 절
#UPDATE JOIN
UPDATE tableA AS A
INNER JOIN tableB AS B
ON A.id = B.id
SET A.columnA = 변경할값
WHERE 절
# update join -> 기존 게시물의 good,bad RP 값을 RP 테이블에서 가져온 데이터로 채운다
UPDATE article AS A
INNER JOIN (
SELECT RP.relTypeCode,RP.relId,
SUM(IF(RP.point > 0, RP.point, 0)) AS goodReactionPoint,
SUM(IF(RP.point < 0, RP.point * -1, 0)) AS badReactionPoint
FROM reactionPoint AS RP
GROUP BY RP.relTypeCode, RP.relId
) AS RP_SUM
ON A.id = RP_SUM.relId
SET A.goodReactionPoint = RP_SUM.goodReactionPoint,
A.badReactionPoint = RP_SUM.badReactionPoint;