3 лаба вроде клиент нормально добавляет посты и удаляет их

Осталось сделать +- тоже самое с комментариями с ссылкой на юзера
This commit is contained in:
Павел Сорокин 2023-03-29 10:38:32 +04:00
parent 071d001e08
commit 45a590f145
3 changed files with 5 additions and 3 deletions

View File

@ -84,7 +84,7 @@ public class Post {
@Override
public String toString() {
return "Technique{" +
return "Post{" +
"id=" + id +
", Heading='" + Heading + '\'' +
", Content ='" + Content + '\'' +

View File

@ -86,7 +86,7 @@ public class UserService {
@Transactional
public void deletePost(Long id, Post post) {
em.createQuery("Delete Comment where post.Id = "+ post.getId()).executeUpdate();
em.createQuery("Delete from Post").executeUpdate();
em.createQuery("Delete from Post where Id = "+post.getId()).executeUpdate();
}

View File

@ -73,6 +73,7 @@ public class JpaClientTests {
userService.deleteAllUsers();
final User user = userService.addUser("Pasha","Sorokin","sorokin.zxcv@gmail.com");
final Post post =userService.addNewPost(user.getId(),"Text1","Text2");
final Post post1=userService.addNewPost(user.getId(),"Привет","Да");
final List<Post> posts =postService.findAllPosts();
final User user1 = userService.findUser(user.getId());
final List<Post> posts1 = user1.getPosts();
@ -83,8 +84,9 @@ public class JpaClientTests {
userService.deletePost(user.getId(),post);
final User us = userService.findUser(user.getId());
Assertions.assertThrows(EntityNotFoundException.class, () -> postService.findPost(post.getId()));
final List<Post> postss =postService.findAllPosts();
log.info(us.getPosts().toString());
log.info(postss.toString());
userService.deleteAllUsers();
postService.deleteAllPosts();
}