working commit
This commit is contained in:
@@ -3,7 +3,7 @@ package maindb
|
||||
import (
|
||||
"context"
|
||||
|
||||
"mbase/app/descr"
|
||||
"mbase/pkg/descr"
|
||||
)
|
||||
|
||||
func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) error {
|
||||
@@ -19,7 +19,7 @@ func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) e
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *Database) UpdateAccountByID(ctx context.Context, accountID int64, account *descr.Account) error {
|
||||
func (db *Database) UpdateAccountByID(ctx context.Context, accountID string, account *descr.Account) error {
|
||||
var err error
|
||||
|
||||
request := `UPDATE account SET username = $1, passhash = $2, disabled = $3, updated_at = $4 WHERE id = $5`
|
||||
@@ -52,7 +52,7 @@ func (db *Database) CompletedListAccounts(ctx context.Context) ([]descr.Account,
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (db *Database) GetAccountByID(ctx context.Context, accountID int64) (bool, *descr.Account, error) {
|
||||
func (db *Database) GetAccountByID(ctx context.Context, accountID string) (bool, *descr.Account, error) {
|
||||
var err error
|
||||
var res *descr.Account
|
||||
var exists bool
|
||||
@@ -91,7 +91,7 @@ func (db *Database) GetAccountByUsername(ctx context.Context, username string) (
|
||||
return exists, res, err
|
||||
}
|
||||
|
||||
func (db *Database) DeleteAccountByID(ctx context.Context, accountID int64) error {
|
||||
func (db *Database) DeleteAccountByID(ctx context.Context, accountID string) error {
|
||||
var err error
|
||||
|
||||
request := `DELETE FROM account WHERE id = $1`
|
||||
|
||||
+3
-34
@@ -11,39 +11,9 @@ import (
|
||||
)
|
||||
|
||||
const schema = `
|
||||
--- DROP TABLE IF EXISTS issuer;
|
||||
CREATE TABLE IF NOT EXISTS issuer (
|
||||
id INT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
cert TEXT NOT NULL,
|
||||
key TEXT,
|
||||
signer_id INT NOT NULL,
|
||||
signer_name TEXT NOT NULL,
|
||||
revoked BOOL
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS issuer_index01
|
||||
ON issuer(id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS issuer_index02
|
||||
ON issuer(name);
|
||||
|
||||
--- DROP TABLE IF EXISTS service;
|
||||
CREATE TABLE IF NOT EXISTS service (
|
||||
id INT NOT NULL,
|
||||
issuer_id INT NOT NULL,
|
||||
issuer_name TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
cert TEXT NOT NULL,
|
||||
key TEXT NOT NULL,
|
||||
revoked BOOL
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS service_index01
|
||||
ON service(id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS service_index02
|
||||
ON service(name);
|
||||
|
||||
--- DROP TABLE IF EXISTS account;
|
||||
CREATE TABLE IF NOT EXISTS account (
|
||||
id INT NOT NULL,
|
||||
id TEXT NOT NULL,
|
||||
username TEXT NOT NULL,
|
||||
passhash TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
@@ -55,11 +25,10 @@ const schema = `
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS account_index02
|
||||
ON account(username);
|
||||
|
||||
|
||||
--- DROP TABLE IF EXISTS grant;
|
||||
CREATE TABLE IF NOT EXISTS grant (
|
||||
id INT NOT NULL,
|
||||
account_id INT NOT NULL,
|
||||
id TEXT NOT NULL,
|
||||
account_id TEXT NOT NULL,
|
||||
operation TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
+5
-5
@@ -3,7 +3,7 @@ package maindb
|
||||
import (
|
||||
"context"
|
||||
|
||||
"mbase/app/descr"
|
||||
"mbase/pkg/descr"
|
||||
)
|
||||
|
||||
func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
|
||||
@@ -17,7 +17,7 @@ func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID int64) ([]descr.Grant, error) {
|
||||
func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID string) ([]descr.Grant, error) {
|
||||
var err error
|
||||
request := `SELECT * FROM grant WHERE account_id = $1`
|
||||
res := make([]descr.Grant, 0)
|
||||
@@ -39,7 +39,7 @@ func (db *Database) ListGrants(ctx context.Context) ([]descr.Grant, error) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (db *Database) GetGrant(ctx context.Context, accountID int64, operation string) (bool, *descr.Grant, error) {
|
||||
func (db *Database) GetGrant(ctx context.Context, accountID, operation string) (bool, *descr.Grant, error) {
|
||||
var err error
|
||||
res := &descr.Grant{}
|
||||
request := `SELECT * FROM grant WHERE account_id = $1 AND operation = $2 LIMIT 1`
|
||||
@@ -56,7 +56,7 @@ func (db *Database) GetGrant(ctx context.Context, accountID int64, operation str
|
||||
return true, res, err
|
||||
}
|
||||
|
||||
func (db *Database) DeleteGrantByAccountID(ctx context.Context, grantID int64, operation string) error {
|
||||
func (db *Database) DeleteGrantByAccountID(ctx context.Context, grantID, operation string) error {
|
||||
var err error
|
||||
request := `DELETE FROM grant WHERE account_id = $1 AND operation = $2`
|
||||
_, err = db.db.Exec(request, grantID, operation)
|
||||
@@ -66,7 +66,7 @@ func (db *Database) DeleteGrantByAccountID(ctx context.Context, grantID int64, o
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID int64) error {
|
||||
func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID string) error {
|
||||
var err error
|
||||
request := `DELETE FROM grant WHERE account_id = $1`
|
||||
_, err = db.db.Exec(request, grantID)
|
||||
|
||||
Reference in New Issue
Block a user