def record_audit_v2(data, db=None, request=None, log_from="python", event_type="training-coach"):
    default = {
        "host_name": "server",
        "user_id": 0

    }
    token_data = request.state.token_data or default
    # need to check host_name by regex that will contain zenarate
    server_name = token_data.get("host_name") or request.state.domain or request.state.host_name
    logged_in_user_id = token_data.get("user_id")
    switched_user_id = request.state.user_info.get("user_id")
    session_id = request.state.session_id
    uuid = request.state.uuid
    brand_name = None
    ip_address = None
    request_uri = None
    user_agent = None
    event_type = event_type
    # event_id = f"loggedIn_id-{logged_in_user_id}-switched_user_id-{switched_user_id}"

    try:
        brand_settings_json = helper.get_brand_settings_json(user_id=logged_in_user_id, db=db)
        if brand_settings_json:
            brand_name = brand_settings_json.get("name")
    except Exception:
        print("Error: brand settings data not found.")

    if settings.environment in ["local"]:
        hostname = "socket.gethostname()"
        if (hostname):
            ip_address = 'socket.gethostbyname(hostname)'
    else:
        hostname = socket.gethostname()
        if (hostname):
            ip_address = socket.gethostbyname(hostname)
    
    if request:
        request_uri = f"{request.url.path}?{request.url.query}" if request.url.query else f"{request.url.path}"
        user_agent = str(request.headers.get('user-agent'))

    data = str(data)

    audit = {
        "log_from": log_from,
        "uuid": uuid,
        "event_type" : event_type,
        "loggedIn_user_id" : logged_in_user_id,
        "switched_user_id" : switched_user_id,
        "session_id" : session_id,
        "brandName" : brand_name,
        "data" : data,
        "ip_address" : ip_address,
        "server_name" : server_name,
        "request_uri" : request_uri,
        "user_agent" : user_agent,
        "created_date" : dtu.get_datetime_db_format()
    }
    logger = config_logger(data=token_data)
    logger.info(json.dumps(audit))
    return None

this is  record audit funtion 

@jwt_token_decorator
async def get_userlist_assignment(
        request: Request,
        param: UserAssignmentQueryParams = Depends(),
        db: Session = Depends(get_db),
        token_data: dict = Depends(verify_jwt_token)
):
    try:
            loggedIn_user_id = token_data.get("user_id", None)
            account_obj = get_account_by_user_id(loggedIn_user_id, db)
            account_id = account_obj.id
            assignmentUtils_obj = AssignmentUtils(db=db, request=request)
            res_data = assignmentUtils_obj.assignment_userlist(
                assignment_id = param.assignment_id,
                account_id = account_id,
                page=param.page,
                limit=param.limit,
                request=request
            )
            return response(data=res_data)
    except Exception as e:
        message = exception_handler(module='assignment', func='get_userlist_assignment', token_data=token_data, db=db,
                                    request=request)
        return try_except_err_response(message=message)

 def assignment_userlist(self, **data):
        try:
            OFFSET = (data.get("page", 1) - 1) * data.get("limit", 10)
            LIMIT = data.get("limit", 10)
            assignment_id=data.get("assignment_id")
            
            tag_coll_obj = self.db.query(TagCollection).filter(
                TagCollection.account_id == data.get("account_id"),
                TagCollection.entity == 1,
                TagCollection.inactive == 0
                ).all()
            
            tag_coll_list = []
            if tag_coll_obj:
                for each_tag_C in tag_coll_obj:
                    tag_coll_list.append(each_tag_C.name)
                    
            query = self.db.query(
                    User.id,
                    User.email,
                    User.username,
                    User.inactive,
                    User.metafields,
                    User.account_id,
                    AuthAssignment.itemname
                ) \
                .select_from(AssignmentContentUserMapping) \
                .join(User, User.id == AssignmentContentUserMapping.user_id) \
                .join(AuthAssignment, AuthAssignment.userid == User.id, isouter=True) \
                .filter(
                    AssignmentContentUserMapping.assignment_id == assignment_id,
                    AssignmentContentUserMapping.is_deleted == 0,
                    User.inactive == 0,
                    User.email.isnot(None),
                    User.email != ""
                )

            all_users = query.all()
            
            seen_user_ids = set()
            resource = []
            
            for user in all_users:
                if user.id not in seen_user_ids:
                    seen_user_ids.add(user.id)

                    user_id = user.id
                    account_id = user.account_id
                    query = self.db.query(
                    UserTagMapping,
                    Tag.name.label('tag_name'),
                    TagCollection.name.label('tag_collection_name')
                    ).join(
                    Tag, UserTagMapping.tag_id == Tag.id 
                    ).join(
                    TagCollection, (Tag.tag_collection_id == TagCollection.id) 
                    ).filter(
                    UserTagMapping.user_id == user_id,
                    UserTagMapping.inactive == 0,
                    Tag.account_id == account_id,
                    Tag.inactive == 0,
                    TagCollection.inactive == 0,
                    TagCollection.account_id == account_id
                    )
                    
                    # tag_coll_list
                    tag_info={}
                    for each in query:
                        tag_info[each.tag_collection_name]=each.tag_name

                    # Prepare user data
                    for each_tag_coll_name in tag_coll_list:
                        if tag_info.get(each_tag_coll_name) is None:
                            tag_info[each_tag_coll_name] = ""
                        
                    user_dict = {
                        "user_id": user.id,
                        "username": user.username.strip() if user.username else None,
                        "email": user.email,
                        "inactive": user.inactive,
                        "role": user.itemname,
                        "account_id": user.account_id,
                        "existing_metafields": tag_info,
                    }
                    resource.append(user_dict)


            final_data = resource
        

            final_data = final_data[OFFSET : OFFSET + LIMIT]
            return {"data_list": final_data, "count": len(resource)}

        except Exception as e:
            raise e

implement record audit in it