[fdfbdde] | 1 | package com.example.task.controller;
|
---|
| 2 |
|
---|
| 3 | import com.example.task.service.TaskService;
|
---|
| 4 | import lombok.AllArgsConstructor;
|
---|
| 5 | import org.springframework.stereotype.Controller;
|
---|
| 6 | import org.springframework.ui.Model;
|
---|
| 7 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
| 8 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
| 9 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
| 10 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
| 11 |
|
---|
| 12 | import java.time.LocalDate;
|
---|
| 13 |
|
---|
| 14 | @Controller
|
---|
| 15 | @AllArgsConstructor
|
---|
| 16 | public class TaskController {
|
---|
| 17 |
|
---|
| 18 | private final TaskService taskService;
|
---|
| 19 |
|
---|
| 20 | @GetMapping("/add/task")
|
---|
| 21 | public String getAddTaskPage() {
|
---|
| 22 | return "task/form";
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | @PostMapping("/add/task")
|
---|
| 26 | public String addTask(@RequestParam(name = "name") String name,
|
---|
| 27 | @RequestParam(name = "description") String description,
|
---|
| 28 | @RequestParam(name = "priority") int priority,
|
---|
| 29 | @RequestParam(name = "dueDate") LocalDate dueDate) {
|
---|
| 30 | taskService.addTask(name, description, priority, dueDate);
|
---|
| 31 | return "redirect:/task";
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | @GetMapping("/task")
|
---|
| 35 | public String getTaskPage(Model model) {
|
---|
| 36 | model.addAttribute("tasks", taskService.getUserTasks());
|
---|
| 37 | return "task/list";
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | @PostMapping("/finish/task/{id}")
|
---|
| 41 | public String finishTask(@PathVariable(name = "id") Integer id) throws Exception {
|
---|
| 42 | taskService.finishTask(id);
|
---|
| 43 | return "redirect:/task";
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | @PostMapping("/delete/task/{id}")
|
---|
| 47 | public String deleteTask(@PathVariable(name = "id") Integer id) {
|
---|
| 48 | taskService.deleteTask(id);
|
---|
| 49 | return "redirect:/task";
|
---|
| 50 | }
|
---|
| 51 | }
|
---|