Skip to content

Commit 7835130

Browse files
committed
Revert "Merge pull request #106 from kookmin-sw/refactor/104"
This reverts commit 1ac28b1, reversing changes made to 137b76c.
1 parent 051c5ec commit 7835130

16 files changed

+224
-163
lines changed

backend/src/main/java/com/example/backend/analysis/controller/CaseStatsController.java

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import org.springframework.http.ResponseEntity;
88
import org.springframework.web.bind.annotation.*;
99

10+
import java.util.Collections;
1011
import java.util.List;
1112
import java.util.Map;
13+
import java.util.NoSuchElementException;
1214

1315
@RestController
1416
@RequestMapping("/api/v1/stats")
@@ -20,18 +22,33 @@ public class CaseStatsController {
2022
// 개요 조회
2123
@GetMapping("/overview")
2224
public ResponseEntity<?> getOverview(HttpSession session) {
23-
// 결과가 없으면 404, 있으면 200
24-
CaseStatsOverviewResponse response = caseStatsService.getOverview(session);
25-
return ResponseEntity.ok(response);
25+
try {
26+
CaseStatsOverviewResponse response = caseStatsService.getOverview(session);
27+
return ResponseEntity.ok(response);
28+
} catch (IllegalStateException e) {
29+
return ResponseEntity.status(401).body(Collections.singletonMap("message", e.getMessage()));
30+
} catch (NoSuchElementException e) {
31+
return ResponseEntity.status(404).body(Collections.singletonMap("message", e.getMessage()));
32+
} catch (Exception e) {
33+
return ResponseEntity.status(500).body(Collections.singletonMap("message", "내부 서버 오류 발생"));
34+
}
2635
}
2736

2837
// 시간대별 사건 수 조회 (0시~23시 모두 반환)
2938
@GetMapping("/hour")
3039
public ResponseEntity<?> getHourlyCaseStats(@RequestParam("date") String date,
3140
@RequestParam(value = "category", required = false) String category,
3241
HttpSession session) {
33-
List<HourlyCaseStatsResponse> stats = caseStatsService.getHourlyCaseStats(date, category, session);
34-
return ResponseEntity.ok(stats);
42+
try {
43+
List<HourlyCaseStatsResponse> stats = caseStatsService.getHourlyCaseStats(date, category, session);
44+
return ResponseEntity.ok(stats);
45+
} catch (IllegalStateException e) {
46+
return ResponseEntity.status(401).body(Collections.singletonMap("message", e.getMessage()));
47+
} catch (NoSuchElementException e) {
48+
return ResponseEntity.status(404).body(Collections.singletonMap("message", e.getMessage()));
49+
} catch (Exception e) {
50+
return ResponseEntity.status(500).body(Collections.singletonMap("message", "내부 서버 오류가 발생했습니다."));
51+
}
3552
}
3653

3754
// 월별/일별 사건 수 조회 (month 파라미터 존재 여부에 따라 분기; 전체 범위를 0으로 채워 반환)
@@ -40,36 +57,70 @@ public ResponseEntity<?> getCaseStats(@RequestParam("year") int year,
4057
@RequestParam(value = "month", required = false) Integer month,
4158
@RequestParam(value = "category", required = false) String category,
4259
HttpSession session) {
43-
// month가 없으면 월별 데이터
44-
if (month == null) {
45-
List<MonthlyCaseStatsResponse> monthlyStats = caseStatsService.getMonthlyCaseStats(year, category, session);
46-
return ResponseEntity.ok(monthlyStats);
60+
try {
61+
if (month == null) {
62+
List<MonthlyCaseStatsResponse> monthlyStats = caseStatsService.getMonthlyCaseStats(year, category, session);
63+
return ResponseEntity.ok(monthlyStats);
64+
}
65+
List<DailyCaseStatsResponse> dailyStats = caseStatsService.getDailyCaseStats(year, month, category, session);
66+
return ResponseEntity.ok(dailyStats);
67+
} catch (IllegalStateException e) {
68+
return ResponseEntity.status(401).body(Collections.singletonMap("message", e.getMessage()));
69+
} catch (NoSuchElementException e) {
70+
return ResponseEntity.status(404).body(Collections.singletonMap("message", e.getMessage()));
71+
} catch (Exception e) {
72+
return ResponseEntity.status(500).body(Collections.singletonMap("message", "내부 서버 오류가 발생했습니다."));
4773
}
48-
49-
// month가 있으면 일별 데이터
50-
List<DailyCaseStatsResponse> dailyStats = caseStatsService.getDailyCaseStats(year, month, category, session);
51-
return ResponseEntity.ok(dailyStats);
5274
}
5375

5476
// 유형별 사건 수 조회 (기본 카테고리 0 포함)
5577
@GetMapping("/category")
5678
public ResponseEntity<?> getCategoryCaseStats(@RequestParam("period") String period, HttpSession session) {
57-
Map<String, Integer> stats = caseStatsService.getCategoryCaseStats(period, session);
58-
return ResponseEntity.ok(stats);
79+
try {
80+
Map<String, Integer> stats = caseStatsService.getCategoryCaseStats(period, session);
81+
return ResponseEntity.ok(stats);
82+
} catch (IllegalStateException e) {
83+
return ResponseEntity.status(401).body(Collections.singletonMap("message", e.getMessage()));
84+
} catch (IllegalArgumentException e) {
85+
return ResponseEntity.status(400).body(Collections.singletonMap("message", e.getMessage()));
86+
} catch (NoSuchElementException e) {
87+
return ResponseEntity.status(404).body(Collections.singletonMap("message", e.getMessage()));
88+
} catch (Exception e) {
89+
return ResponseEntity.status(500).body(Collections.singletonMap("message", "내부 서버 오류가 발생했습니다."));
90+
}
5991
}
6092

6193
// 장소별 사건 수 조회
6294
@GetMapping("/location")
6395
public ResponseEntity<?> getLocationCaseStats(@RequestParam("period") String period, HttpSession session) {
64-
List<LocationCaseStatsResponse> stats = caseStatsService.getLocationCaseStats(period, session);
65-
return ResponseEntity.ok(stats);
96+
try {
97+
List<LocationCaseStatsResponse> stats = caseStatsService.getLocationCaseStats(period, session);
98+
return ResponseEntity.ok(stats);
99+
} catch (IllegalStateException e) {
100+
return ResponseEntity.status(401).body(Collections.singletonMap("message", e.getMessage()));
101+
} catch (IllegalArgumentException e) {
102+
return ResponseEntity.status(400).body(Collections.singletonMap("message", e.getMessage()));
103+
} catch (NoSuchElementException e) {
104+
return ResponseEntity.status(404).body(Collections.singletonMap("message", e.getMessage()));
105+
} catch (Exception e) {
106+
return ResponseEntity.status(500).body(Collections.singletonMap("message", "내부 서버 오류가 발생했습니다."));
107+
}
66108
}
67109

68110
// 지도용 장소별 사건 수 조회
69111
@GetMapping("/map")
70112
public ResponseEntity<?> getMapCaseStats(@RequestParam("period") String period, HttpSession session) {
71-
List<MapCaseStatsResponse> stats = caseStatsService.getMapCaseStats(period, session);
72-
return ResponseEntity.ok(stats);
113+
try {
114+
List<MapCaseStatsResponse> stats = caseStatsService.getMapCaseStats(period, session);
115+
return ResponseEntity.ok(stats);
116+
} catch (IllegalStateException e) {
117+
return ResponseEntity.status(401).body(Collections.singletonMap("message", e.getMessage()));
118+
} catch (IllegalArgumentException e) {
119+
return ResponseEntity.status(400).body(Collections.singletonMap("message", e.getMessage()));
120+
} catch (NoSuchElementException e) {
121+
return ResponseEntity.status(404).body(Collections.singletonMap("message", e.getMessage()));
122+
} catch (Exception e) {
123+
return ResponseEntity.status(500).body(Collections.singletonMap("message", "내부 서버 오류가 발생했습니다."));
124+
}
73125
}
74-
75126
}
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
package com.example.backend.analysis.dto;
22

3-
import com.example.backend.common.domain.CaseEntity;
4-
import com.example.backend.common.domain.CaseStatsOverviewEntity;
53
import lombok.*;
64

75
@Data
8-
@Builder
9-
@NoArgsConstructor
106
@AllArgsConstructor
117
public class CaseStatsOverviewResponse {
128
private int recentCase;
139
private int todayCase;
14-
private CaseEntity.CaseCategory mostCase;
10+
private String mostCase;
1511
private String patrolRegion;
16-
17-
public static CaseStatsOverviewResponse fromEntity(CaseStatsOverviewEntity entity, String patrolRegionAddress) {
18-
return CaseStatsOverviewResponse.builder()
19-
.recentCase(entity.getRecentCaseCount())
20-
.todayCase(entity.getTodayCaseCount())
21-
.mostCase(entity.getMostCase())
22-
.patrolRegion(patrolRegionAddress)
23-
.build();
24-
}
2512
}

backend/src/main/java/com/example/backend/analysis/dto/DailyCaseStatsResponse.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,15 @@
22

33
import lombok.*;
44

5-
@Data
6-
@Builder
7-
@NoArgsConstructor
5+
@Getter
6+
@Setter
87
@AllArgsConstructor
8+
@NoArgsConstructor
99
public class DailyCaseStatsResponse {
1010
private int day;
1111
private int fireCount;
1212
private int assaultCount;
1313
private int crowdCongestionCount;
1414
private int weaponCount;
1515
private int swoonCount;
16-
17-
public static DailyCaseStatsResponse fromRow(Object[] row) {
18-
return DailyCaseStatsResponse.builder()
19-
.day(((Number) row[0]).intValue())
20-
.fireCount(((Number) row[1]).intValue())
21-
.assaultCount(((Number) row[2]).intValue())
22-
.crowdCongestionCount(((Number) row[3]).intValue())
23-
.weaponCount(((Number) row[4]).intValue())
24-
.swoonCount(((Number) row[5]).intValue())
25-
.build();
26-
}
2716
}
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.example.backend.analysis.dto;
22

3-
import lombok.*;
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
45

56
@Data
6-
@Builder
7-
@NoArgsConstructor
87
@AllArgsConstructor
98
public class HourlyCaseStatsResponse {
109
private int hour;
@@ -13,15 +12,4 @@ public class HourlyCaseStatsResponse {
1312
private int crowdCongestionCount;
1413
private int weaponCount;
1514
private int swoonCount;
16-
17-
public static HourlyCaseStatsResponse fromRow(Object[] row) {
18-
return HourlyCaseStatsResponse.builder()
19-
.hour(((Number) row[0]).intValue())
20-
.fireCount(((Number) row[1]).intValue())
21-
.assaultCount(((Number) row[2]).intValue())
22-
.crowdCongestionCount(((Number) row[3]).intValue())
23-
.weaponCount(((Number) row[4]).intValue())
24-
.swoonCount(((Number) row[5]).intValue())
25-
.build();
26-
}
2715
}

backend/src/main/java/com/example/backend/analysis/dto/LocationCaseStatsResponse.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,10 @@
33
import lombok.*;
44

55
@Data
6-
@Builder
7-
@NoArgsConstructor
86
@AllArgsConstructor
97
public class LocationCaseStatsResponse {
10-
private String address;
11-
private double latitude;
12-
private double longitude;
13-
private int count;
14-
15-
public static LocationCaseStatsResponse fromRow(Object[] row) {
16-
return LocationCaseStatsResponse.builder()
17-
.address((String) row[0])
18-
.latitude((Double) row[1])
19-
.longitude((Double) row[2])
20-
.count(((Number) row[3]).intValue())
21-
.build();
22-
}
8+
String address;
9+
double latitude;
10+
double longitude;
11+
int count;
2312
}
Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
11
package com.example.backend.analysis.dto;
22

3-
import lombok.*;
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
45

56
@Data
6-
@Builder
7-
@NoArgsConstructor
87
@AllArgsConstructor
98
public class MapCaseStatsResponse {
10-
private String address;
11-
private double latitude;
12-
private double longitude;
13-
private int fireCount;
14-
private int assaultCount;
15-
private int crowdCongestionCount;
16-
private int weaponCount;
17-
private int swoonCount;
18-
19-
public static MapCaseStatsResponse fromRow(Object[] row) {
20-
return MapCaseStatsResponse.builder()
21-
.address((String) row[0])
22-
.latitude((Double) row[1])
23-
.longitude((Double) row[2])
24-
.fireCount(((Number) row[3]).intValue())
25-
.assaultCount(((Number) row[4]).intValue())
26-
.crowdCongestionCount(((Number) row[5]).intValue())
27-
.weaponCount(((Number) row[6]).intValue())
28-
.swoonCount(((Number) row[7]).intValue())
29-
.build();
30-
}
9+
String address;
10+
double latitude;
11+
double longitude;
12+
int fire_count;
13+
int assault_count;
14+
int crowd_congestion_count;
15+
int weapon_count;
16+
int swoon_count;
3117
}

backend/src/main/java/com/example/backend/analysis/dto/MonthlyCaseStatsResponse.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,15 @@
22

33
import lombok.*;
44

5-
@Data
6-
@Builder
7-
@NoArgsConstructor
5+
@Getter
6+
@Setter
87
@AllArgsConstructor
8+
@NoArgsConstructor
99
public class MonthlyCaseStatsResponse {
1010
private int month;
1111
private int fireCount;
1212
private int assaultCount;
1313
private int crowdCongestionCount;
1414
private int weaponCount;
1515
private int swoonCount;
16-
17-
public static MonthlyCaseStatsResponse fromRow(Object[] row) {
18-
return MonthlyCaseStatsResponse.builder()
19-
.month(((Number) row[0]).intValue())
20-
.fireCount(((Number) row[1]).intValue())
21-
.assaultCount(((Number) row[2]).intValue())
22-
.crowdCongestionCount(((Number) row[3]).intValue())
23-
.weaponCount(((Number) row[4]).intValue())
24-
.swoonCount(((Number) row[5]).intValue())
25-
.build();
26-
}
2716
}

0 commit comments

Comments
 (0)