Private
Public Access
commit parcial de implementacion de builder
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
f2cf7927eb
commit
4704777050
53 files changed
+1054
-863
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// AcumularError agrega un mensaje al error acumulado por un builder.
|
||||
// Se usa dentro de los métodos Con<Parte> para no interrumpir la
|
||||
// construcción y devolver todos los problemas juntos desde Build().
|
||||
func AcumularError(dst *error, mensaje string) {
|
||||
*dst = errors.Join(*dst, errors.New(mensaje))
|
||||
}
|
||||
|
||||
// AcumularErrores agrega errores no nulos al error acumulado.
|
||||
func AcumularErrores(dst *error, errs ...error) {
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
*dst = errors.Join(*dst, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ValidarTexto recorta los espacios de un texto y verifica que no quede
|
||||
// vacío. Devuelve el texto normalizado y si es válido.
|
||||
func ValidarTexto(valor, campo string, dst *error) (string, bool) {
|
||||
valor = strings.TrimSpace(valor)
|
||||
if valor == "" {
|
||||
AcumularError(dst, campo+" no puede ser nulo o vacío")
|
||||
return "", false
|
||||
}
|
||||
return valor, true
|
||||
}
|
||||
|
||||
// ListaNoNil devuelve una lista vacía cuando el slice es nil, para que
|
||||
// el JSON de respuesta sea [] y no null.
|
||||
func ListaNoNil[T any](items []T) []T {
|
||||
if items == nil {
|
||||
return []T{}
|
||||
}
|
||||
return items
|
||||
}
|
||||
Reference in new issue
Block a user