refatoração de tipagem go
This commit is contained in:
parent
6f78511946
commit
0c41ed4279
12 changed files with 175 additions and 117 deletions
128
internal/contratos/tipos.go
Normal file
128
internal/contratos/tipos.go
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
package contratos
|
||||
|
||||
import "time"
|
||||
|
||||
// Tipos centralizados do projeto.
|
||||
//
|
||||
// Regra: este arquivo concentra as tipagens (structs) usadas como contratos de
|
||||
// dados entre camadas (backend, painel e widget/WASM), para manter consistência
|
||||
// e facilitar auditoria.
|
||||
|
||||
// ------------------------------
|
||||
// API do widget
|
||||
// ------------------------------
|
||||
|
||||
type PedidoInput struct {
|
||||
ProdutoNome string `json:"produto_nome"`
|
||||
InquilinoCodigo string `json:"inquilino_codigo"`
|
||||
InquilinoNome string `json:"inquilino_nome"`
|
||||
UsuarioCodigo string `json:"usuario_codigo"`
|
||||
UsuarioNome string `json:"usuario_nome"`
|
||||
UsuarioTelefone string `json:"usuario_telefone"`
|
||||
UsuarioEmail string `json:"usuario_email"`
|
||||
}
|
||||
|
||||
type PedidoResponse struct {
|
||||
PodeAbrir bool `json:"pode_abrir"`
|
||||
Motivo string `json:"motivo,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
// Produto normalizado retornado pelo backend para montar URL segura.
|
||||
Produto string `json:"produto,omitempty"`
|
||||
}
|
||||
|
||||
type PatchInput struct {
|
||||
Nota *int `json:"nota,omitempty"`
|
||||
Justificativa *string `json:"justificativa,omitempty"`
|
||||
Finalizar bool `json:"finalizar,omitempty"`
|
||||
}
|
||||
|
||||
type Registro struct {
|
||||
// ProdutoNome é o nome original do produto como enviado pela integração/widget.
|
||||
// Ele existe apenas para exibição ao usuário.
|
||||
//
|
||||
// Importante: a normalização (remoção de acentos/símbolos) é usada apenas
|
||||
// para formar o nome da tabela no Postgres e o parâmetro {produto} da rota.
|
||||
ProdutoNome string
|
||||
ID string
|
||||
Status string
|
||||
Nota *int
|
||||
Justificativa *string
|
||||
PedidoCriadoEm time.Time
|
||||
RespondidoEm *time.Time
|
||||
}
|
||||
|
||||
// FormPageData é o payload para renderização do formulário no iframe.
|
||||
type FormPageData struct {
|
||||
Produto string
|
||||
ID string
|
||||
Reg Registro
|
||||
}
|
||||
|
||||
// ------------------------------
|
||||
// Painel
|
||||
// ------------------------------
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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 PainelDados struct {
|
||||
Produto string
|
||||
Produtos []string
|
||||
Meses []NPSMensal
|
||||
Respostas []RespostaPainel
|
||||
Pagina int
|
||||
SomenteBaixas bool
|
||||
MsgErro string
|
||||
}
|
||||
|
||||
type ListarRespostasFiltro struct {
|
||||
SomenteNotasBaixas bool
|
||||
Pagina int
|
||||
PorPagina int
|
||||
}
|
||||
|
||||
func (f *ListarRespostasFiltro) Normalizar() {
|
||||
if f.Pagina <= 0 {
|
||||
f.Pagina = 1
|
||||
}
|
||||
if f.PorPagina <= 0 || f.PorPagina > 200 {
|
||||
f.PorPagina = 50
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------
|
||||
// Widget/WASM
|
||||
// ------------------------------
|
||||
|
||||
// ConfigWidget representa as opções passadas para window.ELiNPS.init(...).
|
||||
// No WASM lemos via syscall/js; aqui fica apenas a tipagem centralizada.
|
||||
type ConfigWidget struct {
|
||||
ProdutoNome string
|
||||
InquilinoCodigo string
|
||||
InquilinoNome string
|
||||
UsuarioCodigo string
|
||||
UsuarioNome string
|
||||
UsuarioTelefone string
|
||||
UsuarioEmail string
|
||||
CooldownHours float64
|
||||
DataMinimaAbertura string
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue