Skip to content

Commit

Permalink
pass string instead of enum to sql query (#77)
Browse files Browse the repository at this point in the history
* pass string instead of enum to sql query

* java format :x
  • Loading branch information
a-lor-cab authored Nov 17, 2023
1 parent 253e717 commit 4a21e69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
public interface SpotlightBatchRepository extends JpaRepository<SpotlightBatch, UUID> {

@Query("select (count(s) > 0) from SpotlightBatch s where s.status = ?1 AND SIZE(s.spotlightSubmissions) < ?2")
Boolean existsByStatus(SpotlightBatchStatus status, int maxSize);
Boolean existsByStatus(String status, int maxSize);

@Query("SELECT sb FROM SpotlightBatch sb WHERE sb.status = ?1 AND SIZE(sb.spotlightSubmissions) < ?2")
Optional<SpotlightBatch> findByStatusAndSpotlightSubmissionsSizeLessThan(SpotlightBatchStatus status, int maxSize);
Optional<SpotlightBatch> findByStatusAndSpotlightSubmissionsSizeLessThan(String status, int maxSize);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ public class SpotlightBatchService {
private final SpotlightBatchRepository spotlightBatchRepository;

public Boolean spotlightBatchWithStatusExists(SpotlightBatchStatus status, int maxSize) {
return spotlightBatchRepository.existsByStatus(status, maxSize);
return spotlightBatchRepository.existsByStatus(status.toString(), maxSize);
}

public SpotlightBatch getSpotlightBatchWithStatus(SpotlightBatchStatus status, int maxSize) {
return spotlightBatchRepository.findByStatusAndSpotlightSubmissionsSizeLessThan(status, maxSize).orElseThrow(
() -> new NotFoundException("A spotlight batch with status " + status + " could not be found"));
return spotlightBatchRepository.findByStatusAndSpotlightSubmissionsSizeLessThan(status.toString(), maxSize)
.orElseThrow(
() -> new NotFoundException("A spotlight batch with status " + status + " could not be found"));
}

public SpotlightBatch createSpotlightBatch() {
Expand Down

0 comments on commit 4a21e69

Please sign in to comment.