source: src/main/java/com/example/task/controller/TaskController.java

Last change on this file was fdfbdde, checked in by Stojilkova Sara <sara.stojilkova.students.finki.ukim.mk>, 9 months ago

Initial commit

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[fdfbdde]1package com.example.task.controller;
2
3import com.example.task.service.TaskService;
4import lombok.AllArgsConstructor;
5import org.springframework.stereotype.Controller;
6import org.springframework.ui.Model;
7import org.springframework.web.bind.annotation.GetMapping;
8import org.springframework.web.bind.annotation.PathVariable;
9import org.springframework.web.bind.annotation.PostMapping;
10import org.springframework.web.bind.annotation.RequestParam;
11
12import java.time.LocalDate;
13
14@Controller
15@AllArgsConstructor
16public 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}
Note: See TracBrowser for help on using the repository browser.