Created
August 1, 2023 06:07
-
-
Save itishprasad30/bb0ef3e019ea48da9d4dde1d73525b63 to your computer and use it in GitHub Desktop.
TodoApp Using Spring Boot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
todo-list-app/ | |
├── src/ | |
│ ├── main/ | |
│ │ ├── java/ | |
│ │ │ ├── com.example.todolist/ | |
│ │ │ │ ├── controller/ | |
│ │ │ │ │ ├── TodoController.java | |
│ │ │ │ ├── model/ | |
│ │ │ │ │ ├── Todo.java | |
│ │ │ │ ├── repository/ | |
│ │ │ │ │ ├── TodoRepository.java | |
│ │ │ │ ├── service/ | |
│ │ │ │ │ ├── TodoService.java | |
│ │ │ │ │ ├── TodoServiceImpl.java | |
│ │ │ ├── TodoListApplication.java | |
│ │ ├── resources/ | |
│ │ │ ├── application.properties | |
│ ├── test/ | |
│ │ ├── java/ | |
│ │ │ ├── com.example.todolist/ | |
│ │ │ │ ├── controller/ | |
│ │ │ │ │ ├── TodoControllerTest.java | |
│ │ │ │ ├── service/ | |
│ │ │ │ │ ├── TodoServiceTest.java | |
├── pom.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("/api/todo") | |
public class TodoController { | |
@Autowired | |
private TodoService todoService; | |
@GetMapping | |
public List<Todo> getAllTodos() { | |
return todoService.getAllTodos(); | |
} | |
@PostMapping | |
public Todo createTodo(@RequestBody Todo todo) { | |
return todoService.createTodo(todo); | |
} | |
@DeleteMapping("/{id}") | |
public void deleteTodoById(@PathVariable Long id) { | |
todoService.deleteTodoById(id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface TodoService { | |
List<Todo> getAllTodos(); | |
Todo createTodo(Todo todo); | |
void deleteTodoById(Long id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class TodoServiceImpl implements TodoService { | |
@Autowired | |
private TodoRepository todoRepository; | |
@Override | |
public List<Todo> getAllTodos() { | |
return todoRepository.findAll(); | |
} | |
@Override | |
public Todo createTodo(Todo todo) { | |
return todoRepository.save(todo); | |
} | |
@Override | |
public void deleteTodoById(Long id) { | |
todoRepository.deleteById(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment