diff options
| author | Kyren223 <Kyren223@proton.me> | 2025-01-22 17:23:18 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2025-01-22 17:23:18 +0200 |
| commit | a6ea05146050a8b2ae5963d4ea96434dc3005f37 (patch) | |
| tree | 09128a6f90a0aae8159e0575e11562409f525a1d /internal/data | |
| parent | 645247f4ef489c9084a7d8d30db89b083287f0c6 (diff) | |
Added the ability to trust/untrust users
Diffstat (limited to 'internal/data')
| -rw-r--r-- | internal/data/models.go | 2 | ||||
| -rw-r--r-- | internal/data/trusted_and_blocked_users.sql.go | 95 |
2 files changed, 96 insertions, 1 deletions
diff --git a/internal/data/models.go b/internal/data/models.go index 8815e0b..9bc2961 100644 --- a/internal/data/models.go +++ b/internal/data/models.go @@ -56,7 +56,7 @@ type Network struct { type TrustedUser struct { TrustingUserID snowflake.ID TrustedUserID snowflake.ID - TrustedPublicKey []byte + TrustedPublicKey ed25519.PublicKey } type User struct { diff --git a/internal/data/trusted_and_blocked_users.sql.go b/internal/data/trusted_and_blocked_users.sql.go new file mode 100644 index 0000000..436b8d9 --- /dev/null +++ b/internal/data/trusted_and_blocked_users.sql.go @@ -0,0 +1,95 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 +// source: trusted_and_blocked_users.sql + +package data + +import ( + "context" + + "crypto/ed25519" + "github.com/kyren223/eko/pkg/snowflake" +) + +const getTrustedPublicKey = `-- name: GetTrustedPublicKey :one +SELECT trusted_public_key FROM trusted_users +WHERE trusting_user_id = ? AND trusted_user_id = ? +` + +type GetTrustedPublicKeyParams struct { + TrustingUserID snowflake.ID + TrustedUserID snowflake.ID +} + +func (q *Queries) GetTrustedPublicKey(ctx context.Context, arg GetTrustedPublicKeyParams) (ed25519.PublicKey, error) { + row := q.db.QueryRowContext(ctx, getTrustedPublicKey, arg.TrustingUserID, arg.TrustedUserID) + var trusted_public_key ed25519.PublicKey + err := row.Scan(&trusted_public_key) + return trusted_public_key, err +} + +const getUserTrusteds = `-- name: GetUserTrusteds :many +SELECT trusted_user_id, trusted_public_key FROM trusted_users +WHERE trusting_user_id = ? +` + +type GetUserTrustedsRow struct { + TrustedUserID snowflake.ID + TrustedPublicKey ed25519.PublicKey +} + +func (q *Queries) GetUserTrusteds(ctx context.Context, trustingUserID snowflake.ID) ([]GetUserTrustedsRow, error) { + rows, err := q.db.QueryContext(ctx, getUserTrusteds, trustingUserID) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GetUserTrustedsRow + for rows.Next() { + var i GetUserTrustedsRow + if err := rows.Scan(&i.TrustedUserID, &i.TrustedPublicKey); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const trustUser = `-- name: TrustUser :exec +INSERT OR IGNORE INTO trusted_users ( + trusting_user_id, trusted_user_id, trusted_public_key +) VALUES (?, ?, ?) +` + +type TrustUserParams struct { + TrustingUserID snowflake.ID + TrustedUserID snowflake.ID + TrustedPublicKey ed25519.PublicKey +} + +func (q *Queries) TrustUser(ctx context.Context, arg TrustUserParams) error { + _, err := q.db.ExecContext(ctx, trustUser, arg.TrustingUserID, arg.TrustedUserID, arg.TrustedPublicKey) + return err +} + +const untrustUser = `-- name: UntrustUser :exec +DELETE FROM trusted_users +WHERE trusting_user_id = ? AND trusted_user_id = ? +` + +type UntrustUserParams struct { + TrustingUserID snowflake.ID + TrustedUserID snowflake.ID +} + +func (q *Queries) UntrustUser(ctx context.Context, arg UntrustUserParams) error { + _, err := q.db.ExecContext(ctx, untrustUser, arg.TrustingUserID, arg.TrustedUserID) + return err +} |
