oef/orm/usermodifier.go

48 lines
751 B
Go
Raw Normal View History

2020-01-27 08:35:37 +01:00
package orm
type Modifier interface {
SetCreatorID(id uint)
SetUpdaterID(id uint)
SetCreatorRole(role string)
SetUpdaterRole(role string)
SetCreatorIP(addr string)
SetUpdaterIP(addr string)
}
type UserModifier struct {
CreatorID uint
UpdaterID uint
CreatorRole string
UpdaterRole string
CreatorIP string
UpdaterIP string
Creator *User
Updater *User
}
func (um UserModifier) CreatedBy() *User {
switch um.CreatorRole {
case "administrator":
return &AdministratorUser
case "subscriber":
return &SubscriberUser
}
return um.Creator
}
func (um UserModifier) UpdatedBy() *User {
switch um.UpdaterRole {
case "administrator":
return &AdministratorUser
case "subscriber":
return &SubscriberUser
}
return um.Updater
}