├── settings.gradle
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── vcs.xml
├── jpa-buddy.xml
├── modules
│ ├── crazy-chat.main.iml
│ └── crazy-chat.iml
├── .gitignore
├── misc.xml
├── aws.xml
├── gradle.xml
├── checkstyle-idea.xml
├── compiler.xml
├── jarRepositories.xml
├── libraries-with-intellij-classes.xml
└── uiDesigner.xml
├── src
├── main
│ ├── java
│ │ └── may
│ │ │ └── code
│ │ │ └── crazy_chat
│ │ │ ├── api
│ │ │ ├── RandomIdGenerator.java
│ │ │ ├── dto
│ │ │ │ ├── ParticipantDto.java
│ │ │ │ ├── ChatDto.java
│ │ │ │ ├── ErrorDTO.java
│ │ │ │ └── MessageDto.java
│ │ │ ├── domains
│ │ │ │ ├── Participant.java
│ │ │ │ └── Chat.java
│ │ │ ├── factories
│ │ │ │ ├── ParticipantDtoFactory.java
│ │ │ │ └── ChatDtoFactory.java
│ │ │ ├── controllers
│ │ │ │ ├── exceptions
│ │ │ │ │ ├── CustomExceptionHandler.java
│ │ │ │ │ └── CustomErrorController.java
│ │ │ │ ├── rest
│ │ │ │ │ ├── ChatRestController.java
│ │ │ │ │ └── ParticipantRestController.java
│ │ │ │ └── ws
│ │ │ │ │ ├── ParticipantWsController.java
│ │ │ │ │ └── ChatWsController.java
│ │ │ └── services
│ │ │ │ ├── ChatService.java
│ │ │ │ └── ParticipantService.java
│ │ │ ├── Application.java
│ │ │ └── config
│ │ │ ├── WebConfig.java
│ │ │ ├── WebSocketConfig.java
│ │ │ └── RedisConfig.java
│ └── resources
│ │ └── application.yml
└── test
│ ├── resources
│ └── application-test.yml
│ └── java
│ └── may
│ └── code
│ └── crazy_chat
│ └── api
│ └── controllers
│ └── ws
│ └── WebSocketTests.java
├── gradlew.bat
└── gradlew
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'crazy-chat'
2 |
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Project exclude paths
2 | /.gradle/
3 | /build/
4 | /build/classes/java/main/
5 | /build/classes/java/test/
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FriMay/crazy-chat/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/jpa-buddy.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules/crazy-chat.main.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /../../../../../:\Projects\Arbina\crazy-chat\.idea/dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/api/RandomIdGenerator.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat.api;
2 |
3 | import java.util.UUID;
4 |
5 | public class RandomIdGenerator {
6 |
7 | public static String generate() {
8 | return UUID.randomUUID().toString().substring(0, 4);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/test/resources/application-test.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | spring:
4 | datasource:
5 | driver-class-name: org.h2.Driver
6 | url: jdbc:h2:mem:test-db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
7 | jpa:
8 | hibernate:
9 | ddl-auto: update
10 | show-sql: false
11 | properties:
12 | hibernate:
13 | enable_lazy_load_no_trans: true
--------------------------------------------------------------------------------
/.idea/modules/crazy-chat.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/api/dto/ParticipantDto.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat.api.dto;
2 |
3 | import lombok.*;
4 | import lombok.experimental.FieldDefaults;
5 |
6 | import java.time.Instant;
7 |
8 | @Data
9 | @Builder
10 | @NoArgsConstructor
11 | @AllArgsConstructor
12 | @FieldDefaults(level = AccessLevel.PRIVATE)
13 | public class ParticipantDto {
14 |
15 | String id;
16 |
17 | Instant enterAt;
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/api/dto/ChatDto.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat.api.dto;
2 |
3 | import lombok.*;
4 | import lombok.experimental.FieldDefaults;
5 | import lombok.experimental.SuperBuilder;
6 |
7 | import java.time.Instant;
8 |
9 | @Data
10 | @Builder
11 | @NoArgsConstructor
12 | @AllArgsConstructor
13 | @FieldDefaults(level = AccessLevel.PRIVATE)
14 | public class ChatDto {
15 |
16 | String id;
17 |
18 | String name;
19 |
20 | Instant createdAt;
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | spring:
4 | rabbitmq:
5 | host: localhost
6 | username: guest
7 | password: guest
8 | # datasource:
9 | # driver-class-name: org.h2.Driver
10 | # url: jdbc:h2:mem:crazay-chat-db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
11 | # jpa:
12 | # hibernate:
13 | # ddl-auto: update
14 | # show-sql: false
15 | # properties:
16 | # hibernate:
17 | # enable_lazy_load_no_trans: true
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/api/dto/ErrorDTO.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat.api.dto;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import lombok.*;
5 | import lombok.experimental.FieldDefaults;
6 |
7 | @Data
8 | @Builder
9 | @NoArgsConstructor
10 | @AllArgsConstructor
11 | @FieldDefaults(level = AccessLevel.PRIVATE)
12 | public class ErrorDTO {
13 |
14 | String error;
15 |
16 | @JsonProperty("error_description")
17 | String errorDescription;
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/api/dto/MessageDto.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat.api.dto;
2 |
3 | import lombok.*;
4 | import lombok.experimental.FieldDefaults;
5 |
6 | import java.time.Instant;
7 |
8 | @Data
9 | @Builder
10 | @NoArgsConstructor
11 | @AllArgsConstructor
12 | @FieldDefaults(level = AccessLevel.PRIVATE)
13 | public class MessageDto {
14 |
15 | String from;
16 |
17 | String message;
18 |
19 | @Builder.Default
20 | Instant createdAt = Instant.now();
21 | }
22 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/aws.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/Application.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat;
2 |
3 | import org.springframework.boot.Banner;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.builder.SpringApplicationBuilder;
6 |
7 | @SpringBootApplication
8 | public class Application {
9 |
10 | public static void main(String[] args) {
11 | new SpringApplicationBuilder()
12 | .bannerMode(Banner.Mode.OFF)
13 | .sources(Application.class)
14 | .run(args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/api/domains/Participant.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat.api.domains;
2 |
3 | import lombok.*;
4 | import lombok.experimental.FieldDefaults;
5 |
6 | import java.io.Serializable;
7 | import java.time.Instant;
8 |
9 | @Data
10 | @Builder
11 | @NoArgsConstructor
12 | @AllArgsConstructor
13 | @FieldDefaults(level = AccessLevel.PRIVATE)
14 | public class Participant implements Serializable {
15 |
16 | @Builder.Default
17 | Long enterAt = Instant.now().toEpochMilli();
18 |
19 | String id;
20 |
21 | String sessionId;
22 |
23 | String chatId;
24 | }
25 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/api/factories/ParticipantDtoFactory.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat.api.factories;
2 |
3 | import may.code.crazy_chat.api.domains.Participant;
4 | import may.code.crazy_chat.api.dto.ParticipantDto;
5 | import org.springframework.stereotype.Component;
6 |
7 | import java.time.Instant;
8 |
9 | @Component
10 | public class ParticipantDtoFactory {
11 |
12 | public ParticipantDto makeParticipantDto(Participant participant) {
13 | return ParticipantDto.builder()
14 | .id(participant.getId())
15 | .enterAt(Instant.ofEpochMilli(participant.getEnterAt()))
16 | .build();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/.idea/checkstyle-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/api/domains/Chat.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat.api.domains;
2 |
3 | import lombok.*;
4 | import lombok.experimental.FieldDefaults;
5 | import may.code.crazy_chat.api.RandomIdGenerator;
6 |
7 | import java.io.Serializable;
8 | import java.time.Instant;
9 | import java.util.UUID;
10 |
11 | @Data
12 | @Builder
13 | @NoArgsConstructor
14 | @AllArgsConstructor
15 | @FieldDefaults(level = AccessLevel.PRIVATE)
16 | public class Chat implements Serializable {
17 |
18 | @Builder.Default
19 | String id = RandomIdGenerator.generate();
20 |
21 | String name;
22 |
23 | @Builder.Default
24 | Long createdAt = Instant.now().toEpochMilli();
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/config/WebConfig.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat.config;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.web.servlet.config.annotation.CorsRegistry;
5 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
7 |
8 | @Configuration
9 | @EnableWebMvc
10 | public class WebConfig extends WebMvcConfigurerAdapter {
11 |
12 | @Override
13 | public void addCorsMappings(CorsRegistry registry) {
14 | registry.addMapping("/**")
15 | .allowedMethods("HEAD", "GET", "PUT", "POST", "DELETE", "PATCH");
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/api/factories/ChatDtoFactory.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat.api.factories;
2 |
3 | import may.code.crazy_chat.api.domains.Chat;
4 | import may.code.crazy_chat.api.domains.Participant;
5 | import may.code.crazy_chat.api.dto.ChatDto;
6 | import may.code.crazy_chat.api.dto.ParticipantDto;
7 | import org.springframework.stereotype.Component;
8 |
9 | import java.time.Instant;
10 |
11 | @Component
12 | public class ChatDtoFactory {
13 |
14 | public ChatDto makeChatDto(Chat chat) {
15 | return ChatDto.builder()
16 | .id(chat.getId())
17 | .name(chat.getName())
18 | .createdAt(Instant.ofEpochMilli(chat.getCreatedAt()))
19 | .build();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/java/may/code/crazy_chat/api/controllers/exceptions/CustomExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package may.code.crazy_chat.api.controllers.exceptions;
2 |
3 | import lombok.extern.log4j.Log4j2;
4 | import org.springframework.http.ResponseEntity;
5 | import org.springframework.web.bind.annotation.ControllerAdvice;
6 | import org.springframework.web.bind.annotation.ExceptionHandler;
7 | import org.springframework.web.context.request.WebRequest;
8 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
9 |
10 | @Log4j2
11 | @ControllerAdvice
12 | public class CustomExceptionHandler extends ResponseEntityExceptionHandler {
13 |
14 | @ExceptionHandler(Exception.class)
15 | public ResponseEntity