-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jlc/experience relationships attributes #64
Conversation
COURSE_OVERVIEW_EXTRA_ATTRIBUTES = ["display_name"] | ||
USER_EXTRA_ATTRIBUTES = ["first_name", "last_name", "fullname", "username"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a setting, so we can add an extra attribute whenever we want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be another PR?
@@ -228,13 +228,15 @@ class LikeDislikeUnitExperienceView(UnitExperienceView): | |||
"author": { | |||
"data": { | |||
"type": "User", | |||
"id": "7" | |||
"id": "7", | |||
"attributes": {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why empty if you already added USER_EXTRA_ATTRIBUTES.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it could be variable ?
} | ||
} | ||
} | ||
"relationships": self.make_relationships_data() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where are you testing this new behavior ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.assertEqual(response.json()["data"]["relationships"], expected_data["data"]["relationships"]) |
self.assertEqual(response.json(), self.base_data) |
b368ae3
to
9bd8f11
Compare
Also its is possible to check nested fields if you declarate the field of instance separated by `__` | ||
eg: | ||
{ | ||
"field_level1__field_level2": "key_name" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you interchange that, I mean {"key_name": "field_level1__field_level2"}, I don't have an specific use of that but if you interchange that it's possible to have different keys with same value
{
"key_name": "field_level1__field_level2",
"key_2": "field_level1__field_level2"
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"data": { | ||
"type": "CourseOverview", | ||
"id": f"{self.my_course.id}", | ||
"attributes": map_attributes_from_instance_to_dict(self.user, COURSE_OVERVIEW_EXTRA_FIELD_MAPPING), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.user ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"data": { | ||
"type": "User", | ||
"id": f"{self.user.id}", | ||
"attributes": map_attributes_from_instance_to_dict(self.user, USER_EXTRA_FIELD_MAPPING), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are not you using the method get_course_extra_attributes and get_user_extra_attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I passed, maybe I was more focused on the map_dictionary function. Is better what you suggest.
de7a82f
990ab6d
to
de7a82f
Compare
de7a82f
to
396e258
Compare
refactor: change relationship expected data to tests This allow to match the expected new fields in the attributes relationship to the tests. style: clean pylint and add docstring refactor: change configuration for mapping style: pr recommendation for tests
396e258
to
79c1152
Compare
Description
This change is applied to course-experience api.
The relations file inherits from json api relation but add some extra fields
in the attributes of the relationship model.
The base json api only adds id and type, with this change you can add extra model
attributes.
https://github.com/django-json-api/django-rest-framework-json-api/blob/main/rest_framework_json_api/relations.py#L255
The attributes field was selected due to the recommendation of jsonapi.
https://jsonapi.org/format/#document-resource-objects
Testing instructions
Clone this repo and look al the course experience API endpoints.
Know they have extra data to each relationship.
Before
No extra field data to the relationships. Only id and type.
After
Configurable attributes field with model relation fields.
Additional information
jira story:
https://edunext.atlassian.net/jira/software/c/projects/FUTUREX/boards/36?modal=detail&selectedIssue=FUTUREX-459
next steps
Remove
username
for the main attributes field of each experience APIview because with this change the relationship of the author already has it.Checklist for Merge