package Ġio . j rb . labs . songs . rest Ċ Ċ import Ġcom . github . f ge . json patch . Json Patch Ċ import Ġio . j rb . labs . songs . resource . Song Ċ import Ġio . j rb . labs . songs . service . Song Service Ċ import Ġmu . Kotlin Logging Ċ import Ġorg . springframework . h ate o as . Entity Model Ċ import Ġorg . springframework . h ate o as . Link Ċ import Ġorg . springframework . h ate o as . server . mvc . Web Mvc Link Builder . link To Ċ import Ġorg . springframework . h ate o as . server . mvc . Web Mvc Link Builder . method On Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . web . bind . annotation . Delete Mapping Ċ import Ġorg . springframework . web . bind . annotation . GetMapping Ċ import Ġorg . springframework . web . bind . annotation . Patch Mapping Ċ import Ġorg . springframework . web . bind . annotation . PathVariable Ċ import Ġorg . springframework . web . bind . annotation . PostMapping Ċ import Ġorg . springframework . web . bind . annotation . RequestBody Ċ import Ġorg . springframework . web . bind . annotation . RequestMapping Ċ import Ġorg . springframework . web . bind . annotation . ResponseStatus Ċ import Ġorg . springframework . web . bind . annotation . RestController Ċ import Ġreactor . core . publisher . Flux Ċ import Ġreactor . core . publisher . Mono Ċ import Ġjava . util . UUID Ċ Ċ @ RestController Ċ @ RequestMapping ("/ api / v 1 / songs ") Ċ class ĠSong Controller ( val Ġsong Service : ĠSong Service ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġlog Ġ= ĠKotlin Logging . logger Ġ{} ĊĊĠĠĠ Ġ@ PostMapping ĊĠĠĠ Ġ@ ResponseStatus ( HttpStatus . CREATED ) ĊĠĠĠ Ġfun Ġcreate Song (@ RequestBody Ġsong : ĠSong ): ĠMono < Entity Model < Song >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġsong Service . create Song ( song ). map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEntity Model . of ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add ( self Link ( it . guid !! )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add ( collection Link ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Delete Mapping ("/ { song Guid }") ĊĠĠĠ Ġ@ ResponseStatus ( HttpStatus . NO _ CONTENT ) ĊĠĠĠ Ġfun Ġdelete Song (@ PathVariable Ġsong Guid : ĠUUID ): ĠMono < Void > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġsong Service . delete Song ( song Guid ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ GetMapping ("/ { song Guid }") ĊĠĠĠ Ġfun Ġget Song ById (@ PathVariable Ġsong Guid : ĠUUID ): ĠMono < Entity Model < Song >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġsong Service . find Song By Guid ( song Guid ). map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEntity Model . of ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add ( self Link ( song Guid )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add ( collection Link ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ GetMapping ĊĠĠĠ Ġfun Ġlist S ongs (): ĠFlux < Entity Model < Song >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġsong Service . list All S ongs (). map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEntity Model . of ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add ( self Link ( it . guid !! )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Patch Mapping ( path Ġ= Ġ[" /{ song Guid } "], Ġconsume s Ġ= Ġ[" application / json - patch + json "]) ĊĠĠĠ Ġfun Ġupdate Song (@ PathVariable Ġsong Guid : ĠUUID , Ġ@ RequestBody Ġtask Patch : ĠJson Patch ): ĠMono < Entity Model < Song >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġsong Service . update Song ( song Guid , Ġtask Patch ). map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEntity Model . of ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add ( self Link ( it . guid !! )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add ( collection Link ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcollection Link (): ĠLink Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġlink To ( method On ( java Class ). list S ongs ()). with Rel (" collection ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġself Link ( song Guid : ĠUUID ): ĠLink Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġlink To ( method On ( java Class ). getS ong ById ( song Guid )). with Self Rel () ĊĠĠĠ Ġ} Ċ Ċ } Ċ