turash/bugulma/backend/internal/domain/activity.go
2025-12-15 10:06:41 +01:00

60 lines
2.3 KiB
Go

package domain
import (
"context"
"time"
)
// ActivityAction represents the type of action performed
type ActivityAction string
const (
ActivityActionCreate ActivityAction = "create"
ActivityActionUpdate ActivityAction = "update"
ActivityActionDelete ActivityAction = "delete"
ActivityActionVerify ActivityAction = "verify"
ActivityActionReject ActivityAction = "reject"
ActivityActionLogin ActivityAction = "login"
ActivityActionLogout ActivityAction = "logout"
ActivityActionView ActivityAction = "view"
ActivityActionExport ActivityAction = "export"
ActivityActionImport ActivityAction = "import"
ActivityActionOther ActivityAction = "other"
)
// ActivityLog represents a system activity log entry
type ActivityLog struct {
ID string `gorm:"primaryKey;type:text"`
UserID string `gorm:"type:text;not null;index"`
Action ActivityAction `gorm:"type:varchar(50);not null;index"`
TargetType string `gorm:"type:varchar(50);not null;index"` // organization, user, page, etc.
TargetID string `gorm:"type:text;not null;index"`
Metadata string `gorm:"type:jsonb"` // JSON object with additional data
IPAddress string `gorm:"type:varchar(45)"` // IPv4 or IPv6
UserAgent string `gorm:"type:text"`
Timestamp time.Time `gorm:"not null;index"`
// Associations
User *User `gorm:"foreignKey:UserID"`
}
// TableName specifies the table name for GORM
func (ActivityLog) TableName() string {
return "activity_logs"
}
// SystemSettingsRepository defines access to key-value system settings
type SystemSettingsRepository interface {
Get(ctx context.Context, key string) (map[string]any, error)
Set(ctx context.Context, key string, value map[string]any) error
}
// ActivityLogRepository defines the interface for activity log operations
type ActivityLogRepository interface {
Create(ctx context.Context, activity *ActivityLog) error
GetByUser(ctx context.Context, userID string, limit, offset int) ([]*ActivityLog, int64, error)
GetByTarget(ctx context.Context, targetType, targetID string, limit, offset int) ([]*ActivityLog, int64, error)
GetRecent(ctx context.Context, limit int) ([]*ActivityLog, error)
GetByAction(ctx context.Context, action ActivityAction, limit, offset int) ([]*ActivityLog, int64, error)
}