working commit

This commit is contained in:
2026-02-12 12:00:17 +02:00
parent ae15bddb15
commit b279687623
20 changed files with 639 additions and 192 deletions
+47 -9
View File
@@ -8,9 +8,20 @@ import (
func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
var err error
request := `INSERT INTO grants(id, account_id, operation, created_at)
VALUES ($1, $2, $3, $4)`
_, err = db.db.Exec(request, grant.ID, grant.AccountID, grant.Operation, grant.CreatedAt)
request := `INSERT INTO grants(id, account_id, operation, pattern, created_at, updated_at, created_by, updated_by)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`
_, err = db.db.Exec(request, grant.ID, grant.AccountID, grant.Operation, grant.Pattern,
grant.CreatedAt, grant.UpdatedAt, grant.CreatedBy, grant.UpdatedBy)
if err != nil {
return err
}
return err
}
func (db *Database) UpdateGrantByID(ctx context.Context, grantID string, grant *descr.Grant) error {
var err error
request := `UPDATE accounts SET pattern = $1, updated_at = $2, updated_by = $3 WHERE id = $4`
_, err = db.db.Exec(request, grant.Pattern, grant.UpdatedAt, grant.UpdatedBy, grantID)
if err != nil {
return err
}
@@ -39,12 +50,12 @@ func (db *Database) ListGrants(ctx context.Context) ([]descr.Grant, error) {
return res, err
}
func (db *Database) GetGrant(ctx context.Context, accountID, operation string) (bool, *descr.Grant, error) {
func (db *Database) GetGrantByID(ctx context.Context, id string) (bool, *descr.Grant, error) {
var err error
res := &descr.Grant{}
request := `SELECT * FROM grants WHERE account_id = $1 AND operation = $2 LIMIT 1`
request := `SELECT * FROM grants WHERE id = $1 LIMIT 1`
dbRes := make([]descr.Grant, 0)
err = db.db.Select(&dbRes, request, accountID, operation)
err = db.db.Select(&dbRes, request, id)
if err != nil {
return false, res, err
}
@@ -56,10 +67,37 @@ func (db *Database) GetGrant(ctx context.Context, accountID, operation string) (
return true, res, err
}
func (db *Database) DeleteGrantByAccountID(ctx context.Context, grantID, operation string) error {
func (db *Database) GetGrantByAccoundIDOperationPattern(ctx context.Context, accountID, operation, pattern string) (bool, *descr.Grant, error) {
var err error
request := `DELETE FROM grants WHERE account_id = $1 AND operation = $2`
_, err = db.db.Exec(request, grantID, operation)
res := &descr.Grant{}
request := `SELECT * FROM grants WHERE account_id = $1 AND operation = $2 AND pattern = $3 LIMIT 1`
dbRes := make([]descr.Grant, 0)
err = db.db.Select(&dbRes, request, accountID, operation, pattern)
if err != nil {
return false, res, err
}
if len(dbRes) == 0 {
return false, res, err
}
res = &dbRes[0]
return true, res, err
}
func (db *Database) DeleteGrantByAccountIDOperationPattern(ctx context.Context, accountID, operation, pattern string) error {
var err error
request := `DELETE FROM grants WHERE account_id = $1 AND operation = $2 AND pattern = $3`
_, err = db.db.Exec(request, accountID, operation, pattern)
if err != nil {
return err
}
return err
}
func (db *Database) DeleteGrantByID(ctx context.Context, grantID string) error {
var err error
request := `DELETE FROM grants WHERE id = $1`
_, err = db.db.Exec(request, grantID)
if err != nil {
return err
}