From a330b7be3b99d3379352a994f45641aaa62a5b51 Mon Sep 17 00:00:00 2001 From: "alexander.kerscher" Date: Wed, 5 Mar 2025 17:12:25 +0100 Subject: [PATCH 1/2] =?UTF-8?q?endpunkt=20erweiterut,=20um=20anhand=20der?= =?UTF-8?q?=20mstid=20die=20Messstelle=20laden=20zu=20k=C3=B6nnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dave/controller/MessstelleController.java | 17 +++++++++++++++-- .../services/messstelle/MessstelleService.java | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/muenchen/dave/controller/MessstelleController.java b/src/main/java/de/muenchen/dave/controller/MessstelleController.java index ba49a4f0..23d7d4ad 100644 --- a/src/main/java/de/muenchen/dave/controller/MessstelleController.java +++ b/src/main/java/de/muenchen/dave/controller/MessstelleController.java @@ -4,11 +4,13 @@ import de.muenchen.dave.domain.dtos.messstelle.EditMessstelleDTO; import de.muenchen.dave.domain.dtos.messstelle.MessstelleOverviewDTO; import de.muenchen.dave.domain.dtos.messstelle.ReadMessstelleInfoDTO; +import de.muenchen.dave.exceptions.BadRequestException; import de.muenchen.dave.exceptions.ResourceNotFoundException; import de.muenchen.dave.services.messstelle.MessstelleService; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -31,6 +33,7 @@ public class MessstelleController { private static final String REQUEST_PARAMETER_ID = "id"; + private static final String REQUEST_PARAMETER_MSTID = "mstid"; private final MessstelleService messstelleService; @PreAuthorize( @@ -39,10 +42,20 @@ public class MessstelleController { ) @GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE) @Transactional(readOnly = true) - public ResponseEntity readMessstelleInfo(@RequestParam(value = REQUEST_PARAMETER_ID) final String messstelleId) { + public ResponseEntity readMessstelleInfo( + @RequestParam(value = REQUEST_PARAMETER_ID, required = false) final String messstelleId, + @RequestParam(value = REQUEST_PARAMETER_MSTID, required = false) final String mstId) { log.debug("#readMessstelleInfo with id {}", messstelleId); try { - final ReadMessstelleInfoDTO readMessstelleDTO = this.messstelleService.readMessstelleInfo(messstelleId); + if (StringUtils.isEmpty(messstelleId) && StringUtils.isEmpty(mstId)) { + throw new BadRequestException("ID zum Laden der Messstelle fehlt."); + } + final ReadMessstelleInfoDTO readMessstelleDTO; + if (StringUtils.isNotEmpty(messstelleId)) { + readMessstelleDTO = this.messstelleService.readMessstelleInfo(messstelleId); + } else { + readMessstelleDTO = this.messstelleService.readMessstelleInfoByMstId(mstId); + } return ResponseEntity.ok(readMessstelleDTO); } catch (final ResourceNotFoundException e) { log.error("Fehler im MessstelleController, Messstelle konnte nicht gefunden werden. ID: {}", messstelleId, e); diff --git a/src/main/java/de/muenchen/dave/services/messstelle/MessstelleService.java b/src/main/java/de/muenchen/dave/services/messstelle/MessstelleService.java index 711cf8bb..e7cc0f9d 100644 --- a/src/main/java/de/muenchen/dave/services/messstelle/MessstelleService.java +++ b/src/main/java/de/muenchen/dave/services/messstelle/MessstelleService.java @@ -50,6 +50,11 @@ public ReadMessstelleInfoDTO readMessstelleInfo(final String messstelleId) { return messstelleMapper.bean2readDto(byIdOrThrowException, stadtbezirkMapper); } + public ReadMessstelleInfoDTO readMessstelleInfoByMstId(final String mstId) { + final Messstelle byIdOrThrowException = messstelleIndexService.findByMstIdOrThrowException(mstId); + return messstelleMapper.bean2readDto(byIdOrThrowException, stadtbezirkMapper); + } + public EditMessstelleDTO getMessstelleToEdit(final String messstelleId) { final Messstelle byIdOrThrowException = messstelleIndexService.findByIdOrThrowException(messstelleId); byIdOrThrowException.setMessfaehigkeiten( From 273df11093c247c3c3d8ac2ce3fd57e994d39e58 Mon Sep 17 00:00:00 2001 From: "alexander.kerscher" Date: Thu, 6 Mar 2025 09:41:56 +0100 Subject: [PATCH 2/2] split endpoint --- .../dave/controller/MessstelleController.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/muenchen/dave/controller/MessstelleController.java b/src/main/java/de/muenchen/dave/controller/MessstelleController.java index 23d7d4ad..88a86e0f 100644 --- a/src/main/java/de/muenchen/dave/controller/MessstelleController.java +++ b/src/main/java/de/muenchen/dave/controller/MessstelleController.java @@ -4,13 +4,11 @@ import de.muenchen.dave.domain.dtos.messstelle.EditMessstelleDTO; import de.muenchen.dave.domain.dtos.messstelle.MessstelleOverviewDTO; import de.muenchen.dave.domain.dtos.messstelle.ReadMessstelleInfoDTO; -import de.muenchen.dave.exceptions.BadRequestException; import de.muenchen.dave.exceptions.ResourceNotFoundException; import de.muenchen.dave.services.messstelle.MessstelleService; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -40,22 +38,13 @@ public class MessstelleController { "hasAnyRole(T(de.muenchen.dave.security.AuthoritiesEnum).ANWENDER.name(), " + "T(de.muenchen.dave.security.AuthoritiesEnum).POWERUSER.name())" ) - @GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(value = "/info", params = REQUEST_PARAMETER_ID, produces = MediaType.APPLICATION_JSON_VALUE) @Transactional(readOnly = true) - public ResponseEntity readMessstelleInfo( - @RequestParam(value = REQUEST_PARAMETER_ID, required = false) final String messstelleId, - @RequestParam(value = REQUEST_PARAMETER_MSTID, required = false) final String mstId) { - log.debug("#readMessstelleInfo with id {}", messstelleId); + public ResponseEntity readMessstelleInfoById( + @RequestParam(value = REQUEST_PARAMETER_ID) final String messstelleId) { + log.debug("#readMessstelleInfoById with id {}", messstelleId); try { - if (StringUtils.isEmpty(messstelleId) && StringUtils.isEmpty(mstId)) { - throw new BadRequestException("ID zum Laden der Messstelle fehlt."); - } - final ReadMessstelleInfoDTO readMessstelleDTO; - if (StringUtils.isNotEmpty(messstelleId)) { - readMessstelleDTO = this.messstelleService.readMessstelleInfo(messstelleId); - } else { - readMessstelleDTO = this.messstelleService.readMessstelleInfoByMstId(mstId); - } + final ReadMessstelleInfoDTO readMessstelleDTO = this.messstelleService.readMessstelleInfo(messstelleId); return ResponseEntity.ok(readMessstelleDTO); } catch (final ResourceNotFoundException e) { log.error("Fehler im MessstelleController, Messstelle konnte nicht gefunden werden. ID: {}", messstelleId, e); @@ -66,6 +55,23 @@ public ResponseEntity readMessstelleInfo( } } + @GetMapping(value = "/info", params = REQUEST_PARAMETER_MSTID, produces = MediaType.APPLICATION_JSON_VALUE) + @Transactional(readOnly = true) + public ResponseEntity readMessstelleInfoByMstId( + @RequestParam(value = REQUEST_PARAMETER_MSTID) final String mstId) { + log.debug("#readMessstelleInfoByMstId with id {}", mstId); + try { + final ReadMessstelleInfoDTO readMessstelleDTO = this.messstelleService.readMessstelleInfoByMstId(mstId); + return ResponseEntity.ok(readMessstelleDTO); + } catch (final ResourceNotFoundException e) { + log.error("Fehler im MessstelleController, Messstelle konnte nicht gefunden werden. ID: {}", mstId, e); + throw e; + } catch (final Exception e) { + log.error("Unerwarteter Fehler im MessstelleController beim Laden der Messstelle mit der ID: {}", mstId, e); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Es ist ein unerwarteter Fehler beim Laden der Messstelle aufgetreten."); + } + } + /** * Diese Methode erlaubt das Aktualisieren einer Messstelle. *