diff --git a/SPCServer/springboot/pom.xml b/SPCServer/springboot/pom.xml
index b706ec1..9126c50 100644
--- a/SPCServer/springboot/pom.xml
+++ b/SPCServer/springboot/pom.xml
@@ -31,6 +31,14 @@
2.3.0
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
+
+ org.springframework.kafka
+ spring-kafka
+
org.springframework.boot
spring-boot-starter-graphql
@@ -313,6 +321,24 @@
aspectjweaver
1.9.22.1
+
+
+
+ org.springframework.kafka
+ spring-kafka
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
diff --git a/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/config/WebSocketConfig.java b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/config/WebSocketConfig.java
new file mode 100644
index 0000000..a006b7d
--- /dev/null
+++ b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/config/WebSocketConfig.java
@@ -0,0 +1,25 @@
+package com.lcaohoanq.shoppe.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.messaging.simp.config.MessageBrokerRegistry;
+import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
+import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
+import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
+
+@Configuration
+@EnableWebSocketMessageBroker
+public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
+
+ @Override
+ public void configureMessageBroker(MessageBrokerRegistry config) {
+ config.enableSimpleBroker("/topic");
+ config.setApplicationDestinationPrefixes("/app");
+ }
+
+ @Override
+ public void registerStompEndpoints(StompEndpointRegistry registry) {
+ registry.addEndpoint("/ws-chat")
+ .setAllowedOrigins("*")
+ .withSockJS();
+ }
+}
\ No newline at end of file
diff --git a/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/ChatMessage.java b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/ChatMessage.java
new file mode 100644
index 0000000..1573687
--- /dev/null
+++ b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/ChatMessage.java
@@ -0,0 +1,22 @@
+package com.lcaohoanq.shoppe.domain.chat;
+
+import java.time.LocalDateTime;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class ChatMessage {
+ private Long id;
+ private Long chatRoomId;
+ private Long senderId;
+ private String content;
+ private String attachmentUrl;
+ private LocalDateTime timestamp;
+ private boolean isRead;
+
+}
\ No newline at end of file
diff --git a/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/ChatRoomRepository.java b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/ChatRoomRepository.java
new file mode 100644
index 0000000..0e92cf5
--- /dev/null
+++ b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/ChatRoomRepository.java
@@ -0,0 +1,11 @@
+package com.lcaohoanq.shoppe.domain.chat;
+
+import com.lcaohoanq.shoppe.domain.user.User;
+import java.util.Optional;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface ChatRoomRepository extends JpaRepository {
+
+ Optional findByUser1AndUser2(User user1, User user2);
+
+}
diff --git a/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/MessageRepository.java b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/MessageRepository.java
new file mode 100644
index 0000000..09de412
--- /dev/null
+++ b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/MessageRepository.java
@@ -0,0 +1,7 @@
+package com.lcaohoanq.shoppe.domain.chat;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface MessageRepository extends JpaRepository {
+
+}
diff --git a/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/user/User.java b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/user/User.java
index 1923d5f..469c940 100644
--- a/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/user/User.java
+++ b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/user/User.java
@@ -1,5 +1,6 @@
package com.lcaohoanq.shoppe.domain.user;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.lcaohoanq.shoppe.domain.cart.Cart;
@@ -8,6 +9,7 @@
import com.lcaohoanq.shoppe.enums.UserStatus;
import com.lcaohoanq.shoppe.domain.wallet.Wallet;
import com.lcaohoanq.shoppe.base.entity.BaseEntity;
+import com.lcaohoanq.shoppe.domain.chat.ChatRoom;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@@ -18,6 +20,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
+import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
@@ -108,6 +111,14 @@ public class User extends BaseEntity implements UserDetails {
@Column(name = "last_login_timestamp")
private LocalDateTime lastLoginTimestamp;
+ @OneToMany(mappedBy = "user1")
+ @JsonIgnore
+ private List initiatedChats = new ArrayList<>();
+
+ @OneToMany(mappedBy = "user2")
+ @JsonIgnore
+ private List receivedChats = new ArrayList<>();
+
//Spring Security
@Override
public Collection extends GrantedAuthority> getAuthorities() {
diff --git a/SPCServer/springboot/src/main/resources/application.yml b/SPCServer/springboot/src/main/resources/application.yml
index d549ddd..c636380 100644
--- a/SPCServer/springboot/src/main/resources/application.yml
+++ b/SPCServer/springboot/src/main/resources/application.yml
@@ -49,6 +49,15 @@ spring:
google:
clientId: ${GOOGLE_OAUTH2_CLIENT_ID}
clientSecret: ${GOOGLE_OAUTH2_CLIENT_SECRET}
+
+ kafka:
+ bootstrap-servers: localhost:9092
+ consumer:
+ group-id: shoppe-group
+ auto-offset-reset: earliest
+ producer:
+ key-serializer: org.apache.kafka.common.serialization.StringSerializer
+ value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
data:
redis: