Skip to content

Commit 33d6c52

Browse files
committed
Separated interactor into two interactors to adhere to SRP
1 parent cf9120f commit 33d6c52

File tree

2 files changed

+66
-27
lines changed

2 files changed

+66
-27
lines changed

src/main/java/conversation_history_use_case/ConvHistInteractor.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
import java.util.List;
99

1010
/**
11-
* Interactor responsible for adding messages to a chat's conversation history and displaying this history upon opening
12-
* a chat
11+
* Interactor responsible for displaying this history upon opening a chat
1312
*/
1413
//public class ConvHistInteractor implements ConversationHistoryInputBoundary{
1514
public class ConvHistInteractor{
1615
/**
17-
* File and in-memory storage of users nad their chats (incl. conversation history)
16+
* File and in-memory storage of users and their chats (incl. conversation history)
1817
*/
1918
final UserDatabase userDatabase;
2019
/**
@@ -39,30 +38,6 @@ public ConvHistInteractor(UserDatabase userDatabase, MsgFactory msgFactory) {
3938
// this.convHistPresenter = convHistPresenter;
4039
}
4140

42-
/**
43-
* Creates and adds message to a chat's conversation history
44-
* @param requestModel input data
45-
* @return a response model for presenter
46-
*/
47-
// @Override
48-
public ConvHistResponseModel create(MsgSenderRequestModel requestModel) {
49-
// Create new message
50-
Message message = msgFactory.createMsg(requestModel.getSenderID(), requestModel.getMsgContent());
51-
52-
// Add message to specified chat in user list
53-
String userID = requestModel.getSenderID(); // need a user in the chat to get the chat
54-
String chatID = requestModel.getChatID();
55-
56-
MsgSenderDsRequestModel dsRequestModel = new MsgSenderDsRequestModel(userID, chatID, message);
57-
58-
// Access database (code for database will become functional after PR for issue 15 is merged)
59-
// List<Message> conversationHistory = userDatabase.saveMessage(dsRequestModel);
60-
61-
// Presenter show success view (code to be written); below is temporary
62-
List<Message> conversationHistory = new ArrayList<>();
63-
return new ConvHistResponseModel(conversationHistory);
64-
}
65-
6641
/**
6742
* Displays conversation history upon opening a chat
6843
* @param requestModel input data
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package conversation_history_use_case;
2+
3+
import entities.Message;
4+
import entities.MsgFactory;
5+
import temp_persistence.UserDatabase;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
/**
11+
* Interactor responsible for adding messages to a chat's conversation history
12+
*/
13+
//public class ConvHistInteractor implements ConversationHistoryInputBoundary{
14+
public class MsgSenderInteractor {
15+
/**
16+
* File and in-memory storage of users and their chats (incl. conversation history)
17+
*/
18+
final UserDatabase userDatabase;
19+
/**
20+
* Factory for creating a new Message
21+
*/
22+
final MsgFactory msgFactory;
23+
// /**
24+
// * Presenter with necessary information to display a chat's conversation history
25+
// */
26+
// final ConvHistPresenter convHistPresenter;
27+
28+
/**
29+
* Construct ConvHistInteractor given storage, message factory, and presenter
30+
* @param userDatabase storage
31+
* @param msgFactory message factory
32+
* //@param convHistPresenter presenter
33+
*/
34+
// public ConvHistInteractor(UserDatabase userDatabase, MsgFactory msgFactory, ConvHistPresenter convHistPresenter) {
35+
public MsgSenderInteractor(UserDatabase userDatabase, MsgFactory msgFactory) {
36+
this.userDatabase = userDatabase;
37+
this.msgFactory = msgFactory; // msgType of MsgFactory specified in Main
38+
// this.convHistPresenter = convHistPresenter;
39+
}
40+
41+
/**
42+
* Creates and adds message to a chat's conversation history
43+
* @param requestModel input data
44+
* @return a response model for presenter
45+
*/
46+
// @Override
47+
public ConvHistResponseModel create(MsgSenderRequestModel requestModel) {
48+
// Create new message
49+
Message message = msgFactory.createMsg(requestModel.getSenderID(), requestModel.getMsgContent());
50+
51+
// Add message to specified chat in user list
52+
String userID = requestModel.getSenderID(); // need a user in the chat to get the chat
53+
String chatID = requestModel.getChatID();
54+
55+
MsgSenderDsRequestModel dsRequestModel = new MsgSenderDsRequestModel(userID, chatID, message);
56+
57+
// Access database (code for database will become functional after PR for issue 15 is merged)
58+
// List<Message> conversationHistory = userDatabase.saveMessage(dsRequestModel);
59+
60+
// Presenter show success view (code to be written); below is temporary
61+
List<Message> conversationHistory = new ArrayList<>();
62+
return new ConvHistResponseModel(conversationHistory);
63+
}
64+
}

0 commit comments

Comments
 (0)