Skip to content

Commit

Permalink
split endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Der-Alex-K committed Mar 6, 2025
1 parent a330b7b commit 273df11
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/main/java/de/muenchen/dave/controller/MessstelleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ReadMessstelleInfoDTO> 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<ReadMessstelleInfoDTO> 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);
Expand All @@ -66,6 +55,23 @@ public ResponseEntity<ReadMessstelleInfoDTO> readMessstelleInfo(
}
}

@GetMapping(value = "/info", params = REQUEST_PARAMETER_MSTID, produces = MediaType.APPLICATION_JSON_VALUE)
@Transactional(readOnly = true)
public ResponseEntity<ReadMessstelleInfoDTO> 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.
*
Expand Down

0 comments on commit 273df11

Please sign in to comment.