Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @PostMapping(value = "/creator")
- def submitPost(@Valid @ModelAttribute("post")Post post, BindingResult bindingResult, Authentication authentication) {
- if(bindingResult.hasErrors())
- return "postsForm"
- //Post newPost = new Post()
- if(post.getCreated() == null)
- post.setCreated(date)
- Date update = new Date()
- post.setUpdated(update)
- post.setAuthorName(authentication.getName())
- def splitedTags = post.getTags().split(',')
- postRepository.saveAndFlush(post)
- splitedTags.each {
- String tag ->
- Tags newTag = new Tags()
- newTag.setPostId(post.getId())
- newTag.setTagAuthor(authentication.getName())
- newTag.setTag(tag)
- this.tagsRepository.save(newTag)
- }
- //adding points for creating new post
- UserDTO user = userRepository.findByUsername(authentication.getName())
- int points = user.getPoints() + 1
- user.setPoints(points)
- userRepository.saveAndFlush(user)
- return "redirect:/posts"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement