-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OH2-257 | Revise HTTP response codes in API #433
Open
ArnaudFonzam
wants to merge
9
commits into
informatici:develop
Choose a base branch
from
intesys:OH2-257
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
631cd2c
start update the response entity
9f150cd
update response type using responseEntity
f28ef11
fix good status code
83b9731
Merge branch 'develop' into OH2-257
2b3e712
fix somme changes
a26e2a3
correct all mistake
6865413
correct all mistake
2257cca
update http status
a2cd40c
fix http status
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Open Hospital (www.open-hospital.org) | ||
* Copyright © 2006-2023 Informatici Senza Frontiere ([email protected]) | ||
* Copyright © 2006-2024 Informatici Senza Frontiere ([email protected]) | ||
* | ||
* Open Hospital is a free and open source software for healthcare data management. | ||
* | ||
|
@@ -105,10 +105,10 @@ public BillController(BillBrowserManager billManager, PriceListManager priceList | |
* @throws OHServiceException | ||
*/ | ||
@PostMapping(value = "/bills", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<FullBillDTO> newBill(@RequestBody FullBillDTO newBillDto) throws OHServiceException { | ||
public ResponseEntity<?> newBill(@RequestBody FullBillDTO newBillDto) throws OHServiceException { | ||
|
||
if (newBillDto == null) { | ||
throw new OHAPIException(new OHExceptionMessage("Bill is null.")); | ||
return ResponseEntity.badRequest().body(new OHExceptionMessage("Bill is null.")); | ||
} | ||
LOGGER.info("Create Bill {}", newBillDto); | ||
|
||
|
@@ -123,13 +123,13 @@ public ResponseEntity<FullBillDTO> newBill(@RequestBody FullBillDTO newBillDto) | |
if (pat != null) { | ||
bill.setBillPatient(pat); | ||
} else { | ||
throw new OHAPIException(new OHExceptionMessage("Patient not found.")); | ||
return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); | ||
} | ||
|
||
if (plist != null) { | ||
bill.setPriceList(plist); | ||
} else { | ||
throw new OHAPIException(new OHExceptionMessage("Price list not found.")); | ||
return ResponseEntity.badRequest().body(new OHExceptionMessage("Price list not found.")); | ||
} | ||
|
||
List<BillItems> billItems = billItemsMapper.map2ModelList(newBillDto.getBillItems()); | ||
|
@@ -139,7 +139,7 @@ public ResponseEntity<FullBillDTO> newBill(@RequestBody FullBillDTO newBillDto) | |
try { | ||
billManager.newBill(bill, billItems, billPayments); | ||
} catch (OHServiceException e) { | ||
throw new OHAPIException(new OHExceptionMessage("Bill is not created.")); | ||
return ResponseEntity.internalServerError().body(new OHExceptionMessage("Bill is not created.")); | ||
} | ||
return ResponseEntity.status(HttpStatus.CREATED).body(newBillDto); | ||
} | ||
|
@@ -152,15 +152,15 @@ public ResponseEntity<FullBillDTO> newBill(@RequestBody FullBillDTO newBillDto) | |
* @throws OHServiceException | ||
*/ | ||
@PutMapping(value = "/bills/{id}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<FullBillDTO> updateBill(@PathVariable Integer id, @RequestBody FullBillDTO odBillDto) throws OHServiceException { | ||
public ResponseEntity<?> updateBill(@PathVariable Integer id, @RequestBody FullBillDTO odBillDto) throws OHServiceException { | ||
|
||
LOGGER.info("updated Bill {}", odBillDto); | ||
Bill bill = billMapper.map2Model(odBillDto.getBill()); | ||
|
||
bill.setId(id); | ||
|
||
if (billManager.getBill(id) == null) { | ||
throw new OHAPIException(new OHExceptionMessage("Bill to update not found.")); | ||
return ResponseEntity.badRequest().body(new OHExceptionMessage("Bill to update not found.")); | ||
} | ||
|
||
Patient pat = patientManager.getPatientById(bill.getBillPatient().getCode()); | ||
|
@@ -172,13 +172,13 @@ public ResponseEntity<FullBillDTO> updateBill(@PathVariable Integer id, @Request | |
if (pat != null) { | ||
bill.setBillPatient(pat); | ||
} else { | ||
throw new OHAPIException(new OHExceptionMessage("Patient not found.")); | ||
return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); | ||
} | ||
|
||
if (plist != null) { | ||
bill.setPriceList(plist); | ||
} else { | ||
throw new OHAPIException(new OHExceptionMessage("Price list not found.")); | ||
return ResponseEntity.badRequest().body(new OHExceptionMessage("Price list not found.")); | ||
} | ||
|
||
List<BillItems> billItems = billItemsMapper.map2ModelList(odBillDto.getBillItems()); | ||
|
@@ -188,9 +188,9 @@ public ResponseEntity<FullBillDTO> updateBill(@PathVariable Integer id, @Request | |
try { | ||
billManager.updateBill(bill, billItems, billPayments); | ||
} catch (OHServiceException e) { | ||
throw new OHAPIException(new OHExceptionMessage("Bill is not updated.")); | ||
return ResponseEntity.internalServerError().body(new OHExceptionMessage("Bill is not updated.")); | ||
} | ||
return ResponseEntity.status(HttpStatus.CREATED).body(odBillDto); | ||
return ResponseEntity.ok().body(odBillDto); | ||
} | ||
|
||
/** | ||
|
@@ -222,7 +222,7 @@ public ResponseEntity<List<BillDTO>> searchBills( | |
List<BillDTO> billDTOS = billMapper.map2DTOList(bills); | ||
|
||
if (billDTOS.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(billDTOS); | ||
return ResponseEntity.notFound().build(); | ||
} | ||
return ResponseEntity.ok(billDTOS); | ||
} | ||
|
@@ -255,7 +255,7 @@ public ResponseEntity<List<BillPaymentsDTO>> searchBillsPayments( | |
List<BillPaymentsDTO> paymentsDTOS = billPaymentsMapper.map2DTOList(payments); | ||
|
||
if (paymentsDTOS.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); | ||
return ResponseEntity.notFound().build(); | ||
} | ||
return ResponseEntity.ok(paymentsDTOS); | ||
} | ||
|
@@ -276,7 +276,7 @@ public ResponseEntity<List<BillPaymentsDTO>> getPaymentsByBillId(@PathVariable(v | |
List<BillPaymentsDTO> paymentsDTOS = billPaymentsMapper.map2DTOList(billPayments); | ||
|
||
if (paymentsDTOS.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); | ||
return ResponseEntity.notFound().build(); | ||
} | ||
return ResponseEntity.ok(paymentsDTOS); | ||
} | ||
|
@@ -296,7 +296,7 @@ public ResponseEntity<List<BillItemsDTO>> getItems(@PathVariable(value = "bill_i | |
List<BillItemsDTO> itemsDTOS = billItemsMapper.map2DTOList(items); | ||
|
||
if (itemsDTOS.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); | ||
return ResponseEntity.notFound().build(); | ||
} | ||
return ResponseEntity.ok(itemsDTOS); | ||
} | ||
|
@@ -316,7 +316,7 @@ public ResponseEntity<BillDTO> getBill(@PathVariable Integer id) throws OHServic | |
BillDTO billDTO = billMapper.map2DTO(bill); | ||
|
||
if (billDTO == null) { | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); | ||
return ResponseEntity.notFound().build(); | ||
} | ||
return ResponseEntity.ok(billDTO); | ||
} | ||
|
@@ -336,7 +336,7 @@ public ResponseEntity<List<BillDTO>> getPendingBillsAffiliate(@RequestParam(valu | |
List<BillDTO> billDTOS = billMapper.map2DTOList(bills); | ||
|
||
if (billDTOS.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); | ||
return ResponseEntity.notFound().build(); | ||
} | ||
return ResponseEntity.ok(billDTOS); | ||
} | ||
|
@@ -356,7 +356,7 @@ public ResponseEntity<List<BillDTO>> getPendingBills(@RequestParam(value = "pati | |
List<BillDTO> billDTOS = billMapper.map2DTOList(bills); | ||
|
||
if (billDTOS.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(billDTOS); | ||
return ResponseEntity.notFound().build(); | ||
} | ||
return ResponseEntity.ok(billDTOS); | ||
} | ||
|
@@ -384,7 +384,7 @@ public ResponseEntity<List<BillDTO>> searchBills( | |
List<BillDTO> billDTOS = billMapper.map2DTOList(bills); | ||
|
||
if (billDTOS.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); | ||
return ResponseEntity.notFound().build(); | ||
} | ||
return ResponseEntity.ok(billDTOS); | ||
} | ||
|
@@ -405,17 +405,17 @@ public ResponseEntity<List<BillItemsDTO>> getDistinctItems() throws OHServiceExc | |
List<BillItemsDTO> itemsDTOS = billItemsMapper.map2DTOList(items); | ||
|
||
if (itemsDTOS.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); | ||
return ResponseEntity.notFound().build(); | ||
} | ||
return ResponseEntity.ok(itemsDTOS); | ||
} | ||
|
||
@DeleteMapping(value = "/bills/{id}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<Boolean> deleteBill(@PathVariable Integer id) throws OHServiceException { | ||
public ResponseEntity<?> deleteBill(@PathVariable Integer id) throws OHServiceException { | ||
LOGGER.info("Delete bill id: {}", id); | ||
Bill bill = billManager.getBill(id); | ||
if (bill == null) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); | ||
return ResponseEntity.badRequest().body("No bill found with the specified id."); | ||
} | ||
try { | ||
billManager.deleteBill(bill); | ||
|
@@ -441,7 +441,7 @@ public ResponseEntity<List<BillDTO>> searchBillsByPayments(@RequestBody List<Bil | |
List<BillDTO> billDTOS = billMapper.map2DTOList(bills); | ||
|
||
if (billDTOS.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); | ||
return ResponseEntity.notFound().build(); | ||
} | ||
return ResponseEntity.ok(billDTOS); | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find three different return values for something not found:
Shouldn't there only be one form?