/* Ċ Ġ* Ġ( C ) ĠCopyright Ġ 2 0 1 8 ĠL uk as ĠMor aw iet z Ġ( https :// github . com / F 4 3 nd 1 r ) Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġcom . fa endir . ac ra . rest Ċ Ċ import Ġcom . fa endir . ac ra . model . App Ċ import Ġcom . fa endir . ac ra . model . Bug Ċ import Ġcom . fa endir . ac ra . model . Report Ċ import Ġcom . fa endir . ac ra . model . Stack trace Ċ import Ġcom . fa endir . ac ra . model . Version Ċ import Ġcom . fa endir . ac ra . service . DataService Ċ import Ġorg . springframework . format . annotation . DateTime Format Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . http . Response Entity Ċ import Ġorg . springframework . security . access . pre post . Pre Authorize Ċ import Ġorg . springframework . web . bind . annotation . PathVariable Ċ import Ġorg . springframework . web . bind . annotation . RequestBody Ċ import Ġorg . springframework . web . bind . annotation . RequestMapping Ċ import Ġorg . springframework . web . bind . annotation . Request Method Ċ import Ġorg . springframework . web . bind . annotation . RequestParam Ċ import Ġorg . springframework . web . bind . annotation . RestController Ċ import Ġjava . time . Z onedDateTime Ċ Ċ /** Ċ Ġ* Ġ@ author Ġl uk as Ċ Ġ* Ġ@ since Ġ 2 3 . 0 8 . 1 8 Ċ Ġ*/ Ċ @ RestController Ċ @ RequestMapping ( RestApi Interface . API _ PATH ) Ċ @ Pre Authorize (" has Role ( T ( com . fa endir . ac ra . model . User \$ Role ). API )") Ċ class ĠRest Api Interface ( private Ġval Ġdata Service : ĠData Service ) Ġ{ ĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ[" apps "], Ġproduces Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ], Ġmethod Ġ= Ġ[ Request Method . GET ]) ĊĠĠĠ Ġfun Ġlist Apps (): ĠList < Int > Ġ= Ġdata Service . getApp Ids () ĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ[" apps /{ id } "], Ġproduces Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ], Ġmethod Ġ= Ġ[ Request Method . GET ]) ĊĠĠĠ Ġfun Ġget App (@ PathVariable Ġid : ĠInt ): ĠApp ? Ġ= Ġdata Service . find App ( id ) ĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ[" apps /{ id }/ bugs "], Ġproduces Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ], Ġmethod Ġ= Ġ[ Request Method . GET ]) ĊĠĠĠ Ġfun Ġlist Bugs (@ PathVariable Ġid : ĠInt ): ĠList < Int > Ġ= Ġdata Service . find App ( id )?. let Ġ{ Ġdata Service . get Bug Ids ( it ) Ġ} Ġ?: Ġempty List () ĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ[" bugs /{ id } "], Ġproduces Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ], Ġmethod Ġ= Ġ[ Request Method . GET ]) ĊĠĠĠ Ġfun Ġget Bug (@ PathVariable Ġid : ĠInt ): ĠBug ? Ġ= Ġdata Service . find Bug ( id ) ĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ[" bugs /{ id }/ stack traces "], Ġproduces Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ], Ġmethod Ġ= Ġ[ Request Method . GET ]) ĊĠĠĠ Ġfun Ġlist Stack traces (@ PathVariable Ġid : ĠInt ): ĠList < Int > Ġ= Ġdata Service . find Bug ( id )?. let Ġ{ Ġdata Service . get Stack trace Ids ( it ) Ġ} Ġ?: Ġempty List () ĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ[" stack traces /{ id } "], Ġproduces Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ], Ġmethod Ġ= Ġ[ Request Method . GET ]) ĊĠĠĠ Ġfun Ġget Stack trace (@ PathVariable Ġid : ĠInt ): ĠStack trace ? Ġ= Ġdata Service . find Stack trace ( id ) ĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ[" stack traces /{ id }/ reports "], Ġproduces Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ], Ġmethod Ġ= Ġ[ Request Method . GET ]) ĊĠĠĠ Ġfun Ġlist Reports (@ PathVariable Ġid : ĠInt ): ĠList < String > Ġ= Ġdata Service . find Stack trace ( id )?. let Ġ{ Ġdata Service . get Report Ids ( it ) Ġ} Ġ?: Ġempty List () ĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ[" apps /{ id }/ reports "], Ġproduces Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ], Ġmethod Ġ= Ġ[ Request Method . GET ]) ĊĠĠĠ Ġfun Ġlist Reports Of App ( ĊĠĠĠĠĠĠĠ Ġ@ PathVariable Ġid : ĠInt , Ġ@ RequestParam ( required Ġ= Ġfalse ) Ġ@ DateTime Format ( iso Ġ= ĠDateTime Format . ISO . DATE _ TIME ) Ġbefore : ĠZ onedDateTime ?, ĊĠĠĠĠĠĠĠ Ġ@ RequestParam ( required Ġ= Ġfalse ) Ġ@ DateTime Format ( iso Ġ= ĠDateTime Format . ISO . DATE _ TIME ) Ġafter : ĠZ onedDateTime ? ĊĠĠĠ Ġ): ĠList < String > Ġ= ĊĠĠĠĠĠĠĠ Ġdata Service . find App ( id )?. let Ġ{ Ġdata Service . get Report Ids ( it , Ġbefore , Ġafter ) Ġ} Ġ?: Ġempty List () ĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ[" reports /{ id } "], Ġproduces Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ], Ġmethod Ġ= Ġ[ Request Method . GET ]) ĊĠĠĠ Ġfun Ġget Report (@ PathVariable Ġid : ĠString ): ĠReport ? Ġ= Ġdata Service . find Report ( id ) ĊĊĠĠĠ Ġ@ RequestMapping ( value Ġ= Ġ[" apps /{ id }/ version / upload /{ code } "], Ġconsume s Ġ= Ġ[ MediaType . TEXT _ PLAIN _ VALUE ], Ġmethod Ġ= Ġ[ Request Method . POST ]) ĊĠĠĠ Ġfun Ġupload Pro guard Mapping ( ĊĠĠĠĠĠĠĠ Ġ@ PathVariable Ġid : ĠInt , ĊĠĠĠĠĠĠĠ Ġ@ PathVariable Ġcode : ĠInt , ĊĠĠĠĠĠĠĠ Ġ@ RequestParam ( required Ġ= Ġfalse ) Ġname : ĠString ?, ĊĠĠĠĠĠĠĠ Ġ@ RequestBody Ġcontent : ĠString ĊĠĠĠ Ġ): ĠResponseEntity < *> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġapp Ġ= Ġdata Service . find App ( id ) Ġ?: Ġreturn ĠResponseEntity . not Found (). build < Any >() ĊĠĠĠĠĠĠĠ Ġdata Service . store Version ( data Service . find Version ( app , Ġcode )?. also Ġ{ Ġversion Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġname ?. let Ġ{ Ġit Ġ-> Ġversion . name Ġ= Ġit Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġversion . mappings Ġ= Ġcontent ĊĠĠĠĠĠĠĠ Ġ} Ġ?: ĠVersion ( app , Ġcode , Ġname Ġ?: Ġ" N / A ", Ġcontent )) ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity . ok (). build < Any >() ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠAPI _ PATH Ġ= Ġ" api " ĊĠĠĠ Ġ} Ċ Ċ }