feat(store): sqlc-запросы, dto TemplateDoc, Repository, интеграционные тесты CRUD

This commit is contained in:
2026-07-03 14:08:37 +07:00
parent 9c29d40269
commit 34bc49ee8c
15 changed files with 757 additions and 0 deletions
+119
View File
@@ -0,0 +1,119 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: domains.sql
package db
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createDomain = `-- name: CreateDomain :one
INSERT INTO domains (id, project_id, provider_account_id, zone_name, zone_id, template_id)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, project_id, provider_account_id, zone_name, zone_id, template_id, created_at
`
type CreateDomainParams struct {
ID pgtype.UUID `json:"id"`
ProjectID pgtype.UUID `json:"project_id"`
ProviderAccountID pgtype.UUID `json:"provider_account_id"`
ZoneName string `json:"zone_name"`
ZoneID string `json:"zone_id"`
TemplateID pgtype.UUID `json:"template_id"`
}
func (q *Queries) CreateDomain(ctx context.Context, arg CreateDomainParams) (Domain, error) {
row := q.db.QueryRow(ctx, createDomain,
arg.ID,
arg.ProjectID,
arg.ProviderAccountID,
arg.ZoneName,
arg.ZoneID,
arg.TemplateID,
)
var i Domain
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.ProviderAccountID,
&i.ZoneName,
&i.ZoneID,
&i.TemplateID,
&i.CreatedAt,
)
return i, err
}
const deleteDomain = `-- name: DeleteDomain :exec
DELETE FROM domains WHERE id = $1 AND project_id = $2
`
type DeleteDomainParams struct {
ID pgtype.UUID `json:"id"`
ProjectID pgtype.UUID `json:"project_id"`
}
func (q *Queries) DeleteDomain(ctx context.Context, arg DeleteDomainParams) error {
_, err := q.db.Exec(ctx, deleteDomain, arg.ID, arg.ProjectID)
return err
}
const getDomain = `-- name: GetDomain :one
SELECT id, project_id, provider_account_id, zone_name, zone_id, template_id, created_at FROM domains WHERE id = $1 AND project_id = $2
`
type GetDomainParams struct {
ID pgtype.UUID `json:"id"`
ProjectID pgtype.UUID `json:"project_id"`
}
func (q *Queries) GetDomain(ctx context.Context, arg GetDomainParams) (Domain, error) {
row := q.db.QueryRow(ctx, getDomain, arg.ID, arg.ProjectID)
var i Domain
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.ProviderAccountID,
&i.ZoneName,
&i.ZoneID,
&i.TemplateID,
&i.CreatedAt,
)
return i, err
}
const listDomains = `-- name: ListDomains :many
SELECT id, project_id, provider_account_id, zone_name, zone_id, template_id, created_at FROM domains WHERE project_id = $1 ORDER BY created_at
`
func (q *Queries) ListDomains(ctx context.Context, projectID pgtype.UUID) ([]Domain, error) {
rows, err := q.db.Query(ctx, listDomains, projectID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Domain
for rows.Next() {
var i Domain
if err := rows.Scan(
&i.ID,
&i.ProjectID,
&i.ProviderAccountID,
&i.ZoneName,
&i.ZoneID,
&i.TemplateID,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}