@@ -0,0 +1,40 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
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.referral.Referral;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ReferralJpaRepository extends JpaRepository<Referral, Long> {
|
||||
Referral findByReferralLink(String link);
|
||||
|
||||
Referral findByUserId(Long userId);
|
||||
|
||||
List<Referral> findByInviterId(Long inviterId);
|
||||
|
||||
@Query("SELECT r FROM Referral r WHERE r.inviterId = :userId AND r.isActive = true")
|
||||
List<Referral> findByInviterId(Long inviterId, Pageable pageable);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE Referral r SET r.totalIncome = r.totalIncome + :amount WHERE r.userId = :userId")
|
||||
void increaseIncome(@Param("userId") Long userId, @Param("amount") int amount);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE Referral r SET r.levelId = :newLevelId WHERE r.userId = :userId")
|
||||
void updateLevel(@Param("userId") Long userId, @Param("newLevelId") String newLevelId);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE Referral r SET r.isActive = true WHERE r.userId = :userId")
|
||||
void activateUser(@Param("userId") Long userId);
|
||||
|
||||
@Query("SELECT COUNT(r) FROM Referral r WHERE r.inviterId = :userId AND r.isActive = true")
|
||||
int countActiveInvitees(@Param("userId") Long userId);
|
||||
|
||||
@Query("SELECT COUNT(r) FROM Referral r WHERE r.inviterId = :userId")
|
||||
int countTotalInvitees(@Param("userId") Long userId);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.soune.nocopy.entity.referral.ReferralLevelEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ReferralLevelRepository extends JpaRepository<ReferralLevelEntity, Long> {
|
||||
List<ReferralLevelEntity> findAllByOrderByMinInviteesAsc();
|
||||
ReferralLevelEntity findById(String id);
|
||||
}
|
||||
Reference in New Issue
Block a user