TastingRepository.java
1,830 bytes
| 1 | package com.tasteprint.tasting; |
|---|---|
| 2 | |
| 3 | import java.time.LocalDate; |
| 4 | import java.util.List; |
| 5 | import java.util.Optional; |
| 6 | import java.util.UUID; |
| 7 | |
| 8 | import org.springframework.data.domain.Page; |
| 9 | import org.springframework.data.domain.Pageable; |
| 10 | import org.springframework.data.jpa.repository.JpaRepository; |
| 11 | import org.springframework.data.jpa.repository.Query; |
| 12 | import org.springframework.data.repository.query.Param; |
| 13 | |
| 14 | interface TastingRepository extends JpaRepository<Tasting, UUID> { |
| 15 | |
| 16 | Optional<Tasting> findByIdAndUserId(UUID id, UUID userId); |
| 17 | |
| 18 | Page<Tasting> findByUserIdOrderByTastedOnDescCreatedAtDesc(UUID userId, Pageable pageable); |
| 19 | |
| 20 | List<Tasting> findTop6ByUserIdOrderByTastedOnDescCreatedAtDesc(UUID userId); |
| 21 | |
| 22 | long countByUserId(UUID userId); |
| 23 | |
| 24 | long countByUserIdAndPhotoUrl(UUID userId, String photoUrl); |
| 25 | |
| 26 | @Query("select distinct t.dishSlug from Tasting t where t.userId = :userId") |
| 27 | List<String> findDistinctDishSlugsByUserId(@Param("userId") UUID userId); |
| 28 | |
| 29 | @Query(""" |
| 30 | select distinct t.dishSlug from Tasting t |
| 31 | where t.userId = :userId |
| 32 | and t.countryCode = :countryCode |
| 33 | and t.tastedOn between :startsOn and :endsOn |
| 34 | """) |
| 35 | List<String> findDistinctDishSlugsDuring( |
| 36 | @Param("userId") UUID userId, |
| 37 | @Param("countryCode") String countryCode, |
| 38 | @Param("startsOn") LocalDate startsOn, |
| 39 | @Param("endsOn") LocalDate endsOn |
| 40 | ); |
| 41 | |
| 42 | @Query(""" |
| 43 | select distinct t.dishSlug from Tasting t |
| 44 | where t.userId = :userId |
| 45 | and t.tastedOn between :startsOn and :endsOn |
| 46 | """) |
| 47 | List<String> findDistinctDishSlugsBetween( |
| 48 | @Param("userId") UUID userId, |
| 49 | @Param("startsOn") LocalDate startsOn, |
| 50 | @Param("endsOn") LocalDate endsOn |
| 51 | ); |
| 52 | } |
| 53 | |