-
Notifications
You must be signed in to change notification settings - Fork 10
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
Feat/search bar/backend #472
base: feat/coord-interface/main
Are you sure you want to change the base?
Conversation
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.
Overall, seems good for an initial implementation of a search query, with a few small comments. I'd forsee that you'll need to create a new custom serializer for this data though, since any expansions/modifications to the kinds of data we're querying over would be hard to do with this current implementation.
models.dot
Outdated
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.
The model visualization files should be excluded from the commits (either move them outside of the repository folder, or delete them)
csm_web/scheduler/urls.py
Outdated
@@ -23,4 +23,7 @@ | |||
path("matcher/<int:pk>/mentors/", views.matcher.mentors), | |||
path("matcher/<int:pk>/configure/", views.matcher.configure), | |||
path("matcher/<int:pk>/create/", views.matcher.create), | |||
path( | |||
"search/get-sections/", views.get_sections_of_user, name="get_sections_of_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.
Generally, the path itself shouldn't need to include actions like "get"; the HTTP method that the request has should indicate what the user wants. The more conventional path would be something like search/sections/
.
csm_web/scheduler/views/search.py
Outdated
@api_view(["GET"]) | ||
def get_sections_of_user(request): | ||
""" | ||
Gets all sections that match the queried 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.
I'd recommend adding a little more detail in this docstring describing exactly what the view expects from the request (ex. all of the possible query parameters, possible values for each parameter, how it handles each parameter, etc.)
csm_web/scheduler/views/search.py
Outdated
students = Student.objects.filter( | ||
# pylint: disable-next=unsupported-binary-operation | ||
Q(user__first_name__icontains=query) | ||
| Q(user__last_name__icontains=query) | ||
| Q(user__email__icontains=query), | ||
section__in=sections, | ||
).distinct() |
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 students
object seems to be overwritten in the if statements below when working with student_absences
. If it's possible to provide both the query and the student_absences
parameters, then they should work together properly. (And this should be explained in the docstring as well.)
csm_web/scheduler/views/search.py
Outdated
return Response( | ||
{ | ||
"error": ( | ||
"Invalid value for student_absences. Please provide an integer." |
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.
It seems like you also accept ranges, so more than just integers should be expected (and the error message should reflect that).
An alternative to providing this union of possible types is to specify a new (mutually exclusive) query parameter for a range of student absences. Either works though, so it's up to you whether you want to stick with this or split it up.
Implemented search.py, which has the following functionality:
What we can search for, with "query" or "student_absences":
What it should return:
E.G. if you query student_absences=4, the JSON will look like: