diff --git a/src/main/java/de/tum/cit/ase/artemistelemetry/service/TelemetryService.java b/src/main/java/de/tum/cit/ase/artemistelemetry/service/TelemetryService.java index cca777e..80f8869 100644 --- a/src/main/java/de/tum/cit/ase/artemistelemetry/service/TelemetryService.java +++ b/src/main/java/de/tum/cit/ase/artemistelemetry/service/TelemetryService.java @@ -2,6 +2,7 @@ import de.tum.cit.ase.artemistelemetry.domain.Telemetry; import de.tum.cit.ase.artemistelemetry.repository.TelemetryRepository; +import de.tum.cit.ase.artemistelemetry.service.dto.TelemetryDTO; import org.springframework.stereotype.Service; import java.time.ZonedDateTime; @@ -48,4 +49,19 @@ public Telemetry updateTelemetryByUniversityName(Telemetry newTelemetry) { newTelemetry.setId(telemetry.getId()); return telemetryRepository.save(newTelemetry); } + + public void validateTelemetry(TelemetryDTO telemetry) throws IllegalArgumentException { + if (telemetry.operator() == null || telemetry.operator().isEmpty()) { + throw new IllegalArgumentException("University name must not be empty"); + } + if (telemetry.profiles() == null || telemetry.profiles().isEmpty()) { + throw new IllegalArgumentException("Profiles must not be empty"); + } + if (telemetry.serverUrl() == null || telemetry.serverUrl().isEmpty()) { + throw new IllegalArgumentException("Server URL must not be empty"); + } + if (telemetry.version() == null || telemetry.version().isEmpty()) { + throw new IllegalArgumentException("Version must not be empty"); + } + } } diff --git a/src/main/java/de/tum/cit/ase/artemistelemetry/web/rest/TelemetryResource.java b/src/main/java/de/tum/cit/ase/artemistelemetry/web/rest/TelemetryResource.java index 7fbdb75..fd7ede3 100644 --- a/src/main/java/de/tum/cit/ase/artemistelemetry/web/rest/TelemetryResource.java +++ b/src/main/java/de/tum/cit/ase/artemistelemetry/web/rest/TelemetryResource.java @@ -24,7 +24,12 @@ public ResponseEntity getTelemetry(@PathVariable Long id) { } @PostMapping - public ResponseEntity postTelemetry(@RequestBody TelemetryDTO telemetryDTO) { + public ResponseEntity createTelemetry(@RequestBody TelemetryDTO telemetryDTO) { + try { + telemetryService.validateTelemetry(telemetryDTO); + } catch (IllegalArgumentException e) { + return ResponseEntity.status(400).body(e.getMessage()); + } Telemetry savedTelemetry = telemetryService.saveNewTelemetry(TelemetryDTO.to(telemetryDTO)); return ResponseEntity.ok(TelemetryDTO.from(savedTelemetry)); }