-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminRepository.java
More file actions
63 lines (56 loc) · 1.93 KB
/
AdminRepository.java
File metadata and controls
63 lines (56 loc) · 1.93 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
package repositories;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import services.AdminService;
import services.JsonFileService;
public class AdminRepository implements AdminService {
private final JsonFileService jfs;
public AdminRepository() {
jfs = new JsonFileRepository("resources/databases/users.json");
}
@Override
public boolean getLogin(String username, String password) {
return username.equals("admin") && password.equals("admin");
}
@Override
public boolean createStudent(String username, String password) {
try {
Map<String, String> map = new HashMap<>();
map.put("username", username);
map.put("password", password);
map.put("role", "student");
map.put("marks", "0");
boolean isAdded = jfs.createItemsInJsonFile(map);
if (isAdded == false) {
System.out.println("Student Addition Failed");
}
return true;
} catch (Exception ex) {
System.out.println("Student Addition Failed. Exception occured");
System.out.println(ex.getMessage());
ex.printStackTrace();
return false;
}
}
@Override
public List<Map<String, String>> getStudentMarks() {
try {
List<String> keys = new ArrayList<>();
keys.add("username");
keys.add("marks");
List<Map<String, String>> marks = jfs.getAllRow(keys);
if (!marks.isEmpty()) {
return marks;
}
System.out.println("No Student marks found");
return null;
} catch (Exception ex) {
System.out.println("Student marks retrieval Failed. Exception occured");
System.out.println(ex.getMessage());
ex.printStackTrace();
return null;
}
}
}