-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTodoController.java
More file actions
75 lines (52 loc) · 1.94 KB
/
TodoController.java
File metadata and controls
75 lines (52 loc) · 1.94 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
package study.todolist.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import study.todolist.dto.TodoDto;
import study.todolist.global.Envelope;
import study.todolist.entity.TodoList;
import study.todolist.service.TodoService;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/todo")
public class TodoController {
private final TodoService todoService;
// 생성
@PostMapping("/create")
public ResponseEntity createTodo(@RequestBody TodoDto.Request request){
Long id = todoService.createTodo(request.getTitle());
return ResponseEntity.ok(Envelope.toEnvelope(todoService.findById(id)));
}
// 단건조회
@GetMapping("/find/{id}")
public ResponseEntity findById(@PathVariable("id") Long id){
TodoList todo = todoService.findById(id);
Envelope response = Envelope.toEnvelope(todo);
return ResponseEntity.ok(response);
}
// 전체조회
@GetMapping("/find/all")
public ResponseEntity findAll(){
Envelope envelope = Envelope.toEnvelope(todoService.findAll());
return ResponseEntity.ok(envelope);
}
// 수정
@PatchMapping("/update/{id}")
public ResponseEntity updateTodo(@PathVariable Long id,
@RequestBody TodoDto.Request request){
todoService.updateTitle(id, request.getTitle());
return ResponseEntity.ok(Envelope.toEnvelope(todoService.findById(id)));
}
// check
@PatchMapping("/check/{id}")
public ResponseEntity checkTodo(@PathVariable Long id){
todoService.updateCheck(id);
return ResponseEntity.ok(Envelope.toEnvelope(todoService.findById(id)));
}
// 삭제
@DeleteMapping("/delete/{id}")
public ResponseEntity deleteTodo(@PathVariable Long id){
todoService.delete(id);
return ResponseEntity.ok(true);
}
}