diff --git a/src/main/java/callhub/connect/CallhubconnectApplication.java b/src/main/java/callhub/connect/CallhubconnectApplication.java index 5edf822..7af2592 100644 --- a/src/main/java/callhub/connect/CallhubconnectApplication.java +++ b/src/main/java/callhub/connect/CallhubconnectApplication.java @@ -1,9 +1,11 @@ package callhub.connect; +import callhub.connect.data_access.MessageDataAccess; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -40,4 +42,9 @@ public void addCorsMappings(CorsRegistry registry) { }; } + @Bean + public MessageDataAccess messageDataAccess(ApplicationContext context) { + return new MessageDataAccess(context); + } + } diff --git a/src/main/java/callhub/connect/data_access/MessageDataAccess.java b/src/main/java/callhub/connect/data_access/MessageDataAccess.java new file mode 100644 index 0000000..df12861 --- /dev/null +++ b/src/main/java/callhub/connect/data_access/MessageDataAccess.java @@ -0,0 +1,24 @@ +package callhub.connect.data_access; + +import callhub.connect.entities.Message; +import callhub.connect.entities.Sender; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; + +public class MessageDataAccess { + + private ApplicationContext context; + private MessageRepository messageRepository; + + public MessageDataAccess(ApplicationContext context) { + this.context = context; + this.messageRepository = context.getBean(MessageRepository.class); + } + + public void sendResponseToDatabase(String content, String sessionId, Sender sender) { + Message message = new Message(content, sessionId, sender); + messageRepository.save(message); + } +} diff --git a/src/main/java/callhub/connect/drivers/MessageWebSocketAccess.java b/src/main/java/callhub/connect/drivers/MessageWebSocketAccess.java index 4d62a3d..75922ea 100644 --- a/src/main/java/callhub/connect/drivers/MessageWebSocketAccess.java +++ b/src/main/java/callhub/connect/drivers/MessageWebSocketAccess.java @@ -1,6 +1,6 @@ package callhub.connect.drivers; public class MessageWebSocketAccess { - // this class was moved to MessageController + // this class and its functionality was moved to MessageController and the other MessageCA classes // Attempting to see if this resolves the merge conflict -} +} \ No newline at end of file diff --git a/src/main/java/callhub/connect/entities/Message.java b/src/main/java/callhub/connect/entities/Message.java index 4abff96..2e16813 100644 --- a/src/main/java/callhub/connect/entities/Message.java +++ b/src/main/java/callhub/connect/entities/Message.java @@ -2,7 +2,10 @@ import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.util.Date; @Document("message") public class Message { @@ -12,18 +15,20 @@ public class Message { private String content; private LocalDate timeStamp; private String userId; - + private String sessionId; private Sender sender; - public Message(String content, LocalDate timeStamp, Sender sender) { + public Message(String content, LocalDate timeStamp, String sessionId, Sender sender) { this.content = content; this.timeStamp = timeStamp; + this.sessionId = sessionId; this.sender = sender; } - public Message(String content, Sender sender) { + public Message(String content, String sessionId, Sender sender) { this.content = content; this.timeStamp = LocalDate.now(); + this.sessionId = sessionId; this.sender = sender; } @@ -34,4 +39,13 @@ public String getContent() { public void setContent(String content) { this.content = content; } + + private String getTimeStampString() { + DateFormat df = new SimpleDateFormat("HH:mm:ss a"); + return df.format(this.timeStamp); + } + + public String formattedMessage() { + return String.format("%s %s", this.getTimeStampString(), this.content); + } } diff --git a/src/main/java/callhub/connect/entities/Session.java b/src/main/java/callhub/connect/entities/Session.java index 7acdf03..26c8d2d 100644 --- a/src/main/java/callhub/connect/entities/Session.java +++ b/src/main/java/callhub/connect/entities/Session.java @@ -33,4 +33,8 @@ public String getCode() { return code; } + public ArrayList getMessages() { + return this.messages; + } + }