/
sys_events.go
46 lines (38 loc) · 1.01 KB
/
sys_events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package models
import (
"net/http"
"time"
"github.com/jinzhu/gorm"
"github.com/yapkah/go-api/pkg/e"
)
// SysEvents struct
type SysEvents struct {
ID int `gorm:"primary_key" json:"id"`
Type string `json:"type"`
BatchNo int `json:"batch_no"`
TimeStart time.Time `json:"time_start"`
TimeEnd time.Time `json:"time_end"`
Status int `json:"status"`
Setting string `json:"setting"`
}
// GetSysEventsFn
func GetSysEventsFn(arrCond []WhereCondFn, selectColumn string, debug bool) ([]*SysEvents, error) {
var result []*SysEvents
tx := db.Table("sys_events")
if selectColumn != "" {
tx = tx.Select(selectColumn)
}
if len(arrCond) > 0 {
for _, v := range arrCond {
tx = tx.Where(v.Condition, v.CondValue)
}
}
if debug {
tx = tx.Debug()
}
err := tx.Find(&result).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, &e.CustomError{HTTPCode: http.StatusInternalServerError, Code: e.ERROR, Msg: err.Error(), Data: err}
}
return result, nil
}