dkforest

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

commit cabac784feb226da808d1495e241540d901bea96
parent 281a51d21b42c730ce02bd4c4b79173ce27827f3
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 18 Dec 2023 03:43:38 -0500

cleanup

Diffstat:
Mpkg/web/handlers/handlers.go | 49++++++++++++++++++++++++-------------------------
1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -12,6 +12,7 @@ import ( "dkforest/pkg/web/handlers/poker" hutils "dkforest/pkg/web/handlers/utils" "encoding/base64" + "errors" "fmt" "github.com/asaskevich/govalidator" humanize "github.com/dustin/go-humanize" @@ -896,34 +897,32 @@ func PokerHomeHandler(c echo.Context) error { } else if formName == "cash_out" { pokerTableSlug := c.Request().PostFormValue("table_slug") - tx := db.Begin() - g := poker.PokerInstance.GetGame(poker.RoomID(pokerTableSlug)) - if g != nil { - g.Players.Lock() - defer g.Players.Unlock() - if g.IsSeated2(authUser.Username) { - tx.Rollback() - data.ErrorTable = "Cannot cash out while seated" - return c.Render(http.StatusOK, "poker", data) + if err := db.WithE(func(tx *database.DkfDB) error { + g := poker.PokerInstance.GetGame(poker.RoomID(pokerTableSlug)) + if g != nil { + g.Players.Lock() + defer g.Players.Unlock() + if g.IsSeated2(authUser.Username) { + return errors.New("cannot cash out while seated") + } } - } - pokerTable, err := tx.GetPokerTableBySlug(pokerTableSlug) - if err != nil { - tx.Rollback() - data.ErrorTable = "table mot found" - return c.Render(http.StatusOK, "poker", data) - } - account, err := tx.GetPokerTableAccount(authUser.ID, pokerTable.ID) - if err != nil { - tx.Rollback() - data.ErrorTable = "failed to get table account" + pokerTable, err := tx.GetPokerTableBySlug(pokerTableSlug) + if err != nil { + return errors.New("table mot found") + } + account, err := tx.GetPokerTableAccount(authUser.ID, pokerTable.ID) + if err != nil { + return errors.New("failed to get table account") + } + authUser.IncrUserChips(pokerTable.IsTest, account.Amount, false) + account.Amount = 0 + account.DoSave(tx) + authUser.DoSave(tx) + return nil + }); err != nil { + data.ErrorTable = err.Error() return c.Render(http.StatusOK, "poker", data) } - authUser.IncrUserChips(pokerTable.IsTest, account.Amount, false) - account.Amount = 0 - account.DoSave(tx) - authUser.DoSave(tx) - tx.Commit() return c.Redirect(http.StatusFound, "/poker") } else if formName == "reset_chips" {