28 lines
516 B
Go
28 lines
516 B
Go
package utils
|
|
|
|
import (
|
|
"github.com/labstack/echo/v4"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
)
|
|
|
|
func ApplySort(tx *gorm.DB, column string, isDesc bool) {
|
|
tx.Order(clause.OrderByColumn{
|
|
Column: clause.Column{Name: column},
|
|
Desc: isDesc,
|
|
})
|
|
}
|
|
|
|
func ApplyFilters(tx *gorm.DB, column string, value string) {
|
|
if column != "" && value != "" {
|
|
tx.Where(column + " LIKE '%" + value + "%'")
|
|
}
|
|
}
|
|
|
|
func ApplyIdFilter(c echo.Context, tx *gorm.DB) {
|
|
id := c.Param("id")
|
|
if id != "" {
|
|
tx.Where("id = ?", id)
|
|
}
|
|
}
|