2019-03-12 22:06:04 +01:00
/ * *
* TheCitadelofRicks
*
2020-01-15 13:42:40 +01:00
* Copyright 2019 - 2020 < seil0 @mosad . xyz >
2019-03-12 22:06:04 +01:00
*
* 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
2019-10-20 11:52:44 +02:00
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
2019-10-28 18:39:44 +01:00
import org.mosad.thecitadelofricks.controller.StartupController
2019-10-21 18:46:21 +02:00
import org.mosad.thecitadelofricks.controller.StatusController.Companion.getStatus
import org.mosad.thecitadelofricks.controller.StatusController.Companion.updateMensaMenuRequests
import org.mosad.thecitadelofricks.controller.StatusController.Companion.updateTimetableRequests
import org.mosad.thecitadelofricks.controller.StatusController.Companion.updateTotalRequests
2019-03-13 19:12:05 +01:00
import org.slf4j.Logger
import org.slf4j.LoggerFactory
2019-03-12 22:06:04 +01:00
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
2019-03-13 19:12:05 +01:00
import java.time.LocalDateTime
2019-03-13 15:13:53 +01:00
import java.util.*
2019-03-12 22:06:04 +01:00
@RestController
class APIController {
2019-05-28 12:49:25 +02:00
private val logger : Logger = LoggerFactory . getLogger ( APIController :: class . java )
2019-03-12 22:06:04 +01:00
2019-10-21 18:46:21 +02:00
companion object {
const val apiVersion = " 1.1.4 "
2020-01-15 13:42:40 +01:00
const val softwareVersion = " 1.2.1 "
2019-10-21 18:46:21 +02:00
val startTime = System . currentTimeMillis ( ) / 1000
}
2019-03-12 22:06:04 +01:00
2019-10-20 11:52:44 +02:00
init {
2019-10-28 18:39:44 +01:00
StartupController ( )
CacheController ( )
2019-10-20 11:52:44 +02:00
}
2019-11-21 14:58:34 +01:00
// TODO remove this with API version 2.0.0
2019-05-25 19:37:04 +02:00
@Deprecated ( " courses is replaced by courseList " , replaceWith = ReplaceWith ( " courseList() " ) )
2019-03-12 22:06:04 +01:00
@RequestMapping ( " /courses " )
2020-02-10 17:42:44 +01:00
fun courses ( ) : CoursesList {
2019-05-23 14:56:16 +02:00
return courseList ( )
}
@RequestMapping ( " /courseList " )
2020-02-10 17:42:44 +01:00
fun courseList ( ) : CoursesList {
2019-05-23 14:56:16 +02:00
logger . info ( " courseList request at ${LocalDateTime.now()} ! " )
2019-10-21 18:46:21 +02:00
updateTotalRequests ( )
2019-10-05 17:17:26 +02:00
return courseList
2019-03-12 22:06:04 +01:00
}
@RequestMapping ( " /mensamenu " )
2019-05-28 12:49:25 +02:00
fun mensamenu ( ) : MensaMenu {
2019-03-13 19:12:05 +01:00
logger . info ( " mensamenu request at ${LocalDateTime.now()} ! " )
2019-10-21 18:46:21 +02:00
updateTotalRequests ( )
updateMensaMenuRequests ( )
2019-10-05 17:17:26 +02:00
return mensaMenu
2019-03-12 22:06:04 +01:00
}
@RequestMapping ( " /timetable " )
2019-03-15 23:57:31 +01:00
fun timetable (
@RequestParam ( value = " courseName " , defaultValue = " AI4 " ) courseName : String ,
@RequestParam ( value = " week " , defaultValue = " 0 " ) week : Int
) : TimetableCourseWeek {
2019-03-13 19:12:05 +01:00
logger . info ( " timetable request at ${LocalDateTime.now()} ! " )
2019-10-21 18:46:21 +02:00
updateTotalRequests ( )
2019-10-05 17:17:26 +02:00
updateTimetableRequests ( courseName )
2019-10-20 11:52:44 +02:00
return getTimetable ( courseName , week )
2019-05-23 14:56:16 +02:00
}
@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()} ! " )
2019-10-21 18:46:21 +02:00
updateTotalRequests ( )
2019-06-02 16:55:36 +02:00
return getLessonSubjectList ( courseName , week )
}
2019-10-05 17:17:26 +02:00
@RequestMapping ( " /lessons " )
2019-06-02 16:55:36 +02:00
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()} ! " )
2019-10-21 18:46:21 +02:00
updateTotalRequests ( )
2019-06-02 16:55:36 +02:00
return getLesson ( courseName , lessonSubject , week )
}
@RequestMapping ( " /status " )
fun status ( ) : Status {
2019-10-21 18:46:21 +02:00
logger . info ( " status request at ${LocalDateTime.now()} ! " )
2019-06-02 16:55:36 +02:00
return getStatus ( )
}
2019-10-21 18:46:21 +02:00
@RequestMapping ( " /health " )
fun health ( ) : Int {
logger . info ( " health request at ${LocalDateTime.now()} ! " )
return 200
2019-03-13 15:13:53 +01:00
}
2019-03-12 22:06:04 +01:00
}