Skip to content
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

Added missing fields to Person and CourseRun Search API #94

Open
wants to merge 1 commit into
base: develop-koa
Choose a base branch
from

Conversation

manan-memon
Copy link

This PR adds the following missing fields in the course_runs and people search apis.

course_run:

subject, staff, uuid, status, announcement, external_key, is_marketable, invite_only, outcome, license, hidden, reporting_type, eligible_for_financial_aid, has_ofac_restrictions, ofac_comment, enrollment_count, recent_enrollment_count, expected_program_type, expected_program_name

people:

given_name, family_name, slug, email, major_works, published, phone_number, website, urls, urls_detailed, areas_of_expertise

Testing details:

Curl the following api endpoints to verify the changes

course_run:

curl --location 'https://edlydev.discovery.multisitesdev.edly.io/api/v1/search/course_run/' \
--header 'Authorization: JWT eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiAiZE1icHN6d2tGTVRWZHFjRnozZFJxQnR0UVFYTEI1Tkt4V0oiLCAiZXhwIjogMTcyNzEwOTUxNywgImlhdCI6IDE3MjcwNzM1MTcsICJpc3MiOiAiaHR0cHM6Ly9kZXYuY291cnNlcy5tdWx0aXNpdGVzZGV2LmVkbHkuaW8vb2F1dGgyIiwgInByZWZlcnJlZF91c2VybmFtZSI6ICJkaXNjb3Zlcnlfd29ya2VyIiwgInNjb3BlcyI6IFsicmVhZCIsICJ3cml0ZSIsICJlbWFpbCIsICJwcm9maWxlIl0sICJ2ZXJzaW9uIjogIjEuMi4wIiwgInN1YiI6ICIyOTdmOGQ0ZTYyOThjODU3MzM5ZmVkZGE5YWM1ZWQ0NiIsICJmaWx0ZXJzIjogW10sICJpc19yZXN0cmljdGVkIjogZmFsc2UsICJlbWFpbF92ZXJpZmllZCI6IHRydWUsICJlbWFpbCI6ICJkaXNjb3Zlcnlfd29ya2VyQGV4YW1wbGUuY29tIiwgIm5hbWUiOiAiZGlzY292ZXJ5X3dvcmtlciIsICJmYW1pbHlfbmFtZSI6ICIiLCAiZ2l2ZW5fbmFtZSI6ICIiLCAiYWRtaW5pc3RyYXRvciI6IHRydWUsICJzdXBlcnVzZXIiOiBmYWxzZX0.EKhGhmmonRcxYVneyPgsVjChOrJxwGF_20UE1LzRPSU' \
--header 'Cookie: sessionid=1|791hlyo9ct7qy8exhzv8jwkes7yfd419|xLk7QCOajwmw|ImY0MWJjMzg3MjA0NGFkZDNjMDAyZmUzNTc1YmJiOWI3MjFjMzAwNmE4Mzk1YzA2YzQ5ZTgxMzAzYmY4YzdhMjIi:1sOAO2:mWCkWrzx0nc4Z_ORI1fFR7grhLU; AWSALB=dL4PJgH1RJaQ1psVxjBq5r369Pumb9wcITwEu1UElQro67rI+CCOYL3qUYiFAw/dx288PhGwDVnuZNgHnrODsA3eLEkozQ2+epQKBlFvADUSWGc+CeuWxVa1NaU0; AWSALBCORS=dL4PJgH1RJaQ1psVxjBq5r369Pumb9wcITwEu1UElQro67rI+CCOYL3qUYiFAw/dx288PhGwDVnuZNgHnrODsA3eLEkozQ2+epQKBlFvADUSWGc+CeuWxVa1NaU0; sessionid=1|30ge1irho31r5o9jwnu6m1j0ojd9sx8o|Dnq7eoY3y1Ei|IjdlYTRhOTY3YTY4NzZmMmFiNmU4ZDhiMWI2MDA4N2NhM2Y2NTI4ZTc3NjJjNTZmNmIzNjIzMjcxYTg1YmU4ZTYi:1ssciT:MToY_2PAxnr1L03mnr5-Du0f5q0; AWSALB=nDxnH2ydxWsRP2ibJfpt0qtnWAKO9r59rEfk75OW4XjK+/xDEP09ThBkTI1gkqlxOvVtZ6+FssPDH+qKaCKuxSJVE0uQGSab/ic7O6qYoneT5UDq0BHQqGSNttBz; AWSALBCORS=nDxnH2ydxWsRP2ibJfpt0qtnWAKO9r59rEfk75OW4XjK+/xDEP09ThBkTI1gkqlxOvVtZ6+FssPDH+qKaCKuxSJVE0uQGSab/ic7O6qYoneT5UDq0BHQqGSNttBz'

people:

curl --location 'https://edlydev.discovery.multisitesdev.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lFvADUSWGc+CeuWxVa1NaU0; AWSALBCORS=dL4PJgH1RJaQ1psVxjBq5r369Pumb9wcITwEu1UElQro67rI+CCOYL3qUYiFAw/dx288PhGwDVnuZNgHnrODsA3eLEkozQ2+epQKBlFvADUSWGc+CeuWxVa1NaU0; sessionid=1|30ge1irho31r5o9jwnu6m1j0ojd9sx8o|Dnq7eoY3y1Ei|IjdlYTRhOTY3YTY4NzZmMmFiNmU4ZDhiMWI2MDA4N2NhM2Y2NTI4ZTc3NjJjNTZmNmIzNjIzMjcxYTg1YmU4ZTYi:1ssciT:MToY_2PAxnr1L03mnr5-Du0f5q0; AWSALB=nDxnH2ydxWsRP2ibJfpt0qtnWAKO9r59rEfk75OW4XjK+/xDEP09ThBkTI1gkqlxOvVtZ6+FssPDH+qKaCKuxSJVE0uQGSab/ic7O6qYoneT5UDq0BHQqGSNttBz; AWSALBCORS=nDxnH2ydxWsRP2ibJfpt0qtnWAKO9r59rEfk75OW4XjK+/xDEP09ThBkTI1gkqlxOvVtZ6+FssPDH+qKaCKuxSJVE0uQGSab/ic7O6qYoneT5UDq0BHQqGSNttBz'

Comment on lines +2354 to +2357
return [{
'id': area_of_expertise.id,
'value': area_of_expertise.value,
} for area_of_expertise in sorted(result.object.areas_of_expertise.all(), key=attrgetter('id'))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can break this logic. Maybe into multiple lines for better understanding. One possible sol. can be. Better to order_by it, if it's a DB query.

areas = result.object.areas_of_expertise.all()
sorted_areas = sorted(areas, key=attrgetter('id'))
return [{'id': area.id, 'value': area.value} for area in sorted_areas]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to sort here?

Comment on lines +429 to +436
given_name = indexes.CharField(model_attr='given_name')
family_name = indexes.CharField(model_attr='family_name', null=True)
slug = indexes.CharField(model_attr='slug')
email = indexes.CharField(model_attr='email', null=True)
major_works = indexes.CharField(model_attr='major_works', null=True)
published = indexes.BooleanField(model_attr='published')
phone_number = indexes.CharField(model_attr='phone_number', null=True)
website = indexes.CharField(model_attr='website', null=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not require a migration file?

Comment on lines +2362 to +2364
if social_networks:
return social_networks[0].url
return None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it's better to use it the other way around. Deal with failure flow first in the code and return the happy at last. e.g

if not len(social_networks):
    return None

Comment on lines +2373 to +2380
def get_urls_detailed(self, result):
return [{
'id': network.id,
'type': network.type,
'title': network.title,
'display_title': network.display_title,
'url': network.url,
} for network in sorted(result.object.person_networks.all(), key=attrgetter('id'))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, We can break the logic here.

} for area_of_expertise in sorted(result.object.areas_of_expertise.all(), key=attrgetter('id'))]

def get_social_network_url(self, url_type, obj):
social_networks = [network for network in obj.person_networks.all() if network.type == url_type]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this querying database? Can't we filter in that case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants