refatoração de tipagem go

This commit is contained in:
Luiz Silva 2026-01-01 20:03:47 -03:00
parent 6f78511946
commit 0c41ed4279
12 changed files with 175 additions and 117 deletions

View file

@ -6,6 +6,7 @@ import (
"strings"
"time"
"e-li.nps/internal/contratos"
"e-li.nps/internal/db"
"github.com/jackc/pgx/v5"
@ -43,7 +44,7 @@ ORDER BY tablename`)
// - 16 detratores
// - 78 neutros
// - 910 promotores
func (s *Store) NPSMesAMes(ctx context.Context, tabela string, meses int) ([]NPSMensal, error) {
func (s *Store) NPSMesAMes(ctx context.Context, tabela string, meses int) ([]contratos.NPSMensal, error) {
// Segurança: a tabela é um identificador interpolado. Validamos sempre.
if !db.TableNameValido(tabela) {
return nil, fmt.Errorf("tabela invalida")
@ -75,9 +76,9 @@ ORDER BY mes ASC`, tabela)
}
defer rows.Close()
out := []NPSMensal{}
out := []contratos.NPSMensal{}
for rows.Next() {
var m NPSMensal
var m contratos.NPSMensal
if err := rows.Scan(&m.Mes, &m.Detratores, &m.Neutros, &m.Promotores, &m.Total); err != nil {
return nil, err
}
@ -97,17 +98,10 @@ type ListarRespostasFiltro struct {
PorPagina int
}
func (f *ListarRespostasFiltro) normalizar() {
if f.Pagina <= 0 {
f.Pagina = 1
}
if f.PorPagina <= 0 || f.PorPagina > 200 {
f.PorPagina = 50
}
}
func (f *ListarRespostasFiltro) normalizar() { (*contratos.ListarRespostasFiltro)(f).Normalizar() }
// ListarRespostas retorna respostas respondidas, com paginação e filtro.
func (s *Store) ListarRespostas(ctx context.Context, tabela string, filtro ListarRespostasFiltro) ([]RespostaPainel, error) {
func (s *Store) ListarRespostas(ctx context.Context, tabela string, filtro ListarRespostasFiltro) ([]contratos.RespostaPainel, error) {
// Segurança: a tabela é um identificador interpolado. Validamos sempre.
if !db.TableNameValido(tabela) {
return nil, fmt.Errorf("tabela invalida")
@ -145,9 +139,9 @@ LIMIT $1 OFFSET $2`, tabela, cond)
}
defer rows.Close()
respostas := []RespostaPainel{}
respostas := []contratos.RespostaPainel{}
for rows.Next() {
var r RespostaPainel
var r contratos.RespostaPainel
if err := rows.Scan(
&r.ID,
&r.RespondidoEm,