Skip to content

Commit

Permalink
Merge pull request #252 from WE-ARE-RACCOONS/RAC-351
Browse files Browse the repository at this point in the history
RAC-351 HotFix : μ•Œλ¦Όν†‘ μ˜ˆμ™Έ λ°œμƒμ‹œ κΈ°μ‘΄ λΉ„μ¦ˆλ‹ˆμŠ€ 둜직 영ν–₯ 없도둝 μˆ˜μ •
  • Loading branch information
ywj9811 authored Apr 28, 2024
2 parents 724c89d + c016d3d commit 21b874b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 104 deletions.
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));
}
}
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("μ•Œλ¦Όν†‘ 전솑에 μ„±κ³΅ν•˜μ˜€μŠ΅λ‹ˆλ‹€.");
}
}
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));
}
}

0 comments on commit 21b874b

Please sign in to comment.