Skip to content

Commit 3093fe1

Browse files
authored
Merge pull request #131 from My-Medi/develop
hotfix : not send to user/expert because of key
2 parents 25c72ec + 8b1b36e commit 3093fe1

7 files changed

Lines changed: 22 additions & 10 deletions

File tree

src/main/java/com/my_medi/api/common/dto/NotificationEventDto.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public class NotificationEventDto {
1414
@Builder
1515
@AllArgsConstructor
1616
public static class UserNotificationEventDto{
17+
private String username;
1718
private UserNotificationDto userNotificationDto;
1819
}
1920

2021
@Data
2122
@Builder
2223
@AllArgsConstructor
2324
public static class ExpertNotificationEventDto{
25+
private String username;
2426
private ExpertNotificationDto expertNotificationDto;
2527
}
2628

src/main/java/com/my_medi/api/common/service/SseService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface SseService {
99

1010
SseEmitter connectExpert(String expertUsername);
1111

12-
void sendToUser(Long userId, Object notification);
12+
void sendToUser(String userUsername, Object notification);
1313

14-
void sendToExpert(Long expertId, Object notification);
14+
void sendToExpert(String expertUsername, Object notification);
1515
}

src/main/java/com/my_medi/api/common/service/SseServiceImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public SseEmitter connectExpert(String expertUsername) {
7474
}
7575

7676
@Override
77-
public void sendToUser(Long userId, Object notification) {
78-
String key = "user_" + userId;
77+
public void sendToUser(String userUsername, Object notification) {
78+
String key = "user_" + userUsername;
7979
SseEmitter emitter = userEmitters.get(key);
8080

8181
if (emitter != null) {
@@ -84,15 +84,15 @@ public void sendToUser(Long userId, Object notification) {
8484
.name("notification")
8585
.data(notification));
8686
} catch (IOException e) {
87-
log.error("Failed to send notification to user {}", userId, e);
87+
log.error("Failed to send notification to user {}", userUsername, e);
8888
userEmitters.remove(key);
8989
}
9090
}
9191
}
9292

9393
@Override
94-
public void sendToExpert(Long expertId, Object notification) {
95-
String key = "expert_" + expertId;
94+
public void sendToExpert(String expertUsername, Object notification) {
95+
String key = "expert_" + expertUsername;
9696
SseEmitter emitter = expertEmitters.get(key);
9797

9898
if (emitter != null) {
@@ -101,7 +101,7 @@ public void sendToExpert(Long expertId, Object notification) {
101101
.name("notification")
102102
.data(notification));
103103
} catch (IOException e) {
104-
log.error("Failed to send notification to expert {}", expertId, e);
104+
log.error("Failed to send notification to expert {}", expertUsername, e);
105105
expertEmitters.remove(key);
106106
}
107107
}

src/main/java/com/my_medi/api/consultation/service/ConsultationUseCase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public void approveConsultationRequestAndSendNotificationToUser(Expert expert, L
6464
//sse
6565
applicationEventPublisher.publishEvent(
6666
new NotificationEventDto.UserNotificationEventDto(
67+
userNotification.getUser().getUsername(),
6768
UserNotificationConverter.toUserNotification(userNotification)
6869
)
6970
);
@@ -85,6 +86,7 @@ public void rejectConsultationRequestAndSendNotificationToUser(Expert expert, Lo
8586
//sse
8687
applicationEventPublisher.publishEvent(
8788
new NotificationEventDto.UserNotificationEventDto(
89+
userNotification.getUser().getUsername(),
8890
UserNotificationConverter.toUserNotification(userNotification)
8991
)
9092
);
@@ -102,6 +104,7 @@ public Long sendConsultationRequestNotificationToExpert(User user, Long expertId
102104
//sse
103105
applicationEventPublisher.publishEvent(
104106
new NotificationEventDto.ExpertNotificationEventDto(
107+
expertNotification.getExpert().getUsername(),
105108
ExpertNotificationConverter.toExpertNotification(expertNotification)
106109
)
107110
);

src/main/java/com/my_medi/api/expertNotification/service/ExpertNotificationEventListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import lombok.RequiredArgsConstructor;
1010
import org.springframework.context.event.EventListener;
1111
import org.springframework.scheduling.annotation.Async;
12+
import org.springframework.security.core.Authentication;
13+
import org.springframework.security.core.context.SecurityContextHolder;
1214
import org.springframework.stereotype.Component;
1315
import org.springframework.stereotype.Service;
1416
import org.springframework.transaction.event.TransactionalEventListener;
@@ -27,7 +29,7 @@ public class ExpertNotificationEventListener {
2729
@TransactionalEventListener(phase = AFTER_COMMIT, fallbackExecution=true)
2830
public void handleSendingNotificationEvent(ExpertNotificationEventDto expertNotification) {
2931
sseService.sendToExpert(
30-
expertNotification.getExpertNotificationDto().getExpertId(),
32+
expertNotification.getUsername(),
3133
expertNotification
3234
);
3335
}

src/main/java/com/my_medi/api/schedule/service/ScheduleUseCase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public Long registerScheduleAndSendNotificationToUser(
3434
//sse
3535
applicationEventPublisher.publishEvent(
3636
new NotificationEventDto.UserNotificationEventDto(
37+
userNotification.getUser().getUsername(),
3738
UserNotificationConverter.toUserNotification(userNotification)
3839
)
3940
);

src/main/java/com/my_medi/api/userNotification/service/UserNotificationEventListener.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
import com.my_medi.api.userNotification.mapper.UserNotificationConverter;
88
import com.my_medi.domain.notification.entity.UserNotification;
99
import lombok.RequiredArgsConstructor;
10+
import lombok.extern.slf4j.Slf4j;
1011
import org.springframework.context.event.EventListener;
1112
import org.springframework.scheduling.annotation.Async;
13+
import org.springframework.security.core.Authentication;
14+
import org.springframework.security.core.context.SecurityContextHolder;
1215
import org.springframework.stereotype.Component;
1316
import org.springframework.stereotype.Service;
1417
import org.springframework.transaction.event.TransactionalEventListener;
1518

1619
import static com.my_medi.api.userNotification.dto.UserNotificationResponseDto.*;
1720
import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT;
1821

22+
@Slf4j
1923
@Component
2024
@RequiredArgsConstructor
2125
public class UserNotificationEventListener {
@@ -25,7 +29,7 @@ public class UserNotificationEventListener {
2529
@TransactionalEventListener(phase = AFTER_COMMIT, fallbackExecution=true)
2630
public void handleSendingNotificationEvent(UserNotificationEventDto userNotification){
2731
sseService.sendToUser(
28-
userNotification.getUserNotificationDto().getUserId(),
32+
userNotification.getUsername(),
2933
userNotification
3034
);
3135
}

0 commit comments

Comments
 (0)