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
[request_definition] | |
r = sub, obj, act | |
[policy_definition] | |
p = sub, obj, act | |
[role_definition] | |
g = _, _ | |
[policy_effect] |
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
# Request definition | |
[request_definition] | |
r = sub, obj, act | |
# Policy definition | |
[policy_definition] | |
p = sub, obj, act | |
# Policy effect | |
[policy_effect] |
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
//(1/3) Snippet to getting first error(works even if nested case) | |
import { isObject } from "lodash"; | |
export const getFirstErrorKey = (object: any, keys: string[] = []): any => { | |
let firstErrorKey = ""; | |
if (Array.isArray(object)) { | |
for (let i = 0; i < object.length; i++) { | |
if (object[i]) { | |
firstErrorKey = Object.keys(object)[i]; | |
break; |
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
// WithTrx enables repository with transaction | |
func (u userRepository) WithTrx(trxHandle *gorm.DB) userRepository { | |
if trxHandle == nil { | |
log.Print("Transaction Database not found") | |
return u | |
} | |
u.DB = trxHandle | |
return u | |
} | |
func (u userRepository) IncrementMoney(receiver uint, amount float64) error { |
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
// WithTrx enables service with repository containing of transaction | |
func (u userService) WithTrx(trxHandle *gorm.DB) userService { | |
u.userRepository = u.userRepository.WithTrx(trxHandle) | |
return u | |
} | |
func (u userService) IncrementMoney(receiver uint, amount float64) error { | |
return u.userRepository.IncrementMoney(receiver, amount) | |
} |
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 | |
} |
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
router.POST("/money-transfer", middleware.DBTransactionMiddleware(db), userController.TransferMoney) |
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
//StatusInList -> checks if the given status is in the list | |
func StatusInList(status int, statusList []int) bool { | |
for _, i := range statusList { | |
if i == status { | |
return true | |
} | |
} | |
return false | |
} |
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
// begin a transaction | |
tx := db.Begin() | |
// do some database operations in the transaction (use 'tx' from this point, not 'db') | |
tx.Create(...) | |
// ... | |
// rollback the transaction in case of error | |
tx.Rollback() |
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
=CONCATENATE("INSERT INTO gifts(name,gift_image,coin_value,category,created_at,updated_at) values(","'",A1,"','gif/",B1,".gif',",J1,",'",K1,"','2021-02-23 10:37:32','2021-02-23 10:37:32'",");") |