use of softuni.todolist.entity.Todo in project SoftUni by kostovhg.
the class TodoController method delete.
@GetMapping("/todo/delete/{id}")
@PreAuthorize("isAuthenticated()")
public String delete(Model model, @PathVariable Integer id) {
if (!this.todoRepository.exists(id)) {
return "redirect:/";
}
Todo todo = this.todoRepository.findOne(id);
model.addAttribute("todo", todo);
model.addAttribute("view", "todo/delete");
return "base-layout";
}
use of softuni.todolist.entity.Todo in project SoftUni by kostovhg.
the class TodoController method edit.
@GetMapping("/todo/edit/{id}")
@PreAuthorize("isAuthenticated()")
public String edit(@PathVariable Integer id, Model model) {
if (!this.todoRepository.exists(id)) {
return "redirect:/";
}
Todo todo = this.todoRepository.findOne(id);
model.addAttribute("view", "todo/edit");
model.addAttribute("todo", todo);
return "base-layout";
}
use of softuni.todolist.entity.Todo in project SoftUni by kostovhg.
the class TodoController method createProcess.
@PostMapping("/todo/create")
@PreAuthorize("isAuthenticated()")
public String createProcess(TodoBindingModel todoBindingModel) {
UserDetails user = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
User userEntity = this.userRepository.findByEmail(user.getUsername());
Todo todoEntity = new Todo(todoBindingModel.getTitle(), todoBindingModel.getContent(), userEntity);
this.todoRepository.saveAndFlush(todoEntity);
return "redirect:/";
}
use of softuni.todolist.entity.Todo in project SoftUni by kostovhg.
the class TodoController method deleteProcess.
@PostMapping("/todo/delete/{id}")
@PreAuthorize("isAuthenticated()")
public String deleteProcess(@PathVariable Integer id) {
if (!this.todoRepository.exists(id)) {
return "redirect:/";
}
Todo todo = this.todoRepository.findOne(id);
this.todoRepository.delete(todo);
return "redirect:/";
}
use of softuni.todolist.entity.Todo in project SoftUni by kostovhg.
the class TodoController method editProcess.
@PostMapping("/todo/edit/{id}")
@PreAuthorize("isAuthenticated()")
public String editProcess(@PathVariable Integer id, TodoBindingModel todoBindingModel) {
if (!this.todoRepository.exists(id)) {
return "redirect:/";
}
Todo todo = this.todoRepository.findOne(id);
todo.setContent(todoBindingModel.getContent());
todo.setTitle(todoBindingModel.getTitle());
this.todoRepository.saveAndFlush(todo);
return "redirect:/todo/" + todo.getId();
}
Aggregations