#2 new test

Закрыто
DavidThornley хочет смерджить 4 коммит(ов) из nafis в master
34 измененных файлов: 234 добавлений и 241 удалений
  1. Двоичные данные
      .DS_Store
  2. Двоичные данные
      server/.DS_Store
  3. 0
    0
      server/mvnw
  4. 0
    0
      server/mvnw.cmd
  5. 0
    0
      server/pom.xml
  6. 57
    0
      server/src/main/java/com/ziplinegreen/vault/Controller/PostController.java
  7. 3
    11
      server/src/main/java/com/ziplinegreen/vault/Controller/UserController.java
  8. 0
    0
      server/src/main/java/com/ziplinegreen/vault/Exception/ResourceNotFoundException.java
  9. 0
    0
      server/src/main/java/com/ziplinegreen/vault/Model/AuditModel.java
  10. 11
    20
      server/src/main/java/com/ziplinegreen/vault/Model/Post.java
  11. 61
    0
      server/src/main/java/com/ziplinegreen/vault/Model/User.java
  12. 3
    2
      server/src/main/java/com/ziplinegreen/vault/Repository/PostRepository.java
  13. 0
    0
      server/src/main/java/com/ziplinegreen/vault/Repository/UserRepository.java
  14. 58
    0
      server/src/main/java/com/ziplinegreen/vault/Service/PostService.java
  15. 12
    14
      server/src/main/java/com/ziplinegreen/vault/Service/UserService.java
  16. 0
    0
      server/src/main/java/com/ziplinegreen/vault/VaultApplication.java
  17. 26
    0
      server/src/main/resources/application.properties
  18. 0
    0
      server/src/test/java/com/ziplinegreen/vault/VaultApplicationTests.java
  19. 3
    0
      server/target/classes/application.properties
  20. Двоичные данные
      server/target/classes/com/ziplinegreen/vault/Controller/PostController.class
  21. Двоичные данные
      server/target/classes/com/ziplinegreen/vault/Controller/UserController.class
  22. Двоичные данные
      server/target/classes/com/ziplinegreen/vault/Exception/ResourceNotFoundException.class
  23. Двоичные данные
      server/target/classes/com/ziplinegreen/vault/Model/AuditModel.class
  24. Двоичные данные
      server/target/classes/com/ziplinegreen/vault/Model/Post.class
  25. Двоичные данные
      server/target/classes/com/ziplinegreen/vault/Model/User.class
  26. Двоичные данные
      server/target/classes/com/ziplinegreen/vault/Repository/PostRepository.class
  27. Двоичные данные
      server/target/classes/com/ziplinegreen/vault/Repository/UserRepository.class
  28. Двоичные данные
      server/target/classes/com/ziplinegreen/vault/Service/PostService.class
  29. Двоичные данные
      server/target/classes/com/ziplinegreen/vault/Service/UserService.class
  30. Двоичные данные
      server/target/classes/com/ziplinegreen/vault/VaultApplication.class
  31. Двоичные данные
      server/target/test-classes/com/ziplinegreen/vault/VaultApplicationTests.class
  32. 0
    77
      src/main/java/com/ziplinegreen/vault/Controller/PostController.java
  33. 0
    78
      src/main/java/com/ziplinegreen/vault/Model/User.java
  34. 0
    39
      src/main/java/com/ziplinegreen/vault/Service/PostService.java

Двоичные данные
.DS_Store Просмотреть файл


Двоичные данные
server/.DS_Store Просмотреть файл


mvnw → server/mvnw Просмотреть файл


mvnw.cmd → server/mvnw.cmd Просмотреть файл


pom.xml → server/pom.xml Просмотреть файл


+ 57
- 0
server/src/main/java/com/ziplinegreen/vault/Controller/PostController.java Просмотреть файл

@@ -0,0 +1,57 @@
1
+package com.ziplinegreen.vault.Controller;
2
+
3
+import com.ziplinegreen.vault.Exception.ResourceNotFoundException;
4
+import com.ziplinegreen.vault.Model.Post;
5
+import com.ziplinegreen.vault.Model.User;
6
+import com.ziplinegreen.vault.Repository.PostRepository;
7
+import com.ziplinegreen.vault.Repository.UserRepository;
8
+import com.ziplinegreen.vault.Service.PostService;
9
+import com.ziplinegreen.vault.Service.UserService;
10
+import org.springframework.beans.factory.annotation.Autowired;
11
+import org.springframework.data.domain.Page;
12
+import org.springframework.data.domain.Pageable;
13
+import org.springframework.data.repository.query.Param;
14
+import org.springframework.http.HttpStatus;
15
+import org.springframework.http.ResponseEntity;
16
+import org.springframework.web.bind.annotation.*;
17
+
18
+import javax.validation.Valid;
19
+import java.util.Set;
20
+
21
+@RestController
22
+public class PostController {
23
+
24
+    private PostService postService;
25
+    private UserController userController;
26
+
27
+    @Autowired
28
+    public PostController(PostService postService) {
29
+        this.postService = postService;
30
+    }
31
+
32
+    @PostMapping("/{userId}/posts")
33
+    public ResponseEntity<Post> createPost(@PathVariable Long userId, @RequestBody String message){
34
+        return postService.createPost(userId,message);
35
+    }
36
+
37
+    @GetMapping("/{userId}/posts")
38
+    public ResponseEntity<Iterable<Post>> getAllPostsByUserId(@PathVariable Long userId) {
39
+        return postService.findAllByUserId(userId);
40
+    }
41
+
42
+    @GetMapping("/{userId}/posts/{postId}")
43
+    public ResponseEntity<Post> getPostById(@PathVariable Long userId, @PathVariable Long postId){
44
+        return postService.getPostById(postId);
45
+    }
46
+
47
+    @PutMapping("/{userId}/posts/{postId}")
48
+    public ResponseEntity<Post> updatePost(@PathVariable Long userId, @PathVariable Long postId, @RequestBody String message){
49
+        return postService.updatePost(postId, message);
50
+    }
51
+
52
+    @DeleteMapping("/{userId}/posts/{postId}")
53
+    public ResponseEntity deletePost(@PathVariable Long userId, @PathVariable Long postId){
54
+        return postService.deletePost(postId);
55
+    }
56
+
57
+}

src/main/java/com/ziplinegreen/vault/Controller/UserController.java → server/src/main/java/com/ziplinegreen/vault/Controller/UserController.java Просмотреть файл

@@ -37,20 +37,12 @@ public class UserController {
37 37
     }
38 38
 
39 39
     @PutMapping("/users/{userId}")
40
-    public ResponseEntity<User> updateUsername(@PathVariable Long userId, @Valid @RequestBody User userRequest) {
41
-        return new ResponseEntity<>(userService.updateUsername(userId,userRequest), HttpStatus.OK);
40
+    public ResponseEntity<User> updateUsername(@PathVariable Long userId, @RequestBody String newUsername) {
41
+        return userService.updateUsername(userId,newUsername);
42 42
     }
43 43
 
44
-
45 44
     @DeleteMapping("/users/{userId}")
46
-    public ResponseEntity<?> deleteUser(@PathVariable Long userId) {
45
+    public ResponseEntity deleteUser(@PathVariable Long userId) {
47 46
         return userService.deleteUser(userId);
48 47
     }
49
-
50
-    @PutMapping("/users/{userId}/updatepost")
51
-    public ResponseEntity<?> updatePosts(@PathVariable Long userId, @RequestBody Post post){
52
-        return userService.updatePosts(userId, post);
53
-    }
54
-
55
-
56 48
 }

src/main/java/com/ziplinegreen/vault/Exception/ResourceNotFoundException.java → server/src/main/java/com/ziplinegreen/vault/Exception/ResourceNotFoundException.java Просмотреть файл


src/main/java/com/ziplinegreen/vault/Model/AuditModel.java → server/src/main/java/com/ziplinegreen/vault/Model/AuditModel.java Просмотреть файл


src/main/java/com/ziplinegreen/vault/Model/Post.java → server/src/main/java/com/ziplinegreen/vault/Model/Post.java Просмотреть файл

@@ -2,49 +2,40 @@ package com.ziplinegreen.vault.Model;
2 2
 
3 3
 
4 4
 import com.fasterxml.jackson.annotation.JsonIgnore;
5
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5 6
 import org.hibernate.annotations.OnDelete;
6 7
 import org.hibernate.annotations.OnDeleteAction;
7 8
 
8 9
 import javax.persistence.*;
9 10
 import javax.validation.constraints.NotNull;
10 11
 
11
-@Entity
12
-@Table(name = "post")
12
+@Entity @Table(name = "post")
13
+@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
13 14
 public class Post extends AuditModel{
14 15
 
15
-    @Id
16
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
16
+    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
17 17
     private Long Id;
18 18
 
19 19
     @NotNull
20
-    @Lob
21 20
     private String message;
21
+
22
+    @NotNull
22 23
     private Long userId;
23
-//    @OnDelete(action = OnDeleteAction.CASCADE)
24
-//    @JsonIgnore
25 24
 
26
-    public Post(){
27
-    }
28
-    public Post(@NotNull String message, Long userId) {
25
+    public Post(){}
26
+    public Post(@NotNull String message, @NotNull Long userId) {
29 27
         this.message = message;
30 28
         this.userId = userId;
31 29
     }
32 30
 
33
-    public Long getId() {
34
-        return Id;
35
-    }
36
-
31
+    public Long getId() { return Id; }
37 32
 
38 33
     public String getMessage() {
39 34
         return message;
40 35
     }
41 36
 
42
-    public void setMessage(String message) {
43
-        this.message = message;
44
-    }
37
+    public void setMessage(String message) { this.message = message; }
45 38
 
46
-    public Long getUserId() {
47
-        return userId;
48
-    }
39
+    public Long getUserId() { return userId; }
49 40
 
50 41
 }

+ 61
- 0
server/src/main/java/com/ziplinegreen/vault/Model/User.java Просмотреть файл

@@ -0,0 +1,61 @@
1
+package com.ziplinegreen.vault.Model;
2
+
3
+import com.fasterxml.jackson.annotation.JsonIgnore;
4
+import org.hibernate.annotations.OnDelete;
5
+import org.hibernate.annotations.OnDeleteAction;
6
+
7
+import javax.persistence.*;
8
+import javax.validation.constraints.NotNull;
9
+import java.util.ArrayList;
10
+import java.util.List;
11
+
12
+@Entity
13
+@Table(name = "user")
14
+public class User extends AuditModel{
15
+    @Id
16
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
17
+    private Long id;
18
+    @NotNull
19
+    private String username;
20
+    private String email;
21
+    private String password;
22
+//    @OneToMany(fetch = FetchType.LAZY,
23
+//            cascade= {
24
+//                CascadeType.PERSIST,
25
+//                CascadeType.MERGE
26
+//            })
27
+//    @JoinTable(name = "user_posts",
28
+//            joinColumns = {@JoinColumn(name = "user_id")})
29
+//    private List<Post> posts = new ArrayList<>();
30
+
31
+    public User(){}
32
+    public User(@NotNull String username, String email, String password) {
33
+        this.username = username;
34
+        this.email = email;
35
+        this.password = password;
36
+    }
37
+
38
+    public Long getId() { return id; }
39
+
40
+    public String getEmail() { return email;}
41
+
42
+    public void setEmail(String email) { this.email = email; }
43
+
44
+    public String getPassword() { return password; }
45
+
46
+    public void setPassword(String password) { this.password = password; }
47
+
48
+    public String getUsername() { return username; }
49
+
50
+    public void setUsername(String username) { this.username = username; }
51
+
52
+//    public List<Post> getPosts() {
53
+//        if(posts.size()==0){
54
+//            posts = new ArrayList<>();
55
+//            return posts;
56
+//        }
57
+//        return posts;
58
+//    }
59
+//
60
+//    public void setPosts(List<Post> posts) { this.posts = posts; }
61
+}

src/main/java/com/ziplinegreen/vault/Repository/PostRepository.java → server/src/main/java/com/ziplinegreen/vault/Repository/PostRepository.java Просмотреть файл

@@ -7,11 +7,12 @@ import org.springframework.data.jpa.repository.JpaRepository;
7 7
 import org.springframework.data.jpa.repository.Query;
8 8
 import org.springframework.data.repository.query.Param;
9 9
 import org.springframework.data.rest.core.annotation.RepositoryRestResource;
10
+import org.springframework.http.ResponseEntity;
10 11
 import org.springframework.stereotype.Repository;
11 12
 
12 13
 @RepositoryRestResource
13 14
 public interface PostRepository extends JpaRepository<Post,Long> {
14 15
 
15
-    //@Query("select postcontent,timestamp from Post where user_id = :userId")
16
-    Iterable<Post> findByUserId(Long userId);
16
+    Iterable<Post> findAllByUserId(Long userId);
17
+
17 18
 }

src/main/java/com/ziplinegreen/vault/Repository/UserRepository.java → server/src/main/java/com/ziplinegreen/vault/Repository/UserRepository.java Просмотреть файл


+ 58
- 0
server/src/main/java/com/ziplinegreen/vault/Service/PostService.java Просмотреть файл

@@ -0,0 +1,58 @@
1
+package com.ziplinegreen.vault.Service;
2
+
3
+
4
+import com.ziplinegreen.vault.Controller.UserController;
5
+import com.ziplinegreen.vault.Model.Post;
6
+import com.ziplinegreen.vault.Model.User;
7
+import com.ziplinegreen.vault.Repository.PostRepository;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.http.HttpStatus;
10
+import org.springframework.http.ResponseEntity;
11
+import org.springframework.stereotype.Service;
12
+
13
+import java.util.List;
14
+
15
+@Service
16
+public class PostService {
17
+
18
+    private PostRepository postRepository;
19
+    private UserController userController;
20
+
21
+    @Autowired
22
+    public PostService(PostRepository postRepository) {
23
+        this.postRepository = postRepository;
24
+    }
25
+
26
+    public ResponseEntity<Post> createPost(Long userId, String message){
27
+        Post post = new Post(message,userId);
28
+        return new ResponseEntity<>(postRepository.save(post), HttpStatus.CREATED);
29
+    }
30
+
31
+    public ResponseEntity<Iterable<Post>> findAllByUserId(Long userId) {
32
+        return new ResponseEntity<>(postRepository.findAllByUserId(userId), HttpStatus.OK);
33
+    }
34
+
35
+    public ResponseEntity<Post> updatePost(Long postId, String message) {
36
+        Post post = findById(postId);
37
+        post.setMessage(message);
38
+        return new ResponseEntity<>(postRepository.save(post), HttpStatus.OK);
39
+    }
40
+
41
+
42
+    private Post findById(Long postId) {
43
+        return postRepository.findById(postId).get();
44
+    }
45
+
46
+    public ResponseEntity<Post> getPostById(Long postId) {
47
+        Post post = postRepository.getOne(postId);
48
+        return new ResponseEntity<>(post, HttpStatus.OK);
49
+    }
50
+
51
+    public ResponseEntity<Post> deletePost(Long postId){
52
+        Post post = postRepository.getOne(postId);
53
+        postRepository.delete(post);
54
+        return new ResponseEntity<>(HttpStatus.OK);
55
+    }
56
+
57
+}
58
+

src/main/java/com/ziplinegreen/vault/Service/UserService.java → server/src/main/java/com/ziplinegreen/vault/Service/UserService.java Просмотреть файл

@@ -33,25 +33,23 @@ public class UserService {
33 33
         return new ResponseEntity<>(userRepository.findById(id).get(),HttpStatus.OK);
34 34
     }
35 35
 
36
-    public User updateUsername(Long id, User updatedUser){return userRepository.findById(id).map(user -> {
37
-        user.setUsername(updatedUser.getUsername());
38
-        return userRepository.save(user);
39
-    }).orElseThrow(() -> new ResourceNotFoundException("UserId " + id + " not found"));
36
+    public ResponseEntity<User> updateUsername(Long id, String newUsername) {
37
+        User user = findUserById(id).getBody();
38
+        user.setUsername(newUsername);
39
+        return new ResponseEntity<>(userRepository.save(user),HttpStatus.OK);
40 40
     }
41 41
 
42
-    public ResponseEntity deleteUser(Long id){return userRepository.findById(id).map(user -> {
43
-        userRepository.delete(user);
42
+    public ResponseEntity deleteUser(Long id){
43
+        userRepository.delete(userRepository.findById(id).get());
44 44
         return new ResponseEntity(HttpStatus.OK);
45
-    }).orElseThrow(() -> new ResourceNotFoundException("UserId " + id + " not found"));
46
-
47 45
     }
48 46
 
49
-    public ResponseEntity<User> updatePosts(Long userId, Post post) {
50
-        User user = findUserById(userId).getBody();
51
-        List<Post> posts = user.getPosts();
52
-        posts.add(post);
53
-        return new ResponseEntity<>(userRepository.save(user), HttpStatus.OK);
54
-    }
47
+
48
+
49
+
50
+
51
+
52
+
55 53
 }
56 54
 
57 55
 

src/main/java/com/ziplinegreen/vault/VaultApplication.java → server/src/main/java/com/ziplinegreen/vault/VaultApplication.java Просмотреть файл


+ 26
- 0
server/src/main/resources/application.properties Просмотреть файл

@@ -0,0 +1,26 @@
1
+# H2
2
+spring.h2.console.enabled=true
3
+spring.h2.console.path=/h2
4
+
5
+# Datasource
6
+spring.datasource.url=jdbc:h2:file:~/test
7
+spring.datasource.username=sa
8
+spring.datasource.password=
9
+spring.datasource.driver-class-name=org.h2.Driver
10
+
11
+#logging.level.org.springframework.web=DEBUG
12
+
13
+
14
+
15
+#spring.datasource.url=jdbc:mysql://localhost:3306/zipLine?useSSL=false
16
+#spring.datasource.username=root
17
+#spring.datasource.password=Calcifer1650
18
+#
19
+## The SQL dialect makes Hibernate generate better SQL for the chosen database
20
+#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
21
+#
22
+## Hibernate ddl auto (create, create-drop, validate, update)
23
+#spring.jpa.hibernate.ddl-auto = update
24
+#
25
+#logging.level.org.hibernate.SQL=DEBUG
26
+#logging.level.org.hibernate.type=TRACE

src/test/java/com/ziplinegreen/vault/VaultApplicationTests.java → server/src/test/java/com/ziplinegreen/vault/VaultApplicationTests.java Просмотреть файл


src/main/resources/application.properties → server/target/classes/application.properties Просмотреть файл

@@ -8,6 +8,9 @@ spring.datasource.username=sa
8 8
 spring.datasource.password=
9 9
 spring.datasource.driver-class-name=org.h2.Driver
10 10
 
11
+logging.level.org.springframework.web=DEBUG
12
+
13
+
11 14
 
12 15
 #spring.datasource.url=jdbc:mysql://localhost:3306/zipLine?useSSL=false
13 16
 #spring.datasource.username=root

Двоичные данные
server/target/classes/com/ziplinegreen/vault/Controller/PostController.class Просмотреть файл


Двоичные данные
server/target/classes/com/ziplinegreen/vault/Controller/UserController.class Просмотреть файл


Двоичные данные
server/target/classes/com/ziplinegreen/vault/Exception/ResourceNotFoundException.class Просмотреть файл


Двоичные данные
server/target/classes/com/ziplinegreen/vault/Model/AuditModel.class Просмотреть файл


Двоичные данные
server/target/classes/com/ziplinegreen/vault/Model/Post.class Просмотреть файл


Двоичные данные
server/target/classes/com/ziplinegreen/vault/Model/User.class Просмотреть файл


Двоичные данные
server/target/classes/com/ziplinegreen/vault/Repository/PostRepository.class Просмотреть файл


Двоичные данные
server/target/classes/com/ziplinegreen/vault/Repository/UserRepository.class Просмотреть файл


Двоичные данные
server/target/classes/com/ziplinegreen/vault/Service/PostService.class Просмотреть файл


Двоичные данные
server/target/classes/com/ziplinegreen/vault/Service/UserService.class Просмотреть файл


Двоичные данные
server/target/classes/com/ziplinegreen/vault/VaultApplication.class Просмотреть файл


Двоичные данные
server/target/test-classes/com/ziplinegreen/vault/VaultApplicationTests.class Просмотреть файл


+ 0
- 77
src/main/java/com/ziplinegreen/vault/Controller/PostController.java Просмотреть файл

@@ -1,77 +0,0 @@
1
-package com.ziplinegreen.vault.Controller;
2
-
3
-import com.ziplinegreen.vault.Exception.ResourceNotFoundException;
4
-import com.ziplinegreen.vault.Model.Post;
5
-import com.ziplinegreen.vault.Model.User;
6
-import com.ziplinegreen.vault.Repository.PostRepository;
7
-import com.ziplinegreen.vault.Repository.UserRepository;
8
-import com.ziplinegreen.vault.Service.PostService;
9
-import com.ziplinegreen.vault.Service.UserService;
10
-import org.springframework.beans.factory.annotation.Autowired;
11
-import org.springframework.data.domain.Page;
12
-import org.springframework.data.domain.Pageable;
13
-import org.springframework.http.HttpStatus;
14
-import org.springframework.http.ResponseEntity;
15
-import org.springframework.web.bind.annotation.*;
16
-
17
-import javax.validation.Valid;
18
-import java.util.Set;
19
-
20
-
21
-public class PostController {
22
-
23
-    private PostService postService;
24
-    private UserController userController;
25
-
26
-    @Autowired
27
-    public PostController(PostService postService) {
28
-        this.postService = postService;
29
-    }
30
-
31
-    @PostMapping("/posts/{userId}")
32
-    public ResponseEntity createPost(@PathVariable Long userId, @RequestBody Post post) {
33
-        userController.updatePosts(userId,post);
34
-        return new ResponseEntity(HttpStatus.OK);
35
-
36
-    }
37
-
38
-
39
-    @GetMapping("/posts/{userId}")
40
-    public ResponseEntity<Iterable<Post>> getAllPostsByUserId(@PathVariable Long userId) {
41
-        return postService.findByUserId(userId);
42
-    }
43
-
44
-//    @PutMapping("/users/{userId/posts")
45
-//    public ResponseEntity<Post> updatePost(@PathVariable Long userId, @RequestBody Post post){
46
-//        return postService.updatePost(userId, post);
47
-//    }
48
-
49
-
50
-
51
-//    @PutMapping("/users/{userId}/posts/{postId}")
52
-//    public Post updateComment(@PathVariable (value = "userId") Long userId,
53
-//                                 @PathVariable (value = "postId") Long postId,
54
-//                                 @Valid @RequestBody Post postRequest) {
55
-//        if(!userRepository.existsById(userId)) {
56
-//            throw new ResourceNotFoundException("UserId " + userId + " not found");
57
-//        }
58
-//
59
-//        return postRepository.findById(postId).map(post -> {
60
-//            post.setMessage(postRequest.getMessage());
61
-//            return postRepository.save(post);
62
-//        }).orElseThrow(() -> new ResourceNotFoundException("PostId " + postId + "not found"));
63
-//    }
64
-//
65
-//    @DeleteMapping("/posts/{postId}/comments/{commentId}")
66
-//    public ResponseEntity<?> deleteComment(@PathVariable (value = "userId") Long userId,
67
-//                                           @PathVariable (value = "postId") Long postId) {
68
-//        if(!userRepository.existsById(userId)) {
69
-//            throw new ResourceNotFoundException("UserId " + userId + " not found");
70
-//        }
71
-//
72
-//        return postRepository.findById(postId).map(post -> {
73
-//            postRepository.delete(post);
74
-//            return ResponseEntity.ok().build();
75
-//        }).orElseThrow(() -> new ResourceNotFoundException("PostId " + postId + " not found"));
76
-//    }
77
-}

+ 0
- 78
src/main/java/com/ziplinegreen/vault/Model/User.java Просмотреть файл

@@ -1,78 +0,0 @@
1
-package com.ziplinegreen.vault.Model;
2
-
3
-import com.fasterxml.jackson.annotation.JsonIgnore;
4
-import org.hibernate.annotations.OnDelete;
5
-import org.hibernate.annotations.OnDeleteAction;
6
-
7
-import javax.persistence.*;
8
-import javax.validation.constraints.NotNull;
9
-import java.util.ArrayList;
10
-import java.util.List;
11
-
12
-@Entity
13
-@Table(name = "user")
14
-public class User extends AuditModel{
15
-    @Id
16
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
17
-    private Long id;
18
-    @NotNull
19
-    private String username;
20
-    private String email;
21
-    private String password;
22
-    @OneToMany(fetch = FetchType.LAZY,
23
-            cascade= {
24
-                CascadeType.PERSIST,
25
-                CascadeType.MERGE
26
-            })
27
-    @JoinTable(name = "user_posts",
28
-            joinColumns = {@JoinColumn(name = "user_id")})
29
-    private List<Post> posts = new ArrayList<>();
30
-
31
-    public List<Post> getPosts() {
32
-        if(posts.size()==0){
33
-            posts = new ArrayList<>();
34
-            return posts;
35
-        }
36
-        return posts;
37
-    }
38
-
39
-    public User(){}
40
-    public User(@NotNull String username, String email, String password) {
41
-        this.username = username;
42
-        this.email = email;
43
-        this.password = password;
44
-    }
45
-
46
-    public void setPosts(List<Post> posts) {
47
-        this.posts = posts;
48
-    }
49
-
50
-    public Long getId() {
51
-        return id;
52
-    }
53
-
54
-    public String getEmail() {
55
-        return email;
56
-    }
57
-
58
-    public void setEmail(String email) {
59
-        this.email = email;
60
-    }
61
-
62
-    public String getPassword() {
63
-        return password;
64
-    }
65
-
66
-    public void setPassword(String password) {
67
-        this.password = password;
68
-    }
69
-
70
-    public String getUsername() {
71
-        return username;
72
-    }
73
-
74
-    public void setUsername(String username) {
75
-        this.username = username;
76
-    }
77
-
78
-}

+ 0
- 39
src/main/java/com/ziplinegreen/vault/Service/PostService.java Просмотреть файл

@@ -1,39 +0,0 @@
1
-package com.ziplinegreen.vault.Service;
2
-
3
-
4
-import com.ziplinegreen.vault.Model.Post;
5
-import com.ziplinegreen.vault.Repository.PostRepository;
6
-import org.springframework.beans.factory.annotation.Autowired;
7
-import org.springframework.http.HttpStatus;
8
-import org.springframework.http.ResponseEntity;
9
-import org.springframework.stereotype.Service;
10
-
11
-@Service
12
-public class PostService {
13
-
14
-    private PostRepository postRepository;
15
-
16
-    @Autowired
17
-    public PostService(PostRepository postRepository) {
18
-        this.postRepository = postRepository;
19
-    }
20
-
21
-    public ResponseEntity<Post> createPost(Post post){
22
-        return new ResponseEntity<>(postRepository.save(post), HttpStatus.CREATED);
23
-    }
24
-
25
-    public ResponseEntity<Post> deletePost(Long id){
26
-        Post post = postRepository.getOne(id);
27
-        postRepository.delete(post);
28
-        return new ResponseEntity<>(HttpStatus.OK);
29
-    }
30
-
31
-    public ResponseEntity<Iterable<Post>> findByUserId(Long userId) {
32
-        return new ResponseEntity<>(postRepository.findByUserId(userId), HttpStatus.OK);
33
-    }
34
-
35
-//    public ResponseEntity<Post> updatePost(Long userId, Post post) {
36
-//
37
-//    }
38
-}
39
-