Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Simple messaging server on Spring Boot
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<version>3.1.0</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
Expand All @@ -14,7 +14,7 @@
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
Expand Down
346 changes: 209 additions & 137 deletions src/main/java/com/example/demo/RestFullController.java

Large diffs are not rendered by default.

23 changes: 22 additions & 1 deletion src/main/java/com/example/demo/files/chats.json
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
[]
[
{
"deleted": false,
"messagesIds": [
"M655e9c66-c622-4b08-99b0-d409a4ae0e53"
],
"usersIds": [
"test1",
"test2"
],
"id": "test1"
},
{
"deleted": false,
"messagesIds": [],
"usersIds": [
"test1",
"test2"
],
"id": "test2"
}
]
14 changes: 13 additions & 1 deletion src/main/java/com/example/demo/files/messages.json
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
[]
[
{
"deleted": false,
"text": "TEXT",
"time": 1685384274888,
"chatId": "test1",
"usersIds": [
"test1",
"test2"
],
"id": "M655e9c66-c622-4b08-99b0-d409a4ae0e53"
}
]
30 changes: 29 additions & 1 deletion src/main/java/com/example/demo/files/users.json
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
[{"id":"U0","isAdmin":true,"name":"Матвей Дыгало","login":"muton","password":"PASSWORD","chatArrayList":[]}]
[
{
"admin": true,
"name": "name1",
"password": "1",
"chatsIds": [
"test1",
"test2"
],
"id": "test1"
},
{
"admin": false,
"name": "name2",
"password": "2",
"chatsIds": [
"test1",
"test2"
],
"id": "test2"
},
{
"admin": false,
"name": "rtwetw",
"password": "rwer",
"chatsIds": [],
"id": "Ua91f511e-1abe-4cd1-bc12-bbae88374c0e"
}
]
12 changes: 0 additions & 12 deletions src/main/java/com/example/demo/models/Admin.java

This file was deleted.

69 changes: 58 additions & 11 deletions src/main/java/com/example/demo/models/Chat.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,66 @@
package com.example.demo.models;

import java.util.ArrayList;
import java.util.TreeSet;

public class Chat {
public String id;
public Boolean isDeleted;
public ArrayList<String> messages;
public TreeSet<String> setIdUsers;
public class Chat extends ID {
private Boolean deleted;
private ArrayList<String> messagesIds;
private ArrayList<String> usersIds;

public Chat(String id, Boolean isDeleted, ArrayList<String> messages, TreeSet<String> setIdUsers) {
this.id = id;
this.isDeleted = isDeleted;
this.messages = messages;
this.setIdUsers = setIdUsers;
public Chat(String id, ArrayList<String> usersIds) {
super(id);
this.deleted = false;
this.messagesIds = new ArrayList<String>();
this.usersIds = usersIds;
}

public void addMessage(Message message) {
this.messagesIds.add(message.id);
}

/**
* @return Boolean return the isDeleted
*/
public Boolean isDeleted() {
return deleted;
}

/**
* @param isDeleted the isDeleted to set
*/
public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}

/**
* @return ArrayList<String> return the messagesIds
*/
public ArrayList<String> getMessagesIds() {
return messagesIds;
}

/**
* @param messagesIds the messagesIds to set
*/
public void setMessagesIds(ArrayList<String> messagesIds) {
this.messagesIds = messagesIds;
}

/**
* @return ArrayList<String> return the usersIds
*/
public ArrayList<String> getUsersIds() {
return usersIds;
}

/**
* @param usersIds the usersIds to set
*/
public void setUsersIds(ArrayList<String> usersIds) {
this.usersIds = usersIds;
}

public void deleteMessage(String messageId) {
this.messagesIds.remove(messageId);
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/example/demo/models/ID.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.demo.models;

import java.util.ArrayList;
import java.util.Optional;

public abstract class ID {
public String id;
public ID(String id) {
this.id = id;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public static Optional<ID> findInListById(ArrayList<ID> list, String objId) {
return list.stream().filter(listObj -> listObj.id.equals(objId)).findFirst();
}
}
101 changes: 84 additions & 17 deletions src/main/java/com/example/demo/models/Message.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,91 @@
package com.example.demo.models;

import java.util.ArrayList;
import java.util.TreeSet;

public class Message {
public String id;
public Boolean isDeleted;
public String text;
public Long time;
public String idUserAuthor;
public String idUserRecipient;
public TreeSet<String> setIdUsers;

public Message(String id, Boolean isDeleted, String text, Long time, String idUserAuthor, String idUserRecipient, TreeSet<String> setIdUsers) {
this.id = id;
this.isDeleted = isDeleted;

public class Message extends ID {
private Boolean deleted;
private String text;
private Long time;
private String chatId;
private ArrayList<String> usersIds;

public Message(String id, Boolean deleted, String text, Long time, String chatId, ArrayList<String> usersIds) {
super(id);
this.deleted = deleted;
this.text = text;
this.time = time;
this.idUserAuthor = idUserAuthor;
this.idUserRecipient = idUserRecipient;
this.setIdUsers = setIdUsers;
this.chatId = chatId;
this.usersIds = (ArrayList<String>) usersIds;
}

/**
* @return Boolean return the deleted
*/
public Boolean isDeleted() {
return deleted;
}

/**
* @param deleted the deleted to set
*/
public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}

/**
* @return String return the text
*/
public String getText() {
return text;
}

/**
* @param text the text to set
*/
public void setText(String text) {
this.text = text;
}

/**
* @return Long return the time
*/
public Long getTime() {
return time;
}

/**
* @param time the time to set
*/
public void setTime(Long time) {
this.time = time;
}

/**
* @return ArrayList<String> return the usersIds
*/
public ArrayList<String> getUsersIds() {
return usersIds;
}

/**
* @param usersIds the usersIds to set
*/
public void setUsersIds(ArrayList<String> usersIds) {
this.usersIds = usersIds;
}

/**
* @return String return the chatId
*/
public String getChatId() {
return chatId;
}

/**
* @param chatId the chatId to set
*/
public void setChatId(String chatId) {
this.chatId = chatId;
}

}
Loading