Skip to content

Commit

Permalink
[refac] change the optional return value to boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
kgy1008 committed Jul 16, 2024
1 parent d5e0c7d commit 245c8ad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ public void validateDuplicatedStore(final StoreValidationCommand command) {
}

private void findUniversityStore(final Long universityId, final Store store) {
universityStoreFinder.findByUniversityIdAndStore(universityId, store)
.ifPresent(universityStore -> {
throw new ConflictException(StoreErrorCode.STORE_ALREADY_REGISTERED, new StoreDuplicateValidationResponse(store.getId()));
});
if (universityStoreFinder.findByUniversityIdAndStore(universityId, store)) {
throw new ConflictException(StoreErrorCode.STORE_ALREADY_REGISTERED, new StoreDuplicateValidationResponse(store.getId()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

import lombok.RequiredArgsConstructor;
import org.hankki.hankkiserver.domain.store.model.Store;
import org.hankki.hankkiserver.domain.universitystore.model.UniversityStore;
import org.hankki.hankkiserver.domain.universitystore.repository.UniversityStoreRepository;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
@RequiredArgsConstructor
public class UniversityStoreFinder {

private final UniversityStoreRepository universityStoreRepository;

protected Optional<UniversityStore> findByUniversityIdAndStore(final Long universityId, final Store store) {
return universityStoreRepository.findByUniversityIdAndStore(universityId, store);
protected boolean findByUniversityIdAndStore(final Long universityId, final Store store) {
return universityStoreRepository.existsByUniversityIdAndStore(universityId, store);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import org.hankki.hankkiserver.domain.universitystore.model.UniversityStore;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface UniversityStoreRepository extends JpaRepository<UniversityStore, Long> {

Optional<UniversityStore> findByUniversityIdAndStore(Long universityId, Store store);
boolean existsByUniversityIdAndStore(Long universityId, Store store);
}

0 comments on commit 245c8ad

Please sign in to comment.