Skip to content

Commit 6680f65

Browse files
authored
Merge pull request #293 from prgrms-web-devcourse-final-project/develop
배포
2 parents cbf41b9 + ccf5e5a commit 6680f65

File tree

9 files changed

+163
-30
lines changed

9 files changed

+163
-30
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.ai.lawyer.domain.home.controller;
2+
3+
import com.ai.lawyer.domain.home.dto.FullData;
4+
import com.ai.lawyer.domain.home.service.HomeService;
5+
import io.swagger.v3.oas.annotations.Operation;
6+
import io.swagger.v3.oas.annotations.tags.Tag;
7+
import lombok.RequiredArgsConstructor;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.springframework.http.ResponseEntity;
10+
import org.springframework.web.bind.annotation.PostMapping;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RestController;
13+
14+
@Slf4j
15+
@RestController
16+
@RequestMapping("/api/home")
17+
@RequiredArgsConstructor
18+
@Tag(name = "홈", description = "홈 화면 API")
19+
public class HomeController {
20+
21+
private final HomeService homeService;
22+
23+
@Operation(summary = "데이터 수", description = "판례 법령 채팅 투표 수 조회")
24+
@PostMapping("/data-count")
25+
public ResponseEntity<FullData> getDataCount() {
26+
return ResponseEntity.ok(homeService.getDataCount());
27+
}
28+
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.ai.lawyer.domain.home.dto;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
import lombok.*;
5+
6+
@Getter
7+
@Setter
8+
@Builder
9+
@NoArgsConstructor
10+
@AllArgsConstructor
11+
@Schema(description = "판례수 법령수 채팅수 투표수 DTO")
12+
public class FullData {
13+
14+
@Schema(description = "판례 수", example = "1000")
15+
private Long precedentCount;
16+
17+
@Schema(description = "법령 수", example = "500")
18+
private Long lawCount;
19+
20+
@Schema(description = "채팅 수", example = "2000")
21+
private Long chatCount;
22+
23+
@Schema(description = "투표 수", example = "300")
24+
private Long voteCount;
25+
26+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.ai.lawyer.domain.home.service;
2+
3+
import com.ai.lawyer.domain.chatbot.repository.ChatRepository;
4+
import com.ai.lawyer.domain.home.dto.FullData;
5+
import com.ai.lawyer.domain.law.repository.LawRepository;
6+
import com.ai.lawyer.domain.poll.repository.PollRepository;
7+
import com.ai.lawyer.domain.precedent.repository.PrecedentRepository;
8+
import lombok.RequiredArgsConstructor;
9+
import lombok.extern.slf4j.Slf4j;
10+
import org.springframework.stereotype.Service;
11+
12+
@Slf4j
13+
@Service
14+
@RequiredArgsConstructor
15+
public class HomeService {
16+
17+
private final PrecedentRepository precedentRepository;
18+
private final LawRepository lawRepository;
19+
private final ChatRepository chatRepository;
20+
private final PollRepository pollRepository;
21+
22+
23+
public FullData getDataCount() {
24+
25+
Long precedentCount = precedentRepository.count();
26+
Long lawCount = lawRepository.count();
27+
Long chatCount = chatRepository.count();
28+
Long voteCount = pollRepository.count();
29+
30+
return FullData.builder()
31+
.precedentCount(precedentCount)
32+
.lawCount(lawCount)
33+
.chatCount(chatCount)
34+
.voteCount(voteCount)
35+
.build();
36+
37+
}
38+
39+
}

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
}

backend/src/main/java/com/ai/lawyer/global/security/SecurityConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class SecurityConfig {
5757
"/api/law/**", // 법령 (공개)
5858
"/api/law-word/**", // 법률 용어 (공개)
5959
"/api/chat/**", // 챗봇 (공개)
60+
"/api/home/**", // 홈 (공개)
6061
"/h2-console/**", // H2 콘솔 (개발용)
6162
"/actuator/health", "/actuator/health/**", "/actuator/info", // Spring Actuator
6263
"/api/actuator/health", "/api/actuator/health/**", "/api/actuator/info"

backend/src/main/java/com/ai/lawyer/global/springDoc/SpringDocConfig.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,24 @@ public GroupedOpenApi allApi() {
6868
.build();
6969
}
7070

71-
@Bean GroupedOpenApi chatApi() {
71+
@Bean
72+
GroupedOpenApi chatApi() {
7273
return GroupedOpenApi.builder()
7374
.group("챗봇과 관련된 API")
7475
.pathsToMatch("/api/chat/**")
7576
.packagesToScan("com.ai.lawyer.domain.chatbot.controller")
7677
.build();
7778
}
7879

80+
@Bean
81+
GroupedOpenApi homeApi() {
82+
return GroupedOpenApi.builder()
83+
.group("Home API")
84+
.pathsToMatch("/api/home/**")
85+
.packagesToScan("com.ai.lawyer.domain.home.controller")
86+
.build();
87+
}
88+
7989
@Bean
8090
public OpenAPI customOpenAPI() {
8191
return new OpenAPI()

0 commit comments

Comments
 (0)