22
33import static com .codeforcommunity .rest .ApiRouter .end ;
44
5+ import com .codeforcommunity .api .authenticated .IProtectedBookLogProcessor ;
6+ import com .codeforcommunity .api .authenticated .IProtectedReportProcessor ;
57import com .codeforcommunity .api .authenticated .IProtectedSchoolProcessor ;
68import com .codeforcommunity .auth .JWTData ;
79import com .codeforcommunity .dto .report .ReportGeneric ;
2931
3032public 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