This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.soune.nocopy.entity.payout.PayoutMethod;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface PayoutMethodRepository extends JpaRepository<PayoutMethod, String> {
|
||||
|
||||
Optional<PayoutMethod> findByIdAndUserId(Long id, Long userId);
|
||||
|
||||
@Query("SELECT p FROM PayoutMethod p WHERE p.user.Id = :userId AND TYPE(p) = :type")
|
||||
Optional<PayoutMethod> findByUserAndType(@Param("userId") Long userId,
|
||||
@Param("type") Class<? extends PayoutMethod> type);
|
||||
|
||||
List<PayoutMethod> findByUserId(Long userId);
|
||||
|
||||
Optional<PayoutMethod> findByUserIdAndIsDefaultTrue(Long userId);
|
||||
|
||||
long countByUserId(Long userId);
|
||||
|
||||
@Query("SELECT COUNT(c) > 0 FROM CardPayoutMethod c WHERE c.cardHash = :cardHash")
|
||||
boolean existsByCardHash(@Param("cardHash") String cardHash);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE PayoutMethod p SET p.isDefault = false WHERE p.user.id = :userId AND p.id != :methodId")
|
||||
void clearOtherDefault(@Param("userId") Long userId, @Param("methodId") Long methodId);
|
||||
|
||||
Long user(User user);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.soune.nocopy.entity.payout.PayoutRequest;
|
||||
import ru.soune.nocopy.entity.payout.PayoutRequestStatus;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface PayoutRequestRepository extends JpaRepository<PayoutRequest, Long> {
|
||||
|
||||
List<PayoutRequest> findByUserIdOrderByCreatedAtDesc(Long userId);
|
||||
|
||||
Page<PayoutRequest> findByUserId(Long userId, Pageable pageable);
|
||||
|
||||
Optional<PayoutRequest> findByIdAndUserId(Long id, Long userId);
|
||||
|
||||
@Query("SELECT COALESCE(SUM(pr.amount), 0) FROM PayoutRequest pr " +
|
||||
"WHERE pr.user.Id = :userId AND pr.status = 'COMPLETED'")
|
||||
BigDecimal getTotalPayoutAmountByUser(@Param("userId") Long userId);
|
||||
|
||||
boolean existsByUserIdAndStatusIn(Long userId, List<PayoutRequestStatus> statuses);
|
||||
|
||||
List<PayoutRequest> findByStatusOrderByCreatedAtAsc(PayoutRequestStatus status);
|
||||
|
||||
Page<PayoutRequest> findByStatus(PayoutRequestStatus status, Pageable pageable);
|
||||
|
||||
@Query("SELECT pr FROM PayoutRequest pr WHERE pr.status = 'PENDING' " +
|
||||
"AND pr.createdAt < :threshold")
|
||||
List<PayoutRequest> findPendingOlderThan(@Param("threshold") LocalDateTime threshold);
|
||||
}
|
||||
@@ -24,7 +24,10 @@ public interface ReferralJpaRepository extends JpaRepository<Referral, Long> {
|
||||
List<Referral> findByInviterId(Long inviterId, Pageable pageable);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE Referral r SET r.totalIncome = r.totalIncome + :amount WHERE r.userId = :userId")
|
||||
@Query("UPDATE Referral r SET " +
|
||||
"r.availableIncome = r.availableIncome + :amount ," +
|
||||
"r.totalIncome = r.totalIncome + :amount " +
|
||||
"WHERE r.userId = :userId")
|
||||
void increaseIncome(@Param("userId") Long userId, @Param("amount") int amount);
|
||||
|
||||
@Modifying
|
||||
|
||||
Reference in New Issue
Block a user