Skip to content

Commit 7bb9964

Browse files
committed
refactor: merge moveCase API and alarmList API with code refactoring #95
1 parent abadb4f commit 7bb9964

15 files changed

+230
-341
lines changed

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

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.example.backend.dashboard.controller;
2+
3+
import com.example.backend.dashboard.dto.*;
4+
import com.example.backend.dashboard.service.DashboardService;
5+
import jakarta.servlet.http.HttpSession;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.http.ResponseEntity;
8+
import org.springframework.web.bind.annotation.*;
9+
10+
import java.util.Collections;
11+
import java.util.List;
12+
import java.util.Map;
13+
14+
@RestController
15+
@RequestMapping("/api/v1/case")
16+
@RequiredArgsConstructor
17+
public class DashboardController {
18+
19+
private final DashboardService dashboardService;
20+
21+
@GetMapping("")
22+
public ResponseEntity<?> getCases(HttpSession session) {
23+
List<DashboardResponse> cases = dashboardService.getCases(session);
24+
if (cases.isEmpty()) {
25+
return ResponseEntity.status(404)
26+
.body(Collections.singletonMap("message", "사건이 없습니다."));
27+
}
28+
return ResponseEntity.ok(cases);
29+
}
30+
31+
// 출동 중인 사건 영상 확인
32+
@GetMapping("/{id}")
33+
public ResponseEntity<?> getCaseVideo(@PathVariable("id") int id, HttpSession session) {
34+
Map<String, String> videoResponse = dashboardService.getCaseVideo(id, session);
35+
return ResponseEntity.ok(videoResponse);
36+
}
37+
38+
// 출동 | 미출동 클릭 시 => 1. 이미 출동인 상태 or 2. state를 업데이트
39+
@PutMapping("/ready/{id}")
40+
public ResponseEntity<?> updateCaseState(@PathVariable("id") int id, @RequestBody StateRequest request, HttpSession session) {
41+
Map<Integer, String> message = dashboardService.updateCaseState(id, request.getState(), session);
42+
return ResponseEntity.ok(message);
43+
}
44+
45+
// 출동 중인 사건 해결 처리
46+
@PutMapping("/complete/{id}")
47+
public ResponseEntity<?> completeCase(@PathVariable("id") int id, HttpSession session) {
48+
Map<Integer, String> completedCase = dashboardService.completeCase(id, session);
49+
return ResponseEntity.ok(completedCase);
50+
}
51+
52+
}

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

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.backend.dashboard.controller;
2+
3+
import com.example.backend.dashboard.dto.SurveyRequest;
4+
import com.example.backend.dashboard.dto.SurveyResponse;
5+
import com.example.backend.dashboard.service.SurveyService;
6+
import jakarta.servlet.http.HttpSession;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.web.bind.annotation.*;
10+
11+
@RestController
12+
@RequestMapping("/api/v1/survey")
13+
@RequiredArgsConstructor
14+
public class SurveyController {
15+
16+
private final SurveyService surveyService;
17+
18+
// AI 설문조사 결과 저장
19+
@PutMapping("/{id}")
20+
public ResponseEntity<?> saveSurveyResult(@PathVariable("id") int id,
21+
@RequestBody SurveyRequest surveyRequest,
22+
HttpSession session) {
23+
SurveyResponse surveyResult = surveyService.saveSurveyResult(id, surveyRequest, session);
24+
return ResponseEntity.ok(surveyResult);
25+
}
26+
}

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

Lines changed: 0 additions & 55 deletions
This file was deleted.

backend/src/main/java/com/example/backend/dashboard/dto/ProgressResponse.java renamed to backend/src/main/java/com/example/backend/dashboard/dto/DashboardResponse.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@Data
1212
@Builder
13-
public class ProgressResponse {
13+
public class DashboardResponse {
1414
private Integer id;
1515
private String police_name;
1616
private String police_rank;
@@ -21,22 +21,18 @@ public class ProgressResponse {
2121

2222
private Integer level;
2323
private CaseCategory category;
24-
private String video;
2524
private CaseState state;
26-
private String memo;
2725

28-
public static ProgressResponse fromEntity(CaseEntity entity) {
29-
return ProgressResponse.builder()
26+
public static DashboardResponse fromEntity(CaseEntity entity) {
27+
return DashboardResponse.builder()
3028
.id(entity.getId())
3129
.police_name(entity.getPolice().getName())
3230
.police_rank(String.valueOf(entity.getPolice().getRank()))
3331
.address(entity.getCctv().getAddress())
3432
.date(entity.getDate())
3533
.level(entity.getLevel())
3634
.category(entity.getCategory())
37-
.video(entity.getVideo())
3835
.state(entity.getState())
39-
.memo(entity.getMemo())
4036
.build();
4137
}
4238

backend/src/main/java/com/example/backend/dashboard/dto/AlarmRequest.java renamed to backend/src/main/java/com/example/backend/dashboard/dto/StateRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
@Getter
88
@Setter
9-
public class AlarmRequest {
9+
public class StateRequest {
1010
private CaseState state; // "출동" or "미출동"
1111
}

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

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.example.backend.dashboard.repository;
2+
3+
import com.example.backend.common.domain.CaseEntity;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
import java.util.List;
7+
8+
public interface DashboardRepository extends JpaRepository<CaseEntity, Integer> {
9+
List<CaseEntity> findAllByOfficeIdOrderById(int officeId);
10+
}

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

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)