package Ġio . bw vol ley ball . cookbook . controller Ċ Ċ import Ġio . bw vol ley ball . cookbook . domain . Cook book Ċ import Ġio . bw vol ley ball . cookbook . domain . Typed Recipe Ċ import Ġio . bw vol ley ball . cookbook . repository . Cook book Repository Ċ import Ġmu . Kotlin Logging Ċ import Ġorg . springframework . http . Response Entity Ċ import Ġorg . springframework . web . bind . annotation .* Ċ Ċ @ RestController Ċ @ RequestMapping ( path Ġ= Ġ["/ api / cookbook "]) Ċ class ĠCook book Controller ( private Ġval Ġcook book Repository : ĠCook book Repository ) Ġ{ ĊĊĠĠĠ Ġval Ġlogger Ġ= ĠKotlin Logging . logger {} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠEither Ġget Ġthe Ġcook book Ġfor Ġthis Ġuser Ġor Ġelse Ġreturn Ġthem Ġa Ġnew Ġcook book . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ GetMapping ( path Ġ= Ġ[" /{ userId }" ]) ĊĠĠĠ Ġfun ĠgetC ook book (@ PathVariable (" userId ") ĠuserId : ĠString ): ĠCook book Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . info (" Retrie ving Ġthe Ġcook book Ġfor Ġ{}", ĠuserId ) ĊĠĠĠĠĠĠĠ Ġreturn Ġcook book Repository . findById ( userId ). orElse ( Cook book ( userId )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠSave Ġor Ġupdate Ġa Ġuser 's Ġcook book , Ġwhich Ġtypically Ġis Ġjust Ġchanging Ġthe Ġlist Ġof Ġrecipes Ġcontained Ġwithin Ġthe Ġcook book . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ PostMapping ( path Ġ= Ġ[" /{ userId }" ]) ĊĠĠĠ Ġfun Ġsave Cook book (@ PathVariable (" userId ") ĠuserId : ĠString , Ġ@ RequestBody ( required Ġ= Ġtrue ) Ġrecipes : ĠList < Typed Recipe >): ĠCook book Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . info (" Saving Ġthe Ġcook book Ġfor Ġ{} Ġwith Ġrecipes Ġ{}", ĠuserId , Ġrecipes ) ĊĠĠĠĠĠĠĠ Ġreturn Ġcook book Repository . save And Flush ( Cook book ( userId , Ġrecipes . toSet ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Delete Mapping ( path Ġ= Ġ[" /{ userId }" ]) ĊĠĠĠ Ġfun Ġdelete Cook book (@ PathVariable (" userId ") ĠuserId : ĠString ): ĠResponseEntity < Void > Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . info (" Deleting Ġthe Ġcook book Ġfor Ġ{}", ĠuserId ) ĊĠĠĠĠĠĠĠ Ġcook book Repository . delete ById ( userId ) ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity . no Content (). build () ĊĠĠĠ Ġ} Ċ }