Skip to content

Commit

Permalink
feat: add new learning events for course grades and badges (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo-kh authored May 8, 2024
1 parent d231ed4 commit 6d62a74
Show file tree
Hide file tree
Showing 15 changed files with 645 additions and 43 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "badge",
"type": {
"name": "BadgeData",
"type": "record",
"fields": [
{
"name": "uuid",
"type": "string"
},
{
"name": "user",
"type": {
"name": "UserData",
"type": "record",
"fields": [
{
"name": "id",
"type": "long"
},
{
"name": "is_active",
"type": "boolean"
},
{
"name": "pii",
"type": {
"name": "UserPersonalData",
"type": "record",
"fields": [
{
"name": "username",
"type": "string"
},
{
"name": "email",
"type": "string"
},
{
"name": "name",
"type": "string"
}
]
}
}
]
}
},
{
"name": "template",
"type": {
"name": "BadgeTemplateData",
"type": "record",
"fields": [
{
"name": "uuid",
"type": "string"
},
{
"name": "origin",
"type": "string"
},
{
"name": "name",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "description",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "image_url",
"type": [
"null",
"string"
],
"default": null
}
]
}
}
]
}
}
],
"namespace": "org.openedx.learning.badge.awarded.v1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "badge",
"type": {
"name": "BadgeData",
"type": "record",
"fields": [
{
"name": "uuid",
"type": "string"
},
{
"name": "user",
"type": {
"name": "UserData",
"type": "record",
"fields": [
{
"name": "id",
"type": "long"
},
{
"name": "is_active",
"type": "boolean"
},
{
"name": "pii",
"type": {
"name": "UserPersonalData",
"type": "record",
"fields": [
{
"name": "username",
"type": "string"
},
{
"name": "email",
"type": "string"
},
{
"name": "name",
"type": "string"
}
]
}
}
]
}
},
{
"name": "template",
"type": {
"name": "BadgeTemplateData",
"type": "record",
"fields": [
{
"name": "uuid",
"type": "string"
},
{
"name": "origin",
"type": "string"
},
{
"name": "name",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "description",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "image_url",
"type": [
"null",
"string"
],
"default": null
}
]
}
}
]
}
}
],
"namespace": "org.openedx.learning.badge.revoked.v1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "course_passing_status",
"type": {
"name": "CcxCoursePassingStatusData",
"type": "record",
"fields": [
{
"name": "is_passing",
"type": "boolean"
},
{
"name": "user",
"type": {
"name": "UserData",
"type": "record",
"fields": [
{
"name": "id",
"type": "long"
},
{
"name": "is_active",
"type": "boolean"
},
{
"name": "pii",
"type": {
"name": "UserPersonalData",
"type": "record",
"fields": [
{
"name": "username",
"type": "string"
},
{
"name": "email",
"type": "string"
},
{
"name": "name",
"type": "string"
}
]
}
}
]
}
},
{
"name": "course",
"type": {
"name": "CcxCourseData",
"type": "record",
"fields": [
{
"name": "ccx_course_key",
"type": "string"
},
{
"name": "master_course_key",
"type": "string"
},
{
"name": "display_name",
"type": "string"
},
{
"name": "coach_email",
"type": "string"
},
{
"name": "start",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "end",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "max_students_allowed",
"type": [
"null",
"long"
],
"default": null
}
]
}
}
]
}
}
],
"namespace": "org.openedx.learning.ccx.course.passing.status.updated.v1"
}
Loading

0 comments on commit 6d62a74

Please sign in to comment.