dkforest

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

commit 550e86ceda7df5a635eb12b75ece30d64017f05a
parent 3e56927b2f51c326e8b70d5026a4151109d1adbe
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 18 Dec 2023 15:18:08 -0500

cleanup

Diffstat:
Mpkg/database/tableUsers.go | 9+++++++++
Mpkg/web/handlers/handlers.go | 12++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go @@ -691,6 +691,15 @@ func (d *DkfDB) DecrUserBalance(userID UserID, isTest bool, amount PokerChip) (e return } +func (d *DkfDB) IncrUserBalance(userID UserID, isTest bool, amount PokerChip) (err error) { + if isTest { + err = d.db.Exec(`UPDATE users SET chips_test = chips_test + ? WHERE id = ?`, amount, userID).Error + } else { + err = d.db.Exec(`UPDATE users SET xmr_balance = xmr_balance + ? WHERE id = ?`, amount.ToPiconero(), userID).Error + } + return +} + func (u *User) GetXmrBalance(db *DkfDB) (amount Piconero, err error) { var tmp struct{ XmrBalance Piconero } err = db.db.Table("users").Select("xmr_balance").First(&tmp, "id = ?", u.ID).Error diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -895,6 +895,7 @@ func PokerHomeHandler(c echo.Context) error { } else if formName == "cash_out" { pokerTableSlug := c.Request().PostFormValue("table_slug") if err := db.WithE(func(tx *database.DkfDB) error { + authUserID := authUser.ID if g := poker.PokerInstance.GetGame(poker.RoomID(pokerTableSlug)); g != nil { g.Players.Lock() defer g.Players.Unlock() @@ -906,14 +907,17 @@ func PokerHomeHandler(c echo.Context) error { if err != nil { return errors.New("table mot found") } - account, err := tx.GetPokerTableAccount(authUser.ID, pokerTable.ID) + account, err := tx.GetPokerTableAccount(authUserID, pokerTable.ID) if err != nil { return errors.New("failed to get table account") } - authUser.IncrUserChips(pokerTable.IsTest, account.Amount, false) + if err := tx.IncrUserBalance(authUserID, pokerTable.IsTest, account.Amount); err != nil { + return errors.New("failed to update user's balance") + } account.Amount = 0 - account.DoSave(tx) - authUser.DoSave(tx) + if err := account.Save(tx); err != nil { + return errors.New("failed to update user's table account") + } return nil }); err != nil { data.ErrorTable = err.Error()