From a0bc1c7ae9fb45b89baded5028cb64ff64e294b8 Mon Sep 17 00:00:00 2001 From: Olli Kiljunen Date: Tue, 7 Jan 2025 18:29:44 +0200 Subject: [PATCH] Re-introduce the hack that solves the issue with hasSubmittableFiles --- .../fi/aalto/cs/apluscourses/api/APlusApi.kt | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/fi/aalto/cs/apluscourses/api/APlusApi.kt b/src/main/kotlin/fi/aalto/cs/apluscourses/api/APlusApi.kt index 962115f41..163ffb114 100644 --- a/src/main/kotlin/fi/aalto/cs/apluscourses/api/APlusApi.kt +++ b/src/main/kotlin/fi/aalto/cs/apluscourses/api/APlusApi.kt @@ -11,8 +11,10 @@ import io.ktor.client.request.parameter import io.ktor.client.statement.bodyAsText import io.ktor.http.* import io.ktor.resources.* +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonNamingStrategy import org.jsoup.Jsoup import java.time.ZonedDateTime import kotlin.collections.component1 @@ -41,8 +43,12 @@ object APlusApi { @Resource("exercises") class Exercises(val parent: Course) { suspend fun get(project: Project): List { - return CoursesClient.getInstance(project) - .getBody(this@Exercises).results + // TODO remove after hasSubmittableFiles fixed +// CoursesClient.getInstance(project).getBody(this@Exercises).results + val res = CoursesClient.getInstance(project).get(this@Exercises) + return json.decodeFromString( + res.bodyAsText().replace("\"has_submittable_files\":[]", "\"has_submittable_files\":false") + ).results } @Serializable @@ -71,8 +77,18 @@ object APlusApi { val maxSubmissions: Int, val hierarchicalName: String, val difficulty: String, - val hasSubmittableFiles: Boolean +// val hasSubmittableFiles: Boolean // TODO should always be bool, currently boolean or null or array + val hasSubmittableFiles: Boolean? ) + + companion object { + @OptIn(ExperimentalSerializationApi::class) + private val json = Json { // TODO remove after hasSubmittableFiles fixed + ignoreUnknownKeys = true + isLenient = true + namingStrategy = JsonNamingStrategy.SnakeCase + } + } } @Resource("points/me")