@RequestMapping(method=RequestMethod.POST) ResponseEntity<Bookmark> addBookmark(@PathVariable(value="username") String username,@RequestBody Bookmark bookmark) throws UserNotFoundException {
  Optional<User> optional=usersRepository.findByUsername(username);
  if (optional.isPresent()) {
    User user=optional.get();
    user.addBookmark(bookmark);
    bookmark.setUser(user);
    bookmarksRepository.save(bookmark);
    return new ResponseEntity<>(bookmark,HttpStatus.CREATED);
  }
 else {
    throw new UserNotFoundException(username);
  }
}

@ RequestMapping ( method = RequestMethod . POST ) ResponseEntity < Bookmark > addBookmark ( @ PathVariable ( value = "username" ) String username , @ RequestBody Bookmark bookmark ) throws UserNotFoundException { Optional < User > optional = usersRepository . findByUsername ( username ) ; if ( optional . isPresent ( ) ) { User user = optional . get ( ) ; user . addBookmark ( bookmark ) ; bookmark . setUser ( user ) ; bookmarksRepository . save ( bookmark ) ; return new ResponseEntity < > ( bookmark , HttpStatus . CREATED ) ; } else { throw new UserNotFoundException ( username ) ; } }
a method to add a bookmark .
