dev add referral
Test Workflow / test (push) Successful in 3s

This commit is contained in:
vladp
2026-02-06 01:01:34 +07:00
parent 80c53515fb
commit f52ce6db3c
11 changed files with 258 additions and 16 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ package ru.soune
interface Referral {
val userId: String
val userId: Long
val referralLink: String
val inviter: String?
val currentLevel: String
+10 -10
View File
@@ -2,32 +2,32 @@ package ru.soune
interface ReferralRepo {
fun getUserReferralLink(userId: String): String
fun getUserReferralLink(userId: Long): String
fun getUserIdByLink(link: String): String
fun getInviterIdForUser(userId: String): String?
fun getInviterIdForUser(userId: Long): Long?
fun getReferralLevelForUser(userId: String): String
fun getReferralLevelForUser(userId: Long): String
fun getReferralByUserId(userId: String): Referral
fun getReferralByUserId(userId: Long): Referral
fun getReferralInvitees(userId: String, pageSize: Int, pageNumber: Int): List<ReferralInvitee>
fun getReferralInvitees(userId: Long, pageSize: Int, pageNumber: Int): List<ReferralInvitee>
// создаем новую запись в БД
fun createReferralEntity(entity: Referral)
// прибавить к totalIncome и availableIncome значение transferAmount
fun increaseIncome(userId: String, transferAmount: Int)
fun increaseIncome(userId: Long, transferAmount: Int)
// установить active в true
fun activateUser(userId: String): Boolean
fun activateUser(userId: Long): Boolean
// посчитать записи, у которых inviter == userId и active == true
fun getActiveInviteeForUser(userId: String): Int
fun getActiveInviteeForUser(userId: Long): Int
// посчитать записи, у которых inviter == userId
fun getTotalInviteeForUser(userId: String): Int
fun getTotalInviteeForUser(userId: Long): Int
fun upgradeReferralLevelForUser(userId: String, newLevelId: String)
fun upgradeReferralLevelForUser(userId: Long, newLevelId: String)
}
+5 -5
View File
@@ -5,7 +5,7 @@ class ReferralService(
private val referralRepo: ReferralRepo,
) {
fun onRegister(userId: String, inviterReferralLink: String?) {
fun onRegister(userId: Long, inviterReferralLink: String?) {
val initialReferralLevel = referralLevelProvider.getInitialReferralLevelId()
val referralLink = referralRepo.getUserReferralLink(userId)
val inviter = inviterReferralLink?.let(referralRepo::getUserIdByLink)
@@ -24,7 +24,7 @@ class ReferralService(
referralRepo.createReferralEntity(referral)
}
fun onUserAccountRefill(userId: String, transferAmount: Int) {
fun onUserAccountRefill(userId: Long, transferAmount: Int) {
val wasActivated = referralRepo.activateUser(userId)
val inviterId = referralRepo.getInviterIdForUser(userId) ?: return
val currentInviterLevel = referralRepo.getReferralLevelForUser(inviterId)
@@ -47,11 +47,11 @@ class ReferralService(
referralLevelProvider.getAvailableReferralLevels()
fun getReferralLevelForUser(userId: String): ReferralLevel =
fun getReferralLevelForUser(userId: Long): ReferralLevel =
referralRepo.getReferralLevelForUser(userId)
.let { referralLevelProvider.getReferralLevelById(it) }
fun getReferralStatForUser(userId: String): ReferralStat {
fun getReferralStatForUser(userId: Long): ReferralStat {
var referral = referralRepo.getReferralByUserId(userId)
return ReferralStat(
totalInvitee = referralRepo.getTotalInviteeForUser(userId),
@@ -62,6 +62,6 @@ class ReferralService(
)
}
fun getInviteeForUser(userId: String, pageSize: Int, pageNumber: Int): List<ReferralInvitee> =
fun getInviteeForUser(userId: Long, pageSize: Int, pageNumber: Int): List<ReferralInvitee> =
referralRepo.getReferralInvitees(userId, pageSize, pageNumber)
}