Skip to content

Commit

Permalink
Merge pull request #140 from TeamSobokSobok/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
dev-Crayon authored Jun 3, 2024
2 parents 7c8fbe1 + c808c65 commit af69793
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public ResponseEntity<ApiResponse<JwtTokenResponse>> refresh(
description = "소복소복 서비스를 탈퇴하는 API 입니다."
)
public ResponseEntity<ApiResponse<Void>> leave(
@RequestBody @Valid final LeaveRequest request,
@RequestBody final LeaveRequest request,
@AuthenticationPrincipal User user
) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package io.sobok.SobokSobok.auth.ui.dto;

import jakarta.validation.constraints.NotBlank;

public record LeaveRequest(

@NotBlank
String text
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,44 @@ public void sendNotificationByToken(PushNotificationRequest request) {
sendMessageToFirebase(message, user.getId());
}

public void sendNotificationByTokenWithFriendData(PushNotificationRequest request) {
User user = UserServiceUtil.findUserById(userRepository, request.userId());

Message message = Message.builder()
.setToken(user.getDeviceToken())
.setNotification(
Notification.builder()
.setTitle(request.title())
.setBody(request.body())
.build()
)
.setAndroidConfig(
AndroidConfig.builder()
.setNotification(
AndroidNotification.builder()
.setTitle(request.title())
.setBody(request.body())
.setClickAction("push_click")
.build()
)
.build()
)
.setApnsConfig(
ApnsConfig.builder()
.setAps(Aps.builder()
.setCategory("push_click")
.build())
.build()
)
.putData("title", request.title())
.putData("body", request.body() == null ? "" : request.body())
.putData("type", request.type())
.putData("friendId", request.data().get("friendId"))
.build();

sendMessageToFirebase(message, user.getId());
}

private void sendMessageToFirebase(Message message, Long userId) {
try {
firebaseMessaging.send(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -150,16 +151,17 @@ public HandleFriendRequestResponse updateNoticeStatus(Long userId, Long noticeId
sender.getUsername()
));

fcmPushService.sendNotificationByToken(PushNotificationRequest.builder()
fcmPushService.sendNotificationByTokenWithFriendData(PushNotificationRequest.builder()
.userId(sender.getId())
.title(receiver.getUsername() + "님이 친구를 수락했어요")
.type("notice")
.type("share")
.data(Map.of("friendId", Long.toString(userId)))
.build());
} else {
fcmPushService.sendNotificationByToken(PushNotificationRequest.builder()
.userId(sender.getId())
.title(receiver.getUsername() + "님이 친구를 거절했어요")
.type("notice")
.type("notice")
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Service
Expand All @@ -47,6 +49,8 @@ public NoticeResponse getList(Long userId) {
User user = UserServiceUtil.findUserById(userRepository, userId);

List<NoticeInfo> noticeList = noticeQueryRepository.getNoticeList(userId);
Comparator<NoticeInfo> compareByCreatedAt = Comparator.comparing(NoticeInfo::createdAt).reversed();
noticeList.sort(compareByCreatedAt);

return NoticeResponse.builder()
.username(user.getUsername())
Expand Down

0 comments on commit af69793

Please sign in to comment.