5 lab done
This commit is contained in:
parent
32f3e9483f
commit
2a9507f646
@ -110,10 +110,10 @@ public class PostMvcController {
|
||||
return "redirect:/post";
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{userId}/{postId}")
|
||||
public String deletePost(@PathVariable Long userId,
|
||||
@PostMapping("/delete/{postId}")
|
||||
public String deletePost(
|
||||
@PathVariable Long postId) {
|
||||
userService.deletePost(userId,postId);
|
||||
postService.deletePost(postId);
|
||||
return "redirect:/post";
|
||||
}
|
||||
@PostMapping("/deleteComment/{postId}/{commentId}")
|
||||
|
@ -35,6 +35,7 @@ public class PostService {
|
||||
return postRepository.save(post);
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void savePost(Post post) {
|
||||
postRepository.save(post);
|
||||
|
@ -38,7 +38,7 @@ public class UserService {
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Transactional
|
||||
public User findUser(Long id) {
|
||||
final Optional<User> user = userRepository.findById(id);
|
||||
return user.orElseThrow(() -> new UserNotFoundException(id));
|
||||
@ -64,13 +64,6 @@ public class UserService {
|
||||
userRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllUsers() {
|
||||
commentService.deleteAllComments();
|
||||
postRepository.deleteAll();
|
||||
userRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addNewPost(Long id, PostDto postDto)
|
||||
{
|
||||
@ -82,11 +75,20 @@ public class UserService {
|
||||
postRepository.save(post);
|
||||
}
|
||||
}
|
||||
@Transactional
|
||||
public void deleteAllUsers() {
|
||||
commentService.deleteAllComments();
|
||||
userRepository.deleteAll();
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public List<Post> GetUserPosts(Long id)
|
||||
{
|
||||
return userRepository.getUsersPosts(id);
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void deletePost(Long id, Long postId) {
|
||||
postRepository.deleteById(postId);
|
||||
|
@ -74,7 +74,7 @@
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${post.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
<form th:action="@{'/post/delete/' + ${post.userId} + '/' + ${post.id}}" method="post">
|
||||
<form th:action="@{'/post/delete/' + ${post.id}}" method="post">
|
||||
<button th:id="'remove-' + ${post.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
|
Loading…
Reference in New Issue
Block a user