/
ToDoController.java
35 lines (28 loc) · 1.11 KB
/
ToDoController.java
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
package com.willypuzzle.todospringapplication.controllers.todo;
import com.willypuzzle.todospringapplication.dto.todo.TodoDto;
import com.willypuzzle.todospringapplication.services.todo.contracts.TodoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
@RestController
@RequestMapping("/api/")
public class ToDoController {
@Autowired
private TodoService todoService;
@PostMapping("todo")
public ResponseEntity<TodoDto> createTodo(@Valid @RequestBody TodoDto todoDto){
return new ResponseEntity<TodoDto>(todoService.saveTodo(todoDto), HttpStatus.CREATED);
}
@DeleteMapping("todo/{todoId}")
public ResponseEntity<Object> deleteTodo(@PathVariable Long todoId){
todoService.deleteTodo(todoId);
return new ResponseEntity<Object>(null, HttpStatus.OK);
}
@GetMapping("todo")
public List<TodoDto> indexTodo(){
return todoService.getAllTodos();
}
}