Quellcode durchsuchen

Merge branch 'dev'

"merge dev to master"
David Thornley vor 6 Jahren
Ursprung
Commit
1a76aa57b1

BIN
.DS_Store Datei anzeigen


+ 0
- 0
client-ionic/ClientReadme.md Datei anzeigen


+ 46
- 4
pom.xml Datei anzeigen

@@ -35,11 +35,23 @@
35 35
         </dependency>
36 36
 
37 37
         <dependency>
38
-            <groupId>mysql</groupId>
39
-            <artifactId>mysql-connector-java</artifactId>
40
-            <scope>runtime</scope>
38
+            <groupId>org.postgresql</groupId>
39
+            <artifactId>postgresql</artifactId>
40
+            <version>42.2.1</version>
41
+        </dependency>
42
+        <!--<dependency>-->
43
+            <!--<groupId>mysql</groupId>-->
44
+            <!--<artifactId>mysql-connector-java</artifactId>-->
45
+            <!--<scope>runtime</scope>-->
46
+        <!--</dependency>-->
47
+        <dependency>
48
+            <groupId>org.springframework.boot</groupId>
49
+            <artifactId>spring-boot-starter-websocket</artifactId>
50
+        </dependency>
51
+        <dependency>
52
+            <groupId>org.springframework.boot</groupId>
53
+            <artifactId>spring-boot-starter-data-rest</artifactId>
41 54
         </dependency>
42
-
43 55
         <!--<dependency>-->
44 56
             <!--<groupId>com.h2database</groupId>-->
45 57
             <!--<artifactId>h2</artifactId>-->
@@ -55,6 +67,36 @@
55 67
             <artifactId>spring-restdocs-mockmvc</artifactId>
56 68
             <scope>test</scope>
57 69
         </dependency>
70
+
71
+        <dependency>
72
+            <groupId>org.webjars</groupId>
73
+            <artifactId>webjars-locator-core</artifactId>
74
+        </dependency>
75
+        <dependency>
76
+            <groupId>org.webjars</groupId>
77
+            <artifactId>sockjs-client</artifactId>
78
+            <version>1.0.2</version>
79
+        </dependency>
80
+        <dependency>
81
+            <groupId>org.webjars</groupId>
82
+            <artifactId>stomp-websocket</artifactId>
83
+            <version>2.3.3</version>
84
+        </dependency>
85
+        <dependency>
86
+            <groupId>org.webjars</groupId>
87
+            <artifactId>bootstrap</artifactId>
88
+            <version>3.3.7</version>
89
+        </dependency>
90
+        <dependency>
91
+            <groupId>org.webjars</groupId>
92
+            <artifactId>jquery</artifactId>
93
+            <version>3.1.0</version>
94
+        </dependency>
95
+        <dependency>
96
+            <groupId>org.apache.tomcat</groupId>
97
+            <artifactId>tomcat-jdbc</artifactId>
98
+            <version>8.5.31</version>
99
+        </dependency>
58 100
     </dependencies>
59 101
 
60 102
     <build>

+ 26
- 0
src/main/java/com/ziplinegreen/vault/Config/WebSocketConfig.java Datei anzeigen

@@ -0,0 +1,26 @@
1
+package com.ziplinegreen.vault.Config;
2
+
3
+
4
+import org.springframework.context.annotation.ComponentScan;
5
+import org.springframework.context.annotation.Configuration;
6
+import org.springframework.messaging.simp.config.MessageBrokerRegistry;
7
+import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
8
+import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
9
+import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
10
+
11
+@Configuration
12
+@EnableWebSocketMessageBroker
13
+@ComponentScan(basePackages = "com.ziplinegreen.vault")
14
+public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
15
+
16
+    @Override
17
+    public void configureMessageBroker(MessageBrokerRegistry config) {
18
+        config.enableSimpleBroker("/topic");
19
+        config.setApplicationDestinationPrefixes("/app"); //where the frontend sends things
20
+    }
21
+
22
+    @Override
23
+    public void registerStompEndpoints(StompEndpointRegistry registry) {
24
+        registry.addEndpoint("/vault-socket").setAllowedOrigins("*").withSockJS();
25
+    }
26
+}

+ 49
- 41
src/main/java/com/ziplinegreen/vault/Controller/PostController.java Datei anzeigen

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

+ 23
- 24
src/main/java/com/ziplinegreen/vault/Controller/UserController.java Datei anzeigen

@@ -1,46 +1,45 @@
1 1
 package com.ziplinegreen.vault.Controller;
2 2
 
3
-import com.ziplinegreen.vault.Exception.ResourceNotFoundException;
4 3
 import com.ziplinegreen.vault.Model.User;
5
-import com.ziplinegreen.vault.Repository.UserRepository;
4
+import com.ziplinegreen.vault.Service.UserService;
6 5
 import org.springframework.beans.factory.annotation.Autowired;
7
-import org.springframework.data.domain.Page;
8
-import org.springframework.data.domain.Pageable;
9 6
 import org.springframework.http.ResponseEntity;
10 7
 import org.springframework.web.bind.annotation.*;
11 8
 
12
-import javax.validation.Valid;
13
-
14 9
 @RestController
15 10
 public class UserController {
16 11
 
17
-    @Autowired
18
-    private UserRepository userRepository;
12
+    private UserService userService;
19 13
 
20
-    @GetMapping("/users")
21
-    public Page<User> getAllPosts(Pageable pageable) {
22
-        return userRepository.findAll(pageable);
14
+    @Autowired
15
+    public UserController(UserService userService) {
16
+        this.userService = userService;
23 17
     }
24 18
 
25 19
     @PostMapping("/users")
26
-    public User createPost(@Valid @RequestBody User user) {
27
-        return userRepository.save(user);
20
+    public User createUser(@RequestBody User user) {
21
+        return userService.createUser(user);
28 22
     }
29 23
 
30
-    @PutMapping("/users/{userId}")
31
-    public User updatePost(@PathVariable Long userId, @Valid @RequestBody User userRequest) {
32
-        return userRepository.findById(userId).map(user -> {
33
-            user.setUsername(userRequest.getUsername());
34
-            return userRepository.save(user);
35
-        }).orElseThrow(() -> new ResourceNotFoundException("UserId " + userId + " not found"));
24
+    @GetMapping("/users/{userId}")
25
+    public User getUserById(@PathVariable Long userId) {
26
+
27
+        return userService.findUserById(userId);
36 28
     }
29
+    @CrossOrigin
30
+    @GetMapping("/users/{username}")
31
+    public User getUserById(@PathVariable String username) {
37 32
 
33
+        return userService.findUserByUsername(username);
34
+    }
35
+    @CrossOrigin
36
+    @PutMapping("/users/{userId}")
37
+    public User updateUsername(@PathVariable Long userId, @RequestBody String username) {
38
+        return userService.updateUsername(userId, username);
39
+    }
38 40
 
39 41
     @DeleteMapping("/users/{userId}")
40
-    public ResponseEntity<?> deletePost(@PathVariable Long userId) {
41
-        return userRepository.findById(userId).map(user -> {
42
-            userRepository.delete(user);
43
-            return ResponseEntity.ok().build();
44
-        }).orElseThrow(() -> new ResourceNotFoundException("UserId " + userId + " not found"));
42
+    public ResponseEntity<?> deleteUser(@PathVariable Long userId) {
43
+        return userService.deleteUser(userId);
45 44
     }
46 45
 }

+ 27
- 16
src/main/java/com/ziplinegreen/vault/Model/Post.java Datei anzeigen

@@ -1,7 +1,6 @@
1 1
 package com.ziplinegreen.vault.Model;
2 2
 
3 3
 
4
-import com.fasterxml.jackson.annotation.JsonIgnore;
5 4
 import org.hibernate.annotations.OnDelete;
6 5
 import org.hibernate.annotations.OnDeleteAction;
7 6
 
@@ -13,25 +12,25 @@ import javax.validation.constraints.NotNull;
13 12
 public class Post extends AuditModel{
14 13
 
15 14
     @Id
16
-    @GeneratedValue
15
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
17 16
     private Long Id;
18 17
 
19 18
     @NotNull
20
-    @Lob
21 19
     private String message;
22
-
23
-    @ManyToOne(fetch = FetchType.LAZY, optional = false)
24
-    @JoinColumn(name = "user_id", nullable = false)
25 20
     @OnDelete(action = OnDeleteAction.CASCADE)
26
-    @JsonIgnore
27
-    private User user;
21
+    private Long userId;
22
+    private String userName;
28 23
 
29
-    public Long getId() {
30
-        return Id;
24
+    public Post(){
25
+    }
26
+    public Post(@NotNull String message, Long userId, String userName) {
27
+        this.message = message;
28
+        this.userId = userId;
29
+        this.userName = userName;
31 30
     }
32 31
 
33
-    public void setId(Long id) {
34
-        Id = id;
32
+    public Long getId() {
33
+        return Id;
35 34
     }
36 35
 
37 36
     public String getMessage() {
@@ -42,11 +41,23 @@ public class Post extends AuditModel{
42 41
         this.message = message;
43 42
     }
44 43
 
45
-    public User getUser() {
46
-        return user;
44
+    public Long getUserId() {
45
+        return userId;
46
+    }
47
+
48
+    public String getUserName() { return userName; }
49
+
50
+    public void setUserName(String userName) {
51
+        this.userName = userName;
47 52
     }
48 53
 
49
-    public void setUser(User user) {
50
-        this.user = user;
54
+    @Override
55
+    public String toString() {
56
+        return "Post{" +
57
+                "Id=" + Id +
58
+                ", message='" + message + '\'' +
59
+                ", userId=" + userId +
60
+                ", userName='" + userName + '\'' +
61
+                '}';
51 62
     }
52 63
 }

+ 47
- 7
src/main/java/com/ziplinegreen/vault/Model/User.java Datei anzeigen

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

+ 6
- 3
src/main/java/com/ziplinegreen/vault/Repository/PostRepository.java Datei anzeigen

@@ -4,9 +4,12 @@ import com.ziplinegreen.vault.Model.Post;
4 4
 import org.springframework.data.domain.Page;
5 5
 import org.springframework.data.domain.Pageable;
6 6
 import org.springframework.data.jpa.repository.JpaRepository;
7
-import org.springframework.stereotype.Repository;
7
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
8
+import java.util.Collection;
8 9
 
9
-@Repository
10
+@RepositoryRestResource
10 11
 public interface PostRepository extends JpaRepository<Post,Long> {
11
-    Page<Post> findByUserId(Long userId, Pageable pageable);
12
+    Collection<Post> findByUserId(Long userId);
13
+    Iterable<Post> findAllByUserId(Long userId);
14
+
12 15
 }

+ 0
- 9
src/main/java/com/ziplinegreen/vault/Repository/UserRepository.java Datei anzeigen

@@ -1,9 +0,0 @@
1
-package com.ziplinegreen.vault.Repository;
2
-
3
-import com.ziplinegreen.vault.Model.User;
4
-import org.springframework.data.jpa.repository.JpaRepository;
5
-import org.springframework.stereotype.Repository;
6
-
7
-@Repository
8
-public interface UserRepository extends JpaRepository<User,Long> {
9
-}

+ 12
- 0
src/main/java/com/ziplinegreen/vault/Repository/UsersRepository.java Datei anzeigen

@@ -0,0 +1,12 @@
1
+package com.ziplinegreen.vault.Repository;
2
+
3
+import com.ziplinegreen.vault.Model.User;
4
+import org.springframework.data.jpa.repository.JpaRepository;
5
+import org.springframework.data.jpa.repository.Query;
6
+import org.springframework.data.repository.query.Param;
7
+
8
+public interface UsersRepository extends JpaRepository<User, Long> {
9
+
10
+    @Query(value = "SELECT u FROM User u WHERE u.username = :username")
11
+    User findUserByUsername(@Param("username") String username);
12
+}

+ 90
- 0
src/main/java/com/ziplinegreen/vault/Service/PostService.java Datei anzeigen

@@ -0,0 +1,90 @@
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.data.domain.Page;
8
+import org.springframework.data.domain.PageImpl;
9
+import org.springframework.data.domain.Pageable;
10
+import org.springframework.http.HttpStatus;
11
+import org.springframework.http.ResponseEntity;
12
+import org.springframework.stereotype.Service;
13
+import org.springframework.transaction.annotation.Transactional;
14
+
15
+import java.util.Collection;
16
+import java.util.Collections;
17
+import java.util.List;
18
+import java.util.stream.Collectors;
19
+import java.util.stream.StreamSupport;
20
+
21
+@Service
22
+@Transactional
23
+public class PostService {
24
+
25
+
26
+    private PostRepository postRepository;
27
+
28
+    @Autowired
29
+    public PostService(PostRepository postRepository) {
30
+        this.postRepository = postRepository;
31
+    }
32
+
33
+    public Post createPost(Post post){
34
+        return postRepository.save(post);
35
+    }
36
+
37
+    public Iterable<Post> getAllPosts(){
38
+        return postRepository.findAll();
39
+    }
40
+
41
+    public ResponseEntity deletePost(Long postId){
42
+        postRepository.delete(postRepository.findById(postId).get());
43
+        return new ResponseEntity<>(HttpStatus.OK);
44
+    }
45
+
46
+    public ResponseEntity deleteAllPosts(Long userId){
47
+        Iterable<Post> posts = postRepository.findByUserId(userId);
48
+        for(Post post: posts){
49
+            deletePost(post.getId());
50
+        }
51
+        return new ResponseEntity<>(HttpStatus.OK);
52
+    }
53
+
54
+    public Page<Post> findByUserId(Long userId, Pageable pageable) {
55
+        Iterable<Post> posts = postRepository.findByUserId(userId);
56
+        List<Post> postList = StreamSupport.stream(posts.spliterator(), false)
57
+                .collect(Collectors.toList());
58
+        Collections.reverse(postList);
59
+
60
+        int start = (int)pageable.getOffset();
61
+        int end = (start + pageable.getPageSize()) > postList.size() ? postList.size() : (start + pageable.getPageSize());
62
+
63
+        return new PageImpl<Post>(postList.subList(start,end),pageable, postList.size());
64
+    }
65
+
66
+
67
+
68
+    public Post updatePost(Long postId, String message){
69
+        Post post = postRepository.findById(postId).get();
70
+        post.setMessage(message);
71
+        return postRepository.save(post);
72
+    }
73
+
74
+    public Page<Post> listAllByPage(Pageable pageable) {
75
+       return postRepository.findAll(pageable);
76
+    }
77
+
78
+    public Page<Post> listAllPostsByPageMostRecentFirst(Pageable pageable){
79
+        Iterable<Post> posts = getAllPosts();
80
+        List<Post> postList = StreamSupport.stream(posts.spliterator(), false)
81
+                .collect(Collectors.toList());
82
+        Collections.reverse(postList);
83
+
84
+        int start = (int)pageable.getOffset();
85
+        int end = (start + pageable.getPageSize()) > postList.size() ? postList.size() : (start + pageable.getPageSize());
86
+
87
+        return new PageImpl<Post>(postList.subList(start,end),pageable, postList.size());
88
+    }
89
+}
90
+

+ 47
- 0
src/main/java/com/ziplinegreen/vault/Service/UserService.java Datei anzeigen

@@ -0,0 +1,47 @@
1
+package com.ziplinegreen.vault.Service;
2
+
3
+import com.ziplinegreen.vault.Model.User;
4
+import com.ziplinegreen.vault.Repository.UsersRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.http.HttpStatus;
7
+import org.springframework.http.ResponseEntity;
8
+import org.springframework.stereotype.Service;
9
+
10
+@Service
11
+public class UserService {
12
+
13
+    @Autowired
14
+    private UsersRepository userRepository;
15
+    private PostService postService;
16
+    //private PostController postController;
17
+
18
+    @Autowired
19
+    public UserService(UsersRepository userRepository, PostService postService) {
20
+        this.userRepository = userRepository;
21
+        this.postService = postService;
22
+    }
23
+
24
+    public User createUser(User user){
25
+        return userRepository.save(user);
26
+    }
27
+
28
+    public User findUserById(Long id){
29
+        return userRepository.findById(id).get();
30
+    }
31
+
32
+    public User findUserByUsername(String username) { return userRepository.findUserByUsername(username);}
33
+
34
+    public User updateUsername(Long userId, String username){
35
+        User user = findUserById(userId);
36
+        user.setUsername(username);
37
+        return userRepository.save(user);
38
+    }
39
+
40
+    public ResponseEntity deleteUser(Long userId){
41
+        postService.deleteAllPosts(userId);
42
+        userRepository.delete(userRepository.findById(userId).get());
43
+        return new ResponseEntity(HttpStatus.OK);
44
+    }
45
+}
46
+
47
+

+ 11
- 23
src/main/resources/application.properties Datei anzeigen

@@ -1,23 +1,11 @@
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
-
12
-spring.datasource.url=jdbc:mysql://localhost:3306/zipLine?useSSL=false
13
-spring.datasource.username=root
14
-spring.datasource.password=Calcifer1650
15
-
16
-# The SQL dialect makes Hibernate generate better SQL for the chosen database
17
-spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
18
-
19
-# Hibernate ddl auto (create, create-drop, validate, update)
20
-spring.jpa.hibernate.ddl-auto = update
21
-
22
-logging.level.org.hibernate.SQL=DEBUG
23
-logging.level.org.hibernate.type=TRACE
1
+#PostGresql set up
2
+spring.datasource.url= jdbc:postgresql://localhost:5432/thevault 
3
+spring.datasource.username=postgres
4
+spring.datasource.password=ZipCode4dot1   
5
+spring.jpa.hibernate.ddl-auto=update
6
+        
7
+# Disable feature detection by this undocumented parameter. Check the org.hibernate.engine.jdbc.internal.JdbcServiceImpl.configure method for more details.
8
+spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
9
+
10
+# Because detection is disabled you have to set correct dialect by hand.
11
+spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect

+ 69
- 0
src/main/resources/static/app.js Datei anzeigen

@@ -0,0 +1,69 @@
1
+var stompClient = null;
2
+
3
+function setConnected(connected) {
4
+    $('#connect').prop("disabled", connected);
5
+    $('#disconnect').prop("disabled", !connected);
6
+    if (connected) {
7
+        $("#conversation").show();
8
+    }
9
+    else {
10
+        $("#conversation").hide();
11
+    }
12
+    $("#messages").html("");
13
+}
14
+
15
+function connect() {
16
+    var socket = new SockJS('/vault-socket');
17
+    stompClient = Stomp.over(socket);
18
+    stompClient.connect({}, function (frame) {
19
+        setConnected(true);
20
+        console.log('Connected: ' + frame);
21
+        stompClient.subscribe('/topic/posts', function (greeting) {
22
+            showGreeting(JSON.parse(greeting.body).message, JSON.parse(greeting.body).userName);
23
+        });
24
+    });
25
+}
26
+
27
+function disconnect() {
28
+    if (stompClient !== null) {
29
+        stompClient.disconnect();
30
+    }
31
+    setConnected(false);
32
+    console.log("Disconnected");
33
+}
34
+
35
+var userId = 1;
36
+var userPostUrl = "/app/posts";
37
+
38
+function user1() {
39
+    $('#user1').prop("disabled", true);
40
+    $('#user2').prop("disabled", false);
41
+    userId = 1;
42
+}
43
+
44
+function user2() {
45
+    $('#user1').prop("disabled", false);
46
+    $('#user2').prop("disabled", true);
47
+    userId = 2;
48
+}
49
+
50
+
51
+function sendName() {
52
+
53
+    stompClient.send(userPostUrl, {}, JSON.stringify({'id': '','message': $("#message").val(),'userId': userId}))
54
+}
55
+
56
+function showGreeting(message, userName) {
57
+    $("#messages").append("<tr><td>" + userName + ": " + message + "</td></tr>");
58
+}
59
+
60
+$(function () {
61
+    $("form").on('submit', function (e) {
62
+        e.preventDefault();
63
+    });
64
+    $( "#connect" ).click(function() { connect(); });
65
+    $( "#disconnect" ).click(function() { disconnect(); });
66
+    $( "#send" ).click(function() { sendName(); });
67
+    $( "#user1" ).click(function() { user1(); });
68
+    $( "#user2" ).click(function() { user2(); })
69
+});

+ 56
- 0
src/main/resources/static/index.html Datei anzeigen

@@ -0,0 +1,56 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head>
4
+    <title>Hello WebSocket</title>
5
+    <link href="/webjars/bootstrap/css/bootstrap.min.css" rel="stylesheet">
6
+    <!--<link href="/main.css" rel="stylesheet">-->
7
+    <script src="/webjars/jquery/jquery.min.js"></script>
8
+    <script src="/webjars/sockjs-client/sockjs.min.js"></script>
9
+    <script src="/webjars/stomp-websocket/stomp.min.js"></script>
10
+    <script src="./app.js"></script>
11
+
12
+</head>
13
+<body style=" background-color: #665D78; color: white">
14
+<noscript><h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websocket relies on Javascript being
15
+    enabled. Please enable
16
+    Javascript and reload this page!</h2></noscript>
17
+<div id="main-content" class="container">
18
+    <div class="row">
19
+        <div class="col-md-6">
20
+            <form class="form-inline">
21
+                <div class="form-group">
22
+                    <label for="connect">WebSocket connection:</label>
23
+                    <button id="connect" class="btn btn-default" type="submit">Connect</button>
24
+                    <button id="disconnect" class="btn btn-default" type="submit" disabled="disabled">Disconnect
25
+                    </button>
26
+                    <button id="user1" class="btn btn-default" type="submit" disabled="disabled">User 1</button>
27
+                    <button id="user2" class="btn btn-default" type="submit">User 2</button>
28
+                </div>
29
+            </form>
30
+        </div>
31
+        <div class="col-md-6">
32
+            <form class="form-inline">
33
+                <div class="form-group">
34
+                    <label for="message">Message?</label>
35
+                    <input type="text" id="message" class="form-control" placeholder="What is your message...">
36
+                </div>
37
+                <button id="send" class="btn btn-default" type="submit">Send</button>
38
+            </form>
39
+        </div>
40
+    </div>
41
+    <div class="row">
42
+        <div class="col-md-12">
43
+            <table id="conversation" class="table" style="background-color:#BFAEE2">
44
+                <thead>
45
+                <tr>
46
+                    <th>Messages</th>
47
+                </tr>
48
+                </thead>
49
+                <tbody id="messages" style=" background-color:#BFAEE2; border-radius: 6px;">
50
+                </tbody>
51
+            </table>
52
+        </div>
53
+    </div>
54
+</div>
55
+</body>
56
+</html>