feat: add api server
This commit is contained in:
@@ -2,7 +2,7 @@ CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public."user" (
|
||||
id text NOT NULL,
|
||||
identifier text UNIQUE NOT NULL DEFAULT substr(encode(gen_random_bytes(16), 'hex'), 1, 32),
|
||||
ssh_identifier text UNIQUE NOT NULL DEFAULT substr(encode(gen_random_bytes(16), 'hex'), 1, 32),
|
||||
name text NOT NULL,
|
||||
email text NOT NULL,
|
||||
email_verified boolean DEFAULT false NOT NULL,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
-- name: UserExistsByIdentifier :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM public."user"
|
||||
WHERE identifier = $1
|
||||
) AS exists;
|
||||
-- name: GetVerifiedEmailBySSHIdentifier :one
|
||||
SELECT email
|
||||
FROM public."user"
|
||||
WHERE ssh_identifier = $1
|
||||
AND email_verified = true;
|
||||
|
||||
@@ -37,7 +37,7 @@ type Session struct {
|
||||
|
||||
type User struct {
|
||||
ID string
|
||||
Identifier string
|
||||
SshIdentifier string
|
||||
Name string
|
||||
Email string
|
||||
EmailVerified bool
|
||||
|
||||
@@ -9,17 +9,16 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const userExistsByIdentifier = `-- name: UserExistsByIdentifier :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM public."user"
|
||||
WHERE identifier = $1
|
||||
) AS exists
|
||||
const getVerifiedEmailBySSHIdentifier = `-- name: GetVerifiedEmailBySSHIdentifier :one
|
||||
SELECT email
|
||||
FROM public."user"
|
||||
WHERE ssh_identifier = $1
|
||||
AND email_verified = true
|
||||
`
|
||||
|
||||
func (q *Queries) UserExistsByIdentifier(ctx context.Context, identifier string) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, userExistsByIdentifier, identifier)
|
||||
var exists bool
|
||||
err := row.Scan(&exists)
|
||||
return exists, err
|
||||
func (q *Queries) GetVerifiedEmailBySSHIdentifier(ctx context.Context, sshIdentifier string) (string, error) {
|
||||
row := q.db.QueryRow(ctx, getVerifiedEmailBySSHIdentifier, sshIdentifier)
|
||||
var email string
|
||||
err := row.Scan(&email)
|
||||
return email, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user