Private
Public Access
feat: funcionalidad de logs, paginacion y ui para filtros
This commit is contained in:
1 parent
3af069e9e8
commit
461c381f12
9 files changed
+259
-79
No files matched your search
@@ -2,6 +2,7 @@ package logs
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
dto_builders "repuestera_back/dto/Builders"
|
||||
r "repuestera_back/repositorios"
|
||||
"strconv"
|
||||
|
||||
@@ -31,8 +32,10 @@ func ObtenerLogs(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
logsdto := dto_builders.NewLogTablaBuilder().ConLogs(logs).Build()
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"logs": logs,
|
||||
"logs": logsdto,
|
||||
"maxlenght": cantpags,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
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,15 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"repuestera_back/models/logs"
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
type LogTablaDto struct {
|
||||
ID uint64 `gorm:"primaryKey" json:"id"`
|
||||
UsuarioID uint `gorm:"index;not null" json:"usuarioId"`
|
||||
Accion string `gorm:"type:varchar(50);not null" json:"accion"`
|
||||
Detalles datatypes.JSONSlice[logs.LogDetalle] `gorm:"type:json" json:"detalles,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
@@ -15,6 +15,7 @@ type Log struct {
|
||||
Detalles datatypes.JSONSlice[LogDetalle] `gorm:"type:json" json:"detalles,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Usuario models_seguridad.Usuario `gorm:"foreignKey:UsuarioID" json:"usuario,omitempty"`
|
||||
|
||||
}
|
||||
|
||||
func (Log) TableName() string {
|
||||
|
||||
Reference in new issue
Block a user