Skip to content

Commit

Permalink
Merge branch 'master' into email-ca
Browse files Browse the repository at this point in the history
  • Loading branch information
lucieyang1 authored Dec 4, 2023
2 parents 4a899b6 + 1c9b5d5 commit b3d4b57
Show file tree
Hide file tree
Showing 32 changed files with 934 additions and 301 deletions.
5 changes: 5 additions & 0 deletions src/main/java/callhub/connect/CallhubconnectApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public static void main(String[] args) {
SpringApplication.run(CallhubconnectApplication.class, args);
}

/**
* Configures Cross-Origin Resource Sharing (CORS) for the Callhub application.
*
* @return A WebMvcConfigurer object that defines CORS configuration for the application.
*/
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/callhub/connect/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
@RequestMapping("/")
@EnableMongoRepositories
public class MainController {
@Autowired
MessageRepository messageRepository;

/**
* Returns a welcome message for the Callhub application's home page.
*
* @return A string containing the welcome message.
*/
@GetMapping("/")
public String home() {
return "New New Deployment!";
return "Welcome to Callhub";
}
}
130 changes: 0 additions & 130 deletions src/main/java/callhub/connect/controllers/FileController.java

This file was deleted.

32 changes: 0 additions & 32 deletions src/main/java/callhub/connect/data_access/DataAccess.java

This file was deleted.

78 changes: 78 additions & 0 deletions src/main/java/callhub/connect/data_access/FileDataAcessObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package callhub.connect.data_access;

import callhub.connect.entities.FileDocument;
import callhub.connect.entities.Session;
import callhub.connect.use_case.file.FileDataAccessInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class FileDataAcessObject implements FileDataAccessInterface {
@Autowired
private DocumentRepository documentRepository;

@Autowired
private SessionRepository sessionRepository;

/**
* Searches for and returns a FileDocument by its ID.
*
* @param id The ID of the FileDocument to be retrieved.
* @return An Optional containing the FileDocument if found, or an empty Optional if not found.
*/
@Override
public Optional<FileDocument> findDocumentByID(String id) {
return documentRepository.findById(id);
}

/**
* Attempts to save a FileDocument to the document repository.
*
* This method tries to save the provided FileDocument object to the repository.
* If successful, it returns an Optional containing the saved FileDocument.
* If any exception occurs during the save process, it returns an empty Optional.
*
* @param file The FileDocument to be saved.
* @return An Optional containing the saved FileDocument, or an empty Optional in case of failure.
*/
@Override
public Optional<FileDocument> uploadFile(FileDocument file) {
try {
return Optional.of(documentRepository.save(file));
} catch (Exception e) {
return Optional.empty();
}
}

/**
* Checks if an active session exists with the given code.
*
* This method queries the session repository to determine whether there is an active session
* matching the provided code.
*
* @param code The code of the session to be checked.
* @return true if an active session with the given code exists, false otherwise.
*/
@Override
public boolean findSession(String code) {
return sessionRepository.existsByCodeAndActive(code, true);
}

/**
* Adds a document ID to an active session specified by its code.
*
* Retrieves the active session with the specified code and adds the provided document ID to it.
* The updated session is then saved back to the repository.
*
* @param code The code of the active session to which the document ID will be added.
* @param id The document ID to add to the session.
*/
@Override
public void addIDToSession(String code, String id) {
Session currentSession = sessionRepository.getSessionsByActiveAndCode(true, code);
currentSession.addDocument(id);
sessionRepository.save(currentSession);
}
}
26 changes: 0 additions & 26 deletions src/main/java/callhub/connect/data_access/LocalDataAccess.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public MessageDataAccessObject(MessageRepository messageRepository, SessionDataA
this.sessionDataAccessInterface = sessionDataAccessInterface;
}

/**
* Generates a response map containing a message and its timestamp.
*
* This method creates a HashMap with the given message and the current timestamp,
* formatted as specified by TIME_FORMATTER and adjusted for AM/PM notation.
*
* @param message The message to be included in the response.
* @return A HashMap with keys "message" and "timestamp", holding the message and its formatted timestamp.
*/
public HashMap<String, String> generateResponse(String message){
HashMap<String, String> response = new HashMap<>();
LocalDateTime timestamp = LocalDateTime.now();
Expand All @@ -37,6 +46,17 @@ public HashMap<String, String> generateResponse(String message){
return response;
}

/**
* Saves a message to the database and associates it with a session.
*
* This method creates a new Message object using the provided content, session ID, and sender,
* and saves it to the message repository. It then attempts to add this message to the specified session.
* Any exceptions during the process are caught and their messages are printed to the console.
*
* @param content The content of the message to be saved.
* @param sessionId The ID of the session to which the message will be added.
* @param sender The sender of the message.
*/
public void sendResponseToDatabase(String content, String sessionId, Sender sender) {
Message message = new Message(content, sessionId, sender);
Message result = messageRepository.save(message);
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/callhub/connect/data_access/NetworkDataAccess.java

This file was deleted.

Loading

0 comments on commit b3d4b57

Please sign in to comment.