From c1c293f85980498e1ce9bc733259a3ff594abfa0 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Tue, 23 Jul 2024 10:16:10 +0200 Subject: [PATCH] [kbss-cvut/record-manager-ui#193] Throw validation error in case if user is not assigned to any instituttion --- .../cz/cvut/kbss/study/rest/PatientRecordController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java b/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java index 5e8dae63..63985439 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java @@ -6,6 +6,7 @@ import cz.cvut.kbss.study.dto.PatientRecordDto; import cz.cvut.kbss.study.dto.RecordImportResult; import cz.cvut.kbss.study.exception.NotFoundException; +import cz.cvut.kbss.study.exception.ValidationException; import cz.cvut.kbss.study.model.PatientRecord; import cz.cvut.kbss.study.model.RecordPhase; import cz.cvut.kbss.study.model.User; @@ -157,14 +158,13 @@ private PatientRecord findInternal(String key) { return record; } - - @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity createRecord(@RequestBody PatientRecord record) { if(userService.getCurrentUser().getInstitution() == null) - return ResponseEntity.status(HttpStatus.CONFLICT).body("User is not assigned to any institution"); + throw new ValidationException("record.save-error.user-not-assigned-to-institution", + "User is not assigned to any institution."); recordService.persist(record); if (LOG.isTraceEnabled()) {