@@ -318,6 +318,30 @@ public ResponseEntity<ResendInvitationResponse> resendInvitation(@RequestBody Re
318318 return ResponseEntity .ok (new ResendInvitationResponse (timestamp , 200 , "ok" , "Resend invitation" ));
319319 }
320320
321+ @ GetMapping (value = "/crm/api/v1/organisations" , produces = MediaType .APPLICATION_JSON_VALUE )
322+ @ Operation (summary = "Get all CRM organisations" )
323+ @ SecurityRequirement (name = API_HEADER_SCHEME_NAME )
324+ @ PreAuthorize ("hasRole('CRM')" )
325+ public ResponseEntity <List <CRMOrganisation >> organisations () {
326+ List <Organisation > organisations = organisationRepository .findAll ();
327+ List <CRMOrganisation > crmOrganisations = organisations .stream ().map (organisation -> new CRMOrganisation (
328+ organisation .getCrmOrganisationId (),
329+ organisation .getCrmOrganisationAbbrevation (),
330+ organisation .getCrmOrganisationName ()
331+ )).toList ();
332+ return ResponseEntity .ok (crmOrganisations );
333+ }
334+
335+ @ DeleteMapping (value = "/crm/api/v1/organisations" , produces = MediaType .APPLICATION_JSON_VALUE )
336+ @ Operation (summary = "Delete CRM organisation" )
337+ @ SecurityRequirement (name = API_HEADER_SCHEME_NAME )
338+ @ PreAuthorize ("hasRole('CRM')" )
339+ public ResponseEntity <Void > deleteOrganisation (@ RequestBody CRMOrganisation crmOrganisation ) {
340+ Optional <Organisation > optionalOrganisation = organisationRepository .findByCrmOrganisationId (crmOrganisation .getOrganisationId ());
341+ optionalOrganisation .ifPresent (organisation -> organisationRepository .delete (organisation ));
342+ return ResponseEntity .status (204 ).build ();
343+ }
344+
321345 private ProfileResponse crmUserNotFoundOrNoRoles () {
322346 return new ProfileResponse ("Could not find any profiles with the given search parameters" , 50 , List .of ());
323347 }
0 commit comments