package Ġb rc . study buddy . backend . groups . controller Ċ Ċ import Ġb rc . study buddy . backend . groups . repository . Members Repository Ċ import Ġb rc . study buddy . input . Group Member Input Ċ import Ġb rc . study buddy . model . Group Member Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . web . bind . annotation .* Ċ import Ġreactor . core . publisher . Flux Ċ import Ġreactor . core . publisher . Mono Ċ Ċ @ RestController Ċ @ RequestMapping ( value Ġ= Ġ[" members "], Ġproduces Ġ= Ġ[ MediaType . APPLICATION _ JSON _ VALUE ]) Ċ class ĠMembers Controller Ġ{ ĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmembers Repository : ĠMembers Repository ĊĊĊĠĠĠ Ġ@ PostMapping ĊĠĠĠ Ġfun Ġsave (@ RequestBody Ġinput : ĠGroup Member Input ): ĠMono < Group Member > Ġ= ĊĠĠĠĠĠĠĠ ĠMono . just ( input ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map ( Group Member Input :: to Model ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. flatMap ( members Repository :: save ) ĊĊĊĠĠĠ Ġ@ GetMapping ("/ group /{ id }") ĊĠĠĠ Ġfun ĠfindAll By GroupId (@ PathVariable Ġid : ĠLong ): ĠFlux < Group Member > Ġ= ĊĠĠĠĠĠĠĠ Ġmembers Repository . findAll By GroupId ( id ) ĊĊĠĠĠ Ġ@ GetMapping ("/ user /{ id }") ĊĠĠĠ Ġfun ĠfindAll By UserId (@ PathVariable Ġid : ĠLong ): ĠFlux < Group Member > Ġ= ĊĠĠĠĠĠĠĠ Ġmembers Repository . findAll By UserId ( id ) ĊĊĠĠĠ Ġ@ GetMapping ( path Ġ= Ġ["/ group /{ groupId }/ user /{ userId }", Ġ"/ user /{ userId }/ group /{ groupId }" ]) ĊĠĠĠ Ġfun ĠfindBy GroupId And UserId (@ PathVariable ĠgroupId : ĠLong , Ġ@ PathVariable ĠuserId : ĠLong ): ĠMono < Group Member > Ġ= ĊĠĠĠĠĠĠĠ Ġmembers Repository . findBy GroupId And UserId ( groupId , ĠuserId ) ĊĊĊĠĠĠ Ġ@ Delete Mapping ("/ group /{ id }") ĊĠĠĠ Ġfun Ġdelete All By GroupId (@ PathVariable Ġid : ĠLong ): ĠFlux < Group Member > Ġ= ĊĠĠĠĠĠĠĠ Ġmembers Repository . findAll By GroupId ( id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. flatMap Ġ{ Ġm Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmembers Repository . delete By GroupId And UserId ( m . groupId , Ġm . userId ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( m ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Delete Mapping ("/ user /{ id }") ĊĠĠĠ Ġfun Ġdelete All By UserId (@ PathVariable Ġid : ĠLong ): ĠFlux < Group Member > Ġ= ĊĠĠĠĠĠĠĠ Ġmembers Repository . findAll By UserId ( id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. flatMap Ġ{ Ġm Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmembers Repository . delete By GroupId And UserId ( m . groupId , Ġm . userId ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( m ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Delete Mapping ( path Ġ= Ġ["/ group /{ groupId }/ user /{ userId }", Ġ"/ user /{ userId }/ group /{ groupId }" ]) ĊĠĠĠ Ġfun Ġdelete By GroupId And UserId (@ PathVariable ĠgroupId : ĠLong , Ġ@ PathVariable ĠuserId : ĠLong ): ĠMono < Group Member > Ġ= ĊĠĠĠĠĠĠĠ Ġmembers Repository . findBy GroupId And UserId ( groupId , ĠuserId ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. flatMap Ġ{ Ġm Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmembers Repository . delete By GroupId And UserId ( groupId , ĠuserId ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( m ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ċ } Ċ