-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInstallationController.java
More file actions
87 lines (73 loc) · 3.26 KB
/
Copy pathInstallationController.java
File metadata and controls
87 lines (73 loc) · 3.26 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package devices.installation;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import devices.configuration.management.Coordinates;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
@RestController
@RequiredArgsConstructor
@RequestMapping("/installations")
class InstallationController {
private final InstallationService service;
@GetMapping(path = "/{workOrderId}", produces = APPLICATION_JSON_VALUE)
InstallationSnapshot get(@PathVariable String workOrderId) {
return service
.getInstallation(WorkOrderId.of(workOrderId))
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}
@PostMapping(
path = "/{workOrderId}/assign",
consumes = APPLICATION_JSON_VALUE,
produces = APPLICATION_JSON_VALUE)
InstallationSnapshot assignInstaller(
@PathVariable String workOrderId, @RequestBody AssignInstallerRequest request) {
return service
.assignInstaller(
WorkOrderId.of(workOrderId),
InstallerId.of(request.installerId()),
request.forceReassign())
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}
@PostMapping(path = "/{workOrderId}/start", produces = APPLICATION_JSON_VALUE)
InstallationSnapshot start(@PathVariable String workOrderId) {
return service
.startInstallation(WorkOrderId.of(workOrderId))
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}
@PostMapping(
path = "/{workOrderId}/device",
consumes = APPLICATION_JSON_VALUE,
produces = APPLICATION_JSON_VALUE)
InstallationSnapshot assignDevice(
@PathVariable String workOrderId, @RequestBody AssignDeviceRequest request) {
return service
.assignDevice(WorkOrderId.of(workOrderId), DeviceIdentifier.of(request.deviceIdentifier()))
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}
@PostMapping(path = "/{workOrderId}/boot-confirmation", produces = APPLICATION_JSON_VALUE)
InstallationSnapshot confirmBoot(@PathVariable String workOrderId) {
return service
.confirmBoot(WorkOrderId.of(workOrderId))
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}
@PostMapping(
path = "/{workOrderId}/location",
consumes = APPLICATION_JSON_VALUE,
produces = APPLICATION_JSON_VALUE)
InstallationSnapshot setLocation(
@PathVariable String workOrderId, @RequestBody SetLocationRequest request) {
return service
.setLocation(WorkOrderId.of(workOrderId), request.coordinates())
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}
@PostMapping(path = "/{workOrderId}/finish", produces = APPLICATION_JSON_VALUE)
InstallationSnapshot finish(@PathVariable String workOrderId) {
return service
.finishInstallation(WorkOrderId.of(workOrderId))
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}
record AssignInstallerRequest(String installerId, boolean forceReassign) {}
record AssignDeviceRequest(String deviceIdentifier) {}
record SetLocationRequest(Coordinates coordinates) {}
}