courses is now CourseList, added lessonSubjectList & lesson request

closes #1, #2
pull/18/head
Jannik 4 years ago
parent 4313c78edf
commit 62ad7a3b36
Signed by: Seil0
GPG Key ID: E8459F3723C52C24

@ -39,6 +39,7 @@ import java.net.URL
import java.time.LocalDateTime
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashSet
import kotlin.concurrent.scheduleAtFixedRate
@RestController
@ -88,9 +89,15 @@ class APIController {
}
}
@Deprecated("courses is replaced by courseList")
@RequestMapping("/courses")
fun courses(): CoursesList {
logger.info("courses request at ${LocalDateTime.now()}!")
return courseList()
}
@RequestMapping("/courseList")
fun courseList(): CoursesList {
logger.info("courseList request at ${LocalDateTime.now()}!")
requestCount++
return CoursesList(CoursesMeta(coursesLastUpdate, coursesLinkList.size), coursesLinkList)
}
@ -109,8 +116,48 @@ class APIController {
): TimetableCourseWeek {
logger.info("timetable request at ${LocalDateTime.now()}!")
requestCount++
checkTimetableCourse(courseName, week) // check if we need to update and perform the update if so
return timetableList.stream().filter { x -> x.meta.courseName == courseName && x.meta.week == week }.findAny().orElse(null)
return getTimetable(courseName, week)
}
@RequestMapping("/lessonSubjectList")
fun lessonSubjectList(
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
@RequestParam(value = "week", defaultValue = "0") week: Int
): HashSet<String> {
val lessonSubjectList = ArrayList<String>()
logger.info("lessonSubjectList request at ${LocalDateTime.now()}!")
requestCount++
// get every lesson subject for the given week
val flatMap = getTimetable(courseName, week).timetable.days.flatMap { it.timeslots.asIterable() }
flatMap.forEach {
it.stream().filter { x -> x.lessonSubject.isNotEmpty() }.findAny().ifPresent { x -> lessonSubjectList.add(x.lessonSubject) }
}
return HashSet(lessonSubjectList)
}
@RequestMapping("/lesson")
fun lesson(
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
@RequestParam(value = "lessonSubject", defaultValue = "Mathematik 4") lessonSubject: String,
@RequestParam(value = "week", defaultValue = "0") week: Int
): ArrayList<Lesson> {
val lessonList = ArrayList<Lesson>()
// get all lessons from the weeks timetable
val flatMap = getTimetable(courseName, week).timetable.days.flatMap { it.timeslots.asIterable() }
flatMap.forEach {
it.forEach { lesson ->
if(lesson.lessonSubject.contains(lessonSubject)) {
lessonList.add(lesson)
}
}
//it.stream().filter { x -> x.lessonSubject.contains(lessonSubject) }.findAny().ifPresent { x -> println("${x.lessonSubject}, ${x.lessonTeacher}") }
}
return lessonList
}
@RequestMapping("/status")
@ -213,6 +260,11 @@ class APIController {
}
}
private fun getTimetable(courseName: String, week: Int): TimetableCourseWeek {
checkTimetableCourse(courseName, week) // check if we need to update and perform the update if so
return timetableList.stream().filter { x -> x.meta.courseName == courseName && x.meta.week == week }.findAny().orElse(null)
}
private fun initUpdates() = runBlocking {
// get all courses on startup
val jobCourseUpdate = GlobalScope.async{

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close