Skip to content

Commit

Permalink
OH2-319 Fix Discharge type delete response code
Browse files Browse the repository at this point in the history
  • Loading branch information
mwithi committed Jun 13, 2024
1 parent 30f8a76 commit 017507c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/org/isf/disctype/rest/DischargeTypeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class DischargeTypeController {

@Autowired
protected DischargeTypeBrowserManager discTypeManager;

@Autowired
protected DischargeTypeMapper mapper;

Expand All @@ -68,6 +68,7 @@ public DischargeTypeController(DischargeTypeBrowserManager discTypeManager, Disc

/**
* Create a new {@link DischargeType}
*
* @param dischTypeDTO
* @return {@code true} if the {@link DischargeType} has been stored, {@code false} otherwise.
* @throws OHServiceException
Expand All @@ -85,6 +86,7 @@ ResponseEntity<DischargeTypeDTO> newDischargeType(@RequestBody DischargeTypeDTO

/**
* Update the specified {@link DischargeType}
*
* @param dischTypeDTO
* @return {@code true} if the {@link DischargeType} has been updated, {@code false} otherwise.
* @throws OHServiceException
Expand All @@ -105,6 +107,7 @@ ResponseEntity<DischargeTypeDTO> updateDischargeTypet(@RequestBody DischargeType

/**
* Get all the available {@link DischargeType}s
*
* @return a {@link List} of {@link DischargeType} or NO_CONTENT if there is no data found.
* @throws OHServiceException
*/
Expand All @@ -122,6 +125,7 @@ public ResponseEntity<List<DischargeTypeDTO>> getDischargeTypes() throws OHServi

/**
* Delete {@link DischargeType} for the specified code.
*
* @param code
* @return {@code true} if the {@link DischargeType} has been deleted, {@code false} otherwise.
* @throws OHServiceException
Expand All @@ -132,9 +136,14 @@ public ResponseEntity<Boolean> deleteDischargeType(@PathVariable("code") String
if (discTypeManager.isCodePresent(code)) {
List<DischargeType> dischTypes = discTypeManager.getDischargeType();
List<DischargeType> dischTypeFounds = dischTypes.stream().filter(ad -> ad.getCode().equals(code))
.collect(Collectors.toList());
.collect(Collectors.toList());
if (!dischTypeFounds.isEmpty()) {
discTypeManager.deleteDischargeType(dischTypeFounds.get(0));
try {
discTypeManager.deleteDischargeType(dischTypeFounds.get(0));
} catch (OHServiceException serviceException) {
LOGGER.error("Delete discharge type: {} failed.", code);
throw new OHAPIException(new OHExceptionMessage("Discharge type not deleted."));
}
}
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
Expand Down

0 comments on commit 017507c

Please sign in to comment.