Add id validation and improve code formatting in updateSamplingRate
Enhance input validation and code quality in the SamplingRate service: - Add null check for id parameter in updateSamplingRate() method to prevent potential NullPointerException when calling repository.findById() - Standardize indentation throughout the updateSamplingRate() method body, improving code readability and consistency with project style guidelines This complements the previous validation improvements by ensuring all method parameters are properly validated before use, creating a more defensive and robust API surface. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
ff09d1b89a
commit
94297e75b9
|
|
@ -40,19 +40,22 @@ public class SamplingRateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<SamplingRate> updateSamplingRate(Integer id, String value) {
|
public Optional<SamplingRate> updateSamplingRate(Integer id, String value) {
|
||||||
logger.info("Updating sampling rate:{}", value);
|
if (id == null) {
|
||||||
if (value == null || value.trim().isEmpty()) {
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty");
|
}
|
||||||
}
|
logger.info("Updating sampling rate:{}", value);
|
||||||
Optional<SamplingRate> existingSamplingRate = repository.findById(id);
|
if (value == null || value.trim().isEmpty()) {
|
||||||
if(existingSamplingRate.isEmpty()) {
|
throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty");
|
||||||
logger.warn("Sampling rate not found with id:{}", id);
|
}
|
||||||
return Optional.empty();
|
Optional<SamplingRate> existingSamplingRate = repository.findById(id);
|
||||||
}
|
if(existingSamplingRate.isEmpty()) {
|
||||||
SamplingRate samplingRate = existingSamplingRate.get();
|
logger.warn("Sampling rate not found with id:{}", id);
|
||||||
samplingRate.setValue(value);
|
return Optional.empty();
|
||||||
SamplingRate updatedSamplingRate = repository.update(samplingRate);
|
}
|
||||||
return Optional.of(updatedSamplingRate);
|
SamplingRate samplingRate = existingSamplingRate.get();
|
||||||
|
samplingRate.setValue(value);
|
||||||
|
SamplingRate updatedSamplingRate = repository.update(samplingRate);
|
||||||
|
return Optional.of(updatedSamplingRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean deleteSamplingRate(Integer id) {
|
public boolean deleteSamplingRate(Integer id) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue