Skip to content

Commit

Permalink
update http status
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudFonzam committed Feb 16, 2024
1 parent 6865413 commit 2257cca
Show file tree
Hide file tree
Showing 38 changed files with 236 additions and 207 deletions.
18 changes: 9 additions & 9 deletions src/main/java/org/isf/accounting/rest/BillController.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.isf.patient.model.Patient;
import org.isf.priceslist.manager.PriceListManager;
import org.isf.priceslist.model.PriceList;
import org.isf.shared.exceptions.OHAPIException;
import org.isf.utils.exception.OHServiceException;
import org.isf.utils.exception.model.OHExceptionMessage;
import org.slf4j.Logger;
Expand All @@ -49,6 +48,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -108,7 +108,7 @@ public BillController(BillBrowserManager billManager, PriceListManager priceList
public ResponseEntity<?> newBill(@RequestBody FullBillDTO newBillDto) throws OHServiceException {

if (newBillDto == null) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Bill is null."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Bill is null."));
}
LOGGER.info("Create Bill {}", newBillDto);

Expand All @@ -123,13 +123,13 @@ public ResponseEntity<?> newBill(@RequestBody FullBillDTO newBillDto) throws OHS
if (pat != null) {
bill.setBillPatient(pat);
} else {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found."));
}

if (plist != null) {
bill.setPriceList(plist);
} else {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Price list not found."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Price list not found."));
}

List<BillItems> billItems = billItemsMapper.map2ModelList(newBillDto.getBillItems());
Expand Down Expand Up @@ -160,7 +160,7 @@ public ResponseEntity<?> updateBill(@PathVariable Integer id, @RequestBody FullB
bill.setId(id);

if (billManager.getBill(id) == null) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Bill to update not found."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Bill to update not found."));
}

Patient pat = patientManager.getPatientById(bill.getBillPatient().getCode());
Expand All @@ -172,13 +172,13 @@ public ResponseEntity<?> updateBill(@PathVariable Integer id, @RequestBody FullB
if (pat != null) {
bill.setBillPatient(pat);
} else {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found."));
}

if (plist != null) {
bill.setPriceList(plist);
} else {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Price list not found."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Price list not found."));
}

List<BillItems> billItems = billItemsMapper.map2ModelList(odBillDto.getBillItems());
Expand Down Expand Up @@ -415,12 +415,12 @@ public ResponseEntity<?> deleteBill(@PathVariable Integer id) throws OHServiceEx
LOGGER.info("Delete bill id: {}", id);
Bill bill = billManager.getBill(id);
if (bill == null) {
return ResponseEntity.badRequest().body("No bill found with the specified id.");
return ResponseEntity.notFound().build();
}
try {
billManager.deleteBill(bill);
} catch (OHServiceException e) {
throw new OHAPIException(new OHExceptionMessage("Bill is not deleted."));
return ResponseEntity.internalServerError().body(new OHExceptionMessage("Bill is not deleted."));
}
return ResponseEntity.ok(true);
}
Expand Down
81 changes: 41 additions & 40 deletions src/main/java/org/isf/admission/rest/AdmissionController.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -76,8 +77,8 @@ ResponseEntity<?> newAdmissionType(@RequestBody AdmissionTypeDTO admissionTypeDT
String code = admissionTypeDTO.getCode();
LOGGER.info("Create Admission Type {}", code);
AdmissionType newAdmissionType = admtManager.newAdmissionType(mapper.map2Model(admissionTypeDTO));
if (admtManager.isCodePresent(code)) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("The code of Admission Type is already used."));
if (!admtManager.isCodePresent(code)) {
return ResponseEntity.internalServerError().body(new OHExceptionMessage("The code of Admission Type is already used."));
}
return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(newAdmissionType));
}
Expand All @@ -94,7 +95,7 @@ ResponseEntity<?> updateAdmissionTypes(@RequestBody AdmissionTypeDTO admissionTy
LOGGER.info("Update admissiontypes code: {}", admissionTypeDTO.getCode());
AdmissionType admt = mapper.map2Model(admissionTypeDTO);
if (!admtManager.isCodePresent(admt.getCode())) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Admission Type not found."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Admission Type not found."));
}
AdmissionType updatedAdmissionType = admtManager.updateAdmissionType(admt);
return ResponseEntity.ok(mapper.map2DTO(updatedAdmissionType));
Expand Down Expand Up @@ -134,7 +135,7 @@ public ResponseEntity<?> deleteAdmissionType(@PathVariable("code") String code)
admtManager.deleteAdmissionType(admtFounds.get(0));
}
} else {
return ResponseEntity.badRequest().body("Admission Type not found.");
return ((BodyBuilder) ResponseEntity.notFound()).body("Admission Type not found.");
}
return ResponseEntity.ok(true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/isf/agetype/rest/AgeTypeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
import org.isf.agetype.manager.AgeTypeBrowserManager;
import org.isf.agetype.mapper.AgeTypeMapper;
import org.isf.agetype.model.AgeType;
import org.isf.shared.exceptions.OHAPIException;
import org.isf.utils.exception.OHServiceException;
import org.isf.utils.exception.model.OHExceptionMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
Expand Down Expand Up @@ -95,7 +95,7 @@ public ResponseEntity<List<AgeTypeDTO>> getAllAgeTypes() throws OHServiceExcepti
@PutMapping(value = "/agetypes", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<?> updateAgeType(@Valid @RequestBody AgeTypeDTO ageTypeDTO) throws OHServiceException {
if (ageTypeDTO.getCode() == null || ageTypeDTO.getCode().trim().isEmpty()) {
throw new OHAPIException(new OHExceptionMessage("The age type is not valid."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("The age type is not valid."));
}
LOGGER.info("Update age type");
AgeType ageType = mapper.map2Model(ageTypeDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -77,7 +78,7 @@ ResponseEntity<?> newDischargeType(@RequestBody DischargeTypeDTO dischTypeDTO) t
LOGGER.info("Create discharge type {}", code);
DischargeType newDischargeType = discTypeManager.newDischargeType(mapper.map2Model(dischTypeDTO));
if (!discTypeManager.isCodePresent(code)) {
return ResponseEntity.notFound().build();
return ResponseEntity.internalServerError().body("Discharge Type is not created.");
}
return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(newDischargeType));
}
Expand All @@ -93,11 +94,11 @@ ResponseEntity<?> updateDischargeType(@RequestBody DischargeTypeDTO dischTypeDTO
LOGGER.info("Update discharge type with code: {}", dischTypeDTO.getCode());
DischargeType dischType = mapper.map2Model(dischTypeDTO);
if (!discTypeManager.isCodePresent(dischTypeDTO.getCode())) {
return ResponseEntity.badRequest().body(null);
return ((BodyBuilder) ResponseEntity.notFound()).body("Discharge Type not found.");

This comment has been minimized.

Copy link
@dbmalkovsky

dbmalkovsky Feb 16, 2024

Collaborator

Shouldn't there be a: new OHExceptionMessage() here too?

}
DischargeType updatedDischargeType = discTypeManager.updateDischargeType(dischType);
if (!discTypeManager.isCodePresent(updatedDischargeType.getCode())) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Discharge Type is not updated."));
return ResponseEntity.internalServerError().body(new OHExceptionMessage("Discharge Type is not updated."));
}
return ResponseEntity.ok(mapper.map2DTO(dischType));
}
Expand Down Expand Up @@ -136,7 +137,7 @@ public ResponseEntity<?> deleteDischargeType(@PathVariable("code") String code)
discTypeManager.deleteDischargeType(dischTypeFounds.get(0));
}
} else {
return ResponseEntity.badRequest().body("Discharge Type not found.");
return ((BodyBuilder) ResponseEntity.notFound()).body("Discharge Type not found.");
}
return ResponseEntity.ok(true);
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/isf/disease/rest/DiseaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -244,10 +245,10 @@ public ResponseEntity<DiseaseDTO> getDiseaseByCode(@PathVariable("code") String
public ResponseEntity<?> newDisease(@Valid @RequestBody DiseaseDTO diseaseDTO) throws OHServiceException {
Disease disease = mapper.map2Model(diseaseDTO);
if (diseaseManager.isCodePresent(disease.getCode())) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Duplicated disease code."));
return ResponseEntity.internalServerError().body(new OHExceptionMessage("Duplicated disease code."));
}
if (diseaseManager.descriptionControl(disease.getDescription(), disease.getType().getCode())) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Duplicated disease description for the same disease type."));
return ResponseEntity.internalServerError().body(new OHExceptionMessage("Duplicated disease description for the same disease type."));
}
try {
diseaseManager.newDisease(disease);
Expand All @@ -267,7 +268,7 @@ public ResponseEntity<?> newDisease(@Valid @RequestBody DiseaseDTO diseaseDTO) t
public ResponseEntity<?> updateDisease(@Valid @RequestBody DiseaseDTO diseaseDTO) throws OHServiceException {
Disease disease = mapper.map2Model(diseaseDTO);
if (!diseaseManager.isCodePresent(disease.getCode())) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease not found."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease not found."));
}
disease.setLock(diseaseDTO.getLock());
try {
Expand Down Expand Up @@ -299,7 +300,7 @@ public ResponseEntity<?> deleteDisease(@PathVariable("code") String code) throws
result.put("deleted", isDeleted);
return ResponseEntity.ok(result);
} else {
return ResponseEntity.badRequest().body("No disease found with the specified code.");
return ((BodyBuilder) ResponseEntity.notFound()).body("No disease found with the specified code.");

This comment has been minimized.

Copy link
@dbmalkovsky

dbmalkovsky Feb 16, 2024

Collaborator

Shouldn't there be a: new OHExceptionMessage() here too?

I'm going to stop annotating every single one ..... please review these yourself; thanks.

}
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/isf/distype/rest/DiseaseTypeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -91,7 +92,7 @@ public ResponseEntity<List<DiseaseTypeDTO>> getAllDiseaseTypes() throws OHServic
public ResponseEntity<?> newDiseaseType(@Valid @RequestBody DiseaseTypeDTO diseaseTypeDTO) throws OHServiceException {
DiseaseType diseaseType = mapper.map2Model(diseaseTypeDTO);
if (diseaseTypeManager.isCodePresent(diseaseType.getCode())) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Specified Disease Type code is already used."));
return ResponseEntity.internalServerError().body(new OHExceptionMessage("Specified Disease Type code is already used."));
}
try {
diseaseTypeManager.newDiseaseType(diseaseType);
Expand All @@ -111,7 +112,7 @@ public ResponseEntity<?> newDiseaseType(@Valid @RequestBody DiseaseTypeDTO disea
public ResponseEntity<?> updateDiseaseType(@Valid @RequestBody DiseaseTypeDTO diseaseTypeDTO) throws OHServiceException {
DiseaseType diseaseType = mapper.map2Model(diseaseTypeDTO);
if (!diseaseTypeManager.isCodePresent(diseaseType.getCode())) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease Type not found."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease Type not found."));
}
try {
diseaseTypeManager.updateDiseaseType(diseaseType);
Expand Down Expand Up @@ -143,7 +144,7 @@ public ResponseEntity<?> deleteDiseaseType(@PathVariable String code) throws OHS
return ResponseEntity.internalServerError().body(new OHExceptionMessage("Disease Type not deleted."));
}
} else {
return ResponseEntity.badRequest().body("No Disease Type found with the given code.");
return ((BodyBuilder) ResponseEntity.notFound()).body("No Disease Type found with the given code.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -101,7 +102,7 @@ ResponseEntity<?> updateDeliveryResultTypes(@RequestBody DeliveryResultTypeDTO d
LOGGER.info("Update Delivery Result Type code: {}", dlvrrestTypeDTO.getCode());
DeliveryResultType dlvrrestType = mapper.map2Model(dlvrrestTypeDTO);
if (!dlvrrestManager.isCodePresent(dlvrrestType.getCode())) {
return ResponseEntity.badRequest().body("Delivery Result Type not found.");
return ((BodyBuilder) ResponseEntity.notFound()).body("Delivery Result Type not found.");
}
try {
dlvrrestManager.updateDeliveryResultType(dlvrrestType);
Expand Down Expand Up @@ -150,7 +151,7 @@ public ResponseEntity<?> deleteDeliveryResultType(@PathVariable("code") String c
}
}
} else {
return ResponseEntity.badRequest().body("No delivery result type found with the specified code.");
return ((BodyBuilder) ResponseEntity.notFound()).body("No delivery result type found with the specified code.");
}
return ResponseEntity.ok(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -99,7 +100,7 @@ ResponseEntity<?> updateDeliveryTypes(@RequestBody DeliveryTypeDTO dlvrTypeDTO)
LOGGER.info("Update Delivery Type code: {}", dlvrTypeDTO.getCode());
DeliveryType dlvrType = deliveryTypeMapper.map2Model(dlvrTypeDTO);
if (!dlvrtypeManager.isCodePresent(dlvrType.getCode())) {
return ResponseEntity.badRequest().body("Delivery Type not found.");
return ((BodyBuilder) ResponseEntity.notFound()).body("Delivery Type not found.");
}
try {
dlvrtypeManager.updateDeliveryType(dlvrType);
Expand Down Expand Up @@ -143,7 +144,7 @@ public ResponseEntity<?> deleteDeliveryType(@PathVariable("code") String code) t
dlvrtypeManager.deleteDeliveryType(dlvrTypeFounds.get(0));
}
} else {
return ResponseEntity.badRequest().body("No Delivery Type found with the specified code.");
return ((BodyBuilder) ResponseEntity.notFound()).body("No Delivery Type found with the specified code.");
}
return ResponseEntity.ok(true);
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/isf/exam/rest/ExamController.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -71,7 +72,7 @@ public ResponseEntity<?> newExam(@RequestBody ExamDTO newExam) throws OHServiceE
ExamType examType = examTypeBrowserManager.getExamType().stream().filter(et -> newExam.getExamtype().getCode().equals(et.getCode())).findFirst().orElse(null);

if (examType == null) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam type not found."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam type not found."));
}

Exam exam = examMapper.map2Model(newExam);
Expand All @@ -88,15 +89,15 @@ public ResponseEntity<?> newExam(@RequestBody ExamDTO newExam) throws OHServiceE
public ResponseEntity<?> updateExams(@PathVariable String code, @RequestBody ExamDTO updateExam) throws OHServiceException {

if (!updateExam.getCode().equals(code)) {
return ResponseEntity.badRequest().body("The specified code is different with the Exam code.");
return ((BodyBuilder) ResponseEntity.notFound()).body("The specified code is different with the Exam code.");
}
if (examManager.getExams().stream().noneMatch(e -> e.getCode().equals(code))) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam not found."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam not found."));
}

ExamType examType = examTypeBrowserManager.getExamType().stream().filter(et -> updateExam.getExamtype().getCode().equals(et.getCode())).findFirst().orElse(null);
if (examType == null) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam type not found."));
return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam type not found."));
}

Exam exam = examMapper.map2Model(updateExam);
Expand Down Expand Up @@ -137,7 +138,7 @@ public ResponseEntity<List<ExamDTO>> getExams() throws OHServiceException {
public ResponseEntity<?> deleteExam(@PathVariable String code) throws OHServiceException {
Optional<Exam> exam = examManager.getExams().stream().filter(e -> e.getCode().equals(code)).findFirst();
if (!exam.isPresent()) {
return ResponseEntity.badRequest().body("No Exam found with the specified code.");
return ((BodyBuilder) ResponseEntity.notFound()).body("No Exam found with the specified code.");
}
try {
examManager.deleteExam(exam.get());
Expand Down
Loading

0 comments on commit 2257cca

Please sign in to comment.