Skip to content

Commit b3c08fb

Browse files
authored
Merge pull request #112 from Team-Shaka/fix/111
🐛 Fix: 아직 회원가입 하지 않은 사람에게 초대장을 보낸 경우, 알림 데이터 생성하지 않도록 수정
2 parents 2b514b2 + a76ea3e commit b3c08fb

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/main/java/treehouse/server/api/invitation/business/InvitationService.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,20 @@ public InvitationResponseDTO.createInvitation createInvitation(User user, Invita
7777
Member sender = memberQueryAdapter.findByUserAndTreehouse(user, treehouse);
7878
// 초대 대상이 가입된 사람인지 찾기
7979

80-
User receiverUser = null;
80+
User receiverUser = userQueryAdapter.findByPhoneNumberOptional(request.getPhoneNumber()).orElse(null);
8181

82-
try {
83-
receiverUser = userQueryAdapter.findByPhoneNumber(request.getPhoneNumber());
84-
}
85-
catch (UserException e){
86-
// 뭐 안함
87-
}
8882
// 초대장 만들어서 저장하기
8983

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

9286
//알림 생성
93-
NotificationRequestDTO.createNotification notificationRequest = new NotificationRequestDTO.createNotification();
94-
notificationRequest.setReceiverId(receiverUser.getId()); // 여기서 receiver 설정 (예시)
95-
notificationRequest.setTargetId(invitation.getId());
96-
notificationRequest.setType(NotificationType.INVITATION); // 알림 타입 설정 (예시)
97-
notificationService.createNotification(user, invitation.getTreeHouse().getId(), notificationRequest, null);
98-
87+
if (receiverUser != null) {
88+
NotificationRequestDTO.createNotification notificationRequest = new NotificationRequestDTO.createNotification();
89+
notificationRequest.setReceiverId(receiverUser.getId()); // 여기서 receiver 설정 (예시)
90+
notificationRequest.setTargetId(invitation.getId());
91+
notificationRequest.setType(NotificationType.INVITATION); // 알림 타입 설정 (예시)
92+
notificationService.createNotification(user, invitation.getTreeHouse().getId(), notificationRequest, null);
93+
}
9994
// 리턴하기
10095

10196
return InvitationMapper.toCreateInvitationDTO(invitation);

src/main/java/treehouse/server/api/notification/business/NotificationService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public class NotificationService {
4646
public void createNotification(User user, Long treehouseId, NotificationRequestDTO.createNotification request, String reactionName) {
4747
TreeHouse treeHouse = treehouseQueryAdapter.getTreehouseById(treehouseId);
4848
Member sender = memberQueryAdapter.findByUserAndTreehouse(user, treeHouse);
49-
User receiver = userQueryAdapter.findById(request.getReceiverId());
49+
User receiver = userQueryAdapter.findByIdOptional(request.getReceiverId()).orElse(null);
5050
Notification notification = NotificationMapper.toNotification(sender, receiver, request, reactionName);
51-
if(user.isPushAgree()) {
51+
if(user.isPushAgree() && receiver != null) {
5252
fcmService.sendFcmMessage(receiver, notification.getTitle(), notification.getBody());
5353
}
5454
notificationCommandAdapter.createNotification(notification);

src/main/java/treehouse/server/api/user/implement/UserQueryAdapter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,18 @@ public User findByPhoneNumber(String phone){
3030
return userRepository.findByPhone(phone).orElseThrow(()->new UserException(GlobalErrorCode.USER_NOT_FOUND));
3131
}
3232

33+
public Optional<User> findByPhoneNumberOptional(String phone){
34+
return userRepository.findByPhone(phone);
35+
}
36+
3337
public User findById(Long id){
3438
return userRepository.findById(id).orElseThrow(()->new UserException(GlobalErrorCode.USER_NOT_FOUND));
3539
}
3640

41+
public Optional<User> findByIdOptional(Long id){
42+
return userRepository.findById(id);
43+
}
44+
3745
public Optional<User> optionalUserFindById(Long id){
3846
return userRepository.findById(id);
3947
}

0 commit comments

Comments
 (0)