This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.soune.nocopy.entity.payment.Payment;
|
||||
|
||||
@@ -11,4 +12,23 @@ import java.util.Optional;
|
||||
public interface PaymentRepository extends JpaRepository<Payment, String> {
|
||||
Optional<Payment> findByPaymentUuid(String paymentUuid);
|
||||
List<Payment> findByUserId(Long userId);
|
||||
|
||||
@Query("""
|
||||
SELECT COALESCE(SUM(p.tariff.tokens), 0)
|
||||
FROM Payment p
|
||||
WHERE p.operationType = 'TOKEN'
|
||||
AND p.status = 'SUCCEEDED'
|
||||
""")
|
||||
Long getTotalTokensBought();
|
||||
|
||||
@Query("""
|
||||
SELECT
|
||||
p.user.Id,
|
||||
COALESCE(SUM(p.tariff.tokens), 0)
|
||||
FROM Payment p
|
||||
WHERE p.operationType = 'TOKEN'
|
||||
AND p.status = 'SUCCEEDED'
|
||||
GROUP BY p.user.Id
|
||||
""")
|
||||
List<Object[]> getTokensBoughtPerUser();
|
||||
}
|
||||
|
||||
@@ -38,4 +38,19 @@ public interface TokenOperationRepository extends JpaRepository<TokenOperation,
|
||||
Long sumSpentByUserAndType(@Param("userId") Long userId, @Param("operationType") OperationType operationType);
|
||||
|
||||
Long countByUserId(Long userId);
|
||||
|
||||
@Query("""
|
||||
SELECT COALESCE(SUM(t.spent), 0)
|
||||
FROM TokenOperation t
|
||||
""")
|
||||
Long getTotalTokensSpent();
|
||||
|
||||
@Query("""
|
||||
SELECT
|
||||
t.userId,
|
||||
COALESCE(SUM(t.spent), 0)
|
||||
FROM TokenOperation t
|
||||
GROUP BY t.userId
|
||||
""")
|
||||
List<Object[]> getTokensSpentPerUser();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user