Skip to content

Commit

Permalink
fix: remove roles from backend search
Browse files Browse the repository at this point in the history
  • Loading branch information
BramMeir committed Apr 16, 2024
1 parent ddd7546 commit 41f891c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
26 changes: 10 additions & 16 deletions backend/api/views/assistant_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,18 @@ def create(self, request: Request, *args, **kwargs) -> Response:
def search(self, request: Request) -> Response:
# Extract filter params
search = request.query_params.get("search", "")
roles = request.query_params.getlist("roles[]")
faculties = request.query_params.getlist("faculties[]")

# Make sure that if roles are passed, assistant is a selected role
if roles and "assistant" not in roles:
queryset = []

else:
# Filter the queryset based on the search term
queryset = Assistant.objects.annotate(
full_name=Concat('first_name', Value(' '), 'last_name')
).filter(
full_name__icontains=search
)

# Filter the queryset based on selected faculties
if faculties:
queryset = queryset.filter(faculties__id__in=faculties)
# Filter the queryset based on the search term
queryset = Assistant.objects.annotate(
full_name=Concat('first_name', Value(' '), 'last_name')
).filter(
full_name__icontains=search
)

# Filter the queryset based on selected faculties
if faculties:
queryset = queryset.filter(faculties__id__in=faculties)

# Serialize the resulting queryset
serializer = self.serializer_class(self.paginate_queryset(queryset), many=True, context={
Expand Down
24 changes: 9 additions & 15 deletions backend/api/views/teacher_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,18 @@ def create(self, request: Request, *args, **kwargs) -> Response:
def search(self, request: Request) -> Response:
# Extract filter params
search = request.query_params.get("search", "")
roles = request.query_params.getlist("roles[]")
faculties = request.query_params.getlist("faculties[]")

# Make sure that if roles are passed, teacher is a selected role
if roles and "teacher" not in roles:
queryset = []

else:
# Filter the queryset based on the search term
queryset = Teacher.objects.annotate(
full_name=Concat('first_name', Value(' '), 'last_name')
).filter(
full_name__icontains=search
)
# Filter the queryset based on the search term
queryset = Teacher.objects.annotate(
full_name=Concat('first_name', Value(' '), 'last_name')
).filter(
full_name__icontains=search
)

# Filter the queryset based on selected faculties
if faculties:
queryset = queryset.filter(faculties__id__in=faculties)
# Filter the queryset based on selected faculties
if faculties:
queryset = queryset.filter(faculties__id__in=faculties)

# Serialize the resulting queryset
serializer = self.serializer_class(self.paginate_queryset(queryset), many=True, context={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,20 @@ const filteredUsers = ref<User[] | null>(null);
* Fetch the users based on the filter.
*/
async function fetchUsers(): Promise<void> {
await searchTeachers(filter.value, page.value, pageSize.value);
await searchAssistants(filter.value, page.value, pageSize.value);
if (filter.value.roles.length === 0) {
// No roles selected, so all users should be fetched
await searchTeachers(filter.value, page.value, pageSize.value);
await searchAssistants(filter.value, page.value, pageSize.value);
} else {
// Depending on the roles, fetch the users
if (filter.value.roles.includes('teacher')) {
await searchTeachers(filter.value, page.value, pageSize.value);
}
if (filter.value.roles.includes('assistant')) {
await searchAssistants(filter.value, page.value, pageSize.value);
}
}
// Set the filtered users
filteredUsers.value = [...(teacherPagination.value?.results ?? []), ...(assistantPagination.value?.results ?? [])];
Expand Down
1 change: 0 additions & 1 deletion frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ app.use(ConfirmationService);
app.directive('ripple', Ripple);
app.directive('tooltip', Tooltip);


/* Mount the application */
app.mount('#app');
4 changes: 2 additions & 2 deletions frontend/src/views/courses/roles/TeacherCourseView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ const handleClone = async (): Promise<void> => {
<div class="flex justify-content-between align-items-center my-6">
<Title class="m-0">{{ t('views.courses.teachers_and_assistants.title') }}</Title>

<div v-tooltip.top="t('views.courses.teachers_and_assistants.edit')">
<div v-tooltip.top="t('views.courses.teachers_and_assistants.edit')">
<TeacherAssistantUpdateButton :course="props.course" />
</div>
</div>
</div>
<!-- List with teachers and assistants -->
<TeacherAssistantList :course="props.course" :users="course.teachers.concat(course.assistants)" />
Expand Down

0 comments on commit 41f891c

Please sign in to comment.