Advertisement
Guest User

jpaasda

a guest
Jan 5th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.16 KB | None | 0 0
  1.  @PostMapping(value = "/creator")
  2.     def submitPost(@Valid @ModelAttribute("post")Post post, BindingResult bindingResult, Authentication authentication) {
  3.  
  4.  
  5.         if(bindingResult.hasErrors())
  6.             return "postsForm"
  7.  
  8.         //Post newPost = new Post()
  9.         if(post.getCreated() == null)
  10.             post.setCreated(date)
  11.  
  12.         Date update  = new Date()
  13.         post.setUpdated(update)
  14.  
  15.         post.setAuthorName(authentication.getName())
  16.  
  17.  
  18.         def splitedTags = post.getTags().split(',')
  19.  
  20.         postRepository.saveAndFlush(post)
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.         splitedTags.each {
  28.             String tag ->
  29.                Tags newTag = new Tags()
  30.                 newTag.setPostId(post.getId())
  31.                 newTag.setTagAuthor(authentication.getName())
  32.                 newTag.setTag(tag)
  33.                 this.tagsRepository.save(newTag)
  34.         }
  35.  
  36.  
  37.  
  38.         //adding points for creating new post
  39.         UserDTO user = userRepository.findByUsername(authentication.getName())
  40.         int points = user.getPoints() + 1
  41.         user.setPoints(points)
  42.         userRepository.saveAndFlush(user)
  43.  
  44.  
  45.         return "redirect:/posts"
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement