Skip to content

Commit

Permalink
feat: [ACI-800] implement avro serializer for ccx locator (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrii <[email protected]>
  • Loading branch information
2 people authored and kyrylo-kh committed Apr 14, 2024
1 parent 48b9ed7 commit 5f96415
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions openedx_events/event_bus/avro/custom_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from abc import ABC, abstractmethod
from datetime import datetime

from ccx_keys.locator import CCXLocator
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2

Expand Down Expand Up @@ -49,6 +50,25 @@ def deserialize(data: str):
return CourseKey.from_string(data)


class CcxCourseLocatorAvroSerializer(BaseCustomTypeAvroSerializer):
"""
CustomTypeAvroSerializer for CCXLocator class.
"""

cls = CCXLocator
field_type = PYTHON_TYPE_TO_AVRO_MAPPING[str]

@staticmethod
def serialize(obj) -> str:
"""Serialize obj into string."""
return str(obj)

@staticmethod
def deserialize(data: str):
"""Deserialize string into obj."""
return CCXLocator.from_string(data)


class DatetimeAvroSerializer(BaseCustomTypeAvroSerializer):
"""
CustomTypeAvroSerializer for datetime class.
Expand Down Expand Up @@ -131,6 +151,7 @@ def deserialize(data: str):

DEFAULT_CUSTOM_SERIALIZERS = [
CourseKeyAvroSerializer,
CcxCourseLocatorAvroSerializer,
DatetimeAvroSerializer,
LibraryLocatorV2AvroSerializer,
LibraryUsageLocatorV2AvroSerializer,
Expand Down

0 comments on commit 5f96415

Please sign in to comment.