Skip to content

Commit

Permalink
[FEAT] 알람 조회 시 카테고리 영어명 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ibaesuyeon committed Aug 20, 2024
1 parent a9b63ab commit aed7b86
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public ApiResult<String> markAsViewed(@RequestParam Long alarmId) {
@ApiResponse(responseCode = "400", description = "잘못된 입력 값"),
@ApiResponse(responseCode = "500", description = "서버 오류 발생")
})
@GetMapping("/get")
@GetMapping
public ApiResult<List<AlarmDto>> getAlarm(@RequestParam String SSAID, @RequestParam String keyword) {
try {
List<AlarmDto> alarms = alarmService.getAlarms(SSAID, keyword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -203,7 +204,8 @@ public List<AlarmDto> 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)
Expand All @@ -220,7 +222,8 @@ public List<AlarmDto> 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}

0 comments on commit aed7b86

Please sign in to comment.