uuid used

This commit is contained in:
2026-02-20 15:06:15 +02:00
parent 35e83ed705
commit 8546ad496f
31 changed files with 265 additions and 238 deletions
+4 -3
View File
@@ -3,6 +3,7 @@ package maindb
import (
"context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
)
@@ -19,7 +20,7 @@ func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) e
return err
}
func (db *Database) UpdateAccountByID(ctx context.Context, accountID string, account *descr.Account) error {
func (db *Database) UpdateAccountByID(ctx context.Context, accountID auxuuid.UUID, account *descr.Account) error {
var err error
request := `UPDATE accounts SET username = $1, passhash = $2, disabled = $3, updated_at = $4, updated_by = $5 WHERE id = $6`
_, err = db.db.Exec(request, account.Username, account.Passhash, account.Disabled, account.UpdatedAt, account.UpdatedBy, accountID)
@@ -51,7 +52,7 @@ func (db *Database) ListAccounts(ctx context.Context) ([]descr.Account, error) {
return res, err
}
func (db *Database) GetAccountByID(ctx context.Context, accountID string) (bool, *descr.Account, error) {
func (db *Database) GetAccountByID(ctx context.Context, accountID auxuuid.UUID) (bool, *descr.Account, error) {
var err error
var res *descr.Account
var exists bool = false
@@ -90,7 +91,7 @@ func (db *Database) GetAccountByUsername(ctx context.Context, username string) (
return exists, res, err
}
func (db *Database) DeleteAccountByID(ctx context.Context, accountID string) error {
func (db *Database) DeleteAccountByID(ctx context.Context, accountID auxuuid.UUID) error {
var err error
request := `DELETE FROM accounts WHERE id = $1`
+2 -1
View File
@@ -12,6 +12,7 @@ package maindb
import (
"context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
)
@@ -27,7 +28,7 @@ func (db *Database) InsertFile(ctx context.Context, file *descr.File) error {
return err
}
func (db *Database) UpdateFileByID(ctx context.Context, fileID string, file *descr.File) error {
func (db *Database) UpdateFileByID(ctx context.Context, fileID auxuuid.UUID, file *descr.File) error {
var err error
request := `UPDATE files SET id = $1, collection = $2, name = $3, type = $4, checksum = $5,
size = $6, updated_at = $7, created_by = $8, updated_by = $9
+1 -1
View File
@@ -35,7 +35,7 @@ func TestFile(t *testing.T) {
id := auxuuid.NewUUID()
timenow := auxtool.TimeNow()
creator := "some"
creator := auxuuid.NewUUID()
collection := "foo"
newFile := &descr.File{
ID: id,
+10 -9
View File
@@ -12,6 +12,7 @@ package maindb
import (
"context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
)
@@ -27,7 +28,7 @@ func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
return err
}
func (db *Database) UpdateGrantByID(ctx context.Context, grantID string, grant *descr.Grant) error {
func (db *Database) UpdateGrantByID(ctx context.Context, grantID auxuuid.UUID, grant *descr.Grant) error {
var err error
request := `UPDATE grants SET pattern = $1, updated_at = $2, updated_by = $3 WHERE id = $4`
_, err = db.db.Exec(request, grant.Pattern, grant.UpdatedAt, grant.UpdatedBy, grantID)
@@ -37,7 +38,7 @@ func (db *Database) UpdateGrantByID(ctx context.Context, grantID string, grant *
return err
}
func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID string) ([]descr.Grant, error) {
func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID auxuuid.UUID) ([]descr.Grant, error) {
var err error
request := `SELECT * FROM grants WHERE account_id = $1`
res := make([]descr.Grant, 0)
@@ -59,7 +60,7 @@ func (db *Database) ListGrants(ctx context.Context) ([]descr.Grant, error) {
return res, err
}
func (db *Database) GetGrantByID(ctx context.Context, id string) (bool, *descr.Grant, error) {
func (db *Database) GetGrantByID(ctx context.Context, id auxuuid.UUID) (bool, *descr.Grant, error) {
var err error
res := &descr.Grant{}
request := `SELECT * FROM grants WHERE id = $1 LIMIT 1`
@@ -76,7 +77,7 @@ func (db *Database) GetGrantByID(ctx context.Context, id string) (bool, *descr.G
return true, res, err
}
func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID, right string) (bool, *descr.Grant, error) {
func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID auxuuid.UUID, right string) (bool, *descr.Grant, error) {
var err error
res := &descr.Grant{}
request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2 LIMIT 1`
@@ -93,7 +94,7 @@ func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID, rig
return true, res, err
}
func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID, right string) (bool, []descr.Grant, error) {
func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID auxuuid.UUID, right string) (bool, []descr.Grant, error) {
var err error
request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2`
res := make([]descr.Grant, 0)
@@ -107,7 +108,7 @@ func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID, r
return true, res, err
}
func (db *Database) GetGrantByAccoundIDRightPattern(ctx context.Context, accountID, right, pattern string) (bool, *descr.Grant, error) {
func (db *Database) GetGrantByAccoundIDRightPattern(ctx context.Context, accountID auxuuid.UUID, right, pattern string) (bool, *descr.Grant, error) {
var err error
res := &descr.Grant{}
request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2 AND pattern = $3 LIMIT 1`
@@ -124,7 +125,7 @@ func (db *Database) GetGrantByAccoundIDRightPattern(ctx context.Context, account
return true, res, err
}
func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, accountID, right, pattern string) error {
func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, accountID auxuuid.UUID, right, pattern string) error {
var err error
request := `DELETE FROM grants WHERE account_id = $1 AND right = $2 AND pattern = $3`
_, err = db.db.Exec(request, accountID, right, pattern)
@@ -134,7 +135,7 @@ func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, acco
return err
}
func (db *Database) DeleteGrantByID(ctx context.Context, grantID string) error {
func (db *Database) DeleteGrantByID(ctx context.Context, grantID auxuuid.UUID) error {
var err error
request := `DELETE FROM grants WHERE id = $1`
_, err = db.db.Exec(request, grantID)
@@ -144,7 +145,7 @@ func (db *Database) DeleteGrantByID(ctx context.Context, grantID string) error {
return err
}
func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID string) error {
func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID auxuuid.UUID) error {
var err error
request := `DELETE FROM grants WHERE account_id = $1`
_, err = db.db.Exec(request, grantID)
+5 -1
View File
@@ -11,6 +11,7 @@ package maindb
import (
"context"
"fmt"
"testing"
"time"
@@ -36,7 +37,7 @@ func TestGrant(t *testing.T) {
id := auxuuid.NewUUID()
accountID := auxuuid.NewUUID()
timenow := auxtool.TimeNow()
creator := "some"
creator := auxuuid.NewUUID()
newGrant := &descr.Grant{
ID: id,
AccountID: accountID,
@@ -57,4 +58,7 @@ func TestGrant(t *testing.T) {
require.Equal(t, len(files), 1)
require.Equal(t, files[0].ID, id)
require.Equal(t, files[0].AccountID, accountID)
require.Equal(t, files[0].CreatedBy, creator)
fmt.Println(files[0].CreatedBy)
}