RezinaLMS-BackEnd/internal/domain/activity_log.go
Yared Yemane c742cb01c3 feat: comprehensive activity logging and fix question type definition persistence
Add activity log coverage across mutating APIs with shared recordActivity helper and expanded action/resource constants. Fix question type definition logs to use correct QUESTION_TYPE_DEFINITION actions. Persist question_type_definition_id inside CreateQuestion transaction.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-20 02:50:35 -07:00

204 lines
12 KiB
Go

package domain
import (
"encoding/json"
"time"
)
type ActivityAction string
const (
ActionCourseCreated ActivityAction = "COURSE_CREATED"
ActionCourseUpdated ActivityAction = "COURSE_UPDATED"
ActionCourseDeleted ActivityAction = "COURSE_DELETED"
ActionSubCourseCreated ActivityAction = "SUB_COURSE_CREATED"
ActionSubCourseUpdated ActivityAction = "SUB_COURSE_UPDATED"
ActionSubCourseDeleted ActivityAction = "SUB_COURSE_DELETED"
ActionVideoCreated ActivityAction = "VIDEO_CREATED"
ActionVideoUploaded ActivityAction = "VIDEO_UPLOADED"
ActionVideoPublished ActivityAction = "VIDEO_PUBLISHED"
ActionVideoUpdated ActivityAction = "VIDEO_UPDATED"
ActionVideoArchived ActivityAction = "VIDEO_ARCHIVED"
ActionVideoDeleted ActivityAction = "VIDEO_DELETED"
ActionUserCreated ActivityAction = "USER_CREATED"
ActionUserUpdated ActivityAction = "USER_UPDATED"
ActionUserDeleted ActivityAction = "USER_DELETED"
ActionSettingsUpdated ActivityAction = "SETTINGS_UPDATED"
ActionTeamMemberCreated ActivityAction = "TEAM_MEMBER_CREATED"
ActionTeamMemberInvited ActivityAction = "TEAM_MEMBER_INVITED"
ActionTeamMemberUpdated ActivityAction = "TEAM_MEMBER_UPDATED"
ActionTeamMemberDeleted ActivityAction = "TEAM_MEMBER_DELETED"
ActionCategoryCreated ActivityAction = "CATEGORY_CREATED"
ActionCategoryUpdated ActivityAction = "CATEGORY_UPDATED"
ActionCategoryDeleted ActivityAction = "CATEGORY_DELETED"
ActionAdminCreated ActivityAction = "ADMIN_CREATED"
ActionAdminUpdated ActivityAction = "ADMIN_UPDATED"
ActionSubscriptionPlanCreated ActivityAction = "SUBSCRIPTION_PLAN_CREATED"
ActionSubscriptionPlanUpdated ActivityAction = "SUBSCRIPTION_PLAN_UPDATED"
ActionSubscriptionPlanDeleted ActivityAction = "SUBSCRIPTION_PLAN_DELETED"
ActionQuestionCreated ActivityAction = "QUESTION_CREATED"
ActionQuestionUpdated ActivityAction = "QUESTION_UPDATED"
ActionQuestionDeleted ActivityAction = "QUESTION_DELETED"
ActionQuestionSetCreated ActivityAction = "QUESTION_SET_CREATED"
ActionQuestionSetUpdated ActivityAction = "QUESTION_SET_UPDATED"
ActionQuestionSetDeleted ActivityAction = "QUESTION_SET_DELETED"
ActionSubCourseDeactivated ActivityAction = "SUB_COURSE_DEACTIVATED"
ActionIssueCreated ActivityAction = "ISSUE_CREATED"
ActionIssueStatusUpdated ActivityAction = "ISSUE_STATUS_UPDATED"
ActionIssueDeleted ActivityAction = "ISSUE_DELETED"
ActionProgramCreated ActivityAction = "PROGRAM_CREATED"
ActionProgramUpdated ActivityAction = "PROGRAM_UPDATED"
ActionProgramDeleted ActivityAction = "PROGRAM_DELETED"
ActionModuleCreated ActivityAction = "MODULE_CREATED"
ActionModuleUpdated ActivityAction = "MODULE_UPDATED"
ActionModuleDeleted ActivityAction = "MODULE_DELETED"
ActionLessonCreated ActivityAction = "LESSON_CREATED"
ActionLessonUpdated ActivityAction = "LESSON_UPDATED"
ActionLessonDeleted ActivityAction = "LESSON_DELETED"
ActionPracticeCreated ActivityAction = "PRACTICE_CREATED"
ActionPracticeUpdated ActivityAction = "PRACTICE_UPDATED"
ActionPracticeDeleted ActivityAction = "PRACTICE_DELETED"
ActionQuestionTypeDefinitionCreated ActivityAction = "QUESTION_TYPE_DEFINITION_CREATED"
ActionQuestionTypeDefinitionUpdated ActivityAction = "QUESTION_TYPE_DEFINITION_UPDATED"
ActionQuestionTypeDefinitionDeleted ActivityAction = "QUESTION_TYPE_DEFINITION_DELETED"
ActionQuestionTypeDefinitionGroupCreated ActivityAction = "QUESTION_TYPE_DEFINITION_GROUP_CREATED"
ActionQuestionTypeDefinitionGroupUpdated ActivityAction = "QUESTION_TYPE_DEFINITION_GROUP_UPDATED"
ActionQuestionTypeDefinitionGroupDeleted ActivityAction = "QUESTION_TYPE_DEFINITION_GROUP_DELETED"
ActionExamPrepCatalogCourseCreated ActivityAction = "EXAM_PREP_CATALOG_COURSE_CREATED"
ActionExamPrepCatalogCourseUpdated ActivityAction = "EXAM_PREP_CATALOG_COURSE_UPDATED"
ActionExamPrepCatalogCourseDeleted ActivityAction = "EXAM_PREP_CATALOG_COURSE_DELETED"
ActionExamPrepCatalogCourseReordered ActivityAction = "EXAM_PREP_CATALOG_COURSE_REORDERED"
ActionExamPrepUnitCreated ActivityAction = "EXAM_PREP_UNIT_CREATED"
ActionExamPrepUnitUpdated ActivityAction = "EXAM_PREP_UNIT_UPDATED"
ActionExamPrepUnitDeleted ActivityAction = "EXAM_PREP_UNIT_DELETED"
ActionExamPrepUnitReordered ActivityAction = "EXAM_PREP_UNIT_REORDERED"
ActionExamPrepModuleCreated ActivityAction = "EXAM_PREP_MODULE_CREATED"
ActionExamPrepModuleUpdated ActivityAction = "EXAM_PREP_MODULE_UPDATED"
ActionExamPrepModuleDeleted ActivityAction = "EXAM_PREP_MODULE_DELETED"
ActionExamPrepModuleReordered ActivityAction = "EXAM_PREP_MODULE_REORDERED"
ActionExamPrepLessonCreated ActivityAction = "EXAM_PREP_LESSON_CREATED"
ActionExamPrepLessonUpdated ActivityAction = "EXAM_PREP_LESSON_UPDATED"
ActionExamPrepLessonDeleted ActivityAction = "EXAM_PREP_LESSON_DELETED"
ActionExamPrepLessonReordered ActivityAction = "EXAM_PREP_LESSON_REORDERED"
ActionExamPrepPracticeCreated ActivityAction = "EXAM_PREP_PRACTICE_CREATED"
ActionExamPrepPracticeUpdated ActivityAction = "EXAM_PREP_PRACTICE_UPDATED"
ActionExamPrepPracticeDeleted ActivityAction = "EXAM_PREP_PRACTICE_DELETED"
ActionPersonaCreated ActivityAction = "PERSONA_CREATED"
ActionPersonaUpdated ActivityAction = "PERSONA_UPDATED"
ActionPersonaDeleted ActivityAction = "PERSONA_DELETED"
ActionFAQCreated ActivityAction = "FAQ_CREATED"
ActionFAQUpdated ActivityAction = "FAQ_UPDATED"
ActionFAQDeleted ActivityAction = "FAQ_DELETED"
ActionAppVersionCreated ActivityAction = "APP_VERSION_CREATED"
ActionAppVersionUpdated ActivityAction = "APP_VERSION_UPDATED"
ActionAppVersionDeleted ActivityAction = "APP_VERSION_DELETED"
ActionEmailTemplateCreated ActivityAction = "EMAIL_TEMPLATE_CREATED"
ActionEmailTemplateUpdated ActivityAction = "EMAIL_TEMPLATE_UPDATED"
ActionEmailTemplateDeleted ActivityAction = "EMAIL_TEMPLATE_DELETED"
ActionFieldOptionCreated ActivityAction = "FIELD_OPTION_CREATED"
ActionFieldOptionUpdated ActivityAction = "FIELD_OPTION_UPDATED"
ActionFieldOptionDeleted ActivityAction = "FIELD_OPTION_DELETED"
ActionNotificationCreated ActivityAction = "NOTIFICATION_CREATED"
ActionNotificationUpdated ActivityAction = "NOTIFICATION_UPDATED"
ActionNotificationDeleted ActivityAction = "NOTIFICATION_DELETED"
ActionNotificationBulkSent ActivityAction = "NOTIFICATION_BULK_SENT"
ActionScheduledNotificationCancelled ActivityAction = "SCHEDULED_NOTIFICATION_CANCELLED"
ActionRatingSubmitted ActivityAction = "RATING_SUBMITTED"
ActionRatingDeleted ActivityAction = "RATING_DELETED"
ActionSubscriptionCreated ActivityAction = "SUBSCRIPTION_CREATED"
ActionSubscriptionCancelled ActivityAction = "SUBSCRIPTION_CANCELLED"
ActionSubscriptionAutoRenewUpdated ActivityAction = "SUBSCRIPTION_AUTO_RENEW_UPDATED"
ActionPaymentInitiated ActivityAction = "PAYMENT_INITIATED"
ActionPaymentVerified ActivityAction = "PAYMENT_VERIFIED"
ActionPaymentCancelled ActivityAction = "PAYMENT_CANCELLED"
ActionPaymentWebhookReceived ActivityAction = "PAYMENT_WEBHOOK_RECEIVED"
ActionAssessmentQuestionCreated ActivityAction = "ASSESSMENT_QUESTION_CREATED"
ActionFileUploaded ActivityAction = "FILE_UPLOADED"
ActionFilePresignCreated ActivityAction = "FILE_PRESIGN_CREATED"
ActionAuthLogin ActivityAction = "AUTH_LOGIN"
ActionAuthLogout ActivityAction = "AUTH_LOGOUT"
ActionAuthRegister ActivityAction = "AUTH_REGISTER"
ActionAuthTokenRefreshed ActivityAction = "AUTH_TOKEN_REFRESHED"
ActionUserPasswordReset ActivityAction = "USER_PASSWORD_RESET"
ActionUserProfilePictureUpdated ActivityAction = "USER_PROFILE_PICTURE_UPDATED"
ActionQuestionAudioAnswerSubmitted ActivityAction = "QUESTION_AUDIO_ANSWER_SUBMITTED"
ActionSMSSent ActivityAction = "SMS_SENT"
ActionLessonCompleted ActivityAction = "LESSON_COMPLETED"
ActionPracticeCompleted ActivityAction = "PRACTICE_COMPLETED"
ActionVideoEngagementRecorded ActivityAction = "VIDEO_ENGAGEMENT_RECORDED"
ActionDeviceRegistered ActivityAction = "DEVICE_REGISTERED"
ActionDeviceUnregistered ActivityAction = "DEVICE_UNREGISTERED"
ActionTeamInvitationResent ActivityAction = "TEAM_INVITATION_RESENT"
ActionTeamInvitationRevoked ActivityAction = "TEAM_INVITATION_REVOKED"
ActionTeamMemberPasswordChanged ActivityAction = "TEAM_MEMBER_PASSWORD_CHANGED"
ActionReferralCodeCreated ActivityAction = "REFERRAL_CODE_CREATED"
ActionUsersPurged ActivityAction = "USERS_PURGED"
)
type ResourceType string
const (
ResourceCourse ResourceType = "COURSE"
ResourceSubCourse ResourceType = "SUB_COURSE"
ResourceVideo ResourceType = "VIDEO"
ResourceUser ResourceType = "USER"
ResourceSettings ResourceType = "SETTINGS"
ResourceTeamMember ResourceType = "TEAM_MEMBER"
ResourceCategory ResourceType = "CATEGORY"
ResourceAdmin ResourceType = "ADMIN"
ResourceSubscriptionPlan ResourceType = "SUBSCRIPTION_PLAN"
ResourceQuestion ResourceType = "QUESTION"
ResourceQuestionSet ResourceType = "QUESTION_SET"
ResourceIssue ResourceType = "ISSUE"
ResourceProgram ResourceType = "PROGRAM"
ResourceModule ResourceType = "MODULE"
ResourceLesson ResourceType = "LESSON"
ResourcePractice ResourceType = "PRACTICE"
ResourceQuestionTypeDefinition ResourceType = "QUESTION_TYPE_DEFINITION"
ResourceQuestionTypeDefinitionGroup ResourceType = "QUESTION_TYPE_DEFINITION_GROUP"
ResourceExamPrepCatalogCourse ResourceType = "EXAM_PREP_CATALOG_COURSE"
ResourceExamPrepUnit ResourceType = "EXAM_PREP_UNIT"
ResourceExamPrepModule ResourceType = "EXAM_PREP_MODULE"
ResourceExamPrepLesson ResourceType = "EXAM_PREP_LESSON"
ResourceExamPrepPractice ResourceType = "EXAM_PREP_PRACTICE"
ResourcePersona ResourceType = "PERSONA"
ResourceFAQ ResourceType = "FAQ"
ResourceAppVersion ResourceType = "APP_VERSION"
ResourceEmailTemplate ResourceType = "EMAIL_TEMPLATE"
ResourceFieldOption ResourceType = "FIELD_OPTION"
ResourceNotification ResourceType = "NOTIFICATION"
ResourceRating ResourceType = "RATING"
ResourceSubscription ResourceType = "SUBSCRIPTION"
ResourcePayment ResourceType = "PAYMENT"
ResourceAssessmentQuestion ResourceType = "ASSESSMENT_QUESTION"
ResourceFile ResourceType = "FILE"
ResourceAuth ResourceType = "AUTH"
ResourceDevice ResourceType = "DEVICE"
ResourceReferral ResourceType = "REFERRAL"
)
type ActivityLog struct {
ID int64
ActorID *int64
ActorRole *string
Action string
ResourceType string
ResourceID *int64
Message *string
Metadata json.RawMessage
IPAddress *string
UserAgent *string
CreatedAt time.Time
}
type ActivityLogFilter struct {
ActorID *int64
Action *string
ResourceType *string
ResourceID *int64
After *time.Time
Before *time.Time
Limit int32
Offset int32
}