Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public List<CommentReturn> getComments(Long postId, Integer page, Integer count)
public void addComment(Long postId, Long memberId, String content, Float score) {
Comment comment = Comment.createComment(memberId, postId, content, score);

if(commentRepository.insertComment(comment) == false) {
boolean result = commentRepository.insertComment(comment);
if(!result) {
throw new RuntimeException("삽입에 실패 했습니다.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ public int increaseView(Long postId) {
if(valueOperations.get(key) == null) {
valueOperations.set(generateKey(postId, KeyType.REAL), postRepository.getPostById(postId).getViews());
}
valueOperations.set(generateKey(postId, KeyType.SHADOW) , "", Duration.ofSeconds(1));
resetShadowKey(postId, valueOperations);

return valueOperations.increment(key).intValue();
}

private void resetShadowKey(Long postId, ValueOperations<String, Object> valueOperations) {
valueOperations.set(generateKey(postId, KeyType.SHADOW) , "", Duration.ofMinutes(5));
}

public int getViews(Long postId) {
String key = generateKey(postId, KeyType.REAL);
return (int) redisTemplate.opsForValue().get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public void editPost(Long postId, Long memberId, String title, String content) {

public void deletePost(Long postId, Long memberId) {
checkAuth(postId, memberId);
postRedisDao.deleteAndGet(postId);
int views = postRedisDao.deleteAndGet(postId);
postRepository.updateViews(postId, views);
postRepository.deletePost(postId);
}

Expand Down