Skip to content

Commit

Permalink
do not override already provided methods
Browse files Browse the repository at this point in the history
CrudRepository is provided by spring data and methods are learned by developers.
  • Loading branch information
bseber committed Jun 21, 2024
1 parent 61e7e99 commit 03f9aca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@

import org.springframework.data.repository.CrudRepository;

import java.util.List;

interface FederalStateSettingsRepository extends CrudRepository<FederalStateSettingsEntity, Long> {
List<FederalStateSettingsEntity> findAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.util.Optional;

import static java.util.stream.StreamSupport.stream;

@Service
class SettingsService implements FederalStateSettingsService {

Expand Down Expand Up @@ -40,6 +42,9 @@ FederalStateSettings updateFederalStateSettings(FederalState federalState, boole
}

private Optional<FederalStateSettingsEntity> getFederalStateEntity() {
return federalStateSettingsRepository.findAll().stream().findFirst();
// `findFirst` is sufficient as there exists only one FederalStateSettingsEntity per tenant.
// however, the tenantId is handled transparently in the background. and we only have the public API of `findAll`.
final Iterable<FederalStateSettingsEntity> settings = federalStateSettingsRepository.findAll();
return stream(settings.spliterator(), false).findFirst();
}
}

0 comments on commit 03f9aca

Please sign in to comment.