-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
91 deletions.
There are no files selected for viewing
50 changes: 5 additions & 45 deletions
50
src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CommonRequest> 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)); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSend.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CommonRequest> 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("알림톡 전송에 성공하였습니다."); | ||
} | ||
} |
53 changes: 7 additions & 46 deletions
53
src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,44 @@ | ||
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); | ||
}); | ||
} | ||
|
||
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<CommonRequest> 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)); | ||
} | ||
} |