Skip to content

Commit

Permalink
Merge pull request #51 from fernandokkang/develop
Browse files Browse the repository at this point in the history
fix like count error
  • Loading branch information
dhktjr0204 authored Mar 21, 2024
2 parents 4154d49 + c25fccf commit 92ff11f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ http://bend-doumi.com:8080/

## 🗂 DB 구성도
<img src="src/main/resources/static/images/readMe/doumi_erd.png">

## CI/CD
![CI/CD](/src/main/resources/static/images/readMe/GitAction%20Deploy%20Flow.png)

## Architecture
![CI/CD](/src/main/resources/static/images/readMe/Architecture.png)
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public class LikeController {

))})
public ResponseEntity<?> getLikeInfo(HttpServletRequest request,
@RequestParam(value = "postId") long postId) {
@RequestParam(value = "postId") long postId, @RequestParam(value = "type") String type) {

try {

HttpSession session = request.getSession();
long userId = (long) session.getAttribute("userId");

boolean exists = likeService.existsByUserIdAndPostId(userId, postId);
long likeCount = likeService.getCountLike(postId);
long likeCount = likeService.getCountLike(postId, type);

LikesDto likesDto = new LikesDto();
likesDto.setExists(exists);
Expand Down Expand Up @@ -86,7 +86,7 @@ public ResponseEntity<?> addLike(HttpServletRequest request,
long userId = (long) session.getAttribute("userId");

likeService.addLike(userId, postId, type);
long likeCount = likeService.getCountLike(postId);
long likeCount = likeService.getCountLike(postId, type);

return ResponseEntity.ok(likeCount);
} catch (Exception e) {
Expand Down Expand Up @@ -118,7 +118,7 @@ public ResponseEntity<?> cancelLike(HttpServletRequest request,
long userId = (long) session.getAttribute("userId");

likeService.cancelLike(userId, postId, type);
long likeCount = likeService.getCountLike(postId);
long likeCount = likeService.getCountLike(postId, type);

return ResponseEntity.ok(likeCount);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public void cancelLike(long user_id, long post_id, String type) {
}

@Override
public long countLike(long post_id) {
public long countLike(long post_id, String type) {

String sql = "select count(*) " +
"from likes " +
"where post_id = ?";
"where post_id = ? and type = ? ";

return jdbcTemplate.queryForObject(sql, Long.class, post_id);
return jdbcTemplate.queryForObject(sql, Long.class, post_id, type);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public interface LikeRepository {

public void addLike(long user_id, long post_id, String type);
public void cancelLike(long user_id, long post_id, String type);
public long countLike(long post_id);
public long countLike(long post_id, String type);
public boolean existsByUserIdAndPostId(long user_id, long post_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public interface LikeService {

public void addLike(long user_id, long post_id, String type);
public void cancelLike(long user_id, long post_id, String type);
public long getCountLike(long post_id);
public long getCountLike(long post_id, String type);
public boolean existsByUserIdAndPostId(long user_id, long post_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public void cancelLike(long user_id, long post_id, String type) {
}

@Override
public long getCountLike(long post_id) {
public long getCountLike(long post_id, String type) {

return likeRepository.countLike(post_id);
return likeRepository.countLike(post_id, type);
}

@Override
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 92ff11f

Please sign in to comment.