Skip to content

Commit 259cc5b

Browse files
authored
Merge pull request #245 from TeamDon-tBe/feat/#244
[FEAT]fcm알림에서 아이콘 배지 값 추가
2 parents 75fa381 + 8407de6 commit 259cc5b

File tree

12 files changed

+56
-7
lines changed

12 files changed

+56
-7
lines changed

DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/comment/service/CommentCommendService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void postCommentVer2(Long memberId, Long contentId, MultipartFile comment
108108

109109
if (Boolean.TRUE.equals(contentWritingMember.getIsPushAlarmAllowed())) {
110110
String FcmMessageTitle = usingMember.getNickname() + "님이 답글을 작성했습니다.";
111-
111+
contentWritingMember.increaseFcmBadge();
112112
FcmMessageDto commentFcmMessage = FcmMessageDto.builder()
113113
.validateOnly(false)
114114
.message(FcmMessageDto.Message.builder()
@@ -122,6 +122,7 @@ public void postCommentVer2(Long memberId, Long contentId, MultipartFile comment
122122
.description("답글 푸시 알림")
123123
.relateContentId(String.valueOf(contentId))
124124
.build())
125+
.badge(String.valueOf(contentWritingMember.getFcmBadge()))
125126
.build())
126127
.build();
127128

@@ -182,7 +183,7 @@ public void likeComment(Long memberId, Long commentId, CommentLikedRequestDto co
182183

183184
if (Boolean.TRUE.equals(targetMember.getIsPushAlarmAllowed())) {
184185
String FcmMessageTitle = triggerMember.getNickname() + "님이 " + targetMember.getNickname() + "님의 답글을 좋아합니다.";
185-
186+
targetMember.increaseFcmBadge();
186187
FcmMessageDto commentLikeFcmMessage = FcmMessageDto.builder()
187188
.validateOnly(false)
188189
.message(FcmMessageDto.Message.builder()
@@ -196,6 +197,7 @@ public void likeComment(Long memberId, Long commentId, CommentLikedRequestDto co
196197
.description("답글 좋아요 푸시 알림")
197198
.relateContentId(String.valueOf(contentId))
198199
.build())
200+
.badge(String.valueOf(targetMember.getFcmBadge()))
199201
.build())
200202
.build();
201203

DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/content/controller/ContentController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.dontbe.www.DontBeServer.api.content.dto.response.*;
55
import com.dontbe.www.DontBeServer.api.content.service.ContentCommandService;
66
import com.dontbe.www.DontBeServer.api.content.service.ContentQueryService;
7+
import com.dontbe.www.DontBeServer.api.member.service.MemberCommandService;
78
import com.dontbe.www.DontBeServer.common.response.ApiResponse;
89
import com.dontbe.www.DontBeServer.common.util.MemberUtil;
910
import io.swagger.v3.oas.annotations.Operation;

DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/content/service/ContentCommandService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ public void likeContent(Long memberId, Long contentId, ContentLikedRequestDto co
9595
isDuplicateContentLike(content, triggerMember);
9696

9797
Member targetMember = memberRepository.findMemberByIdOrThrow(content.getMember().getId());
98-
ContentLiked contentLiked = ContentLiked.builder()
98+
ContentLiked contentLiked = ContentLiked.builder()
9999
.content(content)
100100
.member(triggerMember)
101101
.build();
102102
ContentLiked savedContentLiked = contentLikedRepository.save(contentLiked);
103103

104104

105105
//위에가 게시물 좋아요 관련, 아래는 노티 테이블 채우기. 노티에 게시글 내용이 없어서 빈스트링 제공.
106-
if(triggerMember != targetMember) { //자신 게시물에 대한 좋아요 누르면 알림 발생 x
106+
if (triggerMember != targetMember) { //자신 게시물에 대한 좋아요 누르면 알림 발생 x
107107
Notification notification = Notification.builder()
108108
.notificationTargetMember(targetMember)
109109
.notificationTriggerMemberId(triggerMember.getId())
@@ -117,7 +117,7 @@ public void likeContent(Long memberId, Long contentId, ContentLikedRequestDto co
117117

118118
if (Boolean.TRUE.equals(targetMember.getIsPushAlarmAllowed())) {
119119
String FcmMessageTitle = triggerMember.getNickname() + "님이 " + targetMember.getNickname() + "님의 글을 좋아합니다.";
120-
120+
targetMember.increaseFcmBadge();
121121
FcmMessageDto contentLikeFcmMessage = FcmMessageDto.builder()
122122
.validateOnly(false)
123123
.message(FcmMessageDto.Message.builder()
@@ -131,6 +131,7 @@ public void likeContent(Long memberId, Long contentId, ContentLikedRequestDto co
131131
.description("게시글 좋아요 푸시 알림")
132132
.relateContentId(String.valueOf(contentId))
133133
.build())
134+
.badge(String.valueOf(targetMember.getFcmBadge()))
134135
.build())
135136
.build();
136137

@@ -139,6 +140,7 @@ public void likeContent(Long memberId, Long contentId, ContentLikedRequestDto co
139140
}
140141
}
141142

143+
142144
public void unlikeContent(Long memberId, Long contentId) {
143145
Member triggerMember = memberRepository.findMemberByIdOrThrow(memberId);
144146
Content content = contentRepository.findContentByIdOrThrow(contentId);

DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/controller/MemberController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.dontbe.www.DontBeServer.api.member.controller;
22

3+
import com.dontbe.www.DontBeServer.api.member.dto.request.MemberPatchFcmBadgeRequestDto;
34
import com.dontbe.www.DontBeServer.api.member.dto.request.MemberProfilePatchRequestDto;
45
import com.dontbe.www.DontBeServer.api.member.dto.request.MemberWithdrawalPatchRequestDto;
56
import com.dontbe.www.DontBeServer.api.member.dto.request.ProfilePatchRequestDto;
@@ -84,4 +85,12 @@ public ResponseEntity<ApiResponse<Object>> checkMemberNickname(Principal princip
8485
memberQueryService.checkNicknameValidate(memberId, nickname);
8586
return ApiResponse.success(NICKNAME_CHECK_SUCCESS);
8687
}
88+
89+
@PatchMapping(value = "fcmbadge")
90+
@Operation(summary = "유저 아이콘 배지 값 수정 API입니다.", description = "FcmBadgePatch")
91+
public ResponseEntity<ApiResponse<Object>> updateMemberFcmBadge(Principal principal, @RequestBody MemberPatchFcmBadgeRequestDto memberPatchFcmBadgeRequestDto) {
92+
Long memberId = MemberUtil.getMemberId(principal);
93+
memberCommandService.updateMemberFcmBadge(memberId,memberPatchFcmBadgeRequestDto);
94+
return ApiResponse.success(UPDATE_FCM_BADGE_SUCCESS);
95+
}
8796
}

DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/domain/Member.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public class Member extends BaseTimeEntity {
7373
@Column(name = "deleted_Reason")
7474
private String deletedReason;
7575

76+
@Column(name = "fcm_badge", columnDefinition = "INTEGER DEFAULT 0")
77+
private int fcmBadge;
78+
7679
@OneToMany(mappedBy = "notificationTargetMember",cascade = ALL)
7780
private List<Notification> targetNotification = new ArrayList<>();
7881

@@ -95,6 +98,7 @@ private Member(String nickname, SocialPlatform socialPlatform, String socialId,
9598
this.memberGhost = 0;
9699
this.memberEmail = memberEmail;
97100
this.socialNickname = socialNickname;
101+
this.fcmBadge = 0;
98102
}
99103

100104
public void decreaseGhost() {
@@ -133,4 +137,10 @@ public void softDelete() {
133137
public void updateMemberIsPushAlarmAllowed(boolean newIsPushAlarmAllowed) { this.isPushAlarmAllowed = newIsPushAlarmAllowed; }
134138

135139
public void updateMemberFcmToken(String newFcmToken) { this.fcmToken = newFcmToken; }
140+
141+
public void increaseFcmBadge() {this.fcmBadge++; }
142+
143+
public void resetFcmBadge() { this.fcmBadge = 0;}
144+
145+
public void updateFcmBadge(int newFcmBadge) { this.fcmBadge = newFcmBadge;}
136146
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.dontbe.www.DontBeServer.api.member.dto.request;
2+
3+
public record MemberPatchFcmBadgeRequestDto(
4+
int fcmBadge
5+
) {
6+
}

DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/member/service/MemberCommandService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.dontbe.www.DontBeServer.api.content.repository.ContentLikedRepository;
1212
import com.dontbe.www.DontBeServer.api.content.repository.ContentRepository;
1313
import com.dontbe.www.DontBeServer.api.member.domain.Member;
14+
import com.dontbe.www.DontBeServer.api.member.dto.request.MemberPatchFcmBadgeRequestDto;
1415
import com.dontbe.www.DontBeServer.api.member.dto.request.MemberProfilePatchRequestDto;
1516
import com.dontbe.www.DontBeServer.api.member.dto.request.MemberWithdrawalPatchRequestDto;
1617
import com.dontbe.www.DontBeServer.api.member.dto.request.ProfilePatchRequestDto;
@@ -167,6 +168,16 @@ public void updateMemberProfile2(Long memberId, MultipartFile multipartFile, Pro
167168
Member savedMember = memberRepository.save(existingMember);
168169
}
169170

171+
public void resetMemberFcmBadge(Long memberId) {
172+
Member member = memberRepository.findMemberByIdOrThrow(memberId);
173+
member.resetFcmBadge();
174+
}
175+
176+
public void updateMemberFcmBadge(Long memberId, MemberPatchFcmBadgeRequestDto memberPatchFcmBadgeRequestDto) {
177+
Member member = memberRepository.findMemberByIdOrThrow(memberId);
178+
member.updateFcmBadge(Math.max(memberPatchFcmBadgeRequestDto.fcmBadge(), 0));
179+
}
180+
170181
private static String removeBaseUrl(String fullUrl, String baseUrl) {
171182
if (fullUrl.startsWith(baseUrl)) {
172183
return fullUrl.substring(baseUrl.length());

DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/notification/controller/NotificationController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.dontbe.www.DontBeServer.api.notification.controller;
22

3+
import com.dontbe.www.DontBeServer.api.member.service.MemberCommandService;
34
import com.dontbe.www.DontBeServer.api.notification.dto.response.NotificaitonCountResponseDto;
45
import com.dontbe.www.DontBeServer.api.notification.service.NotificationCommandService;
56
import com.dontbe.www.DontBeServer.api.notification.service.NotificationQueryService;
@@ -24,6 +25,7 @@
2425
public class NotificationController {
2526
private final NotificationCommandService notificationCommandService;
2627
private final NotificationQueryService notificationQueryService;
28+
private final MemberCommandService memberCommandService;
2729

2830
@PatchMapping("notification-check")
2931
@Operation(summary = "노티 체크 API 입니다.",description = "NotificationCheck")
@@ -51,13 +53,15 @@ public ResponseEntity<ApiResponse<Object>> getNotification(Principal principal)
5153
@Operation(summary = "페이지네이션이 적용된 노티 전체 리스트 조회 API 입니다.",description = "NotificationGetPagination")
5254
public ResponseEntity<ApiResponse<Object>> getNotificationAllPagination(Principal principal,@RequestParam(value = "cursor") Long cursor) {
5355
Long memberId = MemberUtil.getMemberId(principal);
56+
memberCommandService.resetMemberFcmBadge(memberId);
5457
return ApiResponse.success(NOTIFICATION_ALL_SUCCESS, notificationQueryService.getNotificationAllPagination(memberId, cursor));
5558
}
5659

5760
@GetMapping("notifications")
5861
@Operation(summary = "노티 전체 리스트 조회 ver3 API 입니다.",description = "GetNotificationsVer3")
5962
public ResponseEntity<ApiResponse<Object>> getNotifications(Principal principal,@RequestParam(value = "cursor") Long cursor) {
6063
Long memberId = MemberUtil.getMemberId(principal);
64+
memberCommandService.resetMemberFcmBadge(memberId);
6165
return ApiResponse.success(NOTIFICATION_ALL_SUCCESS, notificationQueryService.getNotifications(memberId, cursor));
6266
}
6367
}

DontBeServer/src/main/java/com/dontbe/www/DontBeServer/common/crontab/PopularContentScheduler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void popularContentNotification() {
6969

7070
if(Boolean.TRUE.equals(topContentWriter.getIsPushAlarmAllowed())) {
7171
String FcmMessageTitle = topContentWriter.getNickname() + "님이 작성하신 글이 인기들로 선정 되었어요.";
72-
72+
topContentWriter.increaseFcmBadge();
7373
FcmMessageDto popularContentFcmMessage = FcmMessageDto.builder()
7474
.validateOnly(false)
7575
.message(FcmMessageDto.Message.builder()
@@ -83,6 +83,7 @@ public void popularContentNotification() {
8383
.description("인기글 관련 푸시 알림")
8484
.relateContentId(String.valueOf(topContent.getId()))
8585
.build())
86+
.badge(String.valueOf(topContentWriter.getFcmBadge()))
8687
.build())
8788
.build();
8889

DontBeServer/src/main/java/com/dontbe/www/DontBeServer/common/response/SuccessStatus.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public enum SuccessStatus {
2626
CONTENT_UNLIKE_SUCCESS(HttpStatus.OK,"게시글 좋아요 취소 성공"),
2727
GET_CONTENT_ALL_SUCCESS(HttpStatus.OK, "게시물 리스트 조회 성공"),
2828
GET_MEMBER_CONTENT_SUCCESS(HttpStatus.OK,"유저에 해당하는 게시글 리스트 조회"),
29+
UPDATE_FCM_BADGE_SUCCESS(HttpStatus.OK, "유저의 배지값 수정 완료"),
2930

3031
/**
3132
* comment

0 commit comments

Comments
 (0)