Library/models/log_action.go

42 lines
938 B
Go
Raw Permalink Normal View History

2018-03-06 11:36:49 +00:00
package models
// ActionType is the action type
type ActionType int
// Define action types
const (
2018-03-06 12:43:07 +00:00
ActionTypeUnknown ActionType = -1
2018-03-06 11:36:49 +00:00
ActionTypeBookAdded ActionType = iota
ActionTypeBookUpdated
ActionTypeBookDeleted
ActionTypeAuthorAdded
ActionTypeAuthorUpdated
ActionTypeAuthorDeleted
ActionTypePublisherAdded
ActionTypePublisherUpdated
ActionTypePublisherDeleted
ActionTypeItemAdded
ActionTypeItemUpdated
ActionTypeItemDeleted
ActionTypeUserAdded
ActionTypeUserUpdated
ActionTypeUserDeleted
ActionTypeChangedUserPassword
)
// LogAction logs a user action
func logAction(actionType ActionType, user *User, itemID int64) (err error) {
_, err = x.Insert(UserLog{Log: actionType, UserID: user.ID, ItemID: itemID})
return
2018-03-06 12:43:07 +00:00
}
2018-03-06 14:33:18 +00:00
2018-04-13 12:41:31 +00:00
// GetAllLogs returns an array with all logs
2018-03-06 14:33:18 +00:00
func GetAllLogs() (logs []UserLog, err error) {
err = x.OrderBy("id DESC").Find(&logs)
if err != nil {
return logs, err
}
return logs, err
}