From c0f98600a6c6f111df49bac8be19305d81dc9c2f Mon Sep 17 00:00:00 2001 From: yang Date: Mon, 29 Apr 2024 02:42:59 +0900 Subject: [PATCH 1/3] =?UTF-8?q?RAC-351=20HotFix=20:=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=ED=86=A1=20=EC=98=88=EC=99=B8=20=EB=B0=9C=EC=83=9D=EC=8B=9C=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=98=81=ED=96=A5=20=EC=97=86=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/BizppurioJuniorMessage.java | 62 +++++++++----- .../usecase/BizppurioSeniorMessage.java | 82 ++++++++++++------- 2 files changed, 92 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java index 03978daa..f1426c88 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java @@ -1,5 +1,6 @@ package com.postgraduate.global.bizppurio.usecase; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; @@ -27,43 +28,60 @@ public class BizppurioJuniorMessage { private String messageUrl; public void mentoringApply(User user) { - CommonRequest commonRequest = mapper.mapToJuniorApplyMessage(user); - sendMessage(commonRequest); + try { + CommonRequest commonRequest = mapper.mapToJuniorApplyMessage(user); + sendMessage(commonRequest); + } catch (Exception ex) { + log.error("알림톡 전송 예외 발생"); + log.error("{}", ex.getMessage()); + } } public void mentoringAccept(User user, Senior senior, String time) { - String chatLink = senior.getProfile().getChatLink(); - CommonRequest commonRequest = mapper.mapToJuniorAcceptMessage(user, chatLink, time); - sendMessage(commonRequest); + try { + String chatLink = senior.getProfile().getChatLink(); + CommonRequest commonRequest = mapper.mapToJuniorAcceptMessage(user, chatLink, time); + sendMessage(commonRequest); + } catch (Exception ex) { + log.error("알림톡 전송 예외 발생"); + log.error("{}", ex.getMessage()); + } } public void mentoringRefuse(User user) { - CommonRequest commonRequest = mapper.mapToJuniorRefuseMessage(user); - sendMessage(commonRequest); - } + try { + CommonRequest commonRequest = mapper.mapToJuniorRefuseMessage(user); + sendMessage(commonRequest); + } catch (Exception ex) { + log.error("알림톡 전송 예외 발생"); + log.error("{}", ex.getMessage()); + } - public void mentoringFinish(User user) { - CommonRequest commonRequest = mapper.mapToJuniorFinish(user); - sendMessage(commonRequest); } - private void sendMessage(CommonRequest commonRequest) { + public void mentoringFinish(User user) { try { - String accessToken = bizppurioAuth.getAuth(); - String request = objectMapper.writeValueAsString(commonRequest); - webClient.post() - .uri(messageUrl) - .headers(h -> h.setContentType(APPLICATION_JSON)) - .headers(h -> h.setBearerAuth(accessToken)) - .bodyValue(request) - .retrieve() - .bodyToMono(MessageResponse.class) - .subscribe(this::check); + CommonRequest commonRequest = mapper.mapToJuniorFinish(user); + sendMessage(commonRequest); } catch (Exception ex) { log.error("알림톡 전송 예외 발생"); + log.error("{}", ex.getMessage()); } } + private void sendMessage(CommonRequest commonRequest) throws JsonProcessingException { + String accessToken = bizppurioAuth.getAuth(); + String request = objectMapper.writeValueAsString(commonRequest); + webClient.post() + .uri(messageUrl) + .headers(h -> h.setContentType(APPLICATION_JSON)) + .headers(h -> h.setBearerAuth(accessToken)) + .bodyValue(request) + .retrieve() + .bodyToMono(MessageResponse.class) + .subscribe(this::check); + } + private void check(MessageResponse response) { if (response.code() != 1000) { log.error("전송실패 errorCode : {} errorMessage : {}", response.code(), response.description()); diff --git a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java index 49eb346c..fb0d808a 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java @@ -11,11 +11,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.client.WebClient; -import static com.postgraduate.global.bizppurio.mapper.BizppurioMapper.*; import static org.springframework.http.MediaType.APPLICATION_JSON; @RequiredArgsConstructor @@ -31,55 +28,80 @@ public class BizppurioSeniorMessage { private String messageUrl; public void signUp(User user) { - CommonRequest commonRequest = mapper.mapToSeniorSignUpMessage(user); - sendMessage(commonRequest); + try { + CommonRequest commonRequest = mapper.mapToSeniorSignUpMessage(user); + sendMessage(commonRequest); + } catch (Exception ex) { + log.error("알림톡 전송 예외 발생"); + log.error("{}", ex.getMessage()); + } } public void mentoringApply(User user) { - CommonRequest commonRequest = mapper.mapToSeniorApplyMessage(user); - sendMessage(commonRequest); + try { + CommonRequest commonRequest = mapper.mapToSeniorApplyMessage(user); + sendMessage(commonRequest); + } catch (Exception ex) { + log.error("알림톡 전송 예외 발생"); + log.error("{}", ex.getMessage()); + } } public void mentoringAccept(Senior senior, String time) { - User user = senior.getUser(); - String chatLink = senior.getProfile().getChatLink(); - CommonRequest commonRequest = mapper.mapToSeniorAcceptMessage(user, chatLink, time); - sendMessage(commonRequest); + try { + User user = senior.getUser(); + String chatLink = senior.getProfile().getChatLink(); + CommonRequest commonRequest = mapper.mapToSeniorAcceptMessage(user, chatLink, time); + sendMessage(commonRequest); + } catch (Exception ex) { + log.error("알림톡 전송 예외 발생"); + log.error("{}", ex.getMessage()); + } } public void certificationApprove(User user) { - CommonRequest commonRequest = mapper.mapToCertificationApprove(user); - sendMessage(commonRequest); + try { + CommonRequest commonRequest = mapper.mapToCertificationApprove(user); + sendMessage(commonRequest); + } catch (Exception ex) { + log.error("알림톡 전송 예외 발생"); + log.error("{}", ex.getMessage()); + } } public void certificationDenied(User user) { - CommonRequest commonRequest = mapper.mapToCertificationDenied(user); - sendMessage(commonRequest); + try { + CommonRequest commonRequest = mapper.mapToCertificationDenied(user); + sendMessage(commonRequest); + } catch (Exception ex) { + log.error("알림톡 전송 예외 발생"); + log.error("{}", ex.getMessage()); + } } public void mentoringFinish(User user) { - CommonRequest commonRequest = mapper.mapToSeniorFinish(user); - sendMessage(commonRequest); - } - - private void sendMessage(CommonRequest commonRequest) { try { - String accessToken = bizppurioAuth.getAuth(); - String request = objectMapper.writeValueAsString(commonRequest); - webClient.post() - .uri(messageUrl) - .headers(h -> h.setContentType(APPLICATION_JSON)) - .headers(h -> h.setBearerAuth(accessToken)) - .bodyValue(request) - .retrieve() - .bodyToMono(MessageResponse.class) - .subscribe(this::check); + CommonRequest commonRequest = mapper.mapToSeniorFinish(user); + sendMessage(commonRequest); } catch (Exception ex) { log.error("알림톡 전송 예외 발생"); log.error("{}", ex.getMessage()); } } + private void sendMessage(CommonRequest commonRequest) throws JsonProcessingException { + String accessToken = bizppurioAuth.getAuth(); + String request = objectMapper.writeValueAsString(commonRequest); + webClient.post() + .uri(messageUrl) + .headers(h -> h.setContentType(APPLICATION_JSON)) + .headers(h -> h.setBearerAuth(accessToken)) + .bodyValue(request) + .retrieve() + .bodyToMono(MessageResponse.class) + .subscribe(this::check); + } + private void check(MessageResponse response) { if (response.code() != 1000) { log.error("전송실패 errorCode : {} errorMessage : {}", response.code(), response.description()); From 5d06c68758c19d2b4a2d22dab156e791229af339 Mon Sep 17 00:00:00 2001 From: yang Date: Mon, 29 Apr 2024 03:03:37 +0900 Subject: [PATCH 2/3] =?UTF-8?q?RAC-351=20fix=20:=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/BizppurioJuniorMessage.java | 63 ++++++--------- .../usecase/BizppurioSeniorMessage.java | 77 ++++++------------- 2 files changed, 47 insertions(+), 93 deletions(-) diff --git a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java index f1426c88..be7d6923 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java @@ -1,6 +1,5 @@ package com.postgraduate.global.bizppurio.usecase; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; @@ -13,6 +12,8 @@ import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; +import java.util.function.Supplier; + import static org.springframework.http.MediaType.APPLICATION_JSON; @RequiredArgsConstructor @@ -28,60 +29,42 @@ public class BizppurioJuniorMessage { private String messageUrl; public void mentoringApply(User user) { - try { - CommonRequest commonRequest = mapper.mapToJuniorApplyMessage(user); - sendMessage(commonRequest); - } catch (Exception ex) { - log.error("알림톡 전송 예외 발생"); - log.error("{}", ex.getMessage()); - } + sendMessageWithExceptionHandling(() -> mapper.mapToJuniorApplyMessage(user)); } public void mentoringAccept(User user, Senior senior, String time) { - try { + sendMessageWithExceptionHandling(() -> { String chatLink = senior.getProfile().getChatLink(); - CommonRequest commonRequest = mapper.mapToJuniorAcceptMessage(user, chatLink, time); - sendMessage(commonRequest); - } catch (Exception ex) { - log.error("알림톡 전송 예외 발생"); - log.error("{}", ex.getMessage()); - } + return mapper.mapToJuniorAcceptMessage(user, chatLink, time); + }); } public void mentoringRefuse(User user) { - try { - CommonRequest commonRequest = mapper.mapToJuniorRefuseMessage(user); - sendMessage(commonRequest); - } catch (Exception ex) { - log.error("알림톡 전송 예외 발생"); - log.error("{}", ex.getMessage()); - } - + sendMessageWithExceptionHandling(() -> mapper.mapToJuniorRefuseMessage(user)); } public void mentoringFinish(User user) { + sendMessageWithExceptionHandling(() -> mapper.mapToJuniorFinish(user)); + } + + private void sendMessageWithExceptionHandling(Supplier messageSupplier) { try { - CommonRequest commonRequest = mapper.mapToJuniorFinish(user); - sendMessage(commonRequest); + CommonRequest commonRequest = messageSupplier.get(); + String accessToken = bizppurioAuth.getAuth(); + String request = objectMapper.writeValueAsString(commonRequest); + webClient.post() + .uri(messageUrl) + .headers(h -> h.setContentType(APPLICATION_JSON)) + .headers(h -> h.setBearerAuth(accessToken)) + .bodyValue(request) + .retrieve() + .bodyToMono(MessageResponse.class) + .subscribe(this::check); } catch (Exception ex) { - log.error("알림톡 전송 예외 발생"); - log.error("{}", ex.getMessage()); + log.error("알림톡 전송 예외 발생: {}", ex.getMessage()); } } - private void sendMessage(CommonRequest commonRequest) throws JsonProcessingException { - String accessToken = bizppurioAuth.getAuth(); - String request = objectMapper.writeValueAsString(commonRequest); - webClient.post() - .uri(messageUrl) - .headers(h -> h.setContentType(APPLICATION_JSON)) - .headers(h -> h.setBearerAuth(accessToken)) - .bodyValue(request) - .retrieve() - .bodyToMono(MessageResponse.class) - .subscribe(this::check); - } - private void check(MessageResponse response) { if (response.code() != 1000) { log.error("전송실패 errorCode : {} errorMessage : {}", response.code(), response.description()); diff --git a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java index fb0d808a..8bbaa9bf 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java @@ -1,6 +1,5 @@ package com.postgraduate.global.bizppurio.usecase; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; @@ -14,6 +13,7 @@ import org.springframework.web.reactive.function.client.WebClient; import static org.springframework.http.MediaType.APPLICATION_JSON; +import java.util.function.Supplier; @RequiredArgsConstructor @Component @@ -28,80 +28,51 @@ public class BizppurioSeniorMessage { private String messageUrl; public void signUp(User user) { - try { - CommonRequest commonRequest = mapper.mapToSeniorSignUpMessage(user); - sendMessage(commonRequest); - } catch (Exception ex) { - log.error("알림톡 전송 예외 발생"); - log.error("{}", ex.getMessage()); - } + sendMessageWithExceptionHandling(() -> mapper.mapToSeniorSignUpMessage(user)); } public void mentoringApply(User user) { - try { - CommonRequest commonRequest = mapper.mapToSeniorApplyMessage(user); - sendMessage(commonRequest); - } catch (Exception ex) { - log.error("알림톡 전송 예외 발생"); - log.error("{}", ex.getMessage()); - } + sendMessageWithExceptionHandling(() -> mapper.mapToSeniorApplyMessage(user)); } public void mentoringAccept(Senior senior, String time) { - try { + sendMessageWithExceptionHandling(() -> { User user = senior.getUser(); String chatLink = senior.getProfile().getChatLink(); - CommonRequest commonRequest = mapper.mapToSeniorAcceptMessage(user, chatLink, time); - sendMessage(commonRequest); - } catch (Exception ex) { - log.error("알림톡 전송 예외 발생"); - log.error("{}", ex.getMessage()); - } + return mapper.mapToSeniorAcceptMessage(user, chatLink, time); + }); } public void certificationApprove(User user) { - try { - CommonRequest commonRequest = mapper.mapToCertificationApprove(user); - sendMessage(commonRequest); - } catch (Exception ex) { - log.error("알림톡 전송 예외 발생"); - log.error("{}", ex.getMessage()); - } + sendMessageWithExceptionHandling(() -> mapper.mapToCertificationApprove(user)); } public void certificationDenied(User user) { - try { - CommonRequest commonRequest = mapper.mapToCertificationDenied(user); - sendMessage(commonRequest); - } catch (Exception ex) { - log.error("알림톡 전송 예외 발생"); - log.error("{}", ex.getMessage()); - } + sendMessageWithExceptionHandling(() -> mapper.mapToCertificationDenied(user)); } public void mentoringFinish(User user) { + sendMessageWithExceptionHandling(() -> mapper.mapToSeniorFinish(user)); + } + + private void sendMessageWithExceptionHandling(Supplier messageSupplier) { try { - CommonRequest commonRequest = mapper.mapToSeniorFinish(user); - sendMessage(commonRequest); + CommonRequest commonRequest = messageSupplier.get(); + String accessToken = bizppurioAuth.getAuth(); + String request = objectMapper.writeValueAsString(commonRequest); + webClient.post() + .uri(messageUrl) + .headers(h -> h.setContentType(APPLICATION_JSON)) + .headers(h -> h.setBearerAuth(accessToken)) + .bodyValue(request) + .retrieve() + .bodyToMono(MessageResponse.class) + .subscribe(this::check); } catch (Exception ex) { - log.error("알림톡 전송 예외 발생"); - log.error("{}", ex.getMessage()); + log.error("알림톡 전송 예외 발생: {}", ex.getMessage()); } } - private void sendMessage(CommonRequest commonRequest) throws JsonProcessingException { - String accessToken = bizppurioAuth.getAuth(); - String request = objectMapper.writeValueAsString(commonRequest); - webClient.post() - .uri(messageUrl) - .headers(h -> h.setContentType(APPLICATION_JSON)) - .headers(h -> h.setBearerAuth(accessToken)) - .bodyValue(request) - .retrieve() - .bodyToMono(MessageResponse.class) - .subscribe(this::check); - } - private void check(MessageResponse response) { if (response.code() != 1000) { log.error("전송실패 errorCode : {} errorMessage : {}", response.code(), response.description()); From c016d3d4dc337a5e096797c44b399a1642f7e745 Mon Sep 17 00:00:00 2001 From: yang Date: Mon, 29 Apr 2024 03:11:20 +0900 Subject: [PATCH 3/3] =?UTF-8?q?RAC-351=20fix=20:=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/BizppurioJuniorMessage.java | 50 ++--------------- .../bizppurio/usecase/BizppurioSend.java | 52 ++++++++++++++++++ .../usecase/BizppurioSeniorMessage.java | 53 +++---------------- 3 files changed, 64 insertions(+), 91 deletions(-) create mode 100644 src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSend.java diff --git a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java index be7d6923..1d3b46c1 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java @@ -1,75 +1,35 @@ package com.postgraduate.global.bizppurio.usecase; -import com.fasterxml.jackson.databind.ObjectMapper; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.global.bizppurio.dto.req.CommonRequest; -import com.postgraduate.global.bizppurio.dto.res.MessageResponse; import com.postgraduate.global.bizppurio.mapper.BizppurioMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import org.springframework.web.reactive.function.client.WebClient; - -import java.util.function.Supplier; - -import static org.springframework.http.MediaType.APPLICATION_JSON; @RequiredArgsConstructor @Component @Slf4j public class BizppurioJuniorMessage { - private final WebClient webClient; - private final BizppurioAuth bizppurioAuth; - private final ObjectMapper objectMapper; private final BizppurioMapper mapper; - - @Value("${bizppurio.message}") - private String messageUrl; + private final BizppurioSend bizppurioSend; public void mentoringApply(User user) { - sendMessageWithExceptionHandling(() -> mapper.mapToJuniorApplyMessage(user)); + bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToJuniorApplyMessage(user)); } public void mentoringAccept(User user, Senior senior, String time) { - sendMessageWithExceptionHandling(() -> { + bizppurioSend.sendMessageWithExceptionHandling(() -> { String chatLink = senior.getProfile().getChatLink(); return mapper.mapToJuniorAcceptMessage(user, chatLink, time); }); } public void mentoringRefuse(User user) { - sendMessageWithExceptionHandling(() -> mapper.mapToJuniorRefuseMessage(user)); + bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToJuniorRefuseMessage(user)); } public void mentoringFinish(User user) { - sendMessageWithExceptionHandling(() -> mapper.mapToJuniorFinish(user)); - } - - private void sendMessageWithExceptionHandling(Supplier messageSupplier) { - try { - CommonRequest commonRequest = messageSupplier.get(); - String accessToken = bizppurioAuth.getAuth(); - String request = objectMapper.writeValueAsString(commonRequest); - webClient.post() - .uri(messageUrl) - .headers(h -> h.setContentType(APPLICATION_JSON)) - .headers(h -> h.setBearerAuth(accessToken)) - .bodyValue(request) - .retrieve() - .bodyToMono(MessageResponse.class) - .subscribe(this::check); - } catch (Exception ex) { - log.error("알림톡 전송 예외 발생: {}", ex.getMessage()); - } - } - - private void check(MessageResponse response) { - if (response.code() != 1000) { - log.error("전송실패 errorCode : {} errorMessage : {}", response.code(), response.description()); - return; - } - log.info("알림톡 전송에 성공하였습니다."); + bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToJuniorFinish(user)); } } diff --git a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSend.java b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSend.java new file mode 100644 index 00000000..3c981791 --- /dev/null +++ b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSend.java @@ -0,0 +1,52 @@ +package com.postgraduate.global.bizppurio.usecase; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.postgraduate.global.bizppurio.dto.req.CommonRequest; +import com.postgraduate.global.bizppurio.dto.res.MessageResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; + +import java.util.function.Supplier; + +import static org.springframework.http.MediaType.APPLICATION_JSON; + +@RequiredArgsConstructor +@Slf4j +@Component +public class BizppurioSend { + private final BizppurioAuth bizppurioAuth; + private final ObjectMapper objectMapper; + private final WebClient webClient; + + @Value("${bizppurio.message}") + private String messageUrl; + + protected void sendMessageWithExceptionHandling(Supplier messageSupplier) { + try { + CommonRequest commonRequest = messageSupplier.get(); + String accessToken = bizppurioAuth.getAuth(); + String request = objectMapper.writeValueAsString(commonRequest); + webClient.post() + .uri(messageUrl) + .headers(h -> h.setContentType(APPLICATION_JSON)) + .headers(h -> h.setBearerAuth(accessToken)) + .bodyValue(request) + .retrieve() + .bodyToMono(MessageResponse.class) + .subscribe(this::check); + } catch (Exception ex) { + log.error("알림톡 전송 예외 발생: {}", ex.getMessage()); + } + } + + private void check(MessageResponse response) { + if (response.code() != 1000) { + log.error("전송실패 errorCode : {} errorMessage : {}", response.code(), response.description()); + return; + } + log.info("알림톡 전송에 성공하였습니다."); + } +} diff --git a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java index 8bbaa9bf..742e9c87 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java @@ -1,42 +1,29 @@ package com.postgraduate.global.bizppurio.usecase; -import com.fasterxml.jackson.databind.ObjectMapper; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.global.bizppurio.dto.req.CommonRequest; -import com.postgraduate.global.bizppurio.dto.res.MessageResponse; import com.postgraduate.global.bizppurio.mapper.BizppurioMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import org.springframework.web.reactive.function.client.WebClient; - -import static org.springframework.http.MediaType.APPLICATION_JSON; -import java.util.function.Supplier; @RequiredArgsConstructor @Component @Slf4j public class BizppurioSeniorMessage { - private final WebClient webClient; private final BizppurioMapper mapper; - private final BizppurioAuth bizppurioAuth; - private final ObjectMapper objectMapper; - - @Value("${bizppurio.message}") - private String messageUrl; + private final BizppurioSend bizppurioSend; public void signUp(User user) { - sendMessageWithExceptionHandling(() -> mapper.mapToSeniorSignUpMessage(user)); + bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToSeniorSignUpMessage(user)); } public void mentoringApply(User user) { - sendMessageWithExceptionHandling(() -> mapper.mapToSeniorApplyMessage(user)); + bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToSeniorApplyMessage(user)); } public void mentoringAccept(Senior senior, String time) { - sendMessageWithExceptionHandling(() -> { + bizppurioSend.sendMessageWithExceptionHandling(() -> { User user = senior.getUser(); String chatLink = senior.getProfile().getChatLink(); return mapper.mapToSeniorAcceptMessage(user, chatLink, time); @@ -44,40 +31,14 @@ public void mentoringAccept(Senior senior, String time) { } public void certificationApprove(User user) { - sendMessageWithExceptionHandling(() -> mapper.mapToCertificationApprove(user)); + bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToCertificationApprove(user)); } public void certificationDenied(User user) { - sendMessageWithExceptionHandling(() -> mapper.mapToCertificationDenied(user)); + bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToCertificationDenied(user)); } public void mentoringFinish(User user) { - sendMessageWithExceptionHandling(() -> mapper.mapToSeniorFinish(user)); - } - - private void sendMessageWithExceptionHandling(Supplier messageSupplier) { - try { - CommonRequest commonRequest = messageSupplier.get(); - String accessToken = bizppurioAuth.getAuth(); - String request = objectMapper.writeValueAsString(commonRequest); - webClient.post() - .uri(messageUrl) - .headers(h -> h.setContentType(APPLICATION_JSON)) - .headers(h -> h.setBearerAuth(accessToken)) - .bodyValue(request) - .retrieve() - .bodyToMono(MessageResponse.class) - .subscribe(this::check); - } catch (Exception ex) { - log.error("알림톡 전송 예외 발생: {}", ex.getMessage()); - } - } - - private void check(MessageResponse response) { - if (response.code() != 1000) { - log.error("전송실패 errorCode : {} errorMessage : {}", response.code(), response.description()); - return; - } - log.info("알림톡 전송에 성공하였습니다."); + bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToSeniorFinish(user)); } }