Skip to content

Commit

Permalink
Merge pull request #36 from DEPthes/feacture/alarm
Browse files Browse the repository at this point in the history
[FEAT] μ•ŒλžŒ 쑰회 μ‹œ μΉ΄ν…Œκ³ λ¦¬ μ˜μ–΄λͺ… μΆ”κ°€
  • Loading branch information
ibaesuyeon authored Aug 20, 2024
2 parents a9b63ab + aed7b86 commit 077917e
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 077917e

Please sign in to comment.