-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrimeReportController.java
More file actions
73 lines (57 loc) · 2.68 KB
/
Copy pathCrimeReportController.java
File metadata and controls
73 lines (57 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.crimeLink.analyzer.controller;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.crimeLink.analyzer.dto.CrimeLocationDTO;
import com.crimeLink.analyzer.dto.CrimeReportDTO;
import com.crimeLink.analyzer.dto.EvidenceDTO;
import com.crimeLink.analyzer.service.CrimeReportService;
import com.crimeLink.analyzer.service.SupabaseService;
import lombok.AllArgsConstructor;
@RestController
@AllArgsConstructor
@RequestMapping("/api/crime-reports")
public class CrimeReportController {
private final CrimeReportService crimeReportService;
private final SupabaseService supabaseService;
@PostMapping
public ResponseEntity<CrimeReportDTO> saveCrimeReport(@RequestBody CrimeReportDTO crimeReportDTO) {
CrimeReportDTO report = crimeReportService.saveCrimeReport(crimeReportDTO);
return new ResponseEntity<>(report, HttpStatus.CREATED);
}
@GetMapping
public ResponseEntity<List<CrimeReportDTO>> getAllCrimeReports() {
List<CrimeReportDTO> crimeReports = crimeReportService.getAllCrimeReports();
return ResponseEntity.ok(crimeReports);
}
@GetMapping("/{id}")
public ResponseEntity<CrimeReportDTO> getCrimeReportById(@PathVariable("id") Long reportId) {
CrimeReportDTO dto = crimeReportService.getCrimeReportById(reportId);
return ResponseEntity.ok(dto);
}
@GetMapping("/map")
public List<CrimeLocationDTO> getCrimeMapLocations() {
return crimeReportService.getCrimeMapLocations();
}
@PostMapping("/upload-evidence")
public ResponseEntity<String> uploadEvidence(@RequestParam("file") MultipartFile file) throws Exception {
String fileUrl = supabaseService.uploadFile(file);
return ResponseEntity.ok(fileUrl);
}
@GetMapping("/download/{reportId}")
public ResponseEntity<List<EvidenceDTO>> downloadEvidence(@PathVariable Long reportId) {
CrimeReportDTO report = crimeReportService.getCrimeReportById(reportId);
if (report.getEvidences() == null || report.getEvidences().isEmpty()) {
return ResponseEntity.badRequest().build();
}
return ResponseEntity.ok(report.getEvidences());
}
}