Skip to content

Commit 99f25e6

Browse files
authored
Merge pull request #38 from kookmin-sw/feat/30
[Backend] feat: 메인 페이지 - 출동 사건 관련 API
2 parents 6798fde + 0a64bde commit 99f25e6

File tree

13 files changed

+325
-0
lines changed

13 files changed

+325
-0
lines changed

backend/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ dependencies {
2727
// https://mvnrepository.com/artifact/org.postgresql/postgresql
2828
implementation 'org.postgresql:postgresql:42.7.3' // PostgreSQL JDBC 드라이버 의존성 추가
2929
runtimeOnly 'org.postgresql:postgresql:42.7.3' // 실행 시에만 필요한 의존성 추가
30+
31+
// Spring Data JPA 의존성 추가
32+
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
33+
34+
// Lombok 의존성 추가
35+
compileOnly 'org.projectlombok:lombok:1.18.30'
36+
annotationProcessor 'org.projectlombok:lombok:1.18.30'
37+
3038
}
3139

3240
tasks.named('test') {

backend/src/main/java/com/example/backend/dashboard/controller/.gitkeep

Whitespace-only changes.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.example.backend.dashboard.controller;
2+
3+
import com.example.backend.dashboard.dto.CaseResponse;
4+
import com.example.backend.dashboard.dto.SurveyRequest;
5+
import com.example.backend.dashboard.dto.SurveyResponse;
6+
import com.example.backend.dashboard.service.DashboardService;
7+
import jakarta.persistence.EntityNotFoundException;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.http.ResponseEntity;
10+
import org.springframework.web.bind.annotation.*;
11+
12+
import java.util.Collections;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
@RestController
17+
@RequestMapping("/api/v1")
18+
@RequiredArgsConstructor
19+
public class DashboardController {
20+
21+
private final DashboardService dashboardService;
22+
23+
// (전체) 출동 중인 사건 조회 (완)
24+
@GetMapping("/case/move")
25+
public ResponseEntity<?> getActiveCases() {
26+
try {
27+
List<CaseResponse> cases = dashboardService.getActiveCases();
28+
29+
if (cases.isEmpty()) {
30+
return ResponseEntity.status(404)
31+
.body(Collections.singletonMap("message", "출동 중인 사건이 없습니다."));
32+
}
33+
34+
return ResponseEntity.ok(cases);
35+
} catch (Exception e) {
36+
return ResponseEntity.status(500)
37+
.body(Collections.singletonMap("message", "내부 서버 오류가 발생했습니다."));
38+
}
39+
}
40+
41+
// 출동 중인 사건 영상 확인
42+
@GetMapping("/case/move/{id}")
43+
public ResponseEntity<Map<String, String>> getCaseVideo(@PathVariable("id") int id) {
44+
try {
45+
Map<String, String> videoResponse = dashboardService.getCaseVideo(id);
46+
return ResponseEntity.ok(videoResponse);
47+
} catch (EntityNotFoundException e) {
48+
return ResponseEntity.status(404)
49+
.body(Collections.singletonMap("message", e.getMessage()));
50+
} catch (IllegalStateException e) {
51+
return ResponseEntity.status(400)
52+
.body(Collections.singletonMap("message", e.getMessage()));
53+
} catch (Exception e) {
54+
return ResponseEntity.status(500)
55+
.body(Collections.singletonMap("message", "내부 서버 오류가 발생했습니다."));
56+
}
57+
}
58+
59+
// 출동 중인 사건 해결 처리
60+
@PutMapping("/case/complete/{id}")
61+
public ResponseEntity<?> completeCase(@PathVariable("id") int id) {
62+
try {
63+
Map<Integer, String> completedCase = dashboardService.completeCase(id);
64+
return ResponseEntity.ok(completedCase);
65+
} catch (EntityNotFoundException e) {
66+
return ResponseEntity.status(404)
67+
.body(Collections.singletonMap("message", e.getMessage()));
68+
} catch (IllegalStateException e) {
69+
return ResponseEntity.status(400)
70+
.body(Collections.singletonMap("message", e.getMessage()));
71+
} catch (Exception e) {
72+
return ResponseEntity.status(500)
73+
.body(Collections.singletonMap("message", "내부 서버 오류가 발생했습니다."));
74+
}
75+
}
76+
77+
// AI 설문조사 결과 저장
78+
@PutMapping("/survey/{id}")
79+
public ResponseEntity<?> saveSurveyResult(@PathVariable("id") int id,
80+
@RequestBody SurveyRequest surveyRequest) {
81+
try {
82+
SurveyResponse surveyResult = dashboardService.saveSurveyResult(id, surveyRequest);
83+
return ResponseEntity.ok(surveyResult);
84+
} catch (EntityNotFoundException e) {
85+
return ResponseEntity.status(404)
86+
.body(Collections.singletonMap("message", e.getMessage()));
87+
} catch (IllegalArgumentException | IllegalStateException e ) {
88+
return ResponseEntity.status(400)
89+
.body(Collections.singletonMap("message", e.getMessage()));
90+
} catch (Exception e) {
91+
return ResponseEntity.status(500)
92+
.body(Collections.singletonMap("message", "내부 서버 오류가 발생했습니다."));
93+
}
94+
}
95+
96+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.example.backend.dashboard.domain;
2+
3+
import jakarta.persistence.*;
4+
import lombok.*;
5+
6+
@Entity
7+
@Table(name = "case_info")
8+
@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder
9+
public class CaseEntity {
10+
11+
@Id
12+
@GeneratedValue(strategy = GenerationType.IDENTITY)
13+
private int id;
14+
15+
private int office_id;
16+
17+
private int police_id;
18+
19+
private int cctv_id;
20+
21+
private String date;
22+
23+
private int level;
24+
25+
@Enumerated(EnumType.STRING)
26+
private CaseCategory category;
27+
28+
private String video;
29+
30+
@Enumerated(EnumType.STRING)
31+
private CaseState state;
32+
33+
private boolean accuracy;
34+
35+
private String memo;
36+
37+
public enum CaseCategory {
38+
fire, assult, crowd_congestion, weapon, swoon
39+
}
40+
41+
public enum CaseState {
42+
미확인, 확인, 미출동, 출동, 완료
43+
}
44+
}

backend/src/main/java/com/example/backend/dashboard/dto/.gitkeep

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.example.backend.dashboard.dto;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class CaseRequest {
7+
private int id;
8+
private int officeId;
9+
private int policeId;
10+
private int cctvId;
11+
private String date;
12+
private int level;
13+
private String category;
14+
private String video;
15+
private String state;
16+
private boolean accuracy;
17+
private String memo;
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.example.backend.dashboard.dto;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class CaseResponse {
7+
private int id;
8+
private int officeId;
9+
private int policeId;
10+
private int cctvId;
11+
private String date;
12+
private int level;
13+
private String category;
14+
private String video;
15+
private String state;
16+
private boolean accuracy;
17+
private String memo;
18+
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.example.backend.dashboard.dto;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class SurveyRequest {
7+
private String category; // 수정된 정확한 사건 카테고리
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example.backend.dashboard.dto;
2+
3+
import lombok.*;
4+
5+
@Getter
6+
@AllArgsConstructor
7+
public class SurveyResponse {
8+
private int id;
9+
private String category;
10+
private String resultMessage;
11+
12+
}

backend/src/main/java/com/example/backend/dashboard/repository/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)