From c9aa7261e6f8cefd7b9bee0e95d2e4f9df09a372 Mon Sep 17 00:00:00 2001 From: bagas Date: Sat, 3 Jan 2026 19:06:35 +0700 Subject: [PATCH] feat: add api server --- db/sqlc/migrations/000001_init_schema.up.sql | 2 +- db/sqlc/queries/query.sql | 11 +++++----- db/sqlc/repository/models.go | 2 +- db/sqlc/repository/query.sql.go | 21 ++++++++++---------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/db/sqlc/migrations/000001_init_schema.up.sql b/db/sqlc/migrations/000001_init_schema.up.sql index 6a793a3..fe65b81 100644 --- a/db/sqlc/migrations/000001_init_schema.up.sql +++ b/db/sqlc/migrations/000001_init_schema.up.sql @@ -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, diff --git a/db/sqlc/queries/query.sql b/db/sqlc/queries/query.sql index c609363..8a26c5b 100644 --- a/db/sqlc/queries/query.sql +++ b/db/sqlc/queries/query.sql @@ -1,6 +1,5 @@ --- name: UserExistsByIdentifier :one -SELECT EXISTS ( - SELECT 1 - FROM public."user" - WHERE identifier = $1 -) AS exists; \ No newline at end of file +-- name: GetVerifiedEmailBySSHIdentifier :one +SELECT email +FROM public."user" +WHERE ssh_identifier = $1 + AND email_verified = true; diff --git a/db/sqlc/repository/models.go b/db/sqlc/repository/models.go index 345378a..da90dbe 100644 --- a/db/sqlc/repository/models.go +++ b/db/sqlc/repository/models.go @@ -37,7 +37,7 @@ type Session struct { type User struct { ID string - Identifier string + SshIdentifier string Name string Email string EmailVerified bool diff --git a/db/sqlc/repository/query.sql.go b/db/sqlc/repository/query.sql.go index acd965d..3aac782 100644 --- a/db/sqlc/repository/query.sql.go +++ b/db/sqlc/repository/query.sql.go @@ -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 }