Private
Public Access
feat: hecho filtro de busqueda para los logs
This commit is contained in:
1 parent
1c0da9d70f
commit
a25afa1750
12 files changed
+288
-57
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package repositorios
|
||||
|
||||
import (
|
||||
dto "repuestera_back/dto/Logs"
|
||||
"repuestera_back/models/logs"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -10,6 +11,8 @@ type RepositorioLogs interface {
|
||||
IRepositorio[*logs.Log]
|
||||
ObtenerPorPaginas(pag uint) ([]logs.Log, error)
|
||||
CantPaginas() (int64, error)
|
||||
ObtenerConFiltros(p int, f dto.BusquedaLogsDto) ([]logs.Log, error)
|
||||
CantPaginasConFiltros(f dto.BusquedaLogsDto) (int64, error)
|
||||
}
|
||||
|
||||
type repositorioLogs struct {
|
||||
@@ -41,3 +44,58 @@ func (r *repositorioLogs) CantPaginas() (int64, error) {
|
||||
}
|
||||
return pags, nil
|
||||
}
|
||||
|
||||
func (r *repositorioLogs) ObtenerConFiltros(p int, f dto.BusquedaLogsDto) ([]logs.Log, error) {
|
||||
var logss []logs.Log
|
||||
|
||||
db := r.db.Model(&logs.Log{})
|
||||
|
||||
if f.UsuarioID != 0 {
|
||||
db = db.Where("usuario_id = ?", f.UsuarioID)
|
||||
}
|
||||
|
||||
if f.Accion != "" {
|
||||
db = db.Where("accion LIKE ?", "%"+f.Accion+"%")
|
||||
}
|
||||
|
||||
if !f.FechaInicio.IsZero() {
|
||||
db = db.Where("created_at >= ?", f.FechaInicio)
|
||||
}
|
||||
|
||||
if !f.FechaFin.IsZero() {
|
||||
db = db.Where("created_at <= ?", f.FechaFin)
|
||||
}
|
||||
|
||||
err := db.
|
||||
Limit(10).
|
||||
Offset(10 * p).
|
||||
Find(&logss).Error
|
||||
|
||||
return logss, err
|
||||
}
|
||||
|
||||
func (r *repositorioLogs) CantPaginasConFiltros(f dto.BusquedaLogsDto) (int64, error) {
|
||||
var cantpags int64
|
||||
|
||||
db := r.db.Model(&logs.Log{})
|
||||
|
||||
if f.UsuarioID != 0 {
|
||||
db = db.Where("usuario_id = ?", f.UsuarioID)
|
||||
}
|
||||
|
||||
if f.Accion != "" {
|
||||
db = db.Where("accion LIKE ?", "%"+f.Accion+"%")
|
||||
}
|
||||
|
||||
if !f.FechaInicio.IsZero() {
|
||||
db = db.Where("created_at >= ?", f.FechaInicio)
|
||||
}
|
||||
|
||||
if !f.FechaFin.IsZero() {
|
||||
db = db.Where("created_at <= ?", f.FechaFin)
|
||||
}
|
||||
|
||||
err := db.Count(&cantpags).Error
|
||||
|
||||
return cantpags, err
|
||||
}
|
||||
Reference in new issue
Block a user