Skip to content

Commit 0af67ee

Browse files
authored
Merge pull request #42 from michkin32/dev
Merge Dev to Master
2 parents c34d8f3 + f4404c2 commit 0af67ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2300
-78
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# Mac
1212
.DS_Store
13+
resources/uploads/
1314

1415
# Maven
1516
log/

README.md

Lines changed: 20 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,28 @@
1-
# Micro Web Application - Server
2-
* **Objective** - to create an implementation of a small web service
3-
* **Purpose** - to demonstrate the construction of a full-stacked web-application
1+
# Chat App (Whomp Chat?)
42

5-
## Developmental Notes
6-
### Minimum Tech Stack
7-
* **Wireframe** - Mockflow
8-
* **Frontend** - Angular / React
9-
* **Business Logic** - Java
10-
* **Data Layer** - MySQL
11-
* **Cloud** - Heroku
3+
A Spring Boot api to provide endpoints for a real-time messaging platform
124

13-
### Installation
14-
* Install [NodeJs](https://nodejs.org/en/). From terminal execute
15-
* `brew install node`
16-
* Install [Angular](http://angular.io/). From terminal execute
17-
* `brew install angular-cli`
18-
* Install [AngularCli](). From terminal execute
19-
* `npm install -g @angular/cli`
20-
* Install [Heroku](). From terminal execute
21-
* `brew tap heroku/brew && brew install heroku`
5+
### Requirements:
6+
#### In-Memory/Cloud:
7+
- Java 8+
8+
- Maven
9+
#### Cloud:
10+
- Mariadb
2211

23-
<hr><hr>
12+
### Installation:
2413

14+
1. Build with maven: ``` mvn package ```
2515

16+
2. Set enviroment variable for profile to either "in-memory" or "cloud"
2617

18+
- Command to set the profile to in-memory on Unix machines:``` export spring_profiles_active=in-memory ```
19+
- Command to set the profile to cloud:``` export spring_profiles_active=cloud ```
2720

21+
3. If profile is set to cloud then set the database url, user, and password using the following enviorment variables:
22+
```
23+
spring_datasource_url
24+
spring_datasource_username
25+
spring_datasource_password
26+
```
2827

29-
30-
31-
32-
## Project Topics
33-
34-
### TCP Application
35-
36-
#### User Stories to Fulfill
37-
* As a client, (not logged in) I
38-
* can send messages to a _peer_.
39-
* can view default channels
40-
* can view all accessible channels
41-
* can view messages live as they are received
42-
43-
<hr>
44-
45-
46-
47-
48-
49-
### Blog Application
50-
51-
#### User Stories to Fulfill
52-
* As a client, (not logged in) I
53-
* can create new blog posts
54-
* A blog post can consist of images and text
55-
* can view list of all blog posts
56-
* can view blog posts filtered by blog-tag
57-
* can view new blog posts upon refreshing the DOM
58-
59-
<hr>
60-
61-
62-
63-
64-
65-
### Video Library Application
66-
67-
#### User Stories to Fulfill
68-
* As a client, (not logged in) I
69-
* can upload new videos
70-
* can view list of all videos
71-
* can post simple text-comments on a video
72-
73-
74-
75-
76-
77-
### Money Management Application
78-
79-
#### User Stories to Fulfill
80-
* As a client, (not logged in) I
81-
* can create new accounts
82-
* deposit money to each account
83-
* withdrawl money from each account
84-
* transfer money to and from any 2 accounts
28+
4. run the packaged jar: ```java -jar build_name.jar```

pom.xml

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<parent>
66
<groupId>org.springframework.boot</groupId>
@@ -19,6 +19,23 @@
1919
</properties>
2020

2121
<dependencies>
22+
<dependency>
23+
<groupId>com.h2database</groupId>
24+
<artifactId>h2</artifactId>
25+
<version>1.4.199</version>
26+
<scope>runtime</scope>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>org.postgresql</groupId>
31+
<artifactId>postgresql</artifactId>
32+
<scope>runtime</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.mariadb.jdbc</groupId>
36+
<artifactId>mariadb-java-client</artifactId>
37+
</dependency>
38+
2239
<dependency>
2340
<groupId>org.springframework.boot</groupId>
2441
<artifactId>spring-boot-starter-data-jpa</artifactId>
@@ -27,7 +44,42 @@
2744
<groupId>org.springframework.boot</groupId>
2845
<artifactId>spring-boot-starter-web</artifactId>
2946
</dependency>
47+
<dependency>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-starter-websocket</artifactId>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>org.webjars</groupId>
54+
<artifactId>webjars-locator-core</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.webjars</groupId>
58+
<artifactId>sockjs-client</artifactId>
59+
<version>1.0.2</version>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.webjars</groupId>
63+
<artifactId>stomp-websocket</artifactId>
64+
<version>2.3.3</version>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.webjars</groupId>
68+
<artifactId>bootstrap</artifactId>
69+
<version>3.3.7</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.webjars</groupId>
73+
<artifactId>jquery</artifactId>
74+
<version>3.3.1</version>
75+
</dependency>
3076

77+
<dependency>
78+
<groupId>junit</groupId>
79+
<artifactId>junit</artifactId>
80+
<version>4.12</version>
81+
<scope>test</scope>
82+
</dependency>
3183
<dependency>
3284
<groupId>org.springframework.boot</groupId>
3385
<artifactId>spring-boot-devtools</artifactId>
@@ -56,4 +108,12 @@
56108
</plugins>
57109
</build>
58110

59-
</project>
111+
<pluginRepositories>
112+
<pluginRepository>
113+
<id>repository.spring.release</id>
114+
<name>Spring GA Repository</name>
115+
<url>https://repo.spring.io/plugins-release/</url>
116+
</pluginRepository>
117+
</pluginRepositories>
118+
119+
</project>

src/main/java/com/groupfour/chatapp/chatapp/ChatappApplication.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.groupfour.chatapp.chatapp;
22

3+
import com.groupfour.chatapp.chatapp.property.FileStorageProperties;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
57

68
@SpringBootApplication
9+
@EnableConfigurationProperties({
10+
FileStorageProperties.class
11+
})
712
public class ChatappApplication {
813

914
public static void main(String[] args) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.groupfour.chatapp.chatapp.configurations;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
5+
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
6+
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
7+
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
8+
9+
@Configuration
10+
@EnableWebSocketMessageBroker
11+
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
12+
13+
14+
@Override
15+
public void registerStompEndpoints(StompEndpointRegistry registry) {
16+
registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS();
17+
}
18+
19+
@Override
20+
public void configureMessageBroker(MessageBrokerRegistry registry) {
21+
registry.setApplicationDestinationPrefixes("/app");
22+
registry.enableSimpleBroker("/chat");
23+
}
24+
25+
26+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.groupfour.chatapp.chatapp.controllers;
2+
3+
import com.groupfour.chatapp.chatapp.dataprojections.ChatDTO;
4+
import com.groupfour.chatapp.chatapp.repositories.ChatRepository;
5+
import com.groupfour.chatapp.chatapp.services.ChatService;
6+
import com.groupfour.chatapp.chatapp.exceptions.ResourceNotFoundException;
7+
import com.groupfour.chatapp.chatapp.models.Chat;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.web.bind.annotation.*;
12+
13+
@CrossOrigin
14+
@RestController
15+
public class ChatController {
16+
17+
private ChatService chatService;
18+
private ChatRepository chatRepository;
19+
20+
@Autowired
21+
public ChatController(ChatService chatService, ChatRepository chatRepository) {
22+
this.chatService = chatService;
23+
this.chatRepository = chatRepository;
24+
}
25+
26+
@GetMapping("/chat/user/{userId}")
27+
public ResponseEntity<Iterable<ChatDTO>> getChatsByUser(@PathVariable Long userId) {
28+
try {
29+
return new ResponseEntity<>(chatService.getUserChats(userId), HttpStatus.OK);
30+
} catch (ResourceNotFoundException e) {
31+
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
32+
}
33+
}
34+
35+
@GetMapping("/chat/{chatId}")
36+
public ResponseEntity<Chat> findChatBy(@PathVariable Long chatId) {
37+
try {
38+
verifyChatById(chatId);
39+
return new ResponseEntity<>(chatService.getChatById(chatId), HttpStatus.OK);
40+
} catch (ResourceNotFoundException ex) {
41+
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
42+
}
43+
}
44+
45+
@PostMapping("/chat/{adminId}")
46+
public ResponseEntity<ChatDTO> createNewChat(@RequestBody Chat chatName, @PathVariable Long adminId) {
47+
Chat chat = chatService.createNewChat(chatName, adminId);
48+
return new ResponseEntity<>(chatRepository.findByChatId(chat.getChatId()), HttpStatus.CREATED);
49+
}
50+
51+
@PutMapping("/chat/{chatId}/user/{username}")
52+
public ResponseEntity<ChatDTO> addUserToChat(@PathVariable Long chatId, @PathVariable String username) {
53+
return new ResponseEntity<>(chatService.addUserToChat(chatId, username), HttpStatus.OK);
54+
}
55+
56+
@PatchMapping("/chat/{chatId}")
57+
public ResponseEntity<Chat> updateChatName(@PathVariable Long chatId, @RequestBody String newChatName) {
58+
try {
59+
verifyChatById(chatId);
60+
chatService.updateChatName(chatId, newChatName);
61+
return new ResponseEntity<>(HttpStatus.OK);
62+
} catch (ResourceNotFoundException ex) {
63+
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
64+
}
65+
}
66+
67+
@PatchMapping("/chat/{chatId}/1")
68+
public ResponseEntity<Chat> updateChatAdmin(@PathVariable Long chatId, @RequestBody Long newAdminId) {
69+
try {
70+
verifyChatById(chatId);
71+
chatService.updateChatAdmin(chatId, newAdminId);
72+
return new ResponseEntity<>(HttpStatus.OK);
73+
} catch (ResourceNotFoundException ex) {
74+
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
75+
}
76+
}
77+
78+
@DeleteMapping("/chat/{chatId}")
79+
public ResponseEntity<Boolean> deleteChat(@PathVariable Long chatId) {
80+
try {
81+
verifyChatById(chatId);
82+
return new ResponseEntity<>(chatService.deleteChatByChatId(chatId), HttpStatus.OK);
83+
} catch (ResourceNotFoundException ex) {
84+
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
85+
}
86+
}
87+
88+
89+
public void verifyChatById(Long chatId) {
90+
if (chatRepository.existsById(chatId)) {
91+
throw new ResourceNotFoundException("Department " + chatId + " not found.");
92+
}
93+
}
94+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.groupfour.chatapp.chatapp.controllers;
2+
3+
import com.groupfour.chatapp.chatapp.services.FileAttachmentService;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.web.bind.annotation.CrossOrigin;
6+
import org.springframework.web.bind.annotation.RestController;
7+
@CrossOrigin
8+
@RestController
9+
public class FileAttachmentController {
10+
11+
private FileAttachmentService fileAttachmentService;
12+
13+
@Autowired
14+
public FileAttachmentController(FileAttachmentService fileAttachmentService) {
15+
this.fileAttachmentService = fileAttachmentService;
16+
}
17+
}

0 commit comments

Comments
 (0)