refatoração de tipagem go
This commit is contained in:
parent
6f78511946
commit
0c41ed4279
12 changed files with 175 additions and 117 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"e-li.nps/internal/contratos"
|
||||
"e-li.nps/internal/db"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
|
@ -98,7 +99,7 @@ LIMIT 1`, table)
|
|||
return true, nil
|
||||
}
|
||||
|
||||
func (s *Store) CreatePedido(ctx context.Context, table string, in PedidoInput, r *http.Request) (string, error) {
|
||||
func (s *Store) CreatePedido(ctx context.Context, table string, in contratos.PedidoInput, r *http.Request) (string, error) {
|
||||
// Segurança: a tabela é um identificador interpolado. Validamos sempre.
|
||||
if !db.TableNameValido(table) {
|
||||
return "", fmt.Errorf("tabela invalida")
|
||||
|
|
@ -122,24 +123,24 @@ RETURNING id`, table)
|
|||
return id, err
|
||||
}
|
||||
|
||||
func (s *Store) GetRegistro(ctx context.Context, table, id string) (Registro, error) {
|
||||
func (s *Store) GetRegistro(ctx context.Context, table, id string) (contratos.Registro, error) {
|
||||
// Segurança: a tabela é um identificador interpolado. Validamos sempre.
|
||||
if !db.TableNameValido(table) {
|
||||
return Registro{}, fmt.Errorf("tabela invalida")
|
||||
return contratos.Registro{}, fmt.Errorf("tabela invalida")
|
||||
}
|
||||
q := fmt.Sprintf(`
|
||||
SELECT id, produto_nome, status, nota, justificativa, pedido_criado_em, respondido_em
|
||||
FROM %s
|
||||
WHERE id=$1`, table)
|
||||
|
||||
var reg Registro
|
||||
var reg contratos.Registro
|
||||
err := s.pool.QueryRow(ctx, q, id).Scan(
|
||||
®.ID, ®.ProdutoNome, ®.Status, ®.Nota, ®.Justificativa, ®.PedidoCriadoEm, ®.RespondidoEm,
|
||||
)
|
||||
return reg, err
|
||||
}
|
||||
|
||||
func (s *Store) PatchRegistro(ctx context.Context, table, id string, in PatchInput) error {
|
||||
func (s *Store) PatchRegistro(ctx context.Context, table, id string, in contratos.PatchInput) error {
|
||||
// Segurança: a tabela é um identificador interpolado. Validamos sempre.
|
||||
if !db.TableNameValido(table) {
|
||||
return fmt.Errorf("tabela invalida")
|
||||
|
|
@ -169,7 +170,7 @@ func (s *Store) TouchAtualizadoEm(ctx context.Context, table, id string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (s *Store) CooldownSuggested(reg Registro) time.Duration {
|
||||
func (s *Store) CooldownSuggested(reg contratos.Registro) time.Duration {
|
||||
// Não é usado pelo servidor hoje; fica como helper se precisarmos.
|
||||
if reg.Status == "respondido" {
|
||||
return 45 * 24 * time.Hour
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue