Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
ActionType ActionType `json:"actionType,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
UpdatedBy *string `json:"updatedBy,omitempty"`
UpdateReason *string `json:"updateReason,omitempty"`
}
Action base fields used in actions
func ActionEntityToAction ¶
func ActionEntityToAction(entity *ActionEntity, model *gorm.Model) (action Action)
ActionEntityToAction action entity to action When we create a model with audit action like
type XXXAction struct {
... // custom business fields
audit.Action
}
And the corresponding DB XXXActionEntity
type XXXActionEntity struct {
gorm.Model
... // custom business fields
audit.ActionEntity
}
When we want to map from the XXXEntity to XXXModel just do as below
func XXXActionEntityToXXXAction(e *XXXActionEntity) * XXXAction {
return &XXXAction{
... // mapping custom business fields
ActionEntity: ActionEntityToAction(&e.Entity, &e.Model)
}
}
type ActionEntity ¶
type ActionEntity struct {
UpdatedBy *string
UpdateReason *string `gorm:"column:update_reason"`
ActionType ActionType
}
ActionEntity base fields used in actions tables
type ActionType ¶
type ActionType string
ActionType action type
const ( Create ActionType = "Create" Update ActionType = "Update" Delete ActionType = "Delete" )
CRUD actions
func NewActionType ¶
func NewActionType(v ActionType) *ActionType
NewActionType create a new ActionType ref
type ChangeRequest ¶
ChangeRequest request to change a model
type DeleteRequest ¶
type DeleteRequest struct {
ChangeRequest
}
DeleteRequest request to delete a model
type Entity ¶
type Entity struct {
LastUpdatedBy *string `gorm:"-"`
UpdateReason *string `gorm:"-"`
ActionType *ActionType `gorm:"-"`
}
Entity base fields used in audit
func RequestToEntity ¶
RequestToEntity request to entity
type IChangeRequest ¶
type IChangeRequest interface {
SetID(uint)
}
IChangeRequest general change request interface
type Model ¶
type Model struct {
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
UpdatedBy *string `json:"updatedBy,omitempty"`
UpdateReason *string `json:"updateReason,omitempty"`
}
Model basic response fields
func EntityToModel ¶
EntityToModel base entity to base model When we create a model with audit like
type XXXModel struct {
... // custom business fields
Actions []*audit.Action
audit.Model
}
And the corresponding DB XXXEntity
type XXXModel struct {
gorm.Model
... // custom business fields
Actions []*audit.ActionEntity
audit.Entity
}
When we want to map from the XXXEntity to XXXModel just do as below
func XXXEntityToXXXModel(e *XXXEntity) * XXXModel {
return &XXXModel{
... // mapping custom business fields
Model: EntityToModel(&e.Entity, &e.Model)
}
}
type Request ¶
type Request struct {
// usually an email address, but can be something else
// for email see the limit here https://stackoverflow.com/a/574698
// for other like names or ids 254 is also enough
RequestedBy *string `json:"requestedBy,omitempty" binding:"required,printascii,max=254"`
Reason *string `json:"reason,omitempty" binding:"required,printascii,max=512"`
}
Request base request