feat: add api server

This commit is contained in:
2026-01-03 19:06:35 +07:00
parent d864027c31
commit c9aa7261e6
4 changed files with 17 additions and 19 deletions

View File

@@ -2,7 +2,7 @@ CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE IF NOT EXISTS public."user" ( CREATE TABLE IF NOT EXISTS public."user" (
id text NOT NULL, 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, name text NOT NULL,
email text NOT NULL, email text NOT NULL,
email_verified boolean DEFAULT false NOT NULL, email_verified boolean DEFAULT false NOT NULL,

View File

@@ -1,6 +1,5 @@
-- name: UserExistsByIdentifier :one -- name: GetVerifiedEmailBySSHIdentifier :one
SELECT EXISTS ( SELECT email
SELECT 1 FROM public."user"
FROM public."user" WHERE ssh_identifier = $1
WHERE identifier = $1 AND email_verified = true;
) AS exists;

View File

@@ -37,7 +37,7 @@ type Session struct {
type User struct { type User struct {
ID string ID string
Identifier string SshIdentifier string
Name string Name string
Email string Email string
EmailVerified bool EmailVerified bool

View File

@@ -9,17 +9,16 @@ import (
"context" "context"
) )
const userExistsByIdentifier = `-- name: UserExistsByIdentifier :one const getVerifiedEmailBySSHIdentifier = `-- name: GetVerifiedEmailBySSHIdentifier :one
SELECT EXISTS ( SELECT email
SELECT 1 FROM public."user"
FROM public."user" WHERE ssh_identifier = $1
WHERE identifier = $1 AND email_verified = true
) AS exists
` `
func (q *Queries) UserExistsByIdentifier(ctx context.Context, identifier string) (bool, error) { func (q *Queries) GetVerifiedEmailBySSHIdentifier(ctx context.Context, sshIdentifier string) (string, error) {
row := q.db.QueryRow(ctx, userExistsByIdentifier, identifier) row := q.db.QueryRow(ctx, getVerifiedEmailBySSHIdentifier, sshIdentifier)
var exists bool var email string
err := row.Scan(&exists) err := row.Scan(&email)
return exists, err return email, err
} }