48 lines
751 B
Go
48 lines
751 B
Go
|
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
|
||
|
}
|