Skip to content

Commit 3254b61

Browse files
authored
Merge pull request #80 from Code-4-Community/staging
Merging Staging to Master
2 parents eedcd81 + 02c31f8 commit 3254b61

File tree

10 files changed

+696
-573
lines changed

10 files changed

+696
-573
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.codeforcommunity.api.authenticated;
2+
3+
import com.codeforcommunity.auth.JWTData;
4+
import com.codeforcommunity.dto.school.BookLog;
5+
import com.codeforcommunity.dto.school.BookLogListResponse;
6+
import com.codeforcommunity.dto.school.UpsertBookLogRequest;
7+
8+
public interface IProtectedBookLogProcessor {
9+
10+
BookLog createBookLog(JWTData userData, int schoolId, UpsertBookLogRequest request);
11+
12+
BookLogListResponse getBookLog(JWTData userData, int schoolId);
13+
14+
BookLog updateBookLog(JWTData userData, int schoolId, int bookId, UpsertBookLogRequest request);
15+
16+
void deleteBookLog(JWTData userData, int schoolId, int bookId);
17+
18+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.codeforcommunity.api.authenticated;
2+
3+
import com.codeforcommunity.auth.JWTData;
4+
import com.codeforcommunity.dto.report.ReportGeneric;
5+
import com.codeforcommunity.dto.report.ReportGenericListResponse;
6+
import com.codeforcommunity.dto.report.ReportWithLibrary;
7+
import com.codeforcommunity.dto.report.ReportWithoutLibrary;
8+
import com.codeforcommunity.dto.report.UpsertReportWithLibrary;
9+
import com.codeforcommunity.dto.report.UpsertReportWithoutLibrary;
10+
11+
public interface IProtectedReportProcessor {
12+
13+
ReportGeneric getMostRecentReport(JWTData userData, int schoolId);
14+
15+
ReportWithLibrary createReportWithLibrary(
16+
JWTData userData, int schoolId, UpsertReportWithLibrary upsertRequest);
17+
18+
ReportWithoutLibrary createReportWithoutLibrary(
19+
JWTData userData, int schoolId, UpsertReportWithoutLibrary upsertRequest);
20+
21+
void updateReportWithLibrary(
22+
JWTData userData, int schoolId, int reportId, UpsertReportWithLibrary upsertRequest);
23+
24+
void updateReportWithoutLibrary(
25+
JWTData userData, int schoolId, int reportId, UpsertReportWithoutLibrary upsertRequest);
26+
27+
ReportGenericListResponse getPaginatedReports(JWTData userData, int schoolId, int page);
28+
29+
String getReportAsCsv(JWTData userData, int reportId, boolean hasLibrary);
30+
}

api/src/main/java/com/codeforcommunity/api/authenticated/IProtectedSchoolProcessor.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,5 @@ void updateSchoolContact(
4848

4949
void unHideSchool(JWTData userData, int schoolId);
5050

51-
ReportGeneric getMostRecentReport(JWTData userData, int schoolId);
52-
53-
ReportWithLibrary createReportWithLibrary(
54-
JWTData userData, int schoolId, UpsertReportWithLibrary upsertRequest);
55-
56-
ReportWithoutLibrary createReportWithoutLibrary(
57-
JWTData userData, int schoolId, UpsertReportWithoutLibrary upsertRequest);
58-
59-
void updateReportWithLibrary(
60-
JWTData userData, int schoolId, int reportId, UpsertReportWithLibrary upsertRequest);
61-
62-
void updateReportWithoutLibrary(
63-
JWTData userData, int schoolId, int reportId, UpsertReportWithoutLibrary upsertRequest);
64-
65-
ReportGenericListResponse getPaginatedReports(JWTData userData, int schoolId, int page);
66-
67-
BookLog createBookLog(JWTData userData, int schoolId, UpsertBookLogRequest request);
68-
69-
BookLogListResponse getBookLog(JWTData userData, int schoolId);
70-
71-
String getReportAsCsv(JWTData userData, int reportId, boolean hasLibrary);
72-
73-
BookLog updateBookLog(JWTData userData, int schoolId, int bookId, UpsertBookLogRequest request);
74-
75-
void deleteBookLog(JWTData userData, int schoolId, int bookId);
76-
7751
SchoolListResponse getSchoolsFromUserIdReports(JWTData userData);
7852
}

api/src/main/java/com/codeforcommunity/rest/ApiRouter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.codeforcommunity.rest;
22

3+
import com.codeforcommunity.api.authenticated.IProtectedBookLogProcessor;
34
import com.codeforcommunity.api.authenticated.IProtectedCountryProcessor;
5+
import com.codeforcommunity.api.authenticated.IProtectedReportProcessor;
46
import com.codeforcommunity.api.authenticated.IProtectedDataProcessor;
57
import com.codeforcommunity.api.authenticated.IProtectedSchoolProcessor;
68
import com.codeforcommunity.api.authenticated.IProtectedUserProcessor;
@@ -30,12 +32,14 @@ public ApiRouter(
3032
IProtectedUserProcessor protectedUserProcessor,
3133
IProtectedCountryProcessor protectedCountryProcessor,
3234
IProtectedSchoolProcessor protectedSchoolProcessor,
35+
IProtectedReportProcessor protectedReportProcessor,
36+
IProtectedBookLogProcessor protectedBookLogProcessor) {
3337
IProtectedDataProcessor protectedDataProcessor) {
3438
this.commonRouter = new CommonRouter(jwtAuthorizer);
3539
this.authRouter = new AuthRouter(authProcessor);
3640
this.protectedUserRouter = new ProtectedUserRouter(protectedUserProcessor);
3741
this.protectedCountryRouter = new ProtectedCountryRouter(protectedCountryProcessor);
38-
this.protectedSchoolRouter = new ProtectedSchoolRouter(protectedSchoolProcessor);
42+
this.protectedSchoolRouter = new ProtectedSchoolRouter(protectedSchoolProcessor, protectedReportProcessor, protectedBookLogProcessor);
3943
this.protectedDataRouter = new ProtectedDataRouter(protectedDataProcessor);
4044
}
4145

api/src/main/java/com/codeforcommunity/rest/subrouter/authenticated/ProtectedSchoolRouter.java

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import static com.codeforcommunity.rest.ApiRouter.end;
44

5+
import com.codeforcommunity.api.authenticated.IProtectedBookLogProcessor;
6+
import com.codeforcommunity.api.authenticated.IProtectedReportProcessor;
57
import com.codeforcommunity.api.authenticated.IProtectedSchoolProcessor;
68
import com.codeforcommunity.auth.JWTData;
79
import com.codeforcommunity.dto.report.ReportGeneric;
@@ -29,10 +31,17 @@
2931

3032
public class ProtectedSchoolRouter implements IRouter {
3133

32-
private final IProtectedSchoolProcessor processor;
34+
private final IProtectedSchoolProcessor schoolProcessor;
35+
private final IProtectedReportProcessor reportProcessor;
36+
private final IProtectedBookLogProcessor bookLogProcessor;
3337

34-
public ProtectedSchoolRouter(IProtectedSchoolProcessor processor) {
35-
this.processor = processor;
38+
public ProtectedSchoolRouter(
39+
IProtectedSchoolProcessor schoolProcessor,
40+
IProtectedReportProcessor reportProcessor,
41+
IProtectedBookLogProcessor bookLogProcessor ) {
42+
this.schoolProcessor = schoolProcessor;
43+
this.reportProcessor = reportProcessor;
44+
this.bookLogProcessor = bookLogProcessor;
3645
}
3746

3847
@Override
@@ -47,6 +56,7 @@ public Router initializeRouter(Vertx vertx) {
4756
registerDeleteSchool(router);
4857
registerHidingSchool(router);
4958
registerUnHidingSchool(router);
59+
registerGetSchoolsFromUserId(router);
5060

5161
// Register all school contact routes
5262
registerGetAllSchoolContacts(router);
@@ -64,7 +74,8 @@ public Router initializeRouter(Vertx vertx) {
6474
registerGetPaginatedReports(router);
6575
registerGetWithLibraryReportAsCsv(router);
6676
registerGetWithoutLibraryReportAsCsv(router);
67-
registerGetSchoolsFromUserId(router);
77+
78+
6879

6980
// Register all book tracking routes
7081
registerCreateBookLog(router);
@@ -202,28 +213,28 @@ private void registerGetSchoolsFromUserId(Router router) {
202213

203214
private void handleGetSchoolsFromUserId(RoutingContext ctx) {
204215
JWTData userData = ctx.get("jwt_data");
205-
SchoolListResponse response = processor.getSchoolsFromUserIdReports(userData);
216+
SchoolListResponse response = schoolProcessor.getSchoolsFromUserIdReports(userData);
206217
end(ctx.response(), 200, JsonObject.mapFrom(response).toString());
207218
}
208219

209220
private void handleGetAllSchoolsRoute(RoutingContext ctx) {
210221
JWTData userData = ctx.get("jwt_data");
211-
SchoolListResponse response = processor.getAllSchools(userData);
222+
SchoolListResponse response = schoolProcessor.getAllSchools(userData);
212223
end(ctx.response(), 200, JsonObject.mapFrom(response).toString());
213224
}
214225

215226
private void handleGetSchoolRoute(RoutingContext ctx) {
216227
JWTData userData = ctx.get("jwt_data");
217228
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
218-
School response = processor.getSchool(userData, schoolId);
229+
School response = schoolProcessor.getSchool(userData, schoolId);
219230
end(ctx.response(), 200, JsonObject.mapFrom(response).toString());
220231
}
221232

222233
private void handleCreateSchoolRoute(RoutingContext ctx) {
223234
JWTData userData = ctx.get("jwt_data");
224235
UpsertSchoolRequest upsertSchoolRequest =
225236
RestFunctions.getJsonBodyAsClass(ctx, UpsertSchoolRequest.class);
226-
School response = processor.createSchool(userData, upsertSchoolRequest);
237+
School response = schoolProcessor.createSchool(userData, upsertSchoolRequest);
227238
end(ctx.response(), 201, JsonObject.mapFrom(response).toString());
228239
}
229240

@@ -232,43 +243,43 @@ private void handleUpdateSchoolRoute(RoutingContext ctx) {
232243
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
233244
UpsertSchoolRequest upsertSchoolRequest =
234245
RestFunctions.getJsonBodyAsClass(ctx, UpsertSchoolRequest.class);
235-
processor.updateSchool(userData, schoolId, upsertSchoolRequest);
246+
schoolProcessor.updateSchool(userData, schoolId, upsertSchoolRequest);
236247
end(ctx.response(), 200);
237248
}
238249

239250
private void handleDeleteSchoolRoute(RoutingContext ctx) {
240251
JWTData userData = ctx.get("jwt_data");
241252
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
242-
processor.deleteSchool(userData, schoolId);
253+
schoolProcessor.deleteSchool(userData, schoolId);
243254
end(ctx.response(), 200);
244255
}
245256

246257
private void handleHidingSchoolRoute(RoutingContext ctx) {
247258
JWTData userData = ctx.get("jwt_data");
248259
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
249-
processor.hideSchool(userData, schoolId);
260+
schoolProcessor.hideSchool(userData, schoolId);
250261
end(ctx.response(), 200);
251262
}
252263

253264
private void handleUnHidingSchoolRoute(RoutingContext ctx) {
254265
JWTData userData = ctx.get("jwt_data");
255266
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
256-
processor.unHideSchool(userData, schoolId);
267+
schoolProcessor.unHideSchool(userData, schoolId);
257268
end(ctx.response(), 200);
258269
}
259270

260271
private void handleGetAllSchoolContactsRoute(RoutingContext ctx) {
261272
JWTData userData = ctx.get("jwt_data");
262273
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
263-
SchoolContactListResponse response = processor.getAllSchoolContacts(userData, schoolId);
274+
SchoolContactListResponse response = schoolProcessor.getAllSchoolContacts(userData, schoolId);
264275
end(ctx.response(), 200, JsonObject.mapFrom(response).toString());
265276
}
266277

267278
private void handleGetSchoolContactRoute(RoutingContext ctx) {
268279
JWTData userData = ctx.get("jwt_data");
269280
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
270281
int contactId = RestFunctions.getPathParamAsInt(ctx, "contact_id");
271-
SchoolContact response = processor.getSchoolContact(userData, schoolId, contactId);
282+
SchoolContact response = schoolProcessor.getSchoolContact(userData, schoolId, contactId);
272283
end(ctx.response(), 200, JsonObject.mapFrom(response).toString());
273284
}
274285

@@ -277,7 +288,7 @@ private void handleCreateSchoolContactRoute(RoutingContext ctx) {
277288
UpsertSchoolContactRequest request =
278289
RestFunctions.getJsonBodyAsClass(ctx, UpsertSchoolContactRequest.class);
279290
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
280-
SchoolContact response = processor.createSchoolContact(userData, schoolId, request);
291+
SchoolContact response = schoolProcessor.createSchoolContact(userData, schoolId, request);
281292
end(ctx.response(), 201, JsonObject.mapFrom(response).toString());
282293
}
283294

@@ -287,15 +298,15 @@ private void handleUpdateSchoolContactRoute(RoutingContext ctx) {
287298
RestFunctions.getJsonBodyAsClass(ctx, UpsertSchoolContactRequest.class);
288299
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
289300
int contactId = RestFunctions.getPathParamAsInt(ctx, "contact_id");
290-
processor.updateSchoolContact(userData, schoolId, contactId, request);
301+
schoolProcessor.updateSchoolContact(userData, schoolId, contactId, request);
291302
end(ctx.response(), 200);
292303
}
293304

294305
private void handleDeleteSchoolContactRoute(RoutingContext ctx) {
295306
JWTData userData = ctx.get("jwt_data");
296307
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
297308
int contactId = RestFunctions.getPathParamAsInt(ctx, "contact_id");
298-
processor.deleteSchoolContact(userData, schoolId, contactId);
309+
schoolProcessor.deleteSchoolContact(userData, schoolId, contactId);
299310
end(ctx.response(), 200);
300311
}
301312

@@ -304,7 +315,7 @@ private void handleCreateReportWithLibrary(RoutingContext ctx) {
304315
UpsertReportWithLibrary request =
305316
RestFunctions.getJsonBodyAsClass(ctx, UpsertReportWithLibrary.class);
306317
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
307-
ReportWithLibrary report = processor.createReportWithLibrary(userData, schoolId, request);
318+
ReportWithLibrary report = reportProcessor.createReportWithLibrary(userData, schoolId, request);
308319
end(ctx.response(), 201, JsonObject.mapFrom(report).toString());
309320
}
310321

@@ -314,14 +325,14 @@ private void handleUpdateReportWithLibrary(RoutingContext ctx) {
314325
RestFunctions.getJsonBodyAsClass(ctx, UpsertReportWithLibrary.class);
315326
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
316327
int reportId = RestFunctions.getPathParamAsInt(ctx, "report_id");
317-
processor.updateReportWithLibrary(userData, schoolId, reportId, request);
328+
reportProcessor.updateReportWithLibrary(userData, schoolId, reportId, request);
318329
end(ctx.response(), 200);
319330
}
320331

321332
private void handleGetMostRecentReport(RoutingContext ctx) {
322333
JWTData userData = ctx.get("jwt_data");
323334
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
324-
ReportGeneric report = processor.getMostRecentReport(userData, schoolId);
335+
ReportGeneric report = reportProcessor.getMostRecentReport(userData, schoolId);
325336
end(ctx.response(), 200, JsonObject.mapFrom(report).toString());
326337
}
327338

@@ -330,7 +341,7 @@ private void handleCreateReportWithoutLibrary(RoutingContext ctx) {
330341
UpsertReportWithoutLibrary request =
331342
RestFunctions.getJsonBodyAsClass(ctx, UpsertReportWithoutLibrary.class);
332343
int schoolID = RestFunctions.getPathParamAsInt(ctx, "school_id");
333-
ReportWithoutLibrary report = processor.createReportWithoutLibrary(userData, schoolID, request);
344+
ReportWithoutLibrary report = reportProcessor.createReportWithoutLibrary(userData, schoolID, request);
334345
end(ctx.response(), 201, JsonObject.mapFrom(report).toString());
335346
}
336347

@@ -340,15 +351,15 @@ private void handleUpdateReportWithoutLibrary(RoutingContext ctx) {
340351
RestFunctions.getJsonBodyAsClass(ctx, UpsertReportWithoutLibrary.class);
341352
int schoolID = RestFunctions.getPathParamAsInt(ctx, "school_id");
342353
int reportId = RestFunctions.getPathParamAsInt(ctx, "report_id");
343-
processor.updateReportWithoutLibrary(userData, schoolID, reportId, request);
354+
reportProcessor.updateReportWithoutLibrary(userData, schoolID, reportId, request);
344355
end(ctx.response(), 200);
345356
}
346357

347358
private void handleGetPaginatedReport(RoutingContext ctx) {
348359
JWTData userData = ctx.get("jwt_data");
349360
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
350361
int page = RestFunctions.getRequestParameterAsInt(ctx.request(), "p");
351-
ReportGenericListResponse reports = processor.getPaginatedReports(userData, schoolId, page);
362+
ReportGenericListResponse reports = reportProcessor.getPaginatedReports(userData, schoolId, page);
352363
end(ctx.response(), 200, JsonObject.mapFrom(reports).toString());
353364
}
354365

@@ -357,14 +368,14 @@ private void handleCreateBookLog(RoutingContext ctx) {
357368
UpsertBookLogRequest request =
358369
RestFunctions.getJsonBodyAsClass(ctx, UpsertBookLogRequest.class);
359370
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
360-
BookLog log = processor.createBookLog(userData, schoolId, request);
371+
BookLog log = bookLogProcessor.createBookLog(userData, schoolId, request);
361372
end(ctx.response(), 201, JsonObject.mapFrom(log).toString());
362373
}
363374

364375
private void handleGetBookLog(RoutingContext ctx) {
365376
JWTData userData = ctx.get("jwt_data");
366377
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
367-
BookLogListResponse response = processor.getBookLog(userData, schoolId);
378+
BookLogListResponse response = bookLogProcessor.getBookLog(userData, schoolId);
368379
end(ctx.response(), 200, JsonObject.mapFrom(response).toString());
369380
}
370381

@@ -374,31 +385,31 @@ private void handleUpdateBookLog(RoutingContext ctx) {
374385
RestFunctions.getJsonBodyAsClass(ctx, UpsertBookLogRequest.class);
375386
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
376387
int bookId = RestFunctions.getPathParamAsInt(ctx, "book_id");
377-
BookLog log = processor.updateBookLog(userData, schoolId, bookId, request);
388+
BookLog log = bookLogProcessor.updateBookLog(userData, schoolId, bookId, request);
378389
end(ctx.response(), 200, JsonObject.mapFrom(log).toString());
379390
}
380391

381392
private void handleDeleteBookLog(RoutingContext ctx) {
382393
JWTData userData = ctx.get("jwt_data");
383394
int schoolId = RestFunctions.getPathParamAsInt(ctx, "school_id");
384395
int bookId = RestFunctions.getPathParamAsInt(ctx, "book_id");
385-
processor.deleteBookLog(userData, schoolId, bookId);
396+
bookLogProcessor.deleteBookLog(userData, schoolId, bookId);
386397
end(ctx.response(), 200);
387398
}
388399

389400
private void handleGetWithoutLibraryReportAsCsv(RoutingContext ctx) {
390401
JWTData userData = ctx.get("jwt_data");
391402
int reportId = RestFunctions.getPathParamAsInt(ctx, "report_id");
392403
String response;
393-
response = processor.getReportAsCsv(userData, reportId, false);
404+
response = reportProcessor.getReportAsCsv(userData, reportId, false);
394405
end(ctx.response(), 200, response, "text/csv");
395406
}
396407

397408
private void handleGetWithLibraryReportAsCsv(RoutingContext ctx) {
398409
JWTData userData = ctx.get("jwt_data");
399410
int reportId = RestFunctions.getPathParamAsInt(ctx, "report_id");
400411
String response;
401-
response = processor.getReportAsCsv(userData, reportId, true);
412+
response = reportProcessor.getReportAsCsv(userData, reportId, true);
402413
end(ctx.response(), 200, response, "text/csv");
403414
}
404415
}

0 commit comments

Comments
 (0)