コード例 #1
0
  private void delete(String bookId) {

    User user = ProfileController.getAuthenticatedUser();
    user.getBooks().remove(bookId);

    userService.save(user);
    ProfileController.authenticateUser(user);
  }
コード例 #2
0
  // lazy removing
  private void updateUsersBooks(List<Book> books) {

    List<String> changedList = new ArrayList<String>();
    for (Book b : books) changedList.add(b.getId());

    User user = ProfileController.getAuthenticatedUser();
    user.setBooks(changedList);
    userService.save(user);
    ProfileController.authenticateUser(user);
  }
コード例 #3
0
  @RequestMapping(value = "/library/add", method = RequestMethod.GET)
  public String addBookToLibrary(@RequestParam(required = true) String id) {

    User user = (User) ProfileController.getAuthenticatedUser();
    if (user.getBooks() == null || !user.getBooks().contains(id)) user.addBook(id);

    userService.save(user);
    ProfileController.authenticateUser(user);

    return "redirect:/library";
  }