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

@ -9,6 +9,7 @@ import (
"strings"
"time"
"e-li.nps/internal/contratos"
"e-li.nps/internal/db"
"github.com/jackc/pgx/v5"
)
@ -57,37 +58,11 @@ func (a AuthPainel) handlerLoginPost(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/painel", http.StatusFound)
}
// NPSMensal representa o cálculo do NPS agregado por mês.
type NPSMensal struct {
Mes string
Detratores int
Neutros int
Promotores int
Total int
NPS int
}
type NPSMensal = contratos.NPSMensal
// RespostaPainel representa uma resposta para listagem no painel.
type RespostaPainel struct {
ID string
RespondidoEm *time.Time
PedidoCriadoEm time.Time
UsuarioCodigo *string
UsuarioNome string
UsuarioEmail *string
Nota *int
Justificativa *string
}
type RespostaPainel = contratos.RespostaPainel
type PainelDados struct {
Produto string
Produtos []string
Meses []NPSMensal
Respostas []RespostaPainel
Pagina int
SomenteBaixas bool
MsgErro string
}
type PainelDados = contratos.PainelDados
func (a AuthPainel) handlerPainel(w http.ResponseWriter, r *http.Request, store *Store) {
ctx := r.Context()
@ -145,7 +120,7 @@ func (a AuthPainel) handlerPainel(w http.ResponseWriter, r *http.Request, store
if err != nil {
// Se a tabela ainda não tem coluna ip_real/ etc, EnsureNPSTable deveria ajustar.
if err == pgx.ErrNoRows {
respostas = []RespostaPainel{}
respostas = []contratos.RespostaPainel{}
} else {
dados.MsgErro = "erro ao listar respostas"
}