Skip to content

Commit

Permalink
Merge branch 'vithu-clean-architecture' of https://github.com/Callhub…
Browse files Browse the repository at this point in the history
…-Connect/callhub-backend into vithu-clean-architecture

restoring commit on local end
  • Loading branch information
vithushon committed Nov 27, 2023
2 parents 255f70a + 49236df commit 0b153b5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/main/java/callhub/connect/CallhubconnectApplication.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -40,4 +42,9 @@ public void addCorsMappings(CorsRegistry registry) {
};
}

@Bean
public MessageDataAccess messageDataAccess(ApplicationContext context) {
return new MessageDataAccess(context);
}

}
24 changes: 24 additions & 0 deletions src/main/java/callhub/connect/data_access/MessageDataAccess.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
20 changes: 17 additions & 3 deletions src/main/java/callhub/connect/entities/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}

Expand All @@ -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);
}
}
4 changes: 4 additions & 0 deletions src/main/java/callhub/connect/entities/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public String getCode() {
return code;
}

public ArrayList<Message> getMessages() {
return this.messages;
}

}

0 comments on commit 0b153b5

Please sign in to comment.