feat: sqlc generate

This commit is contained in:
2025-05-31 16:31:27 +02:00
parent 413a11ee63
commit e49c0bbe45
2 changed files with 33 additions and 22 deletions

View File

@ -7,23 +7,27 @@ package repository
import ( import (
"context" "context"
"github.com/jackc/pgx/v5/pgtype"
) )
const createApiService = `-- name: CreateApiService :one const createApiService = `-- name: CreateApiService :one
INSERT INTO api_services ( INSERT INTO api_services (
client_id, client_secret, name, redirect_uris, scopes, grant_types client_id, client_secret, name, description, redirect_uris, scopes, grant_types, is_active
) VALUES ( ) VALUES (
$1, $2, $3, $4, $5, $6 $1, $2, $3, $4, $5, $6, $7, $8
) RETURNING id, client_id, client_secret, name, redirect_uris, scopes, grant_types, created_at, updated_at, is_active ) RETURNING id, client_id, client_secret, name, redirect_uris, scopes, grant_types, created_at, updated_at, is_active, description
` `
type CreateApiServiceParams struct { type CreateApiServiceParams struct {
ClientID string `json:"client_id"` ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"` ClientSecret string `json:"client_secret"`
Name string `json:"name"` Name string `json:"name"`
RedirectUris []string `json:"redirect_uris"` Description pgtype.Text `json:"description"`
Scopes []string `json:"scopes"` RedirectUris []string `json:"redirect_uris"`
GrantTypes []string `json:"grant_types"` Scopes []string `json:"scopes"`
GrantTypes []string `json:"grant_types"`
IsActive bool `json:"is_active"`
} }
func (q *Queries) CreateApiService(ctx context.Context, arg CreateApiServiceParams) (ApiService, error) { func (q *Queries) CreateApiService(ctx context.Context, arg CreateApiServiceParams) (ApiService, error) {
@ -31,9 +35,11 @@ func (q *Queries) CreateApiService(ctx context.Context, arg CreateApiServicePara
arg.ClientID, arg.ClientID,
arg.ClientSecret, arg.ClientSecret,
arg.Name, arg.Name,
arg.Description,
arg.RedirectUris, arg.RedirectUris,
arg.Scopes, arg.Scopes,
arg.GrantTypes, arg.GrantTypes,
arg.IsActive,
) )
var i ApiService var i ApiService
err := row.Scan( err := row.Scan(
@ -47,6 +53,7 @@ func (q *Queries) CreateApiService(ctx context.Context, arg CreateApiServicePara
&i.CreatedAt, &i.CreatedAt,
&i.UpdatedAt, &i.UpdatedAt,
&i.IsActive, &i.IsActive,
&i.Description,
) )
return i, err return i, err
} }
@ -64,7 +71,7 @@ func (q *Queries) DeactivateApiService(ctx context.Context, clientID string) err
} }
const getApiServiceCID = `-- name: GetApiServiceCID :one const getApiServiceCID = `-- name: GetApiServiceCID :one
SELECT id, client_id, client_secret, name, redirect_uris, scopes, grant_types, created_at, updated_at, is_active FROM api_services SELECT id, client_id, client_secret, name, redirect_uris, scopes, grant_types, created_at, updated_at, is_active, description FROM api_services
WHERE client_id = $1 WHERE client_id = $1
AND is_active = true AND is_active = true
LIMIT 1 LIMIT 1
@ -84,12 +91,13 @@ func (q *Queries) GetApiServiceCID(ctx context.Context, clientID string) (ApiSer
&i.CreatedAt, &i.CreatedAt,
&i.UpdatedAt, &i.UpdatedAt,
&i.IsActive, &i.IsActive,
&i.Description,
) )
return i, err return i, err
} }
const listApiServices = `-- name: ListApiServices :many const listApiServices = `-- name: ListApiServices :many
SELECT id, client_id, client_secret, name, redirect_uris, scopes, grant_types, created_at, updated_at, is_active FROM api_services SELECT id, client_id, client_secret, name, redirect_uris, scopes, grant_types, created_at, updated_at, is_active, description FROM api_services
ORDER BY created_at DESC ORDER BY created_at DESC
` `
@ -113,6 +121,7 @@ func (q *Queries) ListApiServices(ctx context.Context) ([]ApiService, error) {
&i.CreatedAt, &i.CreatedAt,
&i.UpdatedAt, &i.UpdatedAt,
&i.IsActive, &i.IsActive,
&i.Description,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
@ -133,7 +142,7 @@ SET
grant_types = $5, grant_types = $5,
updated_at = NOW() updated_at = NOW()
WHERE client_id = $1 WHERE client_id = $1
RETURNING id, client_id, client_secret, name, redirect_uris, scopes, grant_types, created_at, updated_at, is_active RETURNING id, client_id, client_secret, name, redirect_uris, scopes, grant_types, created_at, updated_at, is_active, description
` `
type UpdateApiServiceParams struct { type UpdateApiServiceParams struct {
@ -164,6 +173,7 @@ func (q *Queries) UpdateApiService(ctx context.Context, arg UpdateApiServicePara
&i.CreatedAt, &i.CreatedAt,
&i.UpdatedAt, &i.UpdatedAt,
&i.IsActive, &i.IsActive,
&i.Description,
) )
return i, err return i, err
} }

View File

@ -12,16 +12,17 @@ import (
) )
type ApiService struct { type ApiService struct {
ID uuid.UUID `json:"id"` ID uuid.UUID `json:"id"`
ClientID string `json:"client_id"` ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"` ClientSecret string `json:"client_secret"`
Name string `json:"name"` Name string `json:"name"`
RedirectUris []string `json:"redirect_uris"` RedirectUris []string `json:"redirect_uris"`
Scopes []string `json:"scopes"` Scopes []string `json:"scopes"`
GrantTypes []string `json:"grant_types"` GrantTypes []string `json:"grant_types"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
IsActive bool `json:"is_active"` IsActive bool `json:"is_active"`
Description pgtype.Text `json:"description"`
} }
type User struct { type User struct {