package Ġme . or ih are l . series manager . api . broadcast Ċ Ċ import Ġme . or ih are l . series manager . api . response . Generic Broadcast Status Ċ import Ġme . or ih are l . series manager . api . response . Watch Status Ċ import Ġme . or ih are l . series manager . api . response . Watch Status Bulk Ċ import Ġme . or ih are l . series manager . dao . broadcast . Search Type Ċ import Ġme . or ih are l . series manager . model . content . Broadcast Ċ import Ġme . or ih are l . series manager . model . content . Episode Ċ import Ġme . or ih are l . series manager . model . content . Season Ċ import Ġme . or ih are l . series manager . model . content . User Serialized Broadcast Ċ import Ġme . or ih are l . series manager . security . CurrentUser Ċ import Ġme . or ih are l . series manager . service . Broadcast Service Ċ import Ġme . or ih are l . series manager . service . UserService Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . web . bind . annotation . PathVariable Ċ import Ġorg . springframework . web . bind . annotation . RequestBody Ċ import Ġorg . springframework . web . server . ResponseStatus Exception Ċ import Ġjava . util .* Ċ import Ġjavax . validation . Valid Ċ import Ġjavax . validation . constraints . NotNull ĊĊ Ċ abstract Ġclass ĠBroadcast Controller Ġconstructor ( ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠuserService : ĠUserService , ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġbroadcast Service : ĠBroadcast Service , ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġsearch Type : ĠSearch Type , Ċ ) Ġ{ ĊĠĠĠ Ġopen Ġfun Ġsearch Broadcast s ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpage : ĠInt , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġquery : ĠString , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġad ult : ĠBoolean , ĊĠĠĠ Ġ): ĠList < Broadcast > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġbroadcast Service . find Broadcast s ( search Type , Ġquery , Ġpage , Ġad ult ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġget Detailed Season ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbroadcast Id : ĠInt , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġseason : ĠInt , ĊĠĠĠ Ġ): ĠSe ason Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġbroadcast Service . get Detailed Season ( User Serialized Broadcast ( broadcast Id , ĠSearch Type . Tv ), Ġseason ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġget Detailed Episode ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbroadcast Id : ĠInt , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġseason : ĠInt , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode : ĠInt , ĊĠĠĠ Ġ): ĠEp isode Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġbroadcast Service . get Detailed Episode ( User Serialized Broadcast ( broadcast Id , ĠSearch Type . Tv ), Ġseason , Ġepisode ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun ĠgetStatus ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbroadcast Id : ĠInt , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġseason : ĠInt ?, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode : ĠInt ?, ĊĠĠĠ Ġ): ĠGeneric Broadcast Status Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠgetStatus ( broadcast Id , Ġseason , Ġepisode , Ġsearch Type ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprotected Ġfun ĠgetStatus ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbroadcast Id : ĠInt , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġseason : ĠInt ?, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġepisode : ĠInt ?, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsearch Type : ĠSearch Type , ĊĠĠĠ Ġ): ĠGeneric Broadcast Status Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsb Ġ= ĠuserService . get Serialized Broadcast ( CurrentUser . current UserId Must Be LoggedIn , ĠUser Serialized Broadcast ( broadcast Id , Ġsearch Type )) ĊĠĠĠĠĠĠĠ Ġval Ġbc Ġ= Ġbroadcast Service . get Detailed Broadcast ( sb ). get () ĊĠĠĠĠĠĠĠ Ġval Ġstatus Ġ= ĠGeneric Broadcast Status () ĊĠĠĠĠĠĠĠ Ġval Ġis Episode Ġ= Ġseason Ġ!= Ġnull Ġ&& Ġepisode Ġ!= Ġnull ĊĠĠĠĠĠĠĠ Ġval Ġis Season Ġ= Ġseason Ġ!= Ġnull Ġ&& Ġepisode Ġ== Ġnull ĊĠĠĠĠĠĠĠ Ġval Ġis Broadcast Ġ= Ġseason Ġ== Ġnull Ġ|| Ġepisode Ġ== Ġnull ĊĊĠĠĠĠĠĠĠ Ġstatus . name Ġ= Ġbc . name ĊĊĠĠĠĠĠĠĠ Ġreturn Ġwhen Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsb . is Movie Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . broadcast W atched Ġ= Ġbroadcast Service . movie Is W atched ( sb ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis Episode Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġseason Details Ġ= Ġbroadcast Service . get Detailed Season ( sb , Ġseason !! ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . broadcast W atched Ġ= Ġbroadcast Service . episode Is W atched ( sb , Ġseason . to Short (), Ġepisode !!. to Short ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . remaining Season Episode s Ġ= Ġbroadcast Service . season Episode s Remaining ( sb , Ġseason . to Short ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . remaining Show Episode s Ġ= Ġbroadcast Service . show Episode s Remaining ( sb ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . episode Name Ġ= Ġseason Details . episodes ?. get ( episode Ġ- Ġ 1 )?. name Ġ?: Ġ"" ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . season Name Ġ= Ġseason Details . name ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis Season Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġseason Details Ġ= Ġbroadcast Service . get Detailed Season ( sb , Ġseason !! ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . remaining Season Episode s Ġ= Ġbroadcast Service . season Episode s Remaining ( sb , Ġseason . to Short ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . broadcast W atched Ġ= Ġstatus . remaining Season Episode s Ġ== Ġ 0 ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . remaining Show Episode s Ġ= Ġbroadcast Service . show Episode s Remaining ( sb ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . season Name Ġ= Ġseason Details . name ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis Broadcast Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . remaining Show Episode s Ġ= Ġbroadcast Service . show Episode s Remaining ( sb ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus . broadcast W atched Ġ= Ġstatus . remaining Show Episode s Ġ== Ġ 0 ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstatus ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġstatus ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġset W atched Status ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ PathVariable (" broadcast Id ") Ġbroadcast Id : ĠInt , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ NotNull Ġ@ Valid Ġ@ RequestBody Ġwatch Status : ĠWatch Status , ĊĠĠĠ Ġ): ĠMap < String , ĠBoolean > Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠuserId Ġ= ĠCurrent User . current UserId Must Be LoggedIn ĊĠĠĠĠĠĠĠ Ġval Ġsb Ġ= ĠuserService . get Serialized Broadcast ( userId , ĠUser Serialized Broadcast ( broadcast Id , Ġsearch Type )) ĊĊĠĠĠĠĠĠĠ Ġif Ġ( watch Status . w atched ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserService . mark Broadcast W atched ( userId , Ġsb , Ġwatch Status . season , Ġwatch Status . episode ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserService . mark Broadcast Un w atched ( userId , Ġsb , Ġwatch Status . season , Ġwatch Status . episode ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġmutable Map Of ( Pair (" success ", Ġtrue )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġset W atched Status ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ PathVariable (" broadcast Id ") Ġbroadcast Id : ĠInt , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ NotNull Ġ@ Valid Ġ@ RequestBody Ġwatch Status : ĠWatch Status Bulk , ĊĠĠĠ Ġ): ĠMap < String , ĠBoolean > Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠuserId Ġ= ĠCurrent User . current UserId Must Be LoggedIn ĊĠĠĠĠĠĠĠ Ġval Ġsb Ġ= ĠuserService . get Serialized Broadcast ( userId , ĠUser Serialized Broadcast ( broadcast Id , Ġsearch Type )) ĊĊĠĠĠĠĠĠĠ Ġif Ġ( watch Status . w atched ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserService . mark Broadcast W atched ( userId , Ġsb , Ġwatch Status . season , Ġ* watch Status . episodes ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠuserService . mark Broadcast Un w atched ( userId , Ġsb , Ġwatch Status . season , Ġ* watch Status . episodes ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġmutable Map Of ( Pair (" success ", Ġtrue )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġget Broadcast s (): ĠList < User Serialized Broadcast > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠuserService . get Broadcast s ( CurrentUser . current UserId Must Be LoggedIn ). get () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . search Type Ġ== Ġsearch Type Ġ|| Ġsearch Type Ġ== ĠSearch Type . Multi Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġget Detailed Broadcast s (): ĠList < Broadcast > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġoptional Ġ= ĠuserService . get Broadcast s ( CurrentUser . current UserId Must Be LoggedIn ) ĊĠĠĠĠĠĠĠ Ġif Ġ( optional . isEmpty ) Ġthrow ĠResponse Status Exception ( HttpStatus . NOT _ FOUND , Ġ" Broadcast s Ġnot Ġfound !") ĊĠĠĠĠĠĠĠ Ġreturn Ġbroadcast Service . get Detailed Broadcast s ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ* optional . get () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . search Type Ġ== Ġsearch Type Ġ|| Ġsearch Type Ġ== ĠSearch Type . Multi Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Typed Array () ĊĠĠĠĠĠĠĠ Ġ). map NotNull Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( it . isPresent ) Ġit . get () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġnull ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġget Broadcast ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbroadcast Id : ĠInt , ĊĠĠĠ Ġ): ĠUser Serialized Broadcast Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠuserService . get Serialized Broadcast ( CurrentUser . current UserId Must Be LoggedIn , ĠUser Serialized Broadcast ( broadcast Id , Ġsearch Type )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġget Detailed Broadcast ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbroadcast Id : ĠInt , ĊĠĠĠ Ġ): ĠBroadcast Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsb Ġ= ĠuserService . get Serialized Broadcast ( CurrentUser . current UserId Must Be LoggedIn , ĠUser Serialized Broadcast ( broadcast Id , Ġsearch Type )) ĊĠĠĠĠĠĠĠ Ġval Ġoptional BC : ĠOptional < Broadcast > Ġ= Ġbroadcast Service . get Detailed Broadcast ( sb ) ĊĠĠĠĠĠĠĠ Ġif Ġ( optional BC . isEmpty ) Ġthrow ĠResponse Status Exception ( HttpStatus . NOT _ FOUND , Ġ" Wrong ĠTM DB ĠID !") ĊĠĠĠĠĠĠĠ Ġreturn Ġoptional BC . get () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġadd Broadcast ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ NotNull Ġ@ Valid Ġ@ RequestBody Ġserialized Broadcast : ĠUser Serialized Broadcast , ĊĠĠĠ Ġ): ĠUser Serialized Broadcast Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġoptional Ġ= ĠuserService . add Broadcast ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCurrent User . current UserId Must Be LoggedIn , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠUser Serialized Broadcast ( serialized Broadcast . id !! , Ġserialized Broadcast . search Type ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġif Ġ( optional . isEmpty ) Ġthrow ĠResponse Status Exception ( HttpStatus . NOT _ FOUND , Ġ" User Ġdoes Ġnot Ġhave Ġthis Ġbroadcast !") ĊĠĠĠĠĠĠĠ Ġreturn Ġoptional . get () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġupdate Broadcast ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ NotNull Ġ@ Valid Ġ@ RequestBody Ġserialized Broadcast : ĠUser Serialized Broadcast , ĊĠĠĠ Ġ): ĠUser Serialized Broadcast Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġoptional Ġ= ĠuserService . update Broadcast ( CurrentUser . current UserId Must Be LoggedIn , Ġserialized Broadcast ) ĊĠĠĠĠĠĠĠ Ġif Ġ( optional . isEmpty ) Ġthrow ĠResponse Status Exception ( HttpStatus . NOT _ FOUND , Ġ" User Ġdoes Ġnot Ġhave Ġthis Ġbroadcast !") ĊĠĠĠĠĠĠĠ Ġreturn Ġoptional . get () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġdelete Broadcast ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ PathVariable (" broadcast Id ") Ġbroadcast Id : ĠInt , ĊĠĠĠ Ġ): ĠUser Serialized Broadcast Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġoptional Ġ= ĠuserService . delete Broadcast ( CurrentUser . current UserId Must Be LoggedIn , ĠUser Serialized Broadcast ( broadcast Id , Ġsearch Type )) ĊĠĠĠĠĠĠĠ Ġif Ġ( optional . isEmpty ) Ġthrow ĠResponse Status Exception ( HttpStatus . NOT _ FOUND , Ġ" User Ġdoes Ġnot Ġhave Ġthis Ġbroadcast !") ĊĠĠĠĠĠĠĠ Ġreturn Ġoptional . get () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġget Broadcast s Watch Status (): ĠMap < String , ĠMutable Map < Int , ĠMutable List < Map < String , ĠBoolean >>>> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġbroadcast Service ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. get Broadcast s Watch Status (* userService . get Broadcast s ( CurrentUser . current UserId Must Be LoggedIn ). get () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . search Type Ġ== Ġsearch Type Ġ|| Ġsearch Type Ġ== ĠSearch Type . Multi Ġ}. to Typed Array () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ }