Skip to content

Commit

Permalink
Refactor LessonsApi
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed May 2, 2024
1 parent a7c2a05 commit ddd28bb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/src/main/kotlin/ivy/learn/api/LessonsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ivy.learn.api

import arrow.core.raise.ensureNotNull
import io.ktor.server.routing.*
import io.ktor.util.*
import ivy.learn.api.common.Api
import ivy.learn.api.common.endpoint
import ivy.learn.api.common.model.ServerError
Expand All @@ -13,7 +14,11 @@ class LessonsApi(
private val repository: LessonsRepository
) : Api {
override fun Routing.endpoints() {
// Endpoint that gets a lesson by ID
lessonById()
}

@KtorDsl
private fun Routing.lessonById() {
get("/lessons/{id}", endpoint<Lesson> { params ->
val lessonId = params["id"]?.let(::LessonId)
ensureNotNull(lessonId) { ServerError.BadRequest("Lesson id is missing!") }
Expand Down

0 comments on commit ddd28bb

Please sign in to comment.