Skip to content

Commit

Permalink
Merge pull request #198 from GSM-MSG/error/filter
Browse files Browse the repository at this point in the history
πŸ”€ :: ν•„ν„° 빈 리슀트 λ³΄λ‚Όλ•Œ λ°˜ν™˜ μ•ˆλ˜λŠ” 이슈 ν•΄κ²°
  • Loading branch information
Huuuunee authored Aug 23, 2023
2 parents 0184f91 + 7a75b5e commit 8672d45
Showing 1 changed file with 60 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,53 @@ class FilterStudentServiceImpl(
"ROLE_STUDENT" -> this.filterStudentsForStudent(students, filters)
else -> this.filterStudentsForAnonymous(students, filters)
}

private fun filterStudentsForTeacher(
students: List<Student.StudentWithUserInfo>,
filters: FiltersRequestData
): List<Student.StudentWithUserInfo> {
var filteredStudents = students

filters.majors?.let { majors -> // 전곡
filteredStudents = filteredStudents.filter { student ->
student.major in majors
}
if (filters.majors.isNotEmpty())
filteredStudents = filteredStudents.filter { student ->
student.major in majors
}
}

filters.techStacks?.let { techStacks -> // techStack
filteredStudents = filteredStudents.filter { student ->
student.techStack.intersect(techStacks.toSet()).isNotEmpty()
}
if (filters.techStacks.isNotEmpty())
filteredStudents = filteredStudents.filter { student ->
student.techStack.intersect(techStacks.toSet()).isNotEmpty()
}
}

filters.grade?.let { grade ->
filteredStudents = filteredStudents.filter { student ->
student.stuNum.substring(0, 1).toInt() in grade
}
if (filters.grade.isNotEmpty())
filteredStudents = filteredStudents.filter { student ->
student.stuNum.substring(0, 1).toInt() in grade
}
}


filters.classNum?.let { classNum ->
filteredStudents = filteredStudents.filter { student ->
student.stuNum.substring(1, 2).toInt() in classNum
}
if (filters.classNum.isNotEmpty())
filteredStudents = filteredStudents.filter { student ->
student.stuNum.substring(1, 2).toInt() in classNum
}
}

filters.department?.let { departments ->
filteredStudents = filteredStudents.filter { student ->
student.department.name in departments
}
if (filters.department.isNotEmpty())
filteredStudents = filteredStudents.filter { student ->
student.department.name in departments
}
}

filters.formOfEmployment?.let { formOfEmployments ->
filteredStudents = filteredStudents.filter { student ->
student.formOfEmployment.name in formOfEmployments
}
if (filters.formOfEmployment.isNotEmpty())
filteredStudents = filteredStudents.filter { student ->
student.formOfEmployment.name in formOfEmployments
}
}

if (filters.minGsmAuthenticationScore != null && filters.maxGsmAuthenticationScore != null)
Expand All @@ -70,6 +77,7 @@ class FilterStudentServiceImpl(
student.salary >= filters.minSalary && student.salary <= filters.maxSalary
}
}

filters.gsmAuthenticationScoreSort?.let { gsmScoreSort ->
filteredStudents =
if (gsmScoreSort == "ASCENDING") filteredStudents.sortedBy { it.gsmAuthenticationScore }
Expand All @@ -91,42 +99,52 @@ class FilterStudentServiceImpl(
return filteredStudents
}


private fun filterStudentsForStudent(
students: List<Student.StudentWithUserInfo>,
filters: FiltersRequestData
): List<Student.StudentWithUserInfo> {
var filteredStudents = students

filters.majors?.let { majors -> // 전곡
filteredStudents = filteredStudents.filter { student ->
student.major in majors
}
if (filters.majors.isNotEmpty())

filteredStudents = filteredStudents.filter { student ->
student.major in majors
}
}

filters.techStacks?.let { techStacks -> // techStack
filteredStudents = filteredStudents.filter { student ->
student.techStack.intersect(techStacks).isNotEmpty()
}
if (filters.techStacks.isNotEmpty())
filteredStudents = filteredStudents.filter { student ->
student.techStack.intersect(techStacks.toSet()).isNotEmpty()
}
}


filters.grade?.let { grade ->
filteredStudents = filteredStudents.filter { student ->
student.stuNum.substring(0, 1).toInt() in grade
}
if (filters.grade.isNotEmpty())
filteredStudents = filteredStudents.filter { student ->
student.stuNum.substring(0, 1).toInt() in grade
}
}

filters.classNum?.let { classNum ->
filteredStudents = filteredStudents.filter { student ->
student.stuNum.substring(1, 2).toInt() in classNum
}
if (filters.classNum.isNotEmpty())

filteredStudents = filteredStudents.filter { student ->
student.stuNum.substring(1, 2).toInt() in classNum
}
}

filters.department?.let { departments ->
filteredStudents = filteredStudents.filter { student ->
student.department.name in departments
}
if (filters.department.isNotEmpty())
filteredStudents = filteredStudents.filter { student ->
student.department.name in departments
}
}


filters.stuNumSort?.let { stuNumSort ->
filteredStudents =
if (stuNumSort == "ASCENDING") filteredStudents.sortedBy { it.stuNum }
Expand All @@ -143,15 +161,17 @@ class FilterStudentServiceImpl(
var filteredStudents = students

filters.majors?.let { majors -> // 전곡
filteredStudents = filteredStudents.filter { student ->
student.major in majors
}
if (filters.majors.isNotEmpty())
filteredStudents = filteredStudents.filter { student ->
student.major in majors
}
}

filters.techStacks?.let { techStacks -> // techStack
filteredStudents = filteredStudents.filter { student ->
student.techStack.intersect(techStacks.toSet()).isNotEmpty()
}
if (filters.techStacks.isNotEmpty())
filteredStudents = filteredStudents.filter { student ->
student.techStack.intersect(techStacks.toSet()).isNotEmpty()
}
}

return filteredStudents
Expand Down

0 comments on commit 8672d45

Please sign in to comment.