forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operation_log.go
70 lines (59 loc) · 1.62 KB
/
operation_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
60
61
62
63
64
65
66
67
68
69
70
package models
import (
"github.com/nneesshh/go-admin/modules/db"
"github.com/nneesshh/go-admin/modules/db/dialect"
)
// OperationLogModel is operation log model structure.
type OperationLogModel struct {
Base
Id int64
UserId int64
Path string
Method string
Ip string
Input string
CreatedAt string
UpdatedAt string
}
// OperationLog return a default operation log model.
func OperationLog() OperationLogModel {
return OperationLogModel{Base: Base{TableName: "goadmin_operation_log"}}
}
// Find return a default operation log model of given id.
func (t OperationLogModel) Find(id interface{}) OperationLogModel {
item, _ := t.Table(t.TableName).Find(id)
return t.MapToModel(item)
}
func (t OperationLogModel) SetConn(con db.Connection) OperationLogModel {
t.Conn = con
return t
}
// New create a new operation log model.
func (t OperationLogModel) New(userId int64, path, method, ip, input string) OperationLogModel {
id, _ := t.Table(t.TableName).Insert(dialect.H{
"user_id": userId,
"path": path,
"method": method,
"ip": ip,
"input": input,
})
t.Id = id
t.UserId = userId
t.Path = path
t.Method = method
t.Ip = ip
t.Input = input
return t
}
// MapToModel get the operation log model from given map.
func (t OperationLogModel) MapToModel(m map[string]interface{}) OperationLogModel {
t.Id = m["id"].(int64)
t.UserId = m["user_id"].(int64)
t.Path, _ = m["path"].(string)
t.Method, _ = m["method"].(string)
t.Ip, _ = m["ip"].(string)
t.Input, _ = m["input"].(string)
t.CreatedAt, _ = m["created_at"].(string)
t.UpdatedAt, _ = m["updated_at"].(string)
return t
}