@Test public void deleteIllness() throws Exception { testClient.addIllnessRecord(record2); mockMvc.perform(delete("/clients/1/illnesses/1")) .andExpect(status().isOk()); }
@DeleteMapping("/clients/{uid}/illnesses/{id}") public ResponseEntity<IllnessRecord> deleteIllness( @PathVariable int uid, @PathVariable int id, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws InvalidRequestException { Optional<Client> optionalClient = State.getClientManager().getClientByID(uid); if (!optionalClient.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } Client client = optionalClient.get(); IllnessRecord removeRecord = client.getIllnessById(id); if (removeRecord == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } State.getAuthenticationManager().verifyClientAccess(authToken, client); DeleteIllnessRecordAction action = new DeleteIllnessRecordAction(client, removeRecord, State.getClientManager()); State.getActionInvoker(authToken).execute(action); Client client1 = State.getClientManager() .getClientByID(client.getUid()) .orElseThrow(IllegalStateException::new); HttpHeaders headers = new HttpHeaders(); return new ResponseEntity<>(removeRecord, headers, HttpStatus.OK); }
ClientIllnessesController { @DeleteMapping("/clients/{uid}/illnesses/{id}") public ResponseEntity<IllnessRecord> deleteIllness( @PathVariable int uid, @PathVariable int id, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws InvalidRequestException { Optional<Client> optionalClient = State.getClientManager().getClientByID(uid); if (!optionalClient.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } Client client = optionalClient.get(); IllnessRecord removeRecord = client.getIllnessById(id); if (removeRecord == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } State.getAuthenticationManager().verifyClientAccess(authToken, client); DeleteIllnessRecordAction action = new DeleteIllnessRecordAction(client, removeRecord, State.getClientManager()); State.getActionInvoker(authToken).execute(action); Client client1 = State.getClientManager() .getClientByID(client.getUid()) .orElseThrow(IllegalStateException::new); HttpHeaders headers = new HttpHeaders(); return new ResponseEntity<>(removeRecord, headers, HttpStatus.OK); } }
ClientIllnessesController { @DeleteMapping("/clients/{uid}/illnesses/{id}") public ResponseEntity<IllnessRecord> deleteIllness( @PathVariable int uid, @PathVariable int id, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws InvalidRequestException { Optional<Client> optionalClient = State.getClientManager().getClientByID(uid); if (!optionalClient.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } Client client = optionalClient.get(); IllnessRecord removeRecord = client.getIllnessById(id); if (removeRecord == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } State.getAuthenticationManager().verifyClientAccess(authToken, client); DeleteIllnessRecordAction action = new DeleteIllnessRecordAction(client, removeRecord, State.getClientManager()); State.getActionInvoker(authToken).execute(action); Client client1 = State.getClientManager() .getClientByID(client.getUid()) .orElseThrow(IllegalStateException::new); HttpHeaders headers = new HttpHeaders(); return new ResponseEntity<>(removeRecord, headers, HttpStatus.OK); }  }
ClientIllnessesController { @DeleteMapping("/clients/{uid}/illnesses/{id}") public ResponseEntity<IllnessRecord> deleteIllness( @PathVariable int uid, @PathVariable int id, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws InvalidRequestException { Optional<Client> optionalClient = State.getClientManager().getClientByID(uid); if (!optionalClient.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } Client client = optionalClient.get(); IllnessRecord removeRecord = client.getIllnessById(id); if (removeRecord == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } State.getAuthenticationManager().verifyClientAccess(authToken, client); DeleteIllnessRecordAction action = new DeleteIllnessRecordAction(client, removeRecord, State.getClientManager()); State.getActionInvoker(authToken).execute(action); Client client1 = State.getClientManager() .getClientByID(client.getUid()) .orElseThrow(IllegalStateException::new); HttpHeaders headers = new HttpHeaders(); return new ResponseEntity<>(removeRecord, headers, HttpStatus.OK); }  @GetMapping("/clients/{id}/illnesses") ResponseEntity<List<IllnessRecord>> getClientCurrentIllnesses(
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PatchMapping("/clients/{uid}/illnesses/{id}") ResponseEntity<IllnessRecord> patchIllness(
            @PathVariable int uid,
            @PathVariable int id,
            @RequestBody ModifyIllnessObject newIllnessDetails,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PostMapping("/clients/{uid}/illnesses") ResponseEntity<List<IllnessRecord>> postIllness(
            @RequestBody CreateIllnessView illnessView,
            @PathVariable int uid,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @DeleteMapping("/clients/{uid}/illnesses/{id}") ResponseEntity<IllnessRecord> deleteIllness(
            @PathVariable int uid,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); }
ClientIllnessesController { @DeleteMapping("/clients/{uid}/illnesses/{id}") public ResponseEntity<IllnessRecord> deleteIllness( @PathVariable int uid, @PathVariable int id, @RequestHeader(value = "X-Auth-Token", required = false) String authToken) throws InvalidRequestException { Optional<Client> optionalClient = State.getClientManager().getClientByID(uid); if (!optionalClient.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } Client client = optionalClient.get(); IllnessRecord removeRecord = client.getIllnessById(id); if (removeRecord == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } State.getAuthenticationManager().verifyClientAccess(authToken, client); DeleteIllnessRecordAction action = new DeleteIllnessRecordAction(client, removeRecord, State.getClientManager()); State.getActionInvoker(authToken).execute(action); Client client1 = State.getClientManager() .getClientByID(client.getUid()) .orElseThrow(IllegalStateException::new); HttpHeaders headers = new HttpHeaders(); return new ResponseEntity<>(removeRecord, headers, HttpStatus.OK); }  @GetMapping("/clients/{id}/illnesses") ResponseEntity<List<IllnessRecord>> getClientCurrentIllnesses(
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PatchMapping("/clients/{uid}/illnesses/{id}") ResponseEntity<IllnessRecord> patchIllness(
            @PathVariable int uid,
            @PathVariable int id,
            @RequestBody ModifyIllnessObject newIllnessDetails,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @PostMapping("/clients/{uid}/illnesses") ResponseEntity<List<IllnessRecord>> postIllness(
            @RequestBody CreateIllnessView illnessView,
            @PathVariable int uid,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken); @DeleteMapping("/clients/{uid}/illnesses/{id}") ResponseEntity<IllnessRecord> deleteIllness(
            @PathVariable int uid,
            @PathVariable int id,
            @RequestHeader(value = "X-Auth-Token", required = false) String authToken);  }