Skip to content

Commit

Permalink
Merge pull request #282 from Team-Smeme/unan#280
Browse files Browse the repository at this point in the history
[REFACTOR] DiscordAlarmSender -> DiscordService interface로 교체
  • Loading branch information
unanchoi authored May 8, 2024
2 parents c4046ee + df41105 commit d30e709
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.smeem.domain.plan.adapter.PlanFinder;
import com.smeem.domain.training.model.DayType;
import com.smeem.domain.training.model.TrainingTime;
import com.smeem.external.discord.DiscordAlarmSender;
import com.smeem.external.discord.AlarmService;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class MemberService {
private final TrainingTimeService trainingTimeService;
private final GoalService goalService;
private final MemberBadgeService memberBadgeService;
private final DiscordAlarmSender discordAlarmSender;
private final AlarmService alarmService;
private final ValueConfig valueConfig;

@Transactional
Expand All @@ -59,7 +59,7 @@ public MemberUpdateServiceResponse updateUserProfile(final MemberServiceUpdateUs
ArrayList<Badge> badges = new ArrayList<>();
if (isNewMember(member)) {
addWelcomeBadge(member, badges);
discordAlarmSender.send(SIGN_IN_MESSAGE + member.getId(), INFO);
alarmService.send(SIGN_IN_MESSAGE + member.getId(), INFO);
}
member.updateUsername(request.username());
return MemberUpdateServiceResponse.of(badges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.smeem.domain.plan.exception.PlanException;
import com.smeem.domain.topic.exception.TopicException;
import com.smeem.domain.training.exception.TrainingTimeException;
import com.smeem.external.discord.DiscordAlarmSender;
import com.smeem.external.discord.AlarmService;
import com.smeem.external.firebase.exception.FcmException;
import com.smeem.external.oauth.apple.exception.AppleException;
import com.smeem.external.oauth.exception.AuthException;
Expand All @@ -25,7 +25,7 @@
@RequiredArgsConstructor
public class ExceptionInterceptor {

private final DiscordAlarmSender discordAlarmSender;
private final AlarmService alarmService;

@ExceptionHandler(TrainingTimeException.class)
public ResponseEntity<FailureResponse> trainingTimeException(TrainingTimeException exception) {
Expand Down Expand Up @@ -89,6 +89,6 @@ public ResponseEntity<FailureResponse> baseException(RuntimeException exception)
}

private void sendDiscordAlarm(RuntimeException exception) {
discordAlarmSender.send(exception.getMessage(), ERROR);
alarmService.send(exception.getMessage(), ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.smeem.external.discord;

public interface AlarmService {
void send(String content, DiscordAlarmCase alarmCase);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
@Component
@RequiredArgsConstructor
@Slf4j
public class DiscordAlarmSender {
public class DiscordAlarmService implements AlarmService {

private static final String APPLICATION_JSON_UTF8_VALUE = "application/json; UTF-8";

private final ObjectMapper objectMapper;
private final ValueConfig valueConfig;
private final Environment environment;

@Override
public void send(final String content, final DiscordAlarmCase alarmCase) {
try {
val restClient = RestClient.create();
Expand Down

0 comments on commit d30e709

Please sign in to comment.