feat: auto activity logging on issue create/delete, fix schema db.add bug
This commit is contained in:
18
app/services/activity.py
Normal file
18
app/services/activity.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""Activity logging helper — auto-record CRUD operations."""
|
||||
import json
|
||||
from sqlalchemy.orm import Session
|
||||
from app.models.activity import ActivityLog
|
||||
|
||||
|
||||
def log_activity(db: Session, action: str, entity_type: str, entity_id: int, user_id: int = None, details: dict = None):
|
||||
"""Record an activity log entry."""
|
||||
entry = ActivityLog(
|
||||
action=action,
|
||||
entity_type=entity_type,
|
||||
entity_id=entity_id,
|
||||
user_id=user_id,
|
||||
details=json.dumps(details) if details else None,
|
||||
)
|
||||
db.add(entry)
|
||||
db.commit()
|
||||
return entry
|
||||
Reference in New Issue
Block a user