좋아요 싫어요 기능이 비슷하므로 좋아요 기능만 설명
1) reactionController
@RequestMapping("/usr/reactionPoint/doGoodReaction")
@ResponseBody
public String doGoodReaction(String relTypeCode , int relId, String replaceUri) {
boolean actorCanMakeReaction = reactionPointService.actorCanMakeReaction(rq.getLoginedMemberId(),relTypeCode,relId );
if(actorCanMakeReaction==false) {
return rq.jsHistoryBack("이미 처리되었습니다.");
}
reactionPointService.addGoodReactionPoint(rq.getLoginedMemberId(),relTypeCode,relId);
return rq.jsReplace("좋아요!", replaceUri);
}
/usr/reactionPoint/doGoodReaction
로 이동이 된다.addGoodReactionPoint()
: 좋아요시 reactionPoint테이블과 article테이블에도 업데이트하는 메소드2) reactionService
public ResultData addGoodReactionPoint(int actorId, String relTypeCode, int relId) {
reactionPointRepository.addGoodReactionPoint(actorId,relTypeCode,relId);
switch (relTypeCode) {
case "article":
articleService.increaseGoodReactionPoint(relId);
break;
}
return ResultData.from("S-1", "좋아요 처리 되었습니다");
}
reactionPointRepository.addGoodReactionPoint()
를 통해 reactionPoint 테이블에도 업데이트하고3) reactionRepository
@Insert("""
<script>
INSERT INTO reactionPoint
SET regDate = NOW(),
updateDate = NOW(),
memberId = #{actorId},
relTypeCode =#{relTypeCode},
relId = #{relId},
`point` = 1;
</script>
""")
public void addGoodReactionPoint(int actorId, String relTypeCode, int relId);
4) rq객체의 getCurrentUri()
public String getCurrentUri() {
String currentUri = req.getRequestURI();
String queryString = req.getQueryString();
if (queryString != null && queryString.length() > 0) {
currentUri += "?" + queryString;
}
return currentUri;
}
detail페이지
를 의미한다.uri
를 가져오는 메소드쿼리스트링
을 가져오는 메소드5) getUriEncoded()
public static String getUriEncoded(String str) {
try {
return URLEncoder.encode(str, "UTF-8");
} catch (UnsupportedEncodingException e) {
return str;
}
}