Skip to content

Commit 77ff795

Browse files
committed
refactor[law-word]: 용어 검색 띄어쓰기, ^ 정규화
1 parent aae94c1 commit 77ff795

File tree

4 files changed

+57
-29
lines changed

4 files changed

+57
-29
lines changed

backend/src/main/java/com/ai/lawyer/domain/law/controller/LawController.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,35 @@ public ResponseEntity<?> getStatisticsCard(
3939

4040
@PostMapping("/search")
4141
@Operation(summary = "볍령 목록 검색 기능", description = "조건에 맞는 법령 목록을 가져옵니다")
42-
public ResponseEntity<PageResponseDto> searchLaws(@RequestBody LawSearchRequestDto searchRequest) {
43-
Page<LawsDto> laws = lawService.searchLaws(searchRequest);
44-
PageResponseDto response = PageResponseDto.builder()
45-
.content(laws.getContent())
46-
.totalElements(laws.getTotalElements())
47-
.totalPages(laws.getTotalPages())
48-
.pageNumber(laws.getNumber())
49-
.pageSize(laws.getSize())
50-
.build();
51-
return ResponseEntity.ok(response);
42+
public ResponseEntity<?> searchLaws(@RequestBody LawSearchRequestDto searchRequest) {
43+
try {
44+
Page<LawsDto> laws = lawService.searchLaws(searchRequest);
45+
PageResponseDto response = PageResponseDto.builder()
46+
.content(laws.getContent())
47+
.totalElements(laws.getTotalElements())
48+
.totalPages(laws.getTotalPages())
49+
.pageNumber(laws.getNumber())
50+
.pageSize(laws.getSize())
51+
.build();
52+
return ResponseEntity.ok(response);
53+
}catch (Exception e){
54+
return ResponseEntity.badRequest().body("법령 목록 검색 에러 : " + e.getMessage());
55+
}
56+
5257
}
5358

5459
@GetMapping("/{id}")
5560
@Operation(summary = "볍령 상세 조회 기능", description = "법령 상세 데이터를 조회합니다 \n" +
5661
"예시: /api/law/1")
57-
public ResponseEntity<Law> getFullLaw(@PathVariable Long id) {
58-
Law law = lawService.getLawWithAllChildren(id);
62+
public ResponseEntity<?> getFullLaw(@PathVariable Long id) {
63+
try {
64+
Law law = lawService.getLawWithAllChildren(id);
65+
return ResponseEntity.ok(law);
66+
}catch (Exception e){
67+
return ResponseEntity.badRequest().body("법령 상세 조회 에러 : " + e.getMessage());
68+
}
69+
70+
5971

60-
return ResponseEntity.ok(law);
6172
}
6273
}

backend/src/main/java/com/ai/lawyer/domain/lawWord/controller/LawWordController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public ResponseEntity<?> getPrecedentV1(@PathVariable String word) {
2626
try {
2727
return ResponseEntity.ok(lawWordService.findDefinition(word));
2828
}catch (Exception e){
29-
return ResponseEntity.badRequest().body(e.getMessage());
29+
return ResponseEntity.badRequest().body("법령 용어 검색 에러 : " + e.getMessage());
3030
}
3131
}
3232

@@ -37,7 +37,7 @@ public ResponseEntity<?> getPrecedentV2(@PathVariable String word) {
3737
try {
3838
return ResponseEntity.ok(lawWordService.findDefinitionV2(word));
3939
}catch (Exception e){
40-
return ResponseEntity.badRequest().body(e.getMessage());
40+
return ResponseEntity.badRequest().body("법령 용어 검색 에러 : " + e.getMessage());
4141
}
4242
}
4343
}

backend/src/main/java/com/ai/lawyer/domain/lawWord/service/LawWordService.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,12 @@ private String extractTop3DefinitionsFromJson(String json, String requestedWord)
153153

154154
// 2. 클라이언트가 요청한 단어와 정확히 일치하는 item만 필터링
155155
List<JsonNode> matchingItems = new ArrayList<>();
156+
String normalizedRequestedWord = normalize(requestedWord);
157+
156158
for (JsonNode item : itemsNode) {
157159
String itemWord = item.path("word").asText();
158-
if (requestedWord.equals(itemWord)) {
160+
String normalizedItemWord = normalize(itemWord);
161+
if (normalizedRequestedWord.equals(normalizedItemWord)) {
159162
matchingItems.add(item);
160163
}
161164
}
@@ -211,4 +214,9 @@ private void saveDefinition(String word, String definition) {
211214
.build();
212215
lawWordRepository.save(entity);
213216
}
217+
218+
// 유틸: 단어 정규화 함수
219+
private String normalize(String input) {
220+
return input.replaceAll("[\\s\\^]", "");
221+
}
214222
}

backend/src/main/java/com/ai/lawyer/domain/precedent/controller/PrecedentController.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,23 @@ public ResponseEntity<?> list(
3737

3838
@PostMapping("/search")
3939
@Operation(summary = "판례 목록 검색 기능", description = "조건에 맞는 판례 목록을 가져옵니다")
40-
public ResponseEntity<PageResponseDto> searchPrecedents(
40+
public ResponseEntity<?> searchPrecedents(
4141
@RequestBody PrecedentSearchRequestDto requestDto) {
42+
try {
43+
Page<PrecedentSummaryListDto> results = precedentService.searchByKeyword(requestDto);
44+
PageResponseDto response = PageResponseDto.builder()
45+
.content(results.getContent())
46+
.totalElements(results.getTotalElements())
47+
.totalPages(results.getTotalPages())
48+
.pageNumber(results.getNumber())
49+
.pageSize(results.getSize())
50+
.build();
51+
return ResponseEntity.ok(response);
52+
}catch (Exception e){
53+
return ResponseEntity.badRequest().body("판례 목록 검색 에러 : " + e.getMessage());
54+
}
55+
4256

43-
Page<PrecedentSummaryListDto> results = precedentService.searchByKeyword(requestDto);
44-
PageResponseDto response = PageResponseDto.builder()
45-
.content(results.getContent())
46-
.totalElements(results.getTotalElements())
47-
.totalPages(results.getTotalPages())
48-
.pageNumber(results.getNumber())
49-
.pageSize(results.getSize())
50-
.build();
51-
return ResponseEntity.ok(response);
5257
}
5358

5459
/**
@@ -61,8 +66,12 @@ public ResponseEntity<PageResponseDto> searchPrecedents(
6166
@GetMapping("/{id}")
6267
@Operation(summary = "판례 상세 조회 기능", description = "판례 상세 데이터를 조회합니다 \n" +
6368
"예시: /api/precedent/1")
64-
public ResponseEntity<Precedent> getPrecedent(@PathVariable Long id) {
65-
Precedent precedent = precedentService.getPrecedentById(id);
66-
return ResponseEntity.ok(precedent);
69+
public ResponseEntity<?> getPrecedent(@PathVariable Long id) {
70+
try {
71+
Precedent precedent = precedentService.getPrecedentById(id);
72+
return ResponseEntity.ok(precedent);
73+
}catch (Exception e){
74+
return ResponseEntity.badRequest().body("판례 상세 조회 에러 : " + e.getMessage());
75+
}
6776
}
6877
}

0 commit comments

Comments
 (0)