dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit e9aa1df7f2cb2f8fc2aa4147fc550937cd2167bd
parent 24cdce06d84d20a250d6313b0f0d04384ab76625
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 27 Dec 2023 12:04:38 -0500

display referred count

Diffstat:
Acmd/dkf/migrations/159.sql | 4++++
Mpkg/database/tableUsers.go | 6++++++
Mpkg/web/handlers/data.go | 1+
Mpkg/web/handlers/poker.go | 1+
Mpkg/web/public/views/pages/poker-rake-back.gohtml | 3+++
5 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/cmd/dkf/migrations/159.sql b/cmd/dkf/migrations/159.sql @@ -0,0 +1,4 @@ +-- +migrate Up +CREATE INDEX users_poker_referred_by_idx ON users (poker_referred_by); + +-- +migrate Down diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go @@ -754,3 +754,9 @@ func (d *DkfDB) IncrUserRakeBack(referredBy UserID, rakeBack PokerChip) (err err err = d.db.Exec(`UPDATE users SET poker_rake_back = poker_rake_back + ? WHERE id = ?`, uint64(rakeBack), int64(referredBy)).Error return } + +func (d *DkfDB) GetRakeBackReferredCount(userID UserID) (count int64, err error) { + var tmp struct{ Count int64 } + err = d.db.Raw(`SELECT COUNT(id) AS count FROM users WHERE poker_referred_by = ?`, int64(userID)).Scan(&tmp).Error + return tmp.Count, err +} diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go @@ -960,6 +960,7 @@ type TmpTable struct { type pokerRakeBackData struct { ReferralToken string ReferralURL string + ReferredCount int64 RakeBackPct float64 SetReferralError string } diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go @@ -333,6 +333,7 @@ func PokerRakeBackHandler(c echo.Context) error { var data pokerRakeBackData data.RakeBackPct = poker.RakeBackPct * 100 + data.ReferredCount, _ = db.GetRakeBackReferredCount(authUser.ID) pokerReferralToken := authUser.PokerReferralToken if pokerReferralToken != nil { data.ReferralToken = *pokerReferralToken diff --git a/pkg/web/public/views/pages/poker-rake-back.gohtml b/pkg/web/public/views/pages/poker-rake-back.gohtml @@ -39,6 +39,9 @@ <button class="btn btn-primary">Generate referral URL</button> </form> {{ end }} + <p> + You referred <strong>{{ .Data.ReferredCount }}</strong> users. + </p> <hr /> <p>