audit_trail

package
v1.0.52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(db *gorm.DB) error

Migrate applies the necessary database migrations for the audit trail model.

It ensures that the underlying database schema is up to date with the current version of the AuditTrailModel.

If the migration fails, the error is returned to the caller.

Types

type AuditAction

type AuditAction string
const (
	ActionCreate   AuditAction = "CREATE"
	ActionUpdate   AuditAction = "UPDATE"
	ActionDelete   AuditAction = "DELETE"
	ActionAccept   AuditAction = "ACCEPT"
	ActionReject   AuditAction = "REJECT"
	ActionComplete AuditAction = "COMPLETE"
)

type AuditTrailModel

type AuditTrailModel struct {
	shared.BaseModel
	UserID   string      `gorm:"not null"` // ID user yang melakukan aksi
	Action   AuditAction `gorm:"not null"` // Jenis aksi (CREATE, UPDATE, DELETE, dll.)
	Entity   string      `gorm:"not null"` // Entitas yang terlibat (misalnya, "OrderRequest")
	EntityID string      `gorm:"not null"` // ID entitas yang terlibat
	Details  string      `gorm:"type:json"`
}

func (*AuditTrailModel) BeforeCreate

func (a *AuditTrailModel) BeforeCreate(tx *gorm.DB) (err error)

func (*AuditTrailModel) TableName

func (a *AuditTrailModel) TableName() string

type AuditTrailService

type AuditTrailService struct {
	// contains filtered or unexported fields
}

func NewAuditTrailService

func NewAuditTrailService(erpContext *context.ERPContext) *AuditTrailService

NewAuditTrailService creates a new instance of AuditTrailService with the given ERP context. It will call Migrate() if SkipMigration is not set to true.

func (*AuditTrailService) GetAuditTrails

func (s *AuditTrailService) GetAuditTrails(entity string, entityID uint) ([]AuditTrailModel, error)

GetAuditTrails retrieves the audit trail for a given entity and entity ID.

It performs a query against the audit trail table with the given entity and entity ID, and returns the results. If the query fails, the error is returned to the caller.

The returned slice is empty if no audit trail records match the query.

func (*AuditTrailService) LogAction

func (s *AuditTrailService) LogAction(userID string, action AuditAction, entity string, entityID, details string) error

LogAction creates a new audit trail record with the provided details.

It constructs an AuditTrailModel using the given userID, action, entity, entityID, and details, and inserts it into the database. If the insertion fails, the error is returned to the caller.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL