Last active
August 15, 2022 13:18
-
-
Save dipeshhkc/675dc924d33be80a7cbe7f1e3a5bec83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (u userController) TransferMoney(c *gin.Context) { | |
log.Print("[UserController]...get all Users") | |
txHandle := c.MustGet("db_trx").(*gorm.DB) | |
var moneyTransfer model.MoneyTransfer | |
if err := c.ShouldBindJSON(&moneyTransfer); err != nil { | |
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | |
return | |
} | |
if err := u.userService.WithTrx(txHandle).IncrementMoney(moneyTransfer.Receiver, moneyTransfer.Amount); err != nil { | |
c.JSON(http.StatusBadRequest, gin.H{"error": "Error while incrementing money"}) | |
return | |
} | |
if err := u.userService.WithTrx(txHandle).DecrementMoney(moneyTransfer.Giver, moneyTransfer.Amount); err != nil { | |
c.JSON(http.StatusBadRequest, gin.H{"error": "Error while decrementing money"}) | |
return | |
} | |
c.JSON(http.StatusOK, gin.H{"msg": "Successfully Money Transferred"}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment