Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: 5차 코드리뷰 기반 개편 (안부전화 요일 변환, URL 환경변수화 관련) 구현 #185

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ jobs:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Run deployment script on server
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.SERVER_IP }} 'bash /home/ubuntu/deploy.sh'
ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.SERVER_IP }} 'SLACK_WEBHOOK_URL=$SLACK_WEBHOOK_URL bash /home/ubuntu/deploy.sh'
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class KakaoApiService {
private static final String KAKAO_AUTH_BASE_URL = "https://kauth.kakao.com/oauth";
private static final String KAKAO_API_BASE_URL = "https://kapi.kakao.com/v2/user";
private static final String LOCALHOST_URL = "localhost:5173";
private static final String FRONT_URL = "dc9u22hnkwb24.cloudfront.net";

private final RestTemplate restTemplate;
private final KakaoProperties kakaoProperties;
Expand All @@ -39,7 +38,7 @@ public String getAuthorizationUrl(HttpServletRequest httpServletRequest) {

if (requestUrl.contains(LOCALHOST_URL)) {
redirectUri = kakaoProperties.devRedirectUri();
} else if (requestUrl.contains(FRONT_URL)) {
} else if (requestUrl.contains(kakaoProperties.frontUriWithoutHttps())) {
redirectUri = kakaoProperties.redirectUri();
} else {
throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl);
Expand All @@ -62,7 +61,7 @@ public KakaoTokenResponse getAccessToken(String authorizationCode, HttpServletRe

if (requestUrl.contains(LOCALHOST_URL)) {
redirectUri = kakaoProperties.devRedirectUri();
} else if (requestUrl.contains(FRONT_URL)) {
} else if (requestUrl.contains(kakaoProperties.frontUriWithoutHttps())) {
redirectUri = kakaoProperties.redirectUri();
} else {
throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public record KakaoProperties(
String clientId,
String redirectUri,
String devRedirectUri,
String frontUri
String frontUri,
String bankName,
String accountNumber,
String name,
String frontUriWithoutHttps
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public KakaoMessageService(KakaoTokenService kakaoTokenService, RestTemplate res
this.kakaoProperties = kakaoProperties;
}

public void sendPointChargeRequestReceivedMessage(String email, int point, String name) {
public void sendPointChargeRequestReceivedMessage(String email, int point, String name, String depositMessage) {
String accessToken = kakaoTokenService.getValidAccessTokenInServer(email);

if (accessToken == null) {
Expand All @@ -45,7 +45,7 @@ public void sendPointChargeRequestReceivedMessage(String email, int point, Strin
"\"object_type\": \"feed\"," +
"\"content\": {" +
"\"title\": \"%s님의 포인트 충전 요청 접수\"," +
"\"description\": \"입금 금액을 입금해주시기 바랍니다.\"," +
"\"description\": \"입금자명을 변경하여 입금해주시기 바랍니다.\"," +
"\"image_url\": \"%s\"," +
"\"image_width\": 640," +
"\"image_height\": 640," +
Expand All @@ -56,11 +56,11 @@ public void sendPointChargeRequestReceivedMessage(String email, int point, Strin
"}," +
"\"item_content\": {" +
"\"items\": [" +
"{\"item\": \"충전 요청\", \"item_op\": \"%d points\"}," +
"{\"item\": \"입금 금액\", \"item_op\": \"%d 원\"}," +
"{\"item\": \"은행\", \"item_op\": \"시니또 은행\"}," +
"{\"item\": \"계좌번호\", \"item_op\": \"3333-11-225533\"}," +
"{\"item\": \"성명\", \"item_op\": \"시니또 매니저\"}" +
"{\"item\": \"입금자명\", \"item_op\": \"%s\"}," +
"{\"item\": \"은행\", \"item_op\": \"%s\"}," +
"{\"item\": \"계좌번호\", \"item_op\": \"%s\"}," +
"{\"item\": \"성명\", \"item_op\": \"%s\"}" +
"]" +
"}," +
"\"buttons\": [" +
Expand All @@ -73,8 +73,8 @@ public void sendPointChargeRequestReceivedMessage(String email, int point, Strin
"}" +
"]" +
"}",
name, SINITTO_IMAGE_URL, kakaoProperties.frontUri(), kakaoProperties.frontUri(), point, point,
kakaoProperties.frontUri(), kakaoProperties.frontUri()
name, SINITTO_IMAGE_URL, kakaoProperties.frontUri(), kakaoProperties.frontUri(), point, depositMessage,
kakaoProperties.bankName(), kakaoProperties.accountNumber(), kakaoProperties.name(), kakaoProperties.frontUri(), kakaoProperties.frontUri()
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Map;

@Service
public class HelloCallPriceService {

private static final int PRICE_PER_ONE_MINUTE = 50;
private static final Map<String, DayOfWeek> DAY_NAME_MAP = Map.of(
"월", DayOfWeek.MONDAY,
"화", DayOfWeek.TUESDAY,
"수", DayOfWeek.WEDNESDAY,
"목", DayOfWeek.THURSDAY,
"금", DayOfWeek.FRIDAY,
"토", DayOfWeek.SATURDAY,
"일", DayOfWeek.SUNDAY
);

public HelloCallPriceResponse calculateHelloCallPrice(HelloCallPriceRequest helloCallPriceRequest) {
int totalServiceCount = calculateTotalServiceCount(helloCallPriceRequest);
Expand All @@ -37,16 +47,11 @@ public int calculateTotalServiceCount(HelloCallPriceRequest helloCallPriceReques
}

private DayOfWeek convertDayStringToDayOfWeek(String dayName) {
return switch (dayName) {
case "월" -> DayOfWeek.MONDAY;
case "화" -> DayOfWeek.TUESDAY;
case "수" -> DayOfWeek.WEDNESDAY;
case "목" -> DayOfWeek.THURSDAY;
case "금" -> DayOfWeek.FRIDAY;
case "토" -> DayOfWeek.SATURDAY;
case "일" -> DayOfWeek.SUNDAY;
default -> throw new BadRequestException("잘못된 dayName 입니다 : " + dayName);
};
DayOfWeek dayOfWeek = DAY_NAME_MAP.get(dayName);
if (dayOfWeek == null) {
throw new BadRequestException("잘못된 dayName 입니다 : " + dayName);
}
return dayOfWeek;
}

private int countOccurrencesOfDay(LocalDate startDate, LocalDate endDate, DayOfWeek targetDayOfWeek) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public PointChargeResponse savePointChargeRequest(Long memberId, int price) {

pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), member, price, PointLog.Status.CHARGE_REQUEST));

kakaoMessageService.sendPointChargeRequestReceivedMessage(member.getEmail(), price, member.getName());
kakaoMessageService.sendPointChargeRequestReceivedMessage(member.getEmail(), price, member.getName(), member.getDepositMessage());

return new PointChargeResponse(member.getDepositMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.springframework.beans.factory.annotation.Value;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -22,15 +21,16 @@ public class KakaoApiServiceTest {
private HttpServletRequest httpServletRequest;
@Mock
private KakaoProperties kakaoProperties;
@Value("kakao.clientId")
private String clientId;
@Value("kakao.devRedirectUri")
private String devRedirectUri;
@Value("kakao.redirectUri")
private String redirectUri;
private String clientId = "testClientId";

private String devRedirectUri = "testDevUri";

private String redirectUri = "https://testRedirectUri";

private String frontUriWithoutHttps = "testRedirectUri";

@Test
@DisplayName("getAuthorizationUrl 메소드 테스트 - devUri 포홤 시")
@DisplayName("getAuthorizationUrl 메소드 테스트 - devUri 포함 시")
void getAuthorizationUrlTestWithDevUri() {
//given
when(httpServletRequest.getHeader("Referer")).thenReturn("http://localhost:5173");
Expand All @@ -49,10 +49,11 @@ void getAuthorizationUrlTestWithDevUri() {
}

@Test
@DisplayName("getAuthorizationUrl 메소드 테스트 - 배포 uri 포홤 시")
@DisplayName("getAuthorizationUrl 메소드 테스트 - 배포 uri 포함 시")
void getAuthorizationUrlTestWithAwsUri() {
//given
when(httpServletRequest.getHeader("Referer")).thenReturn("https://dc9u22hnkwb24.cloudfront.net");
when(kakaoProperties.frontUriWithoutHttps()).thenReturn(frontUriWithoutHttps);
when(httpServletRequest.getHeader("Referer")).thenReturn("https://testRedirectUri");
when(kakaoProperties.redirectUri()).thenReturn(redirectUri);
when(kakaoProperties.clientId()).thenReturn(clientId);

Expand All @@ -72,6 +73,7 @@ void getAuthorizationUrlTestWithAwsUri() {
void getAuthorizationUrlTestWithAnotherUri() {
//given
when(httpServletRequest.getHeader("Referer")).thenReturn("http://test-uri.com");
when(kakaoProperties.frontUriWithoutHttps()).thenReturn(frontUriWithoutHttps);

//when, then
assertThrows(BadRequestException.class, () -> kakaoApiService.getAuthorizationUrl(httpServletRequest));
Expand Down