Skip to content

Commit d20f653

Browse files
committed
Back up temporary UserDatabase used for testing (delete when merging PR)
1 parent 33d6c52 commit d20f653

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package temp_persistence;
2+
3+
import java.io.*;
4+
import java.util.ArrayList;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
import conversation_history_use_case.ConvHistDsRequestModel;
9+
import conversation_history_use_case.MsgSenderDsRequestModel;
10+
import entities.*;
11+
12+
//public class temp_persistence.UserDatabase implements UserExists, UserCreator{
13+
public class UserDatabase{ // this needs to extend an interface
14+
Map<String, User> temp_accounts;
15+
File accounts;
16+
public UserDatabase(File accounts){
17+
this.accounts = accounts;
18+
this.temp_accounts = new HashMap<String, User>();
19+
// Can have code to populate temp_accounts
20+
}
21+
22+
/**
23+
* Pushes a new message to a chat's conversation history (in memory not persisting storage)
24+
* @param dsRequestModel input data containing user ID, chat ID, message content
25+
*/
26+
public void saveMessage(MsgSenderDsRequestModel dsRequestModel) {
27+
String userID = dsRequestModel.getUserID();
28+
String chatID = dsRequestModel.getChatID();
29+
Message message = dsRequestModel.getMessage();
30+
31+
// Find chat under specified User
32+
Chat chat = temp_accounts.get(userID).getChats().get(chatID);
33+
34+
chat.addMessage(message);
35+
}
36+
37+
/**
38+
* Gets a chat's conversation history (from memory not persisting storage)
39+
* @param dsRequestModel input data containing user ID, chat ID
40+
* @return a chat's conversation history
41+
*/
42+
public ArrayList<Message> getConversationHistory(ConvHistDsRequestModel dsRequestModel) {
43+
String userID = dsRequestModel.getUserID();
44+
String chatID = dsRequestModel.getChatID();
45+
46+
// Find chat under specified User
47+
Chat chat = temp_accounts.get(userID).getChats().get(chatID);
48+
49+
return Chat.getConversationHistory();
50+
}
51+
}

0 commit comments

Comments
 (0)