Skip to content

Commit 4b4defa

Browse files
committed
remove unnecessary dependency, improve readablity, remove '/api' from endpoints
1 parent cd0bc4c commit 4b4defa

File tree

7 files changed

+64
-63
lines changed

7 files changed

+64
-63
lines changed

README.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The system uses authentication to do most of tasks.
1414

1515
### Register a user
1616

17-
POST `/api/users`
17+
POST `/users`
1818

1919
Available to `Public`
2020

@@ -54,7 +54,7 @@ Error <font color="yellow"> 500 </font>: For server error
5454

5555
### Login a user
5656

57-
GET `/api/users`
57+
GET `/users`
5858

5959
Available to `Public`
6060

@@ -89,7 +89,7 @@ Error <font color="yellow"> 500 </font>: For server error
8989

9090
### Logout a user
9191

92-
GET `/api/users/logout`
92+
GET `/users/logout`
9393

9494
Available to `Public`
9595

@@ -137,7 +137,7 @@ Tasks are created to evaluate students performance. Contains task details, total
137137

138138
### Creating a task
139139

140-
POST `/api/task`
140+
POST `/task`
141141

142142
Available to `Teachers`, `Admin`
143143

@@ -171,7 +171,7 @@ Error <font color="yellow"> 500 </font>: For server error
171171

172172
### Getting all tasks
173173

174-
GET `/api/task`
174+
GET `/task`
175175

176176
Available to `Students`, `Teachers`, `Admin`
177177

@@ -233,7 +233,7 @@ Error <font color="yellow"> 500 </font>: For server error
233233

234234
### Getting a particular task
235235

236-
GET `/api/task/{task_id}`
236+
GET `/task/{task_id}`
237237

238238
Available to `Students`, `Teachers`, `Admin`
239239

@@ -272,7 +272,7 @@ Error <font color="yellow"> 500 </font>: For server error
272272

273273
### Deleting a task
274274

275-
DELETE `/api/task/{task_id}`
275+
DELETE `/task/{task_id}`
276276

277277
Available to `Teachers`, `Admin`
278278

@@ -337,7 +337,7 @@ Notices can be used by teachers to give updates to students for a given task.
337337

338338
### Creating an notice
339339

340-
POST `/api/task/{task_id}/notice`
340+
POST `/task/{task_id}/notice`
341341

342342
Available to `Teachers`, `Admin`
343343

@@ -370,7 +370,7 @@ Error <font color="yellow"> 500 </font>: For server error
370370

371371
### Getting all notices
372372

373-
GET `/api/task/{task_id}/notice`
373+
GET `/task/{task_id}/notice`
374374

375375
Available to `Students`, `Teachers`, `Admin`
376376

@@ -415,7 +415,7 @@ Error <font color="yellow"> 500 </font>: For server error
415415

416416
### Getting a particular notice
417417

418-
GET `/api/task/{task_id}/notice/{notice_id}`
418+
GET `/task/{task_id}/notice/{notice_id}`
419419

420420
Available to `Students`, `Teachers`, `Admin`
421421

@@ -450,7 +450,7 @@ Error <font color="yellow"> 500 </font>: For server error
450450

451451
### Deleting a notice
452452

453-
DELETE `/api/task/{task_id}/notice/{notice_id}`
453+
DELETE `/task/{task_id}/notice/{notice_id}`
454454

455455
Available to `Teachers`, `Admin`
456456

@@ -513,7 +513,7 @@ These endpoints can be used by a teacher to update marks of students.
513513

514514
### Updating marks of a student
515515

516-
POST `/api/task/{task_id}/updateMarks`
516+
POST `/task/{task_id}/updateMarks`
517517

518518
Available to `Teachers`, `Admin`
519519

@@ -570,7 +570,7 @@ Announcements can be used to give updates to students aside from tasks.
570570

571571
### Creating an announcement
572572

573-
POST `/api/announcement`
573+
POST `/announcement`
574574

575575
Available to `Teachers`, `Admin`
576576

@@ -599,7 +599,7 @@ Error <font color="yellow"> 500 </font>: For server error
599599

600600
### Getting all anouncements
601601

602-
GET `/api/announcement`
602+
GET `/announcement`
603603

604604
Available to `Students`, `Teachers`, `Admin`
605605

@@ -641,7 +641,7 @@ Error <font color="yellow"> 500 </font>: For server error
641641

642642
### Getting particular anouncement
643643

644-
GET `/api/announcement/{announcement_id}`
644+
GET `/announcement/{announcement_id}`
645645

646646
Available to `Students`, `Teachers`, `Admin`
647647

@@ -676,7 +676,7 @@ Error <font color="yellow"> 500 </font>: For server error
676676

677677
### Deleting an announcement
678678

679-
DELETE `/api/announcement/{announcement_id}`
679+
DELETE `/announcement/{announcement_id}`
680680

681681
Available to `Teachers`, `Admin`
682682

src/main/java/lab/management/Controllers/DeleteController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@RestController
1515
public class DeleteController {
1616

17-
@DeleteMapping("/api/announcement/{id}")
17+
@DeleteMapping("/announcement/{id}")
1818
public String deleteAnnouncement(@PathVariable String id, @CookieValue(name = "token", defaultValue = "")String token, HttpServletResponse response){
1919
if(!JWT_Helper.checkTeacher(token)) {
2020
response.setStatus(403);
@@ -23,7 +23,7 @@ public String deleteAnnouncement(@PathVariable String id, @CookieValue(name = "t
2323
return AnnouncementService.delete(id);
2424
}
2525

26-
@DeleteMapping("/api/task/{id}")
26+
@DeleteMapping("/task/{id}")
2727
public String deleteTask(@PathVariable String id, @CookieValue(name = "token", defaultValue = "")String token, HttpServletResponse response){
2828
if(!JWT_Helper.checkTeacher(token)) {
2929
response.setStatus(403);
@@ -32,7 +32,7 @@ public String deleteTask(@PathVariable String id, @CookieValue(name = "token", d
3232
return TaskService.delete(id);
3333
}
3434

35-
@DeleteMapping("/api/task/{id}/notice/{notice}")
35+
@DeleteMapping("/task/{id}/notice/{notice}")
3636
public String deleteNotice(@PathVariable String task, @CookieValue(name = "token", defaultValue = "")String token, @PathVariable String notice, HttpServletResponse response){
3737
if(!JWT_Helper.checkTeacher(token)) {
3838
response.setStatus(403);

src/main/java/lab/management/Controllers/GetControllers.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public String home() {
3131
return "This is home. Go to https://www.github.com/crossphoton/lab-management for API usage.";
3232
}
3333

34-
@GetMapping("/api/announcement")
34+
@GetMapping("/announcement")
3535
public List<Object> getAllAnnouncements(@CookieValue(name = "token", defaultValue = "") String token, HttpServletResponse response) {
3636
if(!JWT_Helper.checkStudent(token)){
3737
response.setStatus(401);
@@ -40,7 +40,7 @@ public List<Object> getAllAnnouncements(@CookieValue(name = "token", defaultValu
4040
return AnnouncementService.get();
4141
}
4242

43-
@GetMapping("/api/announcement/{id}")
43+
@GetMapping("/announcement/{id}")
4444
public Object getAnnouncement(@PathVariable String id, @CookieValue(name = "token", defaultValue = "") String token, HttpServletResponse response) {
4545
if(!JWT_Helper.checkStudent(token)){
4646
response.setStatus(401);
@@ -55,7 +55,7 @@ public Object getAnnouncement(@PathVariable String id, @CookieValue(name = "toke
5555
return result;
5656
}
5757

58-
@GetMapping(value="/api/users")
58+
@GetMapping(value="/users")
5959
public String getMethodName(@RequestBody HashMap<Object, Object> user, HttpServletResponse response) {
6060
String result = null;
6161

@@ -78,13 +78,13 @@ public String getMethodName(@RequestBody HashMap<Object, Object> user, HttpServl
7878
return result;
7979
}
8080

81-
@GetMapping("/api/users/logout")
81+
@GetMapping("/users/logout")
8282
public String logout(HttpServletResponse response){
8383
response.addHeader("Set-Cookie", "token="+null+"; Path=/;HttpOnly;Max-Age=0");
8484
return "Logged out";
8585
}
8686

87-
@GetMapping("/api/task")
87+
@GetMapping("/task")
8888
public List<Object> getAllTasks(@CookieValue(name = "token", defaultValue = "") String token, HttpServletResponse response) {
8989
if(!JWT_Helper.checkStudent(token)){
9090
response.setStatus(401);
@@ -93,7 +93,7 @@ public List<Object> getAllTasks(@CookieValue(name = "token", defaultValue = "")
9393
return TaskService.get();
9494
}
9595

96-
@GetMapping("/api/task/{id}")
96+
@GetMapping("/task/{id}")
9797
public Object getTask(@PathVariable String id, @CookieValue(name = "token", defaultValue = "") String token, HttpServletResponse response) {
9898
if(!JWT_Helper.checkStudent(token)){
9999
response.setStatus(401);
@@ -108,7 +108,7 @@ public Object getTask(@PathVariable String id, @CookieValue(name = "token", defa
108108
return result;
109109
}
110110

111-
@GetMapping("/api/task/{task}/notice")
111+
@GetMapping("/task/{task}/notice")
112112
public List<Object> getAllNotice(@CookieValue(name = "token", defaultValue = "") String token, @PathVariable String task, HttpServletResponse response) {
113113
if(!JWT_Helper.checkStudent(token)){
114114
response.setStatus(401);
@@ -117,7 +117,7 @@ public List<Object> getAllNotice(@CookieValue(name = "token", defaultValue = "")
117117
return TaskService.getNotice(task);
118118
}
119119

120-
@GetMapping("/api/task/{task}/notice/{notice}")
120+
@GetMapping("/task/{task}/notice/{notice}")
121121
public Object getNotice(@CookieValue(name = "token", defaultValue = "") String token, @PathVariable String task, @PathVariable String notice, HttpServletResponse response) {
122122
if(!JWT_Helper.checkStudent(token)){
123123
response.setStatus(401);

src/main/java/lab/management/Controllers/PostControllers.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
@RestController
2424
public class PostControllers {
2525

26-
@PostMapping("/api/announcement")
26+
@PostMapping("/announcement")
2727
public String postAnnouncement(@RequestBody Announcement toSave,
2828
@CookieValue(name = "token", defaultValue = "") String token, HttpServletResponse response) {
2929

@@ -43,7 +43,7 @@ public String postAnnouncement(@RequestBody Announcement toSave,
4343

4444
}
4545

46-
@PostMapping("/api/users")
46+
@PostMapping("/users")
4747
public String newUser(@RequestBody Users user, HttpServletResponse response) {
4848

4949
String result = null;
@@ -64,7 +64,7 @@ public String newUser(@RequestBody Users user, HttpServletResponse response) {
6464
return result;
6565
}
6666

67-
@PostMapping("/api/task")
67+
@PostMapping("/task")
6868
public String postTask(@RequestBody Task toSave, @CookieValue(name = "token", defaultValue = "") String token, HttpServletResponse response)
6969
{
7070

@@ -87,7 +87,7 @@ public String postTask(@RequestBody Task toSave, @CookieValue(name = "token", de
8787
}
8888
}
8989

90-
@PostMapping("/api/task/{id}/updateMarks")
90+
@PostMapping("/task/{id}/updateMarks")
9191
public String updateMarksInTask(@CookieValue(name = "token", defaultValue = "") String token,
9292
@RequestBody UpdateMarks_HelperClass updates, @PathVariable String id, HttpServletResponse response)
9393
throws InterruptedException, ExecutionException {
@@ -111,7 +111,7 @@ static private class UpdateMarks_HelperClass{
111111
public int marks;
112112
}
113113

114-
@PostMapping("/api/task/{task}/notice")
114+
@PostMapping("/task/{task}/notice")
115115
public String addNotice(@CookieValue(name = "token", defaultValue = "") String token,
116116
@RequestBody Announcement notice, @PathVariable String task, HttpServletResponse response)
117117
throws InterruptedException, ExecutionException {

src/main/java/lab/management/Services/AnnouncementService.java

+9-19
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88
import java.util.List;
99

1010
import com.fasterxml.jackson.databind.ObjectMapper;
11-
import com.google.api.core.ApiFuture;
1211
import com.google.cloud.firestore.CollectionReference;
13-
import com.google.cloud.firestore.DocumentReference;
1412
import com.google.cloud.firestore.DocumentSnapshot;
1513
import com.google.cloud.firestore.Firestore;
1614
import com.google.cloud.firestore.QueryDocumentSnapshot;
17-
import com.google.cloud.firestore.QuerySnapshot;
1815
import com.google.firebase.cloud.FirestoreClient;
1916

2017
public class AnnouncementService {
@@ -23,14 +20,12 @@ public class AnnouncementService {
2320
static CollectionReference announcementReference = db.collection("announcement");
2421

2522

26-
public static List<Object>get(){
23+
public static List<Object>get(){
2724

28-
ApiFuture<QuerySnapshot> future = announcementReference.get();
2925
List<Object> data = new ArrayList<>();
30-
List<QueryDocumentSnapshot> docs;
3126

3227
try{
33-
docs = future.get().getDocuments();
28+
List<QueryDocumentSnapshot> docs = announcementReference.get().get().getDocuments();
3429

3530
ObjectMapper mapper = new ObjectMapper();
3631

@@ -51,21 +46,16 @@ public class AnnouncementService {
5146

5247
public static Object get(String document){
5348

54-
DocumentReference docRef = announcementReference.document(document);
55-
56-
ApiFuture<DocumentSnapshot> future = docRef.get();
57-
5849
Object result;
5950

6051
try{
61-
62-
DocumentSnapshot doc = future.get();
63-
if(doc.exists()){
64-
result = doc.toObject(Object.class);
65-
}
66-
else{
67-
result = new NotFound();
68-
}
52+
DocumentSnapshot doc = announcementReference.document(document).get().get();
53+
if(doc.exists()){
54+
result = doc.toObject(Object.class);
55+
}
56+
else{
57+
result = new NotFound();
58+
}
6959

7060
} catch(Exception error){System.out.println(error); result = new ServerError();}
7161

src/main/java/lab/management/Services/TaskService.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import com.fasterxml.jackson.databind.ObjectMapper;
1313
import com.google.cloud.firestore.CollectionReference;
14-
import com.google.cloud.firestore.DocumentReference;
1514
import com.google.cloud.firestore.DocumentSnapshot;
1615
import com.google.cloud.firestore.Firestore;
1716
import com.google.cloud.firestore.QueryDocumentSnapshot;
@@ -92,10 +91,9 @@ public static String delete(String id) {
9291

9392
public static String updateMarks(String taskId, String username, Integer marks)
9493
throws InterruptedException, ExecutionException {
95-
96-
DocumentReference data = taskRef.document(taskId).get().get().getReference();
9794

98-
data.update("studentRecord." + username, marks);
95+
taskRef.document(taskId).get().get().getReference()
96+
.update("studentRecord." + username, marks);
9997

10098
return "Updated!!";
10199
}

0 commit comments

Comments
 (0)