Skip to content

Commit

Permalink
[#112] 리팩토링
Browse files Browse the repository at this point in the history
- discord, notification send 비동기 처리
  • Loading branch information
JAEHEE25 committed Dec 11, 2024
1 parent e2a4e46 commit 9af0600
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;

Expand All @@ -20,11 +21,13 @@ public class DiscordService {

private final WebClient webClient = WebClient.create(webhookUrl);

public void sendMessage(DiscordEventMessage eventMessage, String nickname) {
@Async
public void sendMessage(DiscordEventMessage eventMessage, String nickname) {
DiscordMessage discordMessage = DiscordMessage.of(eventMessage.getUserMessage(nickname));
sendMessageToDiscord(discordMessage);
}

@Async
public void sendMessage(DiscordEventMessage eventMessage, String nickname, String groupTitle) {
DiscordMessage discordMessage = DiscordMessage.of(eventMessage.getGroupMessage(nickname, groupTitle));
sendMessageToDiscord(discordMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.transaction.annotation.Transactional;

import io.driver.codrive.global.exception.InternalServerErrorApplicationException;
import io.driver.codrive.global.exception.NotFoundApplcationException;
import io.driver.codrive.global.exception.NotFoundApplicationException;
import io.driver.codrive.global.util.AuthUtils;
import io.driver.codrive.modules.notification.domain.Notification;
import io.driver.codrive.modules.notification.domain.NotificationRepository;
Expand Down Expand Up @@ -48,7 +48,6 @@ public Flux<ServerSentEvent<NotificationEventDto>> registerUser() {
}

@Async
@Transactional
public void sendNotification(User user, Long dataId, NotificationType type, String... args) {
Notification notification = createNotification(user, dataId, type, args);
Long userId = user.getUserId();
Expand All @@ -59,7 +58,6 @@ public void sendNotification(User user, Long dataId, NotificationType type, Stri
}
}

@Transactional
protected Notification createNotification(User user, Long dataId, NotificationType type, String... args) {
Notification notification = Notification.create(user, dataId, type, args);
return notificationRepository.save(notification);
Expand Down Expand Up @@ -96,7 +94,7 @@ public void readNotification(NotificationReadRequest request) {
List<Long> notificationIds = request.notificationIds();
notificationIds.forEach(id ->
notificationRepository.findById(id)
.orElseThrow(() -> new NotFoundApplcationException("알림이 존재하지 않습니다."))
.orElseThrow(() -> new NotFoundApplicationException("알림이 존재하지 않습니다."))
.changeIsRead(true));
}
}

0 comments on commit 9af0600

Please sign in to comment.