initial commit

This commit is contained in:
kandrusyak
2023-06-23 20:51:41 +03:00
parent 438dc1a716
commit 8e9eeb989c
13 changed files with 458 additions and 0 deletions

27
pkg/utils/query.go Normal file
View File

@@ -0,0 +1,27 @@
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)
}
}