feat: sqlc api_services
generated cpde
This commit is contained in:
186
internal/repository/api_services.sql.go
Normal file
186
internal/repository/api_services.sql.go
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.29.0
|
||||||
|
// source: api_services.sql
|
||||||
|
|
||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
const createApiService = `-- name: CreateApiService :one
|
||||||
|
INSERT INTO api_services (
|
||||||
|
client_id, client_secret, name, redirect_uris, scopes, grant_types
|
||||||
|
) VALUES (
|
||||||
|
$1, $2, $3, $4, $5, $6
|
||||||
|
) RETURNING id, client_id, client_secret, name, redirect_uris, scopes, grant_types, created_at, updated_at, is_active
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateApiServiceParams struct {
|
||||||
|
ClientID string `json:"client_id"`
|
||||||
|
ClientSecret string `json:"client_secret"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
RedirectUris []string `json:"redirect_uris"`
|
||||||
|
Scopes []string `json:"scopes"`
|
||||||
|
GrantTypes []string `json:"grant_types"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateApiService(ctx context.Context, arg CreateApiServiceParams) (ApiService, error) {
|
||||||
|
row := q.db.QueryRow(ctx, createApiService,
|
||||||
|
arg.ClientID,
|
||||||
|
arg.ClientSecret,
|
||||||
|
arg.Name,
|
||||||
|
arg.RedirectUris,
|
||||||
|
arg.Scopes,
|
||||||
|
arg.GrantTypes,
|
||||||
|
)
|
||||||
|
var i ApiService
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.ClientID,
|
||||||
|
&i.ClientSecret,
|
||||||
|
&i.Name,
|
||||||
|
&i.RedirectUris,
|
||||||
|
&i.Scopes,
|
||||||
|
&i.GrantTypes,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
&i.IsActive,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const deactivateApiService = `-- name: DeactivateApiService :exec
|
||||||
|
UPDATE api_services
|
||||||
|
SET is_active = false,
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE client_id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) DeactivateApiService(ctx context.Context, clientID string) error {
|
||||||
|
_, err := q.db.Exec(ctx, deactivateApiService, clientID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
WHERE client_id = $1
|
||||||
|
AND is_active = true
|
||||||
|
LIMIT 1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetApiServiceCID(ctx context.Context, clientID string) (ApiService, error) {
|
||||||
|
row := q.db.QueryRow(ctx, getApiServiceCID, clientID)
|
||||||
|
var i ApiService
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.ClientID,
|
||||||
|
&i.ClientSecret,
|
||||||
|
&i.Name,
|
||||||
|
&i.RedirectUris,
|
||||||
|
&i.Scopes,
|
||||||
|
&i.GrantTypes,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
&i.IsActive,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) ListApiServices(ctx context.Context) ([]ApiService, error) {
|
||||||
|
rows, err := q.db.Query(ctx, listApiServices)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []ApiService
|
||||||
|
for rows.Next() {
|
||||||
|
var i ApiService
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.ClientID,
|
||||||
|
&i.ClientSecret,
|
||||||
|
&i.Name,
|
||||||
|
&i.RedirectUris,
|
||||||
|
&i.Scopes,
|
||||||
|
&i.GrantTypes,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
&i.IsActive,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateApiService = `-- name: UpdateApiService :one
|
||||||
|
UPDATE api_services
|
||||||
|
SET
|
||||||
|
name = $2,
|
||||||
|
redirect_uris = $3,
|
||||||
|
scopes = $4,
|
||||||
|
grant_types = $5,
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE client_id = $1
|
||||||
|
RETURNING id, client_id, client_secret, name, redirect_uris, scopes, grant_types, created_at, updated_at, is_active
|
||||||
|
`
|
||||||
|
|
||||||
|
type UpdateApiServiceParams struct {
|
||||||
|
ClientID string `json:"client_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
RedirectUris []string `json:"redirect_uris"`
|
||||||
|
Scopes []string `json:"scopes"`
|
||||||
|
GrantTypes []string `json:"grant_types"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) UpdateApiService(ctx context.Context, arg UpdateApiServiceParams) (ApiService, error) {
|
||||||
|
row := q.db.QueryRow(ctx, updateApiService,
|
||||||
|
arg.ClientID,
|
||||||
|
arg.Name,
|
||||||
|
arg.RedirectUris,
|
||||||
|
arg.Scopes,
|
||||||
|
arg.GrantTypes,
|
||||||
|
)
|
||||||
|
var i ApiService
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.ClientID,
|
||||||
|
&i.ClientSecret,
|
||||||
|
&i.Name,
|
||||||
|
&i.RedirectUris,
|
||||||
|
&i.Scopes,
|
||||||
|
&i.GrantTypes,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
&i.IsActive,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateClientSecret = `-- name: UpdateClientSecret :exec
|
||||||
|
UPDATE api_services
|
||||||
|
SET client_secret = $2,
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE client_id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
type UpdateClientSecretParams struct {
|
||||||
|
ClientID string `json:"client_id"`
|
||||||
|
ClientSecret string `json:"client_secret"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) UpdateClientSecret(ctx context.Context, arg UpdateClientSecretParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, updateClientSecret, arg.ClientID, arg.ClientSecret)
|
||||||
|
return err
|
||||||
|
}
|
@ -5,10 +5,25 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ApiService struct {
|
||||||
|
ID uuid.UUID `json:"id"`
|
||||||
|
ClientID string `json:"client_id"`
|
||||||
|
ClientSecret string `json:"client_secret"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
RedirectUris []string `json:"redirect_uris"`
|
||||||
|
Scopes []string `json:"scopes"`
|
||||||
|
GrantTypes []string `json:"grant_types"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
IsActive bool `json:"is_active"`
|
||||||
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
|
Reference in New Issue
Block a user