-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseServer.java
More file actions
113 lines (99 loc) · 4.17 KB
/
Copy pathDatabaseServer.java
File metadata and controls
113 lines (99 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package assignment7;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class DatabaseServer {
public static int login(String username, String password) {
Map<String,Object> params = new HashMap<>();
params.put("type", "login");
params.put("username", username);
params.put("password", password);
return DatabaseAccessor.intQuery(params);
}
public static int register(String username, String password) {
Map<String,Object> params = new HashMap<>();
params.put("type", "register");
params.put("username", username);
params.put("password", password);
return DatabaseAccessor.intQuery(params);
}
public static int updatePassword(int client, String newPassword){
Map<String,Object> params = new HashMap<>();
params.put("type", "update_password");
params.put("clientid", client);
params.put("newpassword", newPassword);
return DatabaseAccessor.intQuery(params);
}
public static int sendGroupMessage(int client, int groupId, String message){
Map<String,Object> params = new HashMap<>();
params.put("type", "send_group_message");
params.put("groupid", groupId);
params.put("clientid", client);
params.put("message", message);
return DatabaseAccessor.intQuery(params);
}
public static int sendMessage(int client, String username, String message){
Map<String,Object> params = new HashMap<>();
params.put("type", "send_message");
params.put("recipient", username);
params.put("clientid", client);
params.put("message", message);
return DatabaseAccessor.intQuery(params);
}
public static List<String> getFriends(int client){
Map<String,Object> params = new HashMap<>();
params.put("type", "get_friends");
params.put("clientid", client);
return DatabaseAccessor.strListQuery(params);
}
public static List<Integer> makeChat(int client,String groupName, List<String> friends){
Map<String,Object> params = new HashMap<>();
params.put("type", "make_chat");
params.put("clientid", client);
params.put("groupname",groupName);
params.put("groupmembers",friends.stream().collect(Collectors.joining(",")));
return DatabaseAccessor.intListQuery(params);
}
public static List<String> addFriend(int client,String username){
Map<String,Object> params = new HashMap<>();
params.put("type", "add_friend");
params.put("clientid", client);
params.put("username", username);
return DatabaseAccessor.strListQuery(params);
}
public static int removeFriend(int client,String username){
Map<String,Object> params = new HashMap<>();
params.put("type", "remove_friend");
params.put("clientid", client);
params.put("username", username);
return DatabaseAccessor.intQuery(params);
}
public static List<String> getMessageHistory(int client,String username){
Map<String,Object> params = new HashMap<>();
params.put("type", "get_message_history");
params.put("clientid", client);
params.put("username", username);
return DatabaseAccessor.strListQuery(params);
}
public static List<String> getGroupMessageHistory(int client,int groupId){
Map<String,Object> params = new HashMap<>();
params.put("type", "get_group_message_history");
params.put("clientid", client);
params.put("groupid", groupId);
return DatabaseAccessor.strListQuery(params);
}
public static int leaveGroup(int client, int groupId){
Map<String,Object> params = new HashMap<>();
params.put("type", "leave_group");
params.put("clientid", client);
params.put("groupid", groupId);
return DatabaseAccessor.intQuery(params);
}
public static List<String> getGroups(int client){
Map<String,Object> params = new HashMap<>();
params.put("type", "get_groups");
params.put("clientid", client);
return DatabaseAccessor.strListQuery(params);
}
}