Skip to content

Commit

Permalink
endpunkt erweiterut, um anhand der mstid die Messstelle laden zu können
Browse files Browse the repository at this point in the history
  • Loading branch information
Der-Alex-K committed Mar 5, 2025
1 parent 90e5458 commit a330b7b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -39,10 +42,20 @@ public class MessstelleController {
)
@GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
@Transactional(readOnly = true)
public ResponseEntity<ReadMessstelleInfoDTO> readMessstelleInfo(@RequestParam(value = REQUEST_PARAMETER_ID) final String messstelleId) {
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);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit a330b7b

Please sign in to comment.