Skip to content

Commit

Permalink
Merge pull request #137 from Team-Shaka/refactor/136
Browse files Browse the repository at this point in the history
♻️ Refactor: 토큰 유효시간 증가와 활동량 로직 추가
  • Loading branch information
koojun99 authored Sep 28, 2024
2 parents fa3e3e3 + 8d17d3a commit 6de4b0e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public CommentResponseDTO.CommentIdResponseDto createComment(User user, Long tre
Comment comment = CommentMapper.toComment(writer, post, request.getContext(), CommentType.PARENT, -1L);
Long commentId = commentCommandAdapter.createComment(comment).getId();

//활동량 증가
user.increaseActiveRate(5);

//알림 생성
NotificationRequestDTO.createNotification notificationRequest = new NotificationRequestDTO.createNotification();
notificationRequest.setReceiverId(post.getWriter().getUser().getId()); // 여기서 receiver 설정 (예시)
Expand Down Expand Up @@ -228,6 +231,9 @@ public String reactToComment(User user, Long treehouseId, Long commentId, Commen

member.addReaction(savedReaction);

//활동량 증가
user.increaseActiveRate(1);

//알림 생성
NotificationRequestDTO.createNotification notificationRequest = new NotificationRequestDTO.createNotification();
notificationRequest.setReceiverId(comment.getWriter().getId()); // 여기서 receiver 설정 (예시)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public PostResponseDTO.createPostResult createPost(User user, PostRequestDTO.cre
List<PostImage> postImageList = PostMapper.toPostImageList(request);
postImageList.forEach(postImage -> postImage.setPost(post));
postImageCommandAdapter.savePostImageList(postImageList);

// 활동량 증가
user.increaseActiveRate(5);

return PostMapper.toCreatePostResult(postCommandAdapter.savePost(post));
}

Expand Down Expand Up @@ -305,6 +309,9 @@ public String reactToPost(User user, Long treehouseId, Long postId, PostRequestD

member.addReaction(savedReaction);

// 활동량 증가
user.increaseActiveRate(1);

//알림 생성
NotificationRequestDTO.createNotification notificationRequest = new NotificationRequestDTO.createNotification();
notificationRequest.setReceiverId(post.getWriter().getUser().getId()); // 여기서 receiver 설정 (예시)
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/treehouse/server/global/entity/User/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,18 @@ private void checkAndIncreaseInvitationCount() {
this.invitationCreatedCount = 0; // 카운트 초기화
}
}

public void increaseActiveRate(int rate) {
this.activeRate += rate;
checkAndIncreaseInvitationCountByActiveRate(); // activeRate가 100 단위일 때 invitationCount 증가
}

// activeRate가 100 단위일 때 invitationCount 증가
private void checkAndIncreaseInvitationCountByActiveRate() {
if (this.activeRate >= 100) {
int additionalInvitations = this.activeRate / 100; // 100 단위마다 초대장 증가
this.invitationCount += additionalInvitations; // 초대장 증가
this.activeRate = this.activeRate % 100; // 남은 activeRate는 100 미만으로 유지
}
}
}
8 changes: 4 additions & 4 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ jwt:
key: ${JWT_SECRET}
# secret : ${JWT_SECRET}
authorities-key: authoritiesKey
access-token-validity-in-seconds: 600000 # 10 min
refresh-token-validity-in-seconds: 3600000 # 1 hour
access-token-validity-in-seconds: 7200000 # 2 hour
refresh-token-validity-in-seconds: 2592000000 # 30 day

firebase:
admin-sdk: ${FCM_KEY}
Expand Down Expand Up @@ -143,8 +143,8 @@ jwt:
key: ${JWT_SECRET}
# secret : ${JWT_SECRET}
authorities-key: authoritiesKey
access-token-validity-in-seconds: 2000000 # 30 m
refresh-token-validity-in-seconds: 3000000 # 14 d
access-token-validity-in-seconds: 7200000 # 2 hour
refresh-token-validity-in-seconds: 2592000000 # 30 day

firebase:
admin-sdk: ${FCM_KEY}
Expand Down

0 comments on commit 6de4b0e

Please sign in to comment.