-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessCheckController.java
More file actions
81 lines (68 loc) · 2.65 KB
/
Copy pathProcessCheckController.java
File metadata and controls
81 lines (68 loc) · 2.65 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
package de.datatidehh.processapi.processcheck;
import jakarta.validation.Valid;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PagedModel;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
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.servlet.support.ServletUriComponentsBuilder;
import java.net.URI;
@RestController
@RequestMapping("/api/process-checks")
public class ProcessCheckController {
private final ProcessCheckService service;
public ProcessCheckController(ProcessCheckService service) {
this.service = service;
}
@GetMapping
public PagedModel<ProcessCheckResponse> findAll(
@RequestParam(required = false) ProcessStatus status,
@PageableDefault(
size = 20,
sort = "lastCheckedAt",
direction = Sort.Direction.DESC
) Pageable pageable
) {
return new PagedModel<>(service.findAll(status, pageable));
}
@GetMapping("/{id}")
public ProcessCheckResponse findById(@PathVariable Long id) {
return service.findById(id);
}
@PostMapping
public ResponseEntity<ProcessCheckResponse> create(
@Valid @RequestBody ProcessCheckRequest request
) {
ProcessCheckResponse response = service.create(request);
Long id = response.id();
URI location = buildLocation(id);
return ResponseEntity.created(location).body(response);
}
@PutMapping("/{id}")
public ProcessCheckResponse update(
@PathVariable Long id,
@Valid @RequestBody ProcessCheckRequest request
) {
return service.update(id, request);
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable Long id) {
service.delete(id);
return ResponseEntity.noContent().build();
}
private URI buildLocation(Long id) {
return ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(id)
.toUri();
}
}