You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.6 KiB
124 lines
4.6 KiB
/**
|
|
* TheCitadelofRicks
|
|
*
|
|
* Copyright 2019-2020 <seil0@mosad.xyz>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
* MA 02110-1301, USA.
|
|
*
|
|
*/
|
|
|
|
package org.mosad.thecitadelofricks
|
|
|
|
import org.mosad.thecitadelofricks.controller.CacheController
|
|
import org.mosad.thecitadelofricks.controller.CacheController.Companion.courseList
|
|
import org.mosad.thecitadelofricks.controller.CacheController.Companion.getLesson
|
|
import org.mosad.thecitadelofricks.controller.CacheController.Companion.getLessonSubjectList
|
|
import org.mosad.thecitadelofricks.controller.CacheController.Companion.getTimetable
|
|
import org.mosad.thecitadelofricks.controller.CacheController.Companion.mensaMenu
|
|
import org.mosad.thecitadelofricks.controller.StartupController
|
|
import org.mosad.thecitadelofricks.controller.StatusController.Companion.getStatus
|
|
import org.mosad.thecitadelofricks.controller.StatusController.Companion.updateCourseListRequests
|
|
import org.mosad.thecitadelofricks.controller.StatusController.Companion.updateMensaMenuRequests
|
|
import org.mosad.thecitadelofricks.controller.StatusController.Companion.updateTimetableRequests
|
|
import org.slf4j.Logger
|
|
import org.slf4j.LoggerFactory
|
|
import org.springframework.web.bind.annotation.RequestMapping
|
|
import org.springframework.web.bind.annotation.RequestParam
|
|
import org.springframework.web.bind.annotation.RestController
|
|
import java.time.LocalDateTime
|
|
import java.util.*
|
|
|
|
@RestController
|
|
class APIController {
|
|
|
|
private val logger: Logger = LoggerFactory.getLogger(APIController::class.java)
|
|
|
|
companion object {
|
|
const val apiVersion = "1.1.4"
|
|
const val softwareVersion = "1.2.2"
|
|
val startTime = System.currentTimeMillis() / 1000
|
|
}
|
|
|
|
init {
|
|
StartupController()
|
|
CacheController()
|
|
}
|
|
|
|
// TODO remove this with API version 2.0.0
|
|
@Deprecated("courses is replaced by courseList", replaceWith = ReplaceWith("courseList()"))
|
|
@RequestMapping("/courses")
|
|
fun courses(): CoursesList {
|
|
return courseList()
|
|
}
|
|
|
|
@RequestMapping("/courseList")
|
|
fun courseList(): CoursesList {
|
|
logger.info("courseList request at ${LocalDateTime.now()}!")
|
|
updateCourseListRequests()
|
|
return courseList
|
|
}
|
|
|
|
@RequestMapping("/mensamenu")
|
|
fun mensamenu(): MensaMenu {
|
|
logger.info("mensamenu request at ${LocalDateTime.now()}!")
|
|
updateMensaMenuRequests()
|
|
return mensaMenu
|
|
}
|
|
|
|
@RequestMapping("/timetable")
|
|
fun timetable(
|
|
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
|
|
@RequestParam(value = "week", defaultValue = "0") week: Int
|
|
): TimetableCourseWeek {
|
|
logger.info("timetable request at ${LocalDateTime.now()}!")
|
|
updateTimetableRequests(courseName)
|
|
return getTimetable(courseName, week)
|
|
}
|
|
|
|
@RequestMapping("/lessonSubjectList")
|
|
fun lessonSubjectList(
|
|
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
|
|
@RequestParam(value = "week", defaultValue = "0") week: Int
|
|
): HashSet<String> {
|
|
logger.info("lessonSubjectList request at ${LocalDateTime.now()}!")
|
|
updateTimetableRequests(courseName)
|
|
return getLessonSubjectList(courseName, week)
|
|
}
|
|
|
|
@RequestMapping("/lessons")
|
|
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> {
|
|
logger.info("lesson request at ${LocalDateTime.now()}!")
|
|
updateTimetableRequests(courseName)
|
|
return getLesson(courseName, lessonSubject, week)
|
|
}
|
|
|
|
@RequestMapping("/status")
|
|
fun status(): Status {
|
|
logger.info("status request at ${LocalDateTime.now()}!")
|
|
return getStatus()
|
|
}
|
|
|
|
@RequestMapping("/health")
|
|
fun health(): Int {
|
|
logger.info("health request at ${LocalDateTime.now()}!")
|
|
return 200
|
|
}
|
|
|
|
} |