Browse Source

change some parameters

* fixes #13
* use a HashMap for timetableRequests count
* api version 1.2.0
* software version 1.2.3
pull/18/head 1.2.3
Jannik 2 years ago
parent
commit
ec7a0a7a64
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 2
      build.gradle
  2. 44
      src/main/kotlin/org/mosad/thecitadelofricks/APIController.kt
  3. 3
      src/main/kotlin/org/mosad/thecitadelofricks/DataTypes.kt
  4. 13
      src/main/kotlin/org/mosad/thecitadelofricks/controller/StatusController.kt

2
build.gradle

@ -16,7 +16,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.jetbrains.kotlin:kotlin-reflect'
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.6'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
implementation 'org.jsoup:jsoup:1.13.1'
implementation 'com.google.code.gson:gson:2.8.6'

44
src/main/kotlin/org/mosad/thecitadelofricks/APIController.kt

@ -47,8 +47,8 @@ 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"
const val apiVersion = "1.2.0"
const val softwareVersion = "1.2.3"
val startTime = System.currentTimeMillis() / 1000
}
@ -57,13 +57,6 @@ class APIController {
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()}!")
@ -80,7 +73,7 @@ class APIController {
@RequestMapping("/timetable")
fun timetable(
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
@RequestParam(value = "course", defaultValue = "AI4") courseName: String,
@RequestParam(value = "week", defaultValue = "0") week: Int
): TimetableCourseWeek {
logger.info("timetable request at ${LocalDateTime.now()}!")
@ -88,20 +81,20 @@ class APIController {
return getTimetable(courseName, week)
}
@RequestMapping("/lessonSubjectList")
@RequestMapping("/subjectList")
fun lessonSubjectList(
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
@RequestParam(value = "course", defaultValue = "AI4") courseName: String,
@RequestParam(value = "week", defaultValue = "0") week: Int
): HashSet<String> {
logger.info("lessonSubjectList request at ${LocalDateTime.now()}!")
logger.info("subjectList 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 = "course", defaultValue = "AI4") courseName: String,
@RequestParam(value = "subject", defaultValue = "Mathematik 4") lessonSubject: String,
@RequestParam(value = "week", defaultValue = "0") week: Int
): ArrayList<Lesson> {
logger.info("lesson request at ${LocalDateTime.now()}!")
@ -121,4 +114,25 @@ class APIController {
return 200
}
/**
* Deprecated section
*/
// 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()
}
// TODO remove this with API version 2.0.0
@Deprecated("the parameter courseName is deprecated please use course", ReplaceWith("timetable(courseName, week)"))
@RequestMapping("/timetable", params= ["courseName", "week"])
fun timetableDep(
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
@RequestParam(value = "week", defaultValue = "0") week: Int
): TimetableCourseWeek {
return timetable(courseName, week)
}
}

3
src/main/kotlin/org/mosad/thecitadelofricks/DataTypes.kt

@ -24,6 +24,7 @@ package org.mosad.thecitadelofricks
import java.time.LocalDateTime
import java.util.*
import kotlin.collections.HashMap
// data classes for the course part
data class Course(val courseName: String, val courseLink: String)
@ -72,7 +73,7 @@ data class Status(
val totalRequests: Int,
val mensaMenuRequests: Int,
val courseListRequests: Int,
val timetableRequests: ArrayList<TimetableCounter>,
val timetableRequests: HashMap<String, Int>,
val timetableListSize: Int,
val coursesLastUpdate: Date,
val mensaLastUpdate: Date,

13
src/main/kotlin/org/mosad/thecitadelofricks/controller/StatusController.kt

@ -26,14 +26,13 @@ import org.mosad.thecitadelofricks.APIController.Companion.apiVersion
import org.mosad.thecitadelofricks.APIController.Companion.softwareVersion
import org.mosad.thecitadelofricks.APIController.Companion.startTime
import org.mosad.thecitadelofricks.Status
import org.mosad.thecitadelofricks.TimetableCounter
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.net.HttpURLConnection
import java.net.URL
import java.time.LocalDateTime
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
class StatusController {
@ -43,7 +42,7 @@ class StatusController {
private var totalRequests = 0
private var mensaMenuRequests = 0
private var courseListRequests = 0
private var timetableRequests = ArrayList<TimetableCounter>()
private var timetableRequests = HashMap<String, Int>()
/**
* if a mensamenu/courseList/timetable is requested update the specific and total request count
@ -59,11 +58,7 @@ class StatusController {
}
fun updateTimetableRequests(courseName: String) {
timetableRequests.stream().filter { it.courseName == courseName }.findFirst().ifPresentOrElse({
it.requests++
}, {
timetableRequests.add(TimetableCounter(courseName, 1))
})
timetableRequests[courseName] = timetableRequests.getOrPut(courseName) {0} + 1
totalRequests++
}
@ -82,7 +77,7 @@ class StatusController {
return courseListRequests
}
fun getTimetableRequests(): ArrayList<TimetableCounter> {
fun getTimetableRequests(): HashMap<String, Int> {
return timetableRequests
}

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