Search in sources :

Example 1 with Todo

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";
}
Also used : Todo(softuni.todolist.entity.Todo) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with Todo

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";
}
Also used : Todo(softuni.todolist.entity.Todo) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with Todo

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:/";
}
Also used : Todo(softuni.todolist.entity.Todo) UserDetails(org.springframework.security.core.userdetails.UserDetails) User(softuni.todolist.entity.User) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with Todo

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:/";
}
Also used : Todo(softuni.todolist.entity.Todo) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with Todo

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();
}
Also used : Todo(softuni.todolist.entity.Todo) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Todo (softuni.todolist.entity.Todo)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 User (softuni.todolist.entity.User)1