-
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.
Merge pull request #252 from WE-ARE-RACCOONS/RAC-351
RAC-351 HotFix : μλ¦Όν‘ μμΈ λ°μμ κΈ°μ‘΄ λΉμ¦λμ€ λ‘μ§ μν₯ μλλ‘ μμ
- Loading branch information
Showing
3 changed files
with
71 additions
and
104 deletions.
There are no files selected for viewing
55 changes: 8 additions & 47 deletions
55
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,74 +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 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) { | ||
CommonRequest commonRequest = mapper.mapToJuniorApplyMessage(user); | ||
sendMessage(commonRequest); | ||
bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToJuniorApplyMessage(user)); | ||
} | ||
|
||
public void mentoringAccept(User user, Senior senior, String time) { | ||
String chatLink = senior.getProfile().getChatLink(); | ||
CommonRequest commonRequest = mapper.mapToJuniorAcceptMessage(user, chatLink, time); | ||
sendMessage(commonRequest); | ||
bizppurioSend.sendMessageWithExceptionHandling(() -> { | ||
String chatLink = senior.getProfile().getChatLink(); | ||
return mapper.mapToJuniorAcceptMessage(user, chatLink, time); | ||
}); | ||
} | ||
|
||
public void mentoringRefuse(User user) { | ||
CommonRequest commonRequest = mapper.mapToJuniorRefuseMessage(user); | ||
sendMessage(commonRequest); | ||
bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToJuniorRefuseMessage(user)); | ||
} | ||
|
||
public void mentoringFinish(User user) { | ||
CommonRequest commonRequest = mapper.mapToJuniorFinish(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); | ||
} catch (Exception ex) { | ||
log.error("μλ¦Όν‘ μ μ‘ μμΈ λ°μ"); | ||
} | ||
} | ||
|
||
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("μλ¦Όν‘ μ μ‘μ μ±κ³΅νμμ΅λλ€."); | ||
} | ||
} |
68 changes: 11 additions & 57 deletions
68
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,90 +1,44 @@ | ||
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; | ||
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.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 | ||
@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) { | ||
CommonRequest commonRequest = mapper.mapToSeniorSignUpMessage(user); | ||
sendMessage(commonRequest); | ||
bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToSeniorSignUpMessage(user)); | ||
} | ||
|
||
public void mentoringApply(User user) { | ||
CommonRequest commonRequest = mapper.mapToSeniorApplyMessage(user); | ||
sendMessage(commonRequest); | ||
bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToSeniorApplyMessage(user)); | ||
} | ||
|
||
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); | ||
bizppurioSend.sendMessageWithExceptionHandling(() -> { | ||
User user = senior.getUser(); | ||
String chatLink = senior.getProfile().getChatLink(); | ||
return mapper.mapToSeniorAcceptMessage(user, chatLink, time); | ||
}); | ||
} | ||
|
||
public void certificationApprove(User user) { | ||
CommonRequest commonRequest = mapper.mapToCertificationApprove(user); | ||
sendMessage(commonRequest); | ||
bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToCertificationApprove(user)); | ||
} | ||
|
||
public void certificationDenied(User user) { | ||
CommonRequest commonRequest = mapper.mapToCertificationDenied(user); | ||
sendMessage(commonRequest); | ||
bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToCertificationDenied(user)); | ||
} | ||
|
||
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); | ||
} catch (Exception ex) { | ||
log.error("μλ¦Όν‘ μ μ‘ μμΈ λ°μ"); | ||
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)); | ||
} | ||
} |