From 06a6e432dc048025539bb605b10a226255e0dcfb Mon Sep 17 00:00:00 2001 From: JIHO LEE <161289673+GitJIHO@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:12:55 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=205=EC=B0=A8=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EA=B8=B0=EB=B0=98=20=EA=B0=9C=ED=8E=B8=20?= =?UTF-8?q?(=EC=95=88=EB=B6=80=EC=A0=84=ED=99=94=20=EC=9A=94=EC=9D=BC=20?= =?UTF-8?q?=EB=B3=80=ED=99=98,=20URL=20=ED=99=98=EA=B2=BD=EB=B3=80?= =?UTF-8?q?=EC=88=98=ED=99=94=20=EA=B4=80=EB=A0=A8)=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=20(#185)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 안부전화 요일 변환 로직 Map 사용방식으로 변환 * refactor: SLACK_WEBHOOK_URL 값을 환경변수화 * Refactor: 카카오 메시지 필드 개편, 입금 계좌 정보 gitignore, 프론트 구분용 uri gitignore화 (#186) * fix: 한글 제외 --- .github/workflows/deploy.yml | 4 ++- .../sinitto/auth/service/KakaoApiService.java | 5 ++-- .../common/properties/KakaoProperties.java | 6 ++++- .../common/service/KakaoMessageService.java | 16 ++++++------ .../service/HelloCallPriceService.java | 25 +++++++++++-------- .../sinitto/point/service/PointService.java | 2 +- .../auth/service/KakaoApiServiceTest.java | 22 ++++++++-------- 7 files changed, 46 insertions(+), 34 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fce69f8d..ebfec75d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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' diff --git a/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java b/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java index 71fbe33a..7ee01e8c 100644 --- a/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java +++ b/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java @@ -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; @@ -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); @@ -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); diff --git a/src/main/java/com/example/sinitto/common/properties/KakaoProperties.java b/src/main/java/com/example/sinitto/common/properties/KakaoProperties.java index 49ade0ad..2600627b 100644 --- a/src/main/java/com/example/sinitto/common/properties/KakaoProperties.java +++ b/src/main/java/com/example/sinitto/common/properties/KakaoProperties.java @@ -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 ) { } diff --git a/src/main/java/com/example/sinitto/common/service/KakaoMessageService.java b/src/main/java/com/example/sinitto/common/service/KakaoMessageService.java index 1331e529..d9a6785d 100644 --- a/src/main/java/com/example/sinitto/common/service/KakaoMessageService.java +++ b/src/main/java/com/example/sinitto/common/service/KakaoMessageService.java @@ -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) { @@ -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," + @@ -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\": [" + @@ -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() ); diff --git a/src/main/java/com/example/sinitto/helloCall/service/HelloCallPriceService.java b/src/main/java/com/example/sinitto/helloCall/service/HelloCallPriceService.java index 8f8c6830..a1eda166 100644 --- a/src/main/java/com/example/sinitto/helloCall/service/HelloCallPriceService.java +++ b/src/main/java/com/example/sinitto/helloCall/service/HelloCallPriceService.java @@ -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 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); @@ -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) { diff --git a/src/main/java/com/example/sinitto/point/service/PointService.java b/src/main/java/com/example/sinitto/point/service/PointService.java index 15ed05b4..0794bdc3 100644 --- a/src/main/java/com/example/sinitto/point/service/PointService.java +++ b/src/main/java/com/example/sinitto/point/service/PointService.java @@ -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()); } diff --git a/src/test/java/com/example/sinitto/auth/service/KakaoApiServiceTest.java b/src/test/java/com/example/sinitto/auth/service/KakaoApiServiceTest.java index 0ff276cb..a46820eb 100644 --- a/src/test/java/com/example/sinitto/auth/service/KakaoApiServiceTest.java +++ b/src/test/java/com/example/sinitto/auth/service/KakaoApiServiceTest.java @@ -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; @@ -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"); @@ -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); @@ -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));