/
device_account_bind_log.go
59 lines (50 loc) · 2.01 KB
/
device_account_bind_log.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package models
import (
"net/http"
"time"
"github.com/jinzhu/gorm"
"github.com/yapkah/go-api/pkg/e"
)
// DeviceBindLog struct
type DeviceBindLog struct {
ID int `gorm:"primary_key" gorm:"column:id" json:"id"`
MemberID int `gorm:"column:member_id" json:"member_id"`
TOs string `gorm:"column:t_os" json:"t_os"`
TModel string `gorm:"column:t_model" json:"t_model"`
TManufacturer string `gorm:"column:t_manufacturer" json:"t_manufacturer"`
TAppVersion string `gorm:"column:t_app_version" json:"t_app_version"`
TOsVersion string `gorm:"column:t_os_version" json:"t_os_version"`
TPushNotiToken string `gorm:"column:t_push_noti_token" json:"t_push_noti_token"`
Bind int `gorm:"column:bind" json:"bind"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
CreatedBy string `gorm:"column:created_by" json:"created_by"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
UpdatedBy string `gorm:"column:updated_by" json:"updated_by"`
}
// AddDeviceBindLog add device bind log
func AddDeviceBindLog(saveData DeviceBindLog) error {
if err := db.Table("device_bind_log").Create(&saveData).Error; err != nil {
ErrorLog("AddDeviceBindLog", err.Error(), saveData)
return &e.CustomError{HTTPCode: http.StatusInternalServerError, Code: e.ERROR, Msg: err.Error(), Data: err}
}
return nil
}
// GetLatestDeviceBindLogFn get device_bind_log data with dynamic condition
func GetLatestDeviceBindLogFn(arrCond []WhereCondFn, debug bool) (*DeviceBindLog, error) {
var result DeviceBindLog
tx := db.Table("device_bind_log").
Order("created_at DESC")
if len(arrCond) > 0 {
for _, v := range arrCond {
tx = tx.Where(v.Condition, v.CondValue)
}
}
if debug {
tx = tx.Debug()
}
err := tx.First(&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
}