From aed7b860b4de97efd9711a666c15b4b3cc2c7fc2 Mon Sep 17 00:00:00 2001 From: ibaesuyeon Date: Wed, 21 Aug 2024 08:08:58 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EC=95=8C=EB=9E=8C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=98=81=EC=96=B4=EB=AA=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/AlarmController.java | 2 +- .../thinkerbell/domain/user/dto/AlarmDto.java | 3 +- .../domain/user/service/AlarmService.java | 7 ++- .../global/converter/CaseConverter.java | 57 +++++++++++++++++++ 4 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 src/main/java/depth/mvp/thinkerbell/global/converter/CaseConverter.java diff --git a/src/main/java/depth/mvp/thinkerbell/domain/user/controller/AlarmController.java b/src/main/java/depth/mvp/thinkerbell/domain/user/controller/AlarmController.java index 58f768f..824326e 100644 --- a/src/main/java/depth/mvp/thinkerbell/domain/user/controller/AlarmController.java +++ b/src/main/java/depth/mvp/thinkerbell/domain/user/controller/AlarmController.java @@ -82,7 +82,7 @@ public ApiResult markAsViewed(@RequestParam Long alarmId) { @ApiResponse(responseCode = "400", description = "잘못된 입력 값"), @ApiResponse(responseCode = "500", description = "서버 오류 발생") }) - @GetMapping("/get") + @GetMapping public ApiResult> getAlarm(@RequestParam String SSAID, @RequestParam String keyword) { try { List alarms = alarmService.getAlarms(SSAID, keyword); diff --git a/src/main/java/depth/mvp/thinkerbell/domain/user/dto/AlarmDto.java b/src/main/java/depth/mvp/thinkerbell/domain/user/dto/AlarmDto.java index aaa7f66..ff81afa 100644 --- a/src/main/java/depth/mvp/thinkerbell/domain/user/dto/AlarmDto.java +++ b/src/main/java/depth/mvp/thinkerbell/domain/user/dto/AlarmDto.java @@ -10,7 +10,8 @@ public class AlarmDto { private Long id; private String title; - private String noticeType; + private String noticeType_korean; + private String noticeType_english; private boolean isViewed; private boolean isMarked; private String Url; diff --git a/src/main/java/depth/mvp/thinkerbell/domain/user/service/AlarmService.java b/src/main/java/depth/mvp/thinkerbell/domain/user/service/AlarmService.java index a3527ea..d3d0ffe 100644 --- a/src/main/java/depth/mvp/thinkerbell/domain/user/service/AlarmService.java +++ b/src/main/java/depth/mvp/thinkerbell/domain/user/service/AlarmService.java @@ -14,6 +14,7 @@ import depth.mvp.thinkerbell.domain.user.repository.BookmarkRepository; import depth.mvp.thinkerbell.domain.user.repository.KeywordRepository; import depth.mvp.thinkerbell.domain.user.repository.UserRepository; +import depth.mvp.thinkerbell.global.converter.CaseConverter; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityNotFoundException; import jakarta.persistence.PersistenceContext; @@ -203,7 +204,8 @@ public List getAlarms(String SSAID, String keyword){ AlarmDto alarmDto = AlarmDto.builder() .id(alarm.getId()) .title(alarm.getTitle()) - .noticeType(categoryService.getCategoryNameInKorean(alarm.getNoticeType())) + .noticeType_korean(categoryService.getCategoryNameInKorean(alarm.getNoticeType())) + .noticeType_english(CaseConverter.snakeToPascal(alarm.getNoticeType())) .isViewed(alarm.getIsViewed()) .isMarked(isMarked) .Url(null) @@ -220,7 +222,8 @@ public List getAlarms(String SSAID, String keyword){ AlarmDto alarmDto = AlarmDto.builder() .id(alarm.getId()) .title(alarm.getTitle()) - .noticeType(categoryService.getCategoryNameInKorean(alarm.getNoticeType())) + .noticeType_korean(categoryService.getCategoryNameInKorean(alarm.getNoticeType())) + .noticeType_english(CaseConverter.snakeToPascal(alarm.getNoticeType())) .isViewed(alarm.getIsViewed()) .isMarked(isMarked) .Url(url) diff --git a/src/main/java/depth/mvp/thinkerbell/global/converter/CaseConverter.java b/src/main/java/depth/mvp/thinkerbell/global/converter/CaseConverter.java new file mode 100644 index 0000000..3bf8251 --- /dev/null +++ b/src/main/java/depth/mvp/thinkerbell/global/converter/CaseConverter.java @@ -0,0 +1,57 @@ +package depth.mvp.thinkerbell.global.converter; + +public class CaseConverter { + + /** + * PascalCase 문자열을 snake_case 문자열로 변환합니다. + * + * @param pascalCaseString 변환할 PascalCase 문자열 + * @return 변환된 snake_case 문자열 + */ + public static String pascalToSnake(String pascalCaseString) { + StringBuilder snakeCaseString = new StringBuilder(); + + for (char c : pascalCaseString.toCharArray()) { + if (Character.isUpperCase(c)) { + if (snakeCaseString.length() > 0) { + snakeCaseString.append('_'); + } + snakeCaseString.append(Character.toLowerCase(c)); + } else { + snakeCaseString.append(c); + } + } + + return snakeCaseString.toString(); + } + + /** + * snake_case 문자열을 PascalCase 문자열로 변환합니다. + * + * @param snakeCaseString 변환할 snake_case 문자열 + * @return 변환된 PascalCase 문자열 + */ + public static String snakeToPascal(String snakeCaseString) { + StringBuilder pascalCaseString = new StringBuilder(); + boolean toUpperCase = true; // 첫 문자를 대문자로 변환하기 위해 true로 설정 + + for (char c : snakeCaseString.toCharArray()) { + if (c == '_') { + // 언더스코어 다음 문자를 대문자로 변환하도록 설정합니다. + toUpperCase = true; + } else { + if (toUpperCase) { + // 대문자로 변환 후 설정을 초기화합니다. + pascalCaseString.append(Character.toUpperCase(c)); + toUpperCase = false; + } else { + // 소문자로 추가합니다. + pascalCaseString.append(c); + } + } + } + + return pascalCaseString.toString(); + } + +}