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:
Gustavo Henrique Santos Souza de Miranda
2025-12-06 22:30:51 -03:00
co-authored by Claude Sonnet 4.5
parent ff09d1b89a
commit 94297e75b9
@@ -40,19 +40,22 @@ public class SamplingRateService {
}
public Optional<SamplingRate> updateSamplingRate(Integer id, String value) {
logger.info("Updating sampling rate:{}", value);
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty");
}
Optional<SamplingRate> existingSamplingRate = repository.findById(id);
if(existingSamplingRate.isEmpty()) {
logger.warn("Sampling rate not found with id:{}", id);
return Optional.empty();
}
SamplingRate samplingRate = existingSamplingRate.get();
samplingRate.setValue(value);
SamplingRate updatedSamplingRate = repository.update(samplingRate);
return Optional.of(updatedSamplingRate);
if (id == null) {
throw new IllegalArgumentException("ID cannot be null");
}
logger.info("Updating sampling rate:{}", value);
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty");
}
Optional<SamplingRate> existingSamplingRate = repository.findById(id);
if(existingSamplingRate.isEmpty()) {
logger.warn("Sampling rate not found with id:{}", id);
return Optional.empty();
}
SamplingRate samplingRate = existingSamplingRate.get();
samplingRate.setValue(value);
SamplingRate updatedSamplingRate = repository.update(samplingRate);
return Optional.of(updatedSamplingRate);
}
public boolean deleteSamplingRate(Integer id) {