-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobileDutyController.java
More file actions
63 lines (52 loc) · 2.25 KB
/
Copy pathMobileDutyController.java
File metadata and controls
63 lines (52 loc) · 2.25 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
package com.crimeLink.analyzer.controller;
import com.crimeLink.analyzer.dto.DutyAssignmentDTO;
import com.crimeLink.analyzer.dto.DutyDetailDTO;
import com.crimeLink.analyzer.service.MobileDutyService;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.List;
@RestController
@RequestMapping("/api/duties")
@RequiredArgsConstructor
public class MobileDutyController {
private final MobileDutyService mobileDutyService;
/**
* Get all duties for a specific officer
*/
@GetMapping("/officer/{officerId}")
public ResponseEntity<List<DutyAssignmentDTO>> getDutiesByOfficer(
@PathVariable Long officerId) {
System.out.println(" Mobile API Request: GET /officer/" + officerId);
try {
List<DutyAssignmentDTO> duties = mobileDutyService.getDutiesByOfficerId(officerId);
System.out.println(" Returned " + duties.size() + " duties");
return ResponseEntity.ok(duties);
} catch (Exception e) {
System.err.println(" Error: " + e.getMessage());
e.printStackTrace();
return ResponseEntity.internalServerError().build();
}
}
/**
* GET /api/duties/officer/{officerId}/date?date=2023-10-24
* Get duty details for a specific officer on a specific date
*/
@GetMapping("/officer/{officerId}/date")
public ResponseEntity<List<DutyDetailDTO>> getDutyDetailsByDate(
@PathVariable Long officerId,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) {
System.out.println(" Mobile API Request: GET /officer/" + officerId + "/date?date=" + date);
try {
List<DutyDetailDTO> details = mobileDutyService.getDutyDetailsByDate(officerId, date);
System.out.println("Returned " + details.size() + " duty details");
return ResponseEntity.ok(details);
} catch (Exception e) {
System.err.println(" Error: " + e.getMessage());
e.printStackTrace();
return ResponseEntity.internalServerError().build();
}
}
}