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,10 @@
|
||||
package dto
|
||||
|
||||
// AlmacenResumen es la representación de un almacén sin sus stocks
|
||||
// asociados.
|
||||
type AlmacenResumen struct {
|
||||
ID uint `json:"id"`
|
||||
EmpresaID uint `json:"empresaId"`
|
||||
Codigo string `json:"codigo"`
|
||||
Ubicacion string `json:"ubicacion"`
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dto
|
||||
|
||||
import "repuestera_back/dto"
|
||||
|
||||
// GrupoResponse es la representación pública de un grupo, con sus
|
||||
// permisos, subgrupos y usuarios resumidos.
|
||||
type GrupoResponse struct {
|
||||
ID uint `json:"id"`
|
||||
EmpresaID uint `json:"empresaId"`
|
||||
Nombre string `json:"nombre"`
|
||||
Descripcion string `json:"descripcion"`
|
||||
Imagen string `json:"imagen"`
|
||||
Permisos []PermisoResponse `json:"permisos"`
|
||||
GruposHijos []GrupoResponse `json:"grupos_hijos"`
|
||||
Usuarios []dto.UsuarioResumen `json:"usuarios"`
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// PermisoResponse es la representación pública de un permiso.
|
||||
type PermisoResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Nombre string `json:"nombre"`
|
||||
Alias string `json:"alias"`
|
||||
Descripcion string `json:"descripcion"`
|
||||
Imagen string `json:"imagen"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
dto "repuestera_back/dto/Repuestos"
|
||||
"repuestera_back/models"
|
||||
)
|
||||
@@ -8,40 +10,67 @@ import (
|
||||
type ActualizarRepuestoBuilder struct {
|
||||
dto *dto.ActualizarRepuestoDto
|
||||
marcaID uint
|
||||
err error
|
||||
}
|
||||
|
||||
var _ IBuilder[models.Repuesto] = (*ActualizarRepuestoBuilder)(nil)
|
||||
|
||||
func NewActualizarRepuestoBuilder() *ActualizarRepuestoBuilder {
|
||||
return &ActualizarRepuestoBuilder{}
|
||||
}
|
||||
|
||||
func (b *ActualizarRepuestoBuilder) ConDto(dto dto.ActualizarRepuestoDto) *ActualizarRepuestoBuilder {
|
||||
b.dto = &dto
|
||||
func (b *ActualizarRepuestoBuilder) ConDto(data dto.ActualizarRepuestoDto) *ActualizarRepuestoBuilder {
|
||||
b.dto = &data
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *ActualizarRepuestoBuilder) ConMarca(marcaID uint) *ActualizarRepuestoBuilder {
|
||||
if marcaID == 0 {
|
||||
AcumularError(&b.err, "la marca es obligatoria")
|
||||
return b
|
||||
}
|
||||
b.marcaID = marcaID
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *ActualizarRepuestoBuilder) Build() models.Repuesto {
|
||||
aliases := b.dto.Aliases
|
||||
if aliases == nil {
|
||||
aliases = []string{}
|
||||
func (b *ActualizarRepuestoBuilder) Build() (*models.Repuesto, error) {
|
||||
if b.dto == nil {
|
||||
return nil, errors.New("faltan los datos del repuesto")
|
||||
}
|
||||
if b.dto.ID == nil || *b.dto.ID == 0 {
|
||||
AcumularError(&b.err, "el ID del repuesto es obligatorio")
|
||||
}
|
||||
if b.marcaID == 0 {
|
||||
AcumularError(&b.err, "la marca es obligatoria")
|
||||
}
|
||||
|
||||
repuesto := models.Repuesto{
|
||||
nombre, ok := ValidarTexto(b.dto.Nombre, "el nombre", &b.err)
|
||||
if ok {
|
||||
b.dto.Nombre = nombre
|
||||
}
|
||||
descripcion, ok := ValidarTexto(b.dto.Descripcion, "la descripción", &b.err)
|
||||
if ok {
|
||||
b.dto.Descripcion = descripcion
|
||||
}
|
||||
if b.dto.Precio < 0 {
|
||||
AcumularError(&b.err, "el precio no puede ser negativo")
|
||||
}
|
||||
if b.dto.StockMinimo < 0 {
|
||||
AcumularError(&b.err, "el stock mínimo no puede ser negativo")
|
||||
}
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
|
||||
repuesto := &models.Repuesto{
|
||||
Nombre: b.dto.Nombre,
|
||||
Descripcion: b.dto.Descripcion,
|
||||
Precio: b.dto.Precio,
|
||||
StockMinimo: int64(b.dto.StockMinimo),
|
||||
MarcaID: b.marcaID,
|
||||
Aliases: aliases,
|
||||
Aliases: ListaNoNil(b.dto.Aliases),
|
||||
}
|
||||
repuesto.ID = uint(*b.dto.ID)
|
||||
|
||||
if b.dto.ID != nil {
|
||||
repuesto.ID = uint(*b.dto.ID)
|
||||
}
|
||||
|
||||
return repuesto
|
||||
return repuesto, nil
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"repuestera_back/dto"
|
||||
models_seguridad "repuestera_back/models/seguridad"
|
||||
)
|
||||
|
||||
type AuthResponseBuilder struct {
|
||||
accessToken string
|
||||
refreshToken string
|
||||
tokenType string
|
||||
expiresIn int
|
||||
permisos []uint
|
||||
empresa *dto.EmpresaResumen
|
||||
empresas []dto.EmpresaResumen
|
||||
usuario *dto.UsuarioResumen
|
||||
err error
|
||||
}
|
||||
|
||||
var _ IBuilder[dto.AuthResponse] = (*AuthResponseBuilder)(nil)
|
||||
|
||||
func NewAuthResponseBuilder() *AuthResponseBuilder {
|
||||
return &AuthResponseBuilder{tokenType: "Bearer"}
|
||||
}
|
||||
|
||||
func (b *AuthResponseBuilder) ConTokens(accessToken, refreshToken string, expiresIn int) *AuthResponseBuilder {
|
||||
if accessToken == "" || refreshToken == "" {
|
||||
AcumularError(&b.err, "los tokens de acceso y refresco son obligatorios")
|
||||
return b
|
||||
}
|
||||
if expiresIn <= 0 {
|
||||
AcumularError(&b.err, "la duración del token debe ser positiva")
|
||||
return b
|
||||
}
|
||||
b.accessToken = accessToken
|
||||
b.refreshToken = refreshToken
|
||||
b.expiresIn = expiresIn
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *AuthResponseBuilder) ConPermisos(permisos []uint) *AuthResponseBuilder {
|
||||
b.permisos = ListaNoNil(permisos)
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *AuthResponseBuilder) ConEmpresa(empresa *dto.EmpresaResumen) *AuthResponseBuilder {
|
||||
b.empresa = empresa
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *AuthResponseBuilder) ConEmpresas(empresas []dto.EmpresaResumen) *AuthResponseBuilder {
|
||||
b.empresas = ListaNoNil(empresas)
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *AuthResponseBuilder) ConUsuario(usuario *dto.UsuarioResumen) *AuthResponseBuilder {
|
||||
if usuario == nil {
|
||||
AcumularError(&b.err, "el usuario de la sesión es obligatorio")
|
||||
return b
|
||||
}
|
||||
if usuario.ID == 0 {
|
||||
AcumularError(&b.err, "el usuario de la sesión debe tener un ID válido")
|
||||
return b
|
||||
}
|
||||
b.usuario = usuario
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *AuthResponseBuilder) Build() (*dto.AuthResponse, error) {
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
if b.usuario == nil {
|
||||
return nil, errors.New("falta el usuario de la sesión")
|
||||
}
|
||||
if b.accessToken == "" || b.refreshToken == "" {
|
||||
return nil, errors.New("faltan los tokens de la sesión")
|
||||
}
|
||||
|
||||
respuesta := &dto.AuthResponse{
|
||||
AccessToken: b.accessToken,
|
||||
RefreshToken: b.refreshToken,
|
||||
TokenType: b.tokenType,
|
||||
ExpiresIn: b.expiresIn,
|
||||
Permissions: b.permisos,
|
||||
Empresa: b.empresa,
|
||||
Empresas: b.empresas,
|
||||
Usuario: *b.usuario,
|
||||
DebeCambiarPassword: b.usuario.DebeCambiarPassword,
|
||||
}
|
||||
if b.empresa != nil {
|
||||
respuesta.EmpresaRol = b.empresa.Rol
|
||||
}
|
||||
|
||||
return respuesta, nil
|
||||
}
|
||||
|
||||
// SesionDirector arma la respuesta de login, refresh y cambio de empresa.
|
||||
type SesionDirector struct{}
|
||||
|
||||
func NewSesionDirector() *SesionDirector {
|
||||
return &SesionDirector{}
|
||||
}
|
||||
|
||||
func (d *SesionDirector) Construir(
|
||||
usuario *models_seguridad.Usuario,
|
||||
empresa *models_seguridad.Empresa,
|
||||
rol models_seguridad.RolEmpresa,
|
||||
empresas []dto.EmpresaResumen,
|
||||
permisos []uint,
|
||||
accessToken string,
|
||||
refreshToken string,
|
||||
expiresIn int,
|
||||
) (*dto.AuthResponse, error) {
|
||||
empresaResumen, err := NewEmpresaResumenDirector().DesdeEmpresa(empresa, rol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
usuarioResumen, err := NewUsuarioResumenDirector().DesdeUsuario(usuario)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewAuthResponseBuilder().
|
||||
ConTokens(accessToken, refreshToken, expiresIn).
|
||||
ConPermisos(permisos).
|
||||
ConEmpresa(empresaResumen).
|
||||
ConEmpresas(empresas).
|
||||
ConUsuario(usuarioResumen).
|
||||
Build()
|
||||
}
|
||||
@@ -1,40 +1,70 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
dto "repuestera_back/dto/Repuestos"
|
||||
"repuestera_back/models"
|
||||
)
|
||||
|
||||
type RepuestoBuilder struct {
|
||||
type CrearRepuestoBuilder struct {
|
||||
dto *dto.CrearRepuestoDto
|
||||
marcaID uint
|
||||
err error
|
||||
}
|
||||
|
||||
func NewRepuestoBuilder() *RepuestoBuilder {
|
||||
return &RepuestoBuilder{}
|
||||
var _ IBuilder[models.Repuesto] = (*CrearRepuestoBuilder)(nil)
|
||||
|
||||
func NewCrearRepuestoBuilder() *CrearRepuestoBuilder {
|
||||
return &CrearRepuestoBuilder{}
|
||||
}
|
||||
|
||||
func (b *RepuestoBuilder) ConDto(dto dto.CrearRepuestoDto) *RepuestoBuilder {
|
||||
b.dto = &dto
|
||||
func (b *CrearRepuestoBuilder) ConDto(data dto.CrearRepuestoDto) *CrearRepuestoBuilder {
|
||||
b.dto = &data
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *RepuestoBuilder) ConMarca(marcaID uint) *RepuestoBuilder {
|
||||
func (b *CrearRepuestoBuilder) ConMarca(marcaID uint) *CrearRepuestoBuilder {
|
||||
if marcaID == 0 {
|
||||
AcumularError(&b.err, "la marca es obligatoria")
|
||||
return b
|
||||
}
|
||||
b.marcaID = marcaID
|
||||
return b
|
||||
}
|
||||
func (b *RepuestoBuilder) Build() models.Repuesto {
|
||||
aliases := b.dto.Aliases
|
||||
|
||||
if aliases == nil {
|
||||
aliases = []string{}
|
||||
func (b *CrearRepuestoBuilder) Build() (*models.Repuesto, error) {
|
||||
if b.dto == nil {
|
||||
return nil, errors.New("faltan los datos del repuesto")
|
||||
}
|
||||
return models.Repuesto{
|
||||
if b.marcaID == 0 {
|
||||
AcumularError(&b.err, "la marca es obligatoria")
|
||||
}
|
||||
|
||||
nombre, ok := ValidarTexto(b.dto.Nombre, "el nombre", &b.err)
|
||||
if ok {
|
||||
b.dto.Nombre = nombre
|
||||
}
|
||||
descripcion, ok := ValidarTexto(b.dto.Descripcion, "la descripción", &b.err)
|
||||
if ok {
|
||||
b.dto.Descripcion = descripcion
|
||||
}
|
||||
if b.dto.Precio < 0 {
|
||||
AcumularError(&b.err, "el precio no puede ser negativo")
|
||||
}
|
||||
if b.dto.StockMinimo < 0 {
|
||||
AcumularError(&b.err, "el stock mínimo no puede ser negativo")
|
||||
}
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
|
||||
return &models.Repuesto{
|
||||
Nombre: b.dto.Nombre,
|
||||
Descripcion: b.dto.Descripcion,
|
||||
Precio: b.dto.Precio,
|
||||
StockMinimo: int64(b.dto.StockMinimo),
|
||||
MarcaID: b.marcaID,
|
||||
Aliases: aliases,
|
||||
}
|
||||
Aliases: ListaNoNil(b.dto.Aliases),
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"repuestera_back/dto"
|
||||
models_seguridad "repuestera_back/models/seguridad"
|
||||
)
|
||||
|
||||
type EmpresaActualResponseBuilder struct {
|
||||
empresa *models_seguridad.Empresa
|
||||
rol models_seguridad.RolEmpresa
|
||||
miembros int64
|
||||
err error
|
||||
}
|
||||
|
||||
var _ IBuilder[dto.EmpresaActualResponse] = (*EmpresaActualResponseBuilder)(nil)
|
||||
|
||||
func NewEmpresaActualResponseBuilder() *EmpresaActualResponseBuilder {
|
||||
return &EmpresaActualResponseBuilder{}
|
||||
}
|
||||
|
||||
func (b *EmpresaActualResponseBuilder) ConEmpresa(empresa *models_seguridad.Empresa) *EmpresaActualResponseBuilder {
|
||||
if empresa == nil {
|
||||
AcumularError(&b.err, "la empresa no puede ser nula")
|
||||
return b
|
||||
}
|
||||
b.empresa = empresa
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *EmpresaActualResponseBuilder) ConRol(rol models_seguridad.RolEmpresa) *EmpresaActualResponseBuilder {
|
||||
b.rol = rol
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *EmpresaActualResponseBuilder) ConMiembrosActivos(miembros int64) *EmpresaActualResponseBuilder {
|
||||
b.miembros = miembros
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *EmpresaActualResponseBuilder) Build() (*dto.EmpresaActualResponse, error) {
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
if b.empresa == nil {
|
||||
return nil, errors.New("falta la empresa")
|
||||
}
|
||||
|
||||
return &dto.EmpresaActualResponse{
|
||||
ID: b.empresa.ID,
|
||||
Nombre: b.empresa.Nombre,
|
||||
Slug: b.empresa.Slug,
|
||||
Cuit: b.empresa.Cuit,
|
||||
Activa: b.empresa.Activa,
|
||||
Rol: string(b.rol),
|
||||
MiembrosActivos: b.miembros,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"repuestera_back/dto"
|
||||
models_seguridad "repuestera_back/models/seguridad"
|
||||
)
|
||||
|
||||
type EmpresaAdminResponseBuilder struct {
|
||||
empresa *models_seguridad.Empresa
|
||||
miembros int64
|
||||
owners int64
|
||||
err error
|
||||
}
|
||||
|
||||
var _ IBuilder[dto.EmpresaAdminResponse] = (*EmpresaAdminResponseBuilder)(nil)
|
||||
|
||||
func NewEmpresaAdminResponseBuilder() *EmpresaAdminResponseBuilder {
|
||||
return &EmpresaAdminResponseBuilder{}
|
||||
}
|
||||
|
||||
func (b *EmpresaAdminResponseBuilder) ConEmpresa(empresa *models_seguridad.Empresa) *EmpresaAdminResponseBuilder {
|
||||
if empresa == nil {
|
||||
AcumularError(&b.err, "la empresa no puede ser nula")
|
||||
return b
|
||||
}
|
||||
b.empresa = empresa
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *EmpresaAdminResponseBuilder) ConContadores(miembros, owners int64) *EmpresaAdminResponseBuilder {
|
||||
if miembros < 0 || owners < 0 {
|
||||
AcumularError(&b.err, "los contadores no pueden ser negativos")
|
||||
return b
|
||||
}
|
||||
b.miembros = miembros
|
||||
b.owners = owners
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *EmpresaAdminResponseBuilder) Build() (*dto.EmpresaAdminResponse, error) {
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
if b.empresa == nil {
|
||||
return nil, errors.New("falta la empresa")
|
||||
}
|
||||
|
||||
return &dto.EmpresaAdminResponse{
|
||||
ID: b.empresa.ID,
|
||||
Nombre: b.empresa.Nombre,
|
||||
Slug: b.empresa.Slug,
|
||||
Cuit: b.empresa.Cuit,
|
||||
Activa: b.empresa.Activa,
|
||||
Miembros: b.miembros,
|
||||
Owners: b.owners,
|
||||
CreatedAt: b.empresa.CreatedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -1,39 +1,69 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
|
||||
"repuestera_back/dto"
|
||||
models_seguridad "repuestera_back/models/seguridad"
|
||||
)
|
||||
|
||||
type GrupoSimpleBuilder struct {
|
||||
grupo *models_seguridad.Grupo
|
||||
err error
|
||||
}
|
||||
|
||||
var _ IBuilder[dto.GrupoSimpleDTO] = (*GrupoSimpleBuilder)(nil)
|
||||
|
||||
func NewGrupoSimpleBuilder(grupo *models_seguridad.Grupo) *GrupoSimpleBuilder {
|
||||
return &GrupoSimpleBuilder{
|
||||
grupo: grupo,
|
||||
}
|
||||
builder := &GrupoSimpleBuilder{}
|
||||
builder.ConGrupo(grupo)
|
||||
return builder
|
||||
}
|
||||
|
||||
func (b *GrupoSimpleBuilder) Build() dto.GrupoSimpleDTO {
|
||||
permisosMap := make(map[uint]models_seguridad.Permiso)
|
||||
func (b *GrupoSimpleBuilder) ConGrupo(grupo *models_seguridad.Grupo) *GrupoSimpleBuilder {
|
||||
if grupo == nil {
|
||||
AcumularError(&b.err, "el grupo no puede ser nulo")
|
||||
return b
|
||||
}
|
||||
b.grupo = grupo
|
||||
return b
|
||||
}
|
||||
|
||||
b.grupo.ListarPermisos(permisosMap)
|
||||
func (b *GrupoSimpleBuilder) Build() (*dto.GrupoSimpleDTO, error) {
|
||||
if b.err != nil {
|
||||
return nil, b.err
|
||||
}
|
||||
if b.grupo == nil {
|
||||
return nil, errors.New("falta el grupo")
|
||||
}
|
||||
|
||||
permisosMap := make(map[uint]models_seguridad.Permiso)
|
||||
visitados := make(map[uint]bool)
|
||||
b.grupo.ListarPermisos(permisosMap, visitados)
|
||||
|
||||
permisos := make([]dto.PermisoSimpleDTO, 0, len(permisosMap))
|
||||
|
||||
for _, permiso := range permisosMap {
|
||||
permisos = append(permisos, dto.PermisoSimpleDTO{
|
||||
ID: permiso.ID,
|
||||
Nombre: permiso.Nombre,
|
||||
Alias: permiso.Alias,
|
||||
Imagen: permiso.Imagen,
|
||||
})
|
||||
}
|
||||
|
||||
return dto.GrupoSimpleDTO{
|
||||
sort.Slice(permisos, func(i, j int) bool {
|
||||
if permisos[i].ID == permisos[j].ID {
|
||||
return permisos[i].Nombre < permisos[j].Nombre
|
||||
}
|
||||
return permisos[i].ID < permisos[j].ID
|
||||
})
|
||||
|
||||
return &dto.GrupoSimpleDTO{
|
||||
ID: b.grupo.ID,
|
||||
Nombre: b.grupo.Nombre,
|
||||
Descripcion: b.grupo.Descripcion,
|
||||
Imagen: b.grupo.Imagen,
|
||||
Permisos: permisos,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
@@ -1,223 +0,0 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"repuestera_back/models/logs"
|
||||
)
|
||||
|
||||
type LogDirector struct{}
|
||||
|
||||
func NewLogDirector() *LogDirector {
|
||||
return &LogDirector{}
|
||||
}
|
||||
|
||||
// Custom construye un log para una acción y detalles arbitrarios.
|
||||
func (d *LogDirector) Custom(uid uint, accion string, detalles []logs.LogDetalle) (*logs.Log, error) {
|
||||
builder := NewLogBuilder()
|
||||
builder.Uid(uid)
|
||||
builder.Accion(accion)
|
||||
builder.AñadirDetalles(detalles)
|
||||
return builder.Build()
|
||||
}
|
||||
|
||||
// Crear construye el log de un registro creado, guardando los campos del
|
||||
// registro en la lista de detalles (ValorNuevo).
|
||||
func (d *LogDirector) Crear(uid uint, tabla string, entidad any) (*logs.Log, error) {
|
||||
detalles := generarDetallesCreacion(tabla, entidad)
|
||||
if len(detalles) == 0 {
|
||||
id := ObtenerID(entidad)
|
||||
detalles = []logs.LogDetalle{
|
||||
{
|
||||
NombreTabla: tabla,
|
||||
Columna: "*",
|
||||
ValorNuevo: fmt.Sprintf("Registro creado (ID: %v)", id),
|
||||
},
|
||||
}
|
||||
}
|
||||
return d.Custom(uid, logs.AccionCrear, detalles)
|
||||
}
|
||||
|
||||
// generarDetallesCreacion recorre los campos exportados de la entidad y los
|
||||
// persiste como detalles con ValorNuevo (no hay estado anterior).
|
||||
func generarDetallesCreacion(tabla string, entidad any) []logs.LogDetalle {
|
||||
var detalles []logs.LogDetalle
|
||||
|
||||
val := reflect.ValueOf(entidad)
|
||||
for val.IsValid() && val.Kind() == reflect.Ptr {
|
||||
if val.IsNil() {
|
||||
return detalles
|
||||
}
|
||||
val = val.Elem()
|
||||
}
|
||||
if !val.IsValid() || val.Kind() != reflect.Struct {
|
||||
return detalles
|
||||
}
|
||||
|
||||
tipo := val.Type()
|
||||
|
||||
// Incluye el ID aunque esté dentro del gorm.Model embebido.
|
||||
if id := ObtenerID(entidad); id != nil {
|
||||
detalles = append(detalles, logs.LogDetalle{
|
||||
NombreTabla: tabla,
|
||||
Columna: "ID",
|
||||
ValorNuevo: fmt.Sprintf("%v", id),
|
||||
})
|
||||
}
|
||||
|
||||
for i := 0; i < tipo.NumField(); i++ {
|
||||
campo := tipo.Field(i)
|
||||
if campo.PkgPath != "" {
|
||||
continue
|
||||
}
|
||||
if campo.Name == "Model" || campo.Name == "CreatedAt" || campo.Name == "UpdatedAt" || campo.Name == "DeletedAt" || campo.Name == "ID" {
|
||||
continue
|
||||
}
|
||||
|
||||
valor := val.Field(i)
|
||||
if !valor.CanInterface() {
|
||||
continue
|
||||
}
|
||||
v := fmt.Sprintf("%v", valor.Interface())
|
||||
if strings.TrimSpace(v) == "" || v == "0" {
|
||||
continue
|
||||
}
|
||||
|
||||
detalles = append(detalles, logs.LogDetalle{
|
||||
NombreTabla: tabla,
|
||||
Columna: campo.Name,
|
||||
ValorNuevo: v,
|
||||
})
|
||||
}
|
||||
|
||||
return detalles
|
||||
}
|
||||
|
||||
// Modificar construye el log comparando el estado anterior y el nuevo.
|
||||
// Si no hay diferencias, retorna (nil, nil).
|
||||
func (d *LogDirector) Modificar(uid uint, tabla string, anterior, nuevo any) (*logs.Log, error) {
|
||||
detalles := generarDetalles(tabla, anterior, nuevo)
|
||||
if len(detalles) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return d.Custom(uid, logs.AccionModificar, detalles)
|
||||
}
|
||||
|
||||
// Eliminar construye el log de un borrado físico.
|
||||
func (d *LogDirector) Eliminar(uid uint, tabla string, id any) (*logs.Log, error) {
|
||||
return d.Custom(uid, logs.AccionEliminar, []logs.LogDetalle{
|
||||
{
|
||||
NombreTabla: tabla,
|
||||
Columna: "*",
|
||||
ValorAnterior: fmt.Sprintf("Registro eliminado (ID: %v)", id),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Baja construye el log de un borrado lógico.
|
||||
func (d *LogDirector) Baja(uid uint, tabla string, id any) (*logs.Log, error) {
|
||||
return d.Custom(uid, logs.AccionBaja, []logs.LogDetalle{
|
||||
{
|
||||
NombreTabla: tabla,
|
||||
Columna: "*",
|
||||
ValorAnterior: fmt.Sprintf("Registro activo (ID: %v)", id),
|
||||
ValorNuevo: "Registro dado de baja",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Alta construye el log de la restauración de un registro dado de baja.
|
||||
func (d *LogDirector) Alta(uid uint, tabla string, id any) (*logs.Log, error) {
|
||||
return d.Custom(uid, logs.AccionAlta, []logs.LogDetalle{
|
||||
{
|
||||
NombreTabla: tabla,
|
||||
Columna: "*",
|
||||
ValorAnterior: fmt.Sprintf("Registro dado de baja (ID: %v)", id),
|
||||
ValorNuevo: "Registro dado de alta",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func generarDetalles(tabla string, anterior, nuevo any) []logs.LogDetalle {
|
||||
var detalles []logs.LogDetalle
|
||||
|
||||
valAnterior := reflect.ValueOf(anterior)
|
||||
valNuevo := reflect.ValueOf(nuevo)
|
||||
|
||||
for valAnterior.IsValid() && valAnterior.Kind() == reflect.Ptr {
|
||||
if valAnterior.IsNil() {
|
||||
return detalles
|
||||
}
|
||||
valAnterior = valAnterior.Elem()
|
||||
}
|
||||
for valNuevo.IsValid() && valNuevo.Kind() == reflect.Ptr {
|
||||
if valNuevo.IsNil() {
|
||||
return detalles
|
||||
}
|
||||
valNuevo = valNuevo.Elem()
|
||||
}
|
||||
|
||||
if !valAnterior.IsValid() || !valNuevo.IsValid() {
|
||||
return detalles
|
||||
}
|
||||
if valAnterior.Kind() != reflect.Struct || valNuevo.Kind() != reflect.Struct {
|
||||
return detalles
|
||||
}
|
||||
if valAnterior.Type() != valNuevo.Type() {
|
||||
return detalles
|
||||
}
|
||||
|
||||
tipo := valAnterior.Type()
|
||||
|
||||
for i := 0; i < tipo.NumField(); i++ {
|
||||
campo := tipo.Field(i)
|
||||
|
||||
if campo.PkgPath != "" { // campo no exportado
|
||||
continue
|
||||
}
|
||||
if campo.Name == "Model" || campo.Name == "CreatedAt" || campo.Name == "UpdatedAt" || campo.Name == "DeletedAt" {
|
||||
continue
|
||||
}
|
||||
|
||||
campoNuevo := valNuevo.FieldByName(campo.Name)
|
||||
if !campoNuevo.IsValid() {
|
||||
continue
|
||||
}
|
||||
|
||||
vAnt := fmt.Sprintf("%v", valAnterior.Field(i).Interface())
|
||||
vNue := fmt.Sprintf("%v", campoNuevo.Interface())
|
||||
|
||||
if vAnt != vNue {
|
||||
detalles = append(detalles, logs.LogDetalle{
|
||||
ID: uint(i),
|
||||
NombreTabla: tabla,
|
||||
Columna: campo.Name,
|
||||
ValorAnterior: vAnt,
|
||||
ValorNuevo: vNue,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return detalles
|
||||
}
|
||||
|
||||
// ObtenerID extrae el campo ID de una entidad, siguiendo punteros.
|
||||
func ObtenerID(dest any) any {
|
||||
val := reflect.ValueOf(dest)
|
||||
for val.IsValid() && val.Kind() == reflect.Ptr {
|
||||
if val.IsNil() {
|
||||
return nil
|
||||
}
|
||||
val = val.Elem()
|
||||
}
|
||||
if !val.IsValid() || val.Kind() != reflect.Struct {
|
||||
return nil
|
||||
}
|
||||
campoID := val.FieldByName("ID")
|
||||
if campoID.IsValid() && campoID.CanInterface() {
|
||||
return campoID.Interface()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package dto_builders
|
||||
|
||||
import (
|
||||
dto "repuestera_back/dto/Logs"
|
||||
"repuestera_back/models/logs"
|
||||
)
|
||||
|
||||
type LogTablaBuilder struct {
|
||||
logs []logs.Log
|
||||
}
|
||||
|
||||
func NewLogTablaBuilder() *LogTablaBuilder {
|
||||
return &LogTablaBuilder{}
|
||||
}
|
||||
|
||||
func (b *LogTablaBuilder) ConLogs(logs []logs.Log) *LogTablaBuilder {
|
||||
b.logs = logs
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *LogTablaBuilder) Build() []dto.LogTablaDto {
|
||||
var dtos []dto.LogTablaDto
|
||||
|
||||
for i := 0; i < len(b.logs); i++ {
|
||||
var d = &dto.LogTablaDto{
|
||||
ID: b.logs[i].ID,
|
||||
UsuarioID: b.logs[i].UsuarioID,
|
||||
Accion: b.logs[i].Accion,
|
||||
Detalles: b.logs[i].Detalles,
|
||||
CreatedAt: b.logs[i].CreatedAt,
|
||||
}
|
||||
dtos = append(dtos, *d)
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package dto
|
||||
|
||||
import "time"
|
||||
|
||||
// ClienteResumen es la representación de un cliente sin sus
|
||||
// comprobantes asociados. Se usa dentro de respuestas compuestas,
|
||||
// como FacturaResponse.
|
||||
type ClienteResumen struct {
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt *time.Time `json:"DeletedAt"`
|
||||
EmpresaID uint `json:"empresaId"`
|
||||
Nombre string `json:"nombre"`
|
||||
Cuit string `json:"cuit"`
|
||||
Email string `json:"email,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
dto_base "repuestera_back/dto"
|
||||
dto_clientes "repuestera_back/dto/Clientes"
|
||||
dto_proveedores "repuestera_back/dto/Proveedores"
|
||||
"repuestera_back/models"
|
||||
)
|
||||
|
||||
// FacturaResponse es la representación pública de una factura. Incluye
|
||||
// los resúmenes de cliente, proveedor y responsable, pero no las
|
||||
// relaciones internas de esos modelos.
|
||||
type FacturaResponse struct {
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt *time.Time `json:"DeletedAt"`
|
||||
EmpresaID uint `json:"empresaId"`
|
||||
Numero string `json:"numero"`
|
||||
Estado string `json:"estado"`
|
||||
Total float64 `json:"total"`
|
||||
ClienteID uint `json:"ClienteID,omitempty"`
|
||||
Cliente dto_clientes.ClienteResumen `json:"cliente"`
|
||||
ProveedorID *uint `json:"proveedorId,omitempty"`
|
||||
Proveedor *dto_proveedores.ProveedorResumen `json:"proveedor,omitempty"`
|
||||
SeAviso bool `json:"seAviso"`
|
||||
Detalles []models.FacturaDetalle `json:"detalles,omitempty"`
|
||||
ResponsableID uint `json:"ResponsableID,omitempty"`
|
||||
Responsable *dto_base.UsuarioResumen `json:"usuario,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
dto_base "repuestera_back/dto"
|
||||
"repuestera_back/models/logs"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// LogResponse es la representación pública de un log. Incluye un
|
||||
// resumen del usuario que realizó la acción, sin sus relaciones
|
||||
// internas.
|
||||
type LogResponse struct {
|
||||
ID uint64 `json:"id"`
|
||||
EmpresaID uint `json:"empresaId"`
|
||||
UsuarioID uint `json:"usuarioId"`
|
||||
Usuario *dto_base.UsuarioResumen `json:"usuario,omitempty"`
|
||||
Accion string `json:"accion"`
|
||||
Detalles datatypes.JSONSlice[logs.LogDetalle] `json:"detalles,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dto
|
||||
|
||||
import "time"
|
||||
|
||||
// MarcaResumen es la representación de una marca sin sus repuestos
|
||||
// asociados.
|
||||
type MarcaResumen struct {
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt *time.Time `json:"DeletedAt"`
|
||||
EmpresaID uint `json:"empresaId"`
|
||||
Nombre string `json:"nombre"`
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package dto
|
||||
|
||||
import "time"
|
||||
|
||||
// ProveedorResumen es la representación de un proveedor sin sus
|
||||
// facturas asociadas. Se usa dentro de respuestas compuestas.
|
||||
type ProveedorResumen struct {
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt *time.Time `json:"DeletedAt"`
|
||||
EmpresaID uint `json:"empresaId"`
|
||||
Nombre string `json:"nombre"`
|
||||
Cuit string `json:"cuit,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
Telefono string `json:"telefono,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
dto_marcas "repuestera_back/dto/Marcas"
|
||||
)
|
||||
|
||||
// RepuestoResumen es la representación de un repuesto sin sus stocks
|
||||
// asociados. Se usa dentro de respuestas de stock y de facturas.
|
||||
type RepuestoResumen struct {
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt *time.Time `json:"DeletedAt"`
|
||||
EmpresaID uint `json:"empresaId"`
|
||||
Nombre string `json:"nombre"`
|
||||
Descripcion string `json:"descripcion"`
|
||||
Precio float64 `json:"precio"`
|
||||
StockMinimo int64 `json:"stockMinimo"`
|
||||
MarcaID uint `json:"marcaId"`
|
||||
Marca *dto_marcas.MarcaResumen `json:"marca,omitempty"`
|
||||
Aliases []string `json:"aliases,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
dto_almacenes "repuestera_back/dto/Almacenes"
|
||||
dto_repuestos "repuestera_back/dto/Repuestos"
|
||||
)
|
||||
|
||||
// StockResponse es la representación pública de una fila de stock.
|
||||
// Agrega el disponible y el estado calculados, y evita exponer las
|
||||
// relaciones internas del repuesto y del almacén.
|
||||
type StockResponse struct {
|
||||
ID uint64 `json:"id"`
|
||||
EmpresaID uint64 `json:"empresaId"`
|
||||
RepuestoID uint64 `json:"repuestoId"`
|
||||
Repuesto dto_repuestos.RepuestoResumen `json:"repuesto"`
|
||||
AlmacenID uint `json:"almacenId"`
|
||||
Almacen *dto_almacenes.AlmacenResumen `json:"almacen,omitempty"`
|
||||
Cantidad float64 `json:"cantidad"`
|
||||
CantidadReservada float64 `json:"cantidadReservada"`
|
||||
Disponible float64 `json:"disponible"`
|
||||
Estado string `json:"estado"`
|
||||
Observacion string `json:"observacion"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
DeletedAt *time.Time `json:"deletedAt,omitempty"`
|
||||
}
|
||||
@@ -27,7 +27,6 @@ type AuthResponse struct {
|
||||
Empresa *EmpresaResumen `json:"empresa,omitempty"`
|
||||
Empresas []EmpresaResumen `json:"empresas"`
|
||||
EmpresaRol string `json:"empresa_rol"`
|
||||
EsPlataformaAdmin bool `json:"es_plataforma_admin"`
|
||||
Usuario UsuarioResumen `json:"usuario"`
|
||||
DebeCambiarPassword bool `json:"debe_cambiar_password"`
|
||||
}
|
||||
@@ -55,7 +54,6 @@ type MeResponse struct {
|
||||
Empresa *EmpresaResumen `json:"empresa,omitempty"`
|
||||
Empresas []EmpresaResumen `json:"empresas"`
|
||||
EmpresaRol string `json:"empresa_rol"`
|
||||
EsPlataformaAdmin bool `json:"es_plataforma_admin"`
|
||||
Activo bool `json:"activo"`
|
||||
DebeCambiarPassword bool `json:"debe_cambiar_password"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package dto
|
||||
|
||||
import "time"
|
||||
|
||||
// EmpresaResponse es la representación pública de una empresa.
|
||||
type EmpresaResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Nombre string `json:"nombre"`
|
||||
Slug string `json:"slug"`
|
||||
Cuit *string `json:"cuit,omitempty"`
|
||||
Activa bool `json:"activa"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// EmpresaActualResponse describe la empresa activa de la sesión.
|
||||
type EmpresaActualResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Nombre string `json:"nombre"`
|
||||
Slug string `json:"slug"`
|
||||
Cuit *string `json:"cuit,omitempty"`
|
||||
Activa bool `json:"activa"`
|
||||
Rol string `json:"rol"`
|
||||
MiembrosActivos int64 `json:"miembros_activos"`
|
||||
}
|
||||
|
||||
// EmpresasResponse es el envelope de empresas del usuario.
|
||||
type EmpresasResponse struct {
|
||||
Empresas []EmpresaResumen `json:"empresas"`
|
||||
}
|
||||
|
||||
// MiembrosListadoResponse conserva las claves usuarios y miembros por
|
||||
// compatibilidad con clientes anteriores.
|
||||
type MiembrosListadoResponse struct {
|
||||
Usuarios []MiembroResponse `json:"usuarios"`
|
||||
Miembros []MiembroResponse `json:"miembros"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
// MiembroCreadoResponse es la respuesta de alta de un miembro.
|
||||
type MiembroCreadoResponse struct {
|
||||
Usuario MiembroResponse `json:"usuario"`
|
||||
PasswordTemporal string `json:"password_temporal"`
|
||||
UsuarioExistente bool `json:"usuario_existente"`
|
||||
}
|
||||
|
||||
// InvitacionResponse es la representación pública de una invitación.
|
||||
type InvitacionResponse struct {
|
||||
ID uint `json:"id"`
|
||||
EmpresaID uint `json:"empresa_id"`
|
||||
Email string `json:"email"`
|
||||
Rol string `json:"rol"`
|
||||
GrupoID uint `json:"grupo_id"`
|
||||
ExpiraEn time.Time `json:"expira_en"`
|
||||
UsadaEn *time.Time `json:"usada_en,omitempty"`
|
||||
CreadaPor uint `json:"creada_por"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// InvitacionesResponse es el envelope de invitaciones de una empresa.
|
||||
type InvitacionesResponse struct {
|
||||
Invitaciones []InvitacionResponse `json:"invitaciones"`
|
||||
}
|
||||
|
||||
// InvitacionCreadaResponse Agrega los datos de entrega al alta de invitación.
|
||||
type InvitacionCreadaResponse struct {
|
||||
Invitacion InvitacionResponse `json:"invitacion"`
|
||||
Token string `json:"token"`
|
||||
Link string `json:"link"`
|
||||
EmailEnviado bool `json:"email_enviado"`
|
||||
ExpiraEn time.Time `json:"expira_en"`
|
||||
}
|
||||
|
||||
// EmpresaAdminResponse es la vista de empresa para plataforma.
|
||||
type EmpresaAdminResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Nombre string `json:"nombre"`
|
||||
Slug string `json:"slug"`
|
||||
Cuit *string `json:"cuit,omitempty"`
|
||||
Activa bool `json:"activa"`
|
||||
Miembros int64 `json:"miembros"`
|
||||
Owners int64 `json:"owners"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// EmpresasAdminListadoResponse es el envelope de empresas de plataforma.
|
||||
type EmpresasAdminListadoResponse struct {
|
||||
Empresas []EmpresaAdminResponse `json:"empresas"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
// EmpresaCreadaResponse es la respuesta de alta de empresa desde plataforma.
|
||||
type EmpresaCreadaResponse struct {
|
||||
Empresa EmpresaAdminResponse `json:"empresa"`
|
||||
Owner MiembroResponse `json:"owner"`
|
||||
PasswordTemporal string `json:"password_temporal"`
|
||||
OwnerExistente bool `json:"owner_existente"`
|
||||
}
|
||||
|
||||
// UsuarioAdminResponse es la vista global de usuario para plataforma.
|
||||
type UsuarioAdminResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Activo bool `json:"activo"`
|
||||
DebeCambiarPassword bool `json:"debe_cambiar_password"`
|
||||
Empresas int `json:"empresas"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// UsuariosAdminListadoResponse es el envelope de usuarios de plataforma.
|
||||
type UsuariosAdminListadoResponse struct {
|
||||
Usuarios []UsuarioAdminResponse `json:"usuarios"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
// UsuariosListadoResponse es el envelope de usuarios de una empresa.
|
||||
type UsuariosListadoResponse struct {
|
||||
Usuarios []UsuarioResponse `json:"usuarios"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
@@ -9,6 +9,7 @@ type GrupoSimpleDTO struct {
|
||||
}
|
||||
|
||||
type PermisoSimpleDTO struct {
|
||||
ID uint `json:"id"`
|
||||
Nombre string `json:"nombre"`
|
||||
Alias string `json:"alias"`
|
||||
Imagen string `json:"imagen"`
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package dto
|
||||
|
||||
import "time"
|
||||
|
||||
// UsuarioResponse es la representación pública de un usuario.
|
||||
// No incluye contraseña, grupos ni empresas; esos datos se exponen
|
||||
// mediante DTOs específicos cuando el endpoint los necesita.
|
||||
type UsuarioResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Activo bool `json:"activo"`
|
||||
DebeCambiarPassword bool `json:"debe_cambiar_password"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
||||
}
|
||||
Reference in new issue
Block a user