- Cria tabela 'cadastro_fot' com integracao (FKs) para Empresas, Cursos e Formaturas - Implementa endpoints (GET/POST/PUT/DELETE) em '/api/cadastro-fot' - Otimiza rota GET utilizando JOINs para retornar nomes das entidades estrangeiras - Define campo 'pre_venda' como BOOLEAN e 'fot' como identificador unico (int) - Adiciona tratativa robusta para tipos numericos no Postgres
288 lines
8.2 KiB
Go
288 lines
8.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: cadastro_fot.sql
|
|
|
|
package generated
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createCadastroFot = `-- name: CreateCadastroFot :one
|
|
INSERT INTO cadastro_fot (
|
|
fot, empresa_id, curso_id, ano_formatura_id, instituicao, cidade, estado, observacoes, gastos_captacao, pre_venda
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10
|
|
) RETURNING id, fot, empresa_id, curso_id, ano_formatura_id, instituicao, cidade, estado, observacoes, gastos_captacao, pre_venda, created_at, updated_at
|
|
`
|
|
|
|
type CreateCadastroFotParams struct {
|
|
Fot int32 `json:"fot"`
|
|
EmpresaID pgtype.UUID `json:"empresa_id"`
|
|
CursoID pgtype.UUID `json:"curso_id"`
|
|
AnoFormaturaID pgtype.UUID `json:"ano_formatura_id"`
|
|
Instituicao pgtype.Text `json:"instituicao"`
|
|
Cidade pgtype.Text `json:"cidade"`
|
|
Estado pgtype.Text `json:"estado"`
|
|
Observacoes pgtype.Text `json:"observacoes"`
|
|
GastosCaptacao pgtype.Numeric `json:"gastos_captacao"`
|
|
PreVenda pgtype.Bool `json:"pre_venda"`
|
|
}
|
|
|
|
func (q *Queries) CreateCadastroFot(ctx context.Context, arg CreateCadastroFotParams) (CadastroFot, error) {
|
|
row := q.db.QueryRow(ctx, createCadastroFot,
|
|
arg.Fot,
|
|
arg.EmpresaID,
|
|
arg.CursoID,
|
|
arg.AnoFormaturaID,
|
|
arg.Instituicao,
|
|
arg.Cidade,
|
|
arg.Estado,
|
|
arg.Observacoes,
|
|
arg.GastosCaptacao,
|
|
arg.PreVenda,
|
|
)
|
|
var i CadastroFot
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Fot,
|
|
&i.EmpresaID,
|
|
&i.CursoID,
|
|
&i.AnoFormaturaID,
|
|
&i.Instituicao,
|
|
&i.Cidade,
|
|
&i.Estado,
|
|
&i.Observacoes,
|
|
&i.GastosCaptacao,
|
|
&i.PreVenda,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteCadastroFot = `-- name: DeleteCadastroFot :exec
|
|
DELETE FROM cadastro_fot WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteCadastroFot(ctx context.Context, id pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteCadastroFot, id)
|
|
return err
|
|
}
|
|
|
|
const getCadastroFotByFOT = `-- name: GetCadastroFotByFOT :one
|
|
SELECT id, fot, empresa_id, curso_id, ano_formatura_id, instituicao, cidade, estado, observacoes, gastos_captacao, pre_venda, created_at, updated_at FROM cadastro_fot WHERE fot = $1
|
|
`
|
|
|
|
func (q *Queries) GetCadastroFotByFOT(ctx context.Context, fot int32) (CadastroFot, error) {
|
|
row := q.db.QueryRow(ctx, getCadastroFotByFOT, fot)
|
|
var i CadastroFot
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Fot,
|
|
&i.EmpresaID,
|
|
&i.CursoID,
|
|
&i.AnoFormaturaID,
|
|
&i.Instituicao,
|
|
&i.Cidade,
|
|
&i.Estado,
|
|
&i.Observacoes,
|
|
&i.GastosCaptacao,
|
|
&i.PreVenda,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getCadastroFotByID = `-- name: GetCadastroFotByID :one
|
|
SELECT
|
|
c.id, c.fot, c.empresa_id, c.curso_id, c.ano_formatura_id, c.instituicao, c.cidade, c.estado, c.observacoes, c.gastos_captacao, c.pre_venda, c.created_at, c.updated_at,
|
|
e.nome as empresa_nome,
|
|
cur.nome as curso_nome,
|
|
a.ano_semestre as ano_formatura_label
|
|
FROM cadastro_fot c
|
|
JOIN empresas e ON c.empresa_id = e.id
|
|
JOIN cursos cur ON c.curso_id = cur.id
|
|
JOIN anos_formaturas a ON c.ano_formatura_id = a.id
|
|
WHERE c.id = $1
|
|
`
|
|
|
|
type GetCadastroFotByIDRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Fot int32 `json:"fot"`
|
|
EmpresaID pgtype.UUID `json:"empresa_id"`
|
|
CursoID pgtype.UUID `json:"curso_id"`
|
|
AnoFormaturaID pgtype.UUID `json:"ano_formatura_id"`
|
|
Instituicao pgtype.Text `json:"instituicao"`
|
|
Cidade pgtype.Text `json:"cidade"`
|
|
Estado pgtype.Text `json:"estado"`
|
|
Observacoes pgtype.Text `json:"observacoes"`
|
|
GastosCaptacao pgtype.Numeric `json:"gastos_captacao"`
|
|
PreVenda pgtype.Bool `json:"pre_venda"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
EmpresaNome string `json:"empresa_nome"`
|
|
CursoNome string `json:"curso_nome"`
|
|
AnoFormaturaLabel string `json:"ano_formatura_label"`
|
|
}
|
|
|
|
func (q *Queries) GetCadastroFotByID(ctx context.Context, id pgtype.UUID) (GetCadastroFotByIDRow, error) {
|
|
row := q.db.QueryRow(ctx, getCadastroFotByID, id)
|
|
var i GetCadastroFotByIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Fot,
|
|
&i.EmpresaID,
|
|
&i.CursoID,
|
|
&i.AnoFormaturaID,
|
|
&i.Instituicao,
|
|
&i.Cidade,
|
|
&i.Estado,
|
|
&i.Observacoes,
|
|
&i.GastosCaptacao,
|
|
&i.PreVenda,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.EmpresaNome,
|
|
&i.CursoNome,
|
|
&i.AnoFormaturaLabel,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listCadastroFot = `-- name: ListCadastroFot :many
|
|
SELECT
|
|
c.id, c.fot, c.empresa_id, c.curso_id, c.ano_formatura_id, c.instituicao, c.cidade, c.estado, c.observacoes, c.gastos_captacao, c.pre_venda, c.created_at, c.updated_at,
|
|
e.nome as empresa_nome,
|
|
cur.nome as curso_nome,
|
|
a.ano_semestre as ano_formatura_label
|
|
FROM cadastro_fot c
|
|
JOIN empresas e ON c.empresa_id = e.id
|
|
JOIN cursos cur ON c.curso_id = cur.id
|
|
JOIN anos_formaturas a ON c.ano_formatura_id = a.id
|
|
ORDER BY c.fot DESC
|
|
`
|
|
|
|
type ListCadastroFotRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Fot int32 `json:"fot"`
|
|
EmpresaID pgtype.UUID `json:"empresa_id"`
|
|
CursoID pgtype.UUID `json:"curso_id"`
|
|
AnoFormaturaID pgtype.UUID `json:"ano_formatura_id"`
|
|
Instituicao pgtype.Text `json:"instituicao"`
|
|
Cidade pgtype.Text `json:"cidade"`
|
|
Estado pgtype.Text `json:"estado"`
|
|
Observacoes pgtype.Text `json:"observacoes"`
|
|
GastosCaptacao pgtype.Numeric `json:"gastos_captacao"`
|
|
PreVenda pgtype.Bool `json:"pre_venda"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
EmpresaNome string `json:"empresa_nome"`
|
|
CursoNome string `json:"curso_nome"`
|
|
AnoFormaturaLabel string `json:"ano_formatura_label"`
|
|
}
|
|
|
|
func (q *Queries) ListCadastroFot(ctx context.Context) ([]ListCadastroFotRow, error) {
|
|
rows, err := q.db.Query(ctx, listCadastroFot)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListCadastroFotRow
|
|
for rows.Next() {
|
|
var i ListCadastroFotRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Fot,
|
|
&i.EmpresaID,
|
|
&i.CursoID,
|
|
&i.AnoFormaturaID,
|
|
&i.Instituicao,
|
|
&i.Cidade,
|
|
&i.Estado,
|
|
&i.Observacoes,
|
|
&i.GastosCaptacao,
|
|
&i.PreVenda,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.EmpresaNome,
|
|
&i.CursoNome,
|
|
&i.AnoFormaturaLabel,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateCadastroFot = `-- name: UpdateCadastroFot :one
|
|
UPDATE cadastro_fot SET
|
|
fot = $2,
|
|
empresa_id = $3,
|
|
curso_id = $4,
|
|
ano_formatura_id = $5,
|
|
instituicao = $6,
|
|
cidade = $7,
|
|
estado = $8,
|
|
observacoes = $9,
|
|
gastos_captacao = $10,
|
|
pre_venda = $11,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
RETURNING id, fot, empresa_id, curso_id, ano_formatura_id, instituicao, cidade, estado, observacoes, gastos_captacao, pre_venda, created_at, updated_at
|
|
`
|
|
|
|
type UpdateCadastroFotParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Fot int32 `json:"fot"`
|
|
EmpresaID pgtype.UUID `json:"empresa_id"`
|
|
CursoID pgtype.UUID `json:"curso_id"`
|
|
AnoFormaturaID pgtype.UUID `json:"ano_formatura_id"`
|
|
Instituicao pgtype.Text `json:"instituicao"`
|
|
Cidade pgtype.Text `json:"cidade"`
|
|
Estado pgtype.Text `json:"estado"`
|
|
Observacoes pgtype.Text `json:"observacoes"`
|
|
GastosCaptacao pgtype.Numeric `json:"gastos_captacao"`
|
|
PreVenda pgtype.Bool `json:"pre_venda"`
|
|
}
|
|
|
|
func (q *Queries) UpdateCadastroFot(ctx context.Context, arg UpdateCadastroFotParams) (CadastroFot, error) {
|
|
row := q.db.QueryRow(ctx, updateCadastroFot,
|
|
arg.ID,
|
|
arg.Fot,
|
|
arg.EmpresaID,
|
|
arg.CursoID,
|
|
arg.AnoFormaturaID,
|
|
arg.Instituicao,
|
|
arg.Cidade,
|
|
arg.Estado,
|
|
arg.Observacoes,
|
|
arg.GastosCaptacao,
|
|
arg.PreVenda,
|
|
)
|
|
var i CadastroFot
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Fot,
|
|
&i.EmpresaID,
|
|
&i.CursoID,
|
|
&i.AnoFormaturaID,
|
|
&i.Instituicao,
|
|
&i.Cidade,
|
|
&i.Estado,
|
|
&i.Observacoes,
|
|
&i.GastosCaptacao,
|
|
&i.PreVenda,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|