refatoração de segurança e logs
This commit is contained in:
parent
6873b87a85
commit
663a8d5bf2
12 changed files with 362 additions and 37 deletions
|
|
@ -52,6 +52,10 @@ func (s *Store) EnsureTableForProduto(ctx context.Context, produtoNome string) (
|
|||
}
|
||||
|
||||
func (s *Store) HasRespostaValidaRecente(ctx context.Context, table, inquilinoCodigo, usuarioCodigo string) (bool, error) {
|
||||
// Segurança: a tabela é um identificador interpolado. Validamos sempre.
|
||||
if !db.TableNameValido(table) {
|
||||
return false, fmt.Errorf("tabela invalida")
|
||||
}
|
||||
q := fmt.Sprintf(`
|
||||
SELECT 1
|
||||
FROM %s
|
||||
|
|
@ -72,6 +76,10 @@ LIMIT 1`, table)
|
|||
}
|
||||
|
||||
func (s *Store) HasPedidoEmAbertoRecente(ctx context.Context, table, inquilinoCodigo, usuarioCodigo string) (bool, error) {
|
||||
// Segurança: a tabela é um identificador interpolado. Validamos sempre.
|
||||
if !db.TableNameValido(table) {
|
||||
return false, fmt.Errorf("tabela invalida")
|
||||
}
|
||||
q := fmt.Sprintf(`
|
||||
SELECT 1
|
||||
FROM %s
|
||||
|
|
@ -91,6 +99,10 @@ LIMIT 1`, table)
|
|||
}
|
||||
|
||||
func (s *Store) CreatePedido(ctx context.Context, table string, in PedidoInput, r *http.Request) (string, error) {
|
||||
// Segurança: a tabela é um identificador interpolado. Validamos sempre.
|
||||
if !db.TableNameValido(table) {
|
||||
return "", fmt.Errorf("tabela invalida")
|
||||
}
|
||||
q := fmt.Sprintf(`
|
||||
INSERT INTO %s (
|
||||
produto_nome,
|
||||
|
|
@ -111,6 +123,10 @@ RETURNING id`, table)
|
|||
}
|
||||
|
||||
func (s *Store) GetRegistro(ctx context.Context, table, id string) (Registro, error) {
|
||||
// Segurança: a tabela é um identificador interpolado. Validamos sempre.
|
||||
if !db.TableNameValido(table) {
|
||||
return Registro{}, fmt.Errorf("tabela invalida")
|
||||
}
|
||||
q := fmt.Sprintf(`
|
||||
SELECT id, produto_nome, status, nota, justificativa, pedido_criado_em, respondido_em
|
||||
FROM %s
|
||||
|
|
@ -124,6 +140,10 @@ WHERE id=$1`, table)
|
|||
}
|
||||
|
||||
func (s *Store) PatchRegistro(ctx context.Context, table, id string, in PatchInput) error {
|
||||
// Segurança: a tabela é um identificador interpolado. Validamos sempre.
|
||||
if !db.TableNameValido(table) {
|
||||
return fmt.Errorf("tabela invalida")
|
||||
}
|
||||
// UPDATE único com campos opcionais.
|
||||
q := fmt.Sprintf(`
|
||||
UPDATE %s
|
||||
|
|
@ -140,6 +160,10 @@ WHERE id=$1`, table)
|
|||
}
|
||||
|
||||
func (s *Store) TouchAtualizadoEm(ctx context.Context, table, id string) error {
|
||||
// Segurança: a tabela é um identificador interpolado. Validamos sempre.
|
||||
if !db.TableNameValido(table) {
|
||||
return fmt.Errorf("tabela invalida")
|
||||
}
|
||||
q := fmt.Sprintf(`UPDATE %s SET atualizado_em=now() WHERE id=$1`, table)
|
||||
_, err := s.pool.Exec(ctx, q, id)
|
||||
return err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue