modificaciones de mejora
This commit is contained in:
+29
-6
@@ -26,25 +26,48 @@ func (OssApi) TableName() string {
|
||||
return "oss_api"
|
||||
}
|
||||
|
||||
// GetAllQrVcard obtiene todos los registros de QrVcard con paginación y búsqueda
|
||||
func GetAllOssApi(limit, offset int, search string) ([]OssApi, int64, error) {
|
||||
// GetAllOssApi obtiene todos los registros de OssApi con paginación, búsqueda, filtros y orden
|
||||
func GetAllOssApi(limit, offset int, search, provider, estado, sortBy, sortDir, dateFrom, dateTo string) ([]OssApi, int64, error) {
|
||||
var items []OssApi
|
||||
var total int64
|
||||
db := app.Http.Database.DB.Model(&OssApi{})
|
||||
|
||||
// Si se pasa un término de búsqueda, lo aplicamos en la consulta
|
||||
if search != "" {
|
||||
db = db.Where("name LIKE ?", "%"+search+"%")
|
||||
}
|
||||
if provider != "" {
|
||||
db = db.Where("provider = ?", provider)
|
||||
}
|
||||
if estado == "activo" {
|
||||
db = db.Where("is_active = ?", true)
|
||||
} else if estado == "inactivo" {
|
||||
db = db.Where("is_active = ?", false)
|
||||
}
|
||||
if dateFrom != "" {
|
||||
db = db.Where("created_at >= ?", dateFrom)
|
||||
}
|
||||
if dateTo != "" {
|
||||
db = db.Where("created_at <= ?", dateTo+" 23:59:59")
|
||||
}
|
||||
|
||||
// Contamos el total de registros
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
log.Printf("Error counting OssApi: %v", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// Obtenemos los registros con paginación
|
||||
if err := db.Order("id DESC").Limit(limit).Offset(offset).Find(&items).Error; err != nil {
|
||||
allowedSorts := map[string]bool{
|
||||
"id": true, "name": true, "provider": true,
|
||||
"endpoint": true, "bucket_name": true, "region": true,
|
||||
"is_active": true, "created_at": true,
|
||||
}
|
||||
if !allowedSorts[sortBy] {
|
||||
sortBy = "id"
|
||||
}
|
||||
if sortDir != "asc" {
|
||||
sortDir = "desc"
|
||||
}
|
||||
|
||||
if err := db.Order(sortBy+" "+sortDir).Limit(limit).Offset(offset).Find(&items).Error; err != nil {
|
||||
log.Printf("Error retrieving OssApi: %v", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user