-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathReminderController.java
More file actions
55 lines (46 loc) · 2.12 KB
/
ReminderController.java
File metadata and controls
55 lines (46 loc) · 2.12 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
package br.com.springnoobs.reminderapi.reminder.controller;
import br.com.springnoobs.reminderapi.reminder.dto.request.CreateReminderRequestDTO;
import br.com.springnoobs.reminderapi.reminder.dto.request.UpdateReminderRequestDTO;
import br.com.springnoobs.reminderapi.reminder.dto.response.ReminderResponseDTO;
import br.com.springnoobs.reminderapi.reminder.service.ReminderService;
import jakarta.validation.Valid;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/reminders")
public class ReminderController {
private final ReminderService reminderService;
public ReminderController(ReminderService reminderService) {
this.reminderService = reminderService;
}
@GetMapping
public ResponseEntity<Page<ReminderResponseDTO>> findAll(
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<ReminderResponseDTO> reminderPage = reminderService.findAll(pageable);
return ResponseEntity.ok(reminderPage);
}
@GetMapping("/{id}")
public ResponseEntity<ReminderResponseDTO> findById(@PathVariable Long id) {
return ResponseEntity.ok(reminderService.findById(id));
}
@PostMapping
public ResponseEntity<ReminderResponseDTO> create(@RequestBody @Valid CreateReminderRequestDTO dto) {
return ResponseEntity.status(HttpStatus.CREATED).body(reminderService.create(dto));
}
@PutMapping("/{id}")
public ResponseEntity<ReminderResponseDTO> update(
@PathVariable Long id, @RequestBody @Valid UpdateReminderRequestDTO dto)
{
return ResponseEntity.ok(reminderService.update(id, dto));
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable Long id) {
reminderService.delete(id);
return ResponseEntity.noContent().build();
}
}