-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat] 서울 제외 교통사고 다발지역 응답 추가 #67
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,7 +23,7 @@ public class KoroadHotspot { | |||||||||||||
| * - SCHOOL : 어린이보호구역 | ||||||||||||||
| */ | ||||||||||||||
| @Column(nullable = false, length = 20) | ||||||||||||||
| private String type; | ||||||||||||||
| private KoroadType type; | ||||||||||||||
|
Comment on lines
25
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enum 매핑 방식 지정 누락으로 데이터 불일치 위험.
🐛 수정 제안- `@Column`(nullable = false, length = 20)
+ `@Enumerated`(EnumType.STRING)
+ `@Column`(nullable = false, length = 20)
private KoroadType type;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| @Column(name = "afos_fid", length = 50) | ||||||||||||||
| private String afosFid; | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||||||||||||||||||||||||||
| package backend.knowhow.domain.alert.domain; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import backend.knowhow.global.common.exception.BaseException; | ||||||||||||||||||||||||||||||
| import backend.knowhow.global.common.response.ErrorType; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import java.util.Arrays; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public enum KoroadType { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| OLD_MAN("oldman"), | ||||||||||||||||||||||||||||||
| CHILD("child"), | ||||||||||||||||||||||||||||||
| SCHOOL("school"); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| private final String param; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| KoroadType(String param) { | ||||||||||||||||||||||||||||||
| this.param = param; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public String param() { | ||||||||||||||||||||||||||||||
| return param; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public static KoroadType from(String value) { | ||||||||||||||||||||||||||||||
| return Arrays.stream(values()) | ||||||||||||||||||||||||||||||
| .filter(type -> type.param.equalsIgnoreCase(value)) | ||||||||||||||||||||||||||||||
| .findFirst() | ||||||||||||||||||||||||||||||
| .orElseThrow(() -> new BaseException(ErrorType.BAD_REQUEST)); | ||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. null 입력 시 NPE로 500 발생 가능.
🐛 수정 제안 public static KoroadType from(String value) {
+ if (value == null || value.isBlank()) {
+ throw new BaseException(ErrorType.BAD_REQUEST);
+ }
return Arrays.stream(values())
.filter(type -> type.param.equalsIgnoreCase(value))
.findFirst()
.orElseThrow(() -> new BaseException(ErrorType.BAD_REQUEST));
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,16 @@ | ||
| package backend.knowhow.domain.alert.repository; | ||
|
|
||
| import backend.knowhow.domain.alert.domain.KoroadHotspot; | ||
| import backend.knowhow.domain.alert.domain.KoroadType; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface KoroadHotspotRepository extends JpaRepository<KoroadHotspot, Long> { | ||
|
|
||
| List<KoroadHotspot> findByType(String type); | ||
| List<KoroadHotspot> findByType(KoroadType type); | ||
|
|
||
| List<KoroadHotspot> findByTypeAndSiDoAndGuGun(String type, Integer siDo, Integer guGun); | ||
| List<KoroadHotspot> findByTypeAndSiDoAndGuGun(KoroadType type, Integer siDo, Integer guGun); | ||
|
|
||
| void deleteByTypeAndSiDoAndGuGun(String type, Integer siDo, Integer guGun); | ||
| void deleteByTypeAndSiDoAndGuGun(KoroadType type, Integer siDo, Integer guGun); | ||
| } |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: Care-Ride/backend
Length of output: 149
🏁 Script executed:
Repository: Care-Ride/backend
Length of output: 128
🏁 Script executed:
Repository: Care-Ride/backend
Length of output: 143
🏁 Script executed:
# Read KoroadType.java cat ./src/main/java/backend/knowhow/domain/alert/domain/KoroadType.javaRepository: Care-Ride/backend
Length of output: 772
🏁 Script executed:
# Read the full KoroadHotspotSyncController.java cat ./src/main/java/backend/knowhow/domain/alert/controller/KoroadHotspotSyncController.javaRepository: Care-Ride/backend
Length of output: 1324
🏁 Script executed:
# Read the syncService implementation cat ./src/main/java/backend/knowhow/domain/alert/service/KoroadHotspotSyncService.javaRepository: Care-Ride/backend
Length of output: 2846
🏁 Script executed:
Repository: Care-Ride/backend
Length of output: 135
🏁 Script executed:
Repository: Care-Ride/backend
Length of output: 130
🏁 Script executed:
# Read BaseException cat ./src/main/java/backend/knowhow/global/common/exception/BaseException.javaRepository: Care-Ride/backend
Length of output: 561
🏁 Script executed:
# Read ErrorType cat ./src/main/java/backend/knowhow/global/common/response/ErrorType.javaRepository: Care-Ride/backend
Length of output: 3365
요청 파라미터
type검증을 루프 시작 전에 추가하기요청 파라미터
type이 잘못되면 중첩 루프 내에서syncService.syncHotspots()를 호출할 때마다 외부 API 통신을 시도하다가 결국KoroadType.from(type)에서BaseException(ErrorType.BAD_REQUEST)를 던지게 됩니다. 루프 시작 전에 미리 한 번 검증하여 불필요한 외부 API 호출을 방지하고 즉시 400으로 응답하세요.✅ 제안 수정안
`@PostMapping`("/sync") public String syncSeoul( `@RequestParam` String type // KoroadApiClient 에서 사용하는 구분자 ("oldman", "child", "school" 등) ) { + KoroadType.from(type); // 루프 전에 한 번만 검증 log.info("sync start"); int total = 0;참고:
KoroadType.from(type)이 이미BaseException(ErrorType.BAD_REQUEST)를 던지므로, 별도의 try-catch 처리 없이 기존 예외 처리 메커니즘이 자동으로 400을 반환합니다.📝 Committable suggestion
🤖 Prompt for AI Agents