Skip to content

Commit

Permalink
Merge pull request #112 from Team-Shaka/fix/111
Browse files Browse the repository at this point in the history
🐛 Fix: 아직 회원가입 하지 않은 사람에게 초대장을 보낸 경우, 알림 데이터 생성하지 않도록 수정
  • Loading branch information
koojun99 authored Aug 30, 2024
2 parents 2b514b2 + a76ea3e commit b3c08fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,20 @@ public InvitationResponseDTO.createInvitation createInvitation(User user, Invita
Member sender = memberQueryAdapter.findByUserAndTreehouse(user, treehouse);
// 초대 대상이 가입된 사람인지 찾기

User receiverUser = null;
User receiverUser = userQueryAdapter.findByPhoneNumberOptional(request.getPhoneNumber()).orElse(null);

try {
receiverUser = userQueryAdapter.findByPhoneNumber(request.getPhoneNumber());
}
catch (UserException e){
// 뭐 안함
}
// 초대장 만들어서 저장하기

Invitation invitation = invitationCommandAdapter.saveInvitation(InvitationMapper.toInvitation(request.getPhoneNumber(), sender, receiverUser, treehouse));

//알림 생성
NotificationRequestDTO.createNotification notificationRequest = new NotificationRequestDTO.createNotification();
notificationRequest.setReceiverId(receiverUser.getId()); // 여기서 receiver 설정 (예시)
notificationRequest.setTargetId(invitation.getId());
notificationRequest.setType(NotificationType.INVITATION); // 알림 타입 설정 (예시)
notificationService.createNotification(user, invitation.getTreeHouse().getId(), notificationRequest, null);

if (receiverUser != null) {
NotificationRequestDTO.createNotification notificationRequest = new NotificationRequestDTO.createNotification();
notificationRequest.setReceiverId(receiverUser.getId()); // 여기서 receiver 설정 (예시)
notificationRequest.setTargetId(invitation.getId());
notificationRequest.setType(NotificationType.INVITATION); // 알림 타입 설정 (예시)
notificationService.createNotification(user, invitation.getTreeHouse().getId(), notificationRequest, null);
}
// 리턴하기

return InvitationMapper.toCreateInvitationDTO(invitation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public class NotificationService {
public void createNotification(User user, Long treehouseId, NotificationRequestDTO.createNotification request, String reactionName) {
TreeHouse treeHouse = treehouseQueryAdapter.getTreehouseById(treehouseId);
Member sender = memberQueryAdapter.findByUserAndTreehouse(user, treeHouse);
User receiver = userQueryAdapter.findById(request.getReceiverId());
User receiver = userQueryAdapter.findByIdOptional(request.getReceiverId()).orElse(null);
Notification notification = NotificationMapper.toNotification(sender, receiver, request, reactionName);
if(user.isPushAgree()) {
if(user.isPushAgree() && receiver != null) {
fcmService.sendFcmMessage(receiver, notification.getTitle(), notification.getBody());
}
notificationCommandAdapter.createNotification(notification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ public User findByPhoneNumber(String phone){
return userRepository.findByPhone(phone).orElseThrow(()->new UserException(GlobalErrorCode.USER_NOT_FOUND));
}

public Optional<User> findByPhoneNumberOptional(String phone){
return userRepository.findByPhone(phone);
}

public User findById(Long id){
return userRepository.findById(id).orElseThrow(()->new UserException(GlobalErrorCode.USER_NOT_FOUND));
}

public Optional<User> findByIdOptional(Long id){
return userRepository.findById(id);
}

public Optional<User> optionalUserFindById(Long id){
return userRepository.findById(id);
}
Expand Down

0 comments on commit b3c08fb

Please sign in to comment.