package Ġcom . int workers . application . controller . school system Ċ Ċ import Ġcom . int workers . application . model . school system . School Ċ import Ġcom . int workers . application . service . school system . School Admin Service Ċ import Ġcom . int workers . application . service . school system . School Service Ċ import Ġcom . int workers . application . service . user . UserService Ċ import Ġio . swagger . annotations . Api Implicit Param Ċ import Ġio . swagger . annotations . Api Implicit Params Ċ import Ġio . swagger . annotations . ApiOperation Ċ import Ġio . swagger . annotations . Api Param Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . data . domain . Page able Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . http . Response Entity Ċ import Ġorg . springframework . security . access . pre post . Pre Authorize Ċ import Ġorg . springframework . security . core . Authentication Ċ import Ġorg . springframework . security . core . user details . UserDetails Ċ import Ġorg . springframework . web . bind . annotation .* Ċ import Ġjavax . validation . Valid Ċ Ċ @ RestController Ċ @ RequestMapping ("/ sch ools ") Ċ class ĠSchool Controller Ġ{ ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġschool Service : ĠSchool Service ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠuserService : ĠUserService ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġschool Admin Service : ĠSchool Admin Service ĊĊĠĠĠ Ġ@ ApiOperation ( value Ġ= Ġ" Find Ġa ĠSchool Ġby ĠId ", Ġresponse Ġ= ĠSchool :: class ) ĊĠĠĠ Ġ@ Pre Authorize (" has Any Authority (' ROLE _ SO CIAL WORK ER ', Ġ' ROLE _ ADMIN ') ") ĊĠĠĠ Ġ@ GetMapping ( value Ġ= Ġ["/ school /{ id } "], Ġproduces Ġ= Ġ[" application / json "]) ĊĠĠĠ Ġfun Ġfind ById (@ Api Param ( value Ġ= Ġ" Id Ġof Ġthe ĠSchool Ġto Ġbe Ġfound ", Ġrequired Ġ= Ġtrue , Ġexample Ġ= Ġ" 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ@ PathVariable Ġid : ĠLong ): ĠResponseEntity < *> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( school Service . findById ( id ), ĠHttpStatus . OK ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ApiOperation ( value Ġ= Ġ" Find Ġall ĠSch ools ", Ġresponse Ġ= ĠSchool :: class , Ġresponse Container Ġ= Ġ" List ") ĊĠĠĠ Ġ@ Api Implicit Params ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠApi Implicit Param ( name Ġ= Ġ" page ", ĠdataType Ġ= Ġ" integer ", Ġparam Type Ġ= Ġ" query ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġvalue Ġ= Ġ" Results Ġpage Ġyou Ġwant Ġto Ġretrieve Ġ( 0 .. N )"), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠApi Implicit Param ( name Ġ= Ġ" size ", ĠdataType Ġ= Ġ" integer ", Ġparam Type Ġ= Ġ" query ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġvalue Ġ= Ġ" Number Ġof Ġrecords Ġper Ġpage ."), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠApi Implicit Param ( name Ġ= Ġ" sort ", Ġallow Multiple Ġ= Ġtrue , ĠdataType Ġ= Ġ" string ", Ġparam Type Ġ= Ġ" query ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġvalue Ġ= Ġ" Sorting Ġcriteria Ġin Ġthe Ġformat : Ġproperty ( , asc | desc ). Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Default Ġsort Ġorder Ġis Ġascending . Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Multiple Ġsort Ġcriteria Ġare Ġsupported .")) ĊĠĠĠ Ġ@ Pre Authorize (" has Any Authority (' ROLE _ SO CIAL WORK ER ', Ġ' ROLE _ ADMIN ') ") ĊĠĠĠ Ġ@ GetMapping ( value Ġ= Ġ["/ all "], Ġproduces Ġ= Ġ[" application / json "]) ĊĠĠĠ Ġfun ĠfindAll ( page able : ĠPage able ): ĠResponseEntity < *> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( school Service . findAll ( page able ), ĠHttpStatus . OK ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ApiOperation ( value Ġ= Ġ" Find Ġcurrent ĠSchool ĠAdmin 's Ġschool ", Ġresponse Ġ= ĠSchool :: class ) ĊĠĠĠ Ġ@ Pre Authorize (" has Authority (' ROLE _ S CHO OL ADMIN ') ") ĊĠĠĠ Ġ@ GetMapping ( value Ġ= Ġ["/ mys ch ool "], Ġproduces Ġ= Ġ[" application / json "]) ĊĠĠĠ Ġfun Ġget My School ( authentication : ĠAuthentication ): ĠResponseEntity < Any > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġusername Ġ= Ġ( authentication . principal Ġas ĠUser Details ). username ĊĠĠĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . findBy Username ( username ) ĊĠĠĠĠĠĠĠ Ġval Ġschool Admin Ġ= Ġschool Admin Service . findById ( user . userId ) ĊĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( school Admin . school Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠResponseEntity ( school Service . findById ( school Admin . school !!. school Id ), ĠHttpStatus . CREATED ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠResponseEntity ( HttpStatus . CONF LI CT ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ApiOperation ( value Ġ= Ġ" Create Ġa Ġnew ĠSchool Ġunder Ġcurrent ĠSchool ĠAdmin ", Ġresponse Ġ= ĠSchool :: class ) ĊĠĠĠ Ġ@ Pre Authorize (" has Authority (' ROLE _ S CHO OL ADMIN ') ") ĊĠĠĠ Ġ@ PostMapping ( value Ġ= Ġ["/ mys ch ool "], Ġconsume s Ġ= Ġ[" application / json "], Ġproduces Ġ= Ġ[" application / json "]) ĊĠĠĠ Ġfun Ġcreate (@ Api Param ( value Ġ= Ġ" New ĠSchool Ġto Ġbe Ġcreated ", Ġrequired Ġ= Ġtrue ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ@ Valid Ġ@ RequestBody Ġschool : ĠSchool , Ġauthentication : ĠAuthentication ): ĠResponseEntity < Any > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġusername Ġ= Ġ( authentication . principal Ġas ĠUser Details ). username ĊĠĠĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . findBy Username ( username ) ĊĠĠĠĠĠĠĠ Ġval Ġschool Admin Ġ= Ġschool Admin Service . findById ( user . userId ) ĊĠĠĠĠĠĠĠ Ġschool . school Admin Ġ= Ġschool Admin ĊĠĠĠĠĠĠĠ Ġval Ġsaved School Ġ= Ġschool Service . save ( school ) ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( school Service . findById ( saved School . school Id ), ĠHttpStatus . CREATED ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ApiOperation ( value Ġ= Ġ" Update Ġcurrent ĠSchool ĠAdmin 's ĠSchool ", Ġresponse Ġ= ĠSchool :: class ) ĊĠĠĠ Ġ@ Pre Authorize (" has Authority (' ROLE _ S CHO OL ADMIN ') ") ĊĠĠĠ Ġ@ Put Mapping ( value Ġ= Ġ["/ mys ch ool "], Ġconsume s Ġ= Ġ[" application / json "], Ġproduces Ġ= Ġ[" application / json "]) ĊĠĠĠ Ġfun Ġupdate (@ Api Param ( value Ġ= Ġ" School Ġwith Ġinfo Ġto Ġbe Ġupdated ", Ġrequired Ġ= Ġtrue ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ@ Valid Ġ@ RequestBody Ġschool : ĠSchool , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġauthentication : ĠAuthentication ): ĠResponseEntity < Any > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġusername Ġ= Ġ( authentication . principal Ġas ĠUser Details ). username ĊĠĠĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . findBy Username ( username ) ĊĠĠĠĠĠĠĠ Ġval Ġschool Admin Ġ= Ġschool Admin Service . findById ( user . userId ) ĊĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( school Admin . school Ġ!= Ġnull ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠResponseEntity ( school Service . update ( school , Ġschool Admin . school !!. school Id ), ĠHttpStatus . OK ) ĊĠĠĠĠĠĠĠ Ġelse ĠResponseEntity ( HttpStatus . CONF LI CT ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ApiOperation ( value Ġ= Ġ" Delete Ġcurrent ĠSchool ĠAdmin 's ĠSchool . ĠWill Ġalso Ġdelete Ġall Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Classes Ġand ĠGr ades Ġwithin ĠSchool ", Ġresponse Ġ= ĠVoid :: class ) ĊĠĠĠ Ġ@ Pre Authorize (" has Authority (' ROLE _ S CHO OL ADMIN ') ") ĊĠĠĠ Ġ@ Delete Mapping ( value Ġ= Ġ["/ mys ch ool "]) ĊĠĠĠ Ġfun Ġdelete ( authentication : ĠAuthentication ): ĠResponseEntity < Any > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġusername Ġ= Ġ( authentication . principal Ġas ĠUser Details ). username ĊĠĠĠĠĠĠĠ Ġval Ġuser Ġ= ĠuserService . findBy Username ( username ) ĊĠĠĠĠĠĠĠ Ġval Ġschool Admin Ġ= Ġschool Admin Service . findById ( user . userId ) ĊĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( school Admin . school Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġschool Service . delete ( school Admin . school !!. school Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠResponseEntity ( HttpStatus . OK ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse ĠResponseEntity ( HttpStatus . CONF LI CT ) ĊĠĠĠ Ġ} Ċ }