diff --git a/build.gradle.kts b/build.gradle.kts index 5979f7a..4d9c35a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,13 @@ plugins { } group = "com.nano" -version = "0.0.2" +version = "0.0.3" + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} application { mainClass = "com.nano.ApplicationKt" @@ -35,3 +41,20 @@ dependencies { testImplementation("io.ktor:ktor-server-test-host") testImplementation("org.jetbrains.kotlin:kotlin-test-junit:2.1.10") } + +ktor { + fatJar { + archiveFileName.set("webdav-service-fat.jar") + } +} + +tasks.withType { + manifest { + attributes( + mapOf( + "Main-Class" to application.mainClass.get(), + "Implementation-Version" to version + ) + ) + } +} diff --git a/openapi.yaml b/openapi.yaml index baa4532..7b3de04 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -9,7 +9,7 @@ servers: paths: /calendar/{calendarId}/events: get: - description: "Получение всех событий" + description: "Получение всех событий с возможностью фильтрации по дате" parameters: - name: "Authorization" in: "header" @@ -21,6 +21,18 @@ paths: required: true schema: type: "string" + - name: "startDate" + in: "query" + required: false + description: "Начальная дата для фильтрации событий (ISO формат: YYYY-MM-DDTHH:mm:ss)" + schema: + type: "string" + - name: "endDate" + in: "query" + required: false + description: "Конечная дата для фильтрации событий (ISO формат: YYYY-MM-DDTHH:mm:ss)" + schema: + type: "string" responses: "400": description: "Bad Request" diff --git a/src/main/kotlin/Routing.kt b/src/main/kotlin/Routing.kt index 478274a..1b45206 100644 --- a/src/main/kotlin/Routing.kt +++ b/src/main/kotlin/Routing.kt @@ -67,30 +67,56 @@ fun Application.configureRouting() { ApiResponse(success = false, message = "Не найден параметр calendarId") ) + // Получаем параметры фильтрации по датам (если они указаны) + val startDateParam = call.request.queryParameters["startDate"] + val endDateParam = call.request.queryParameters["endDate"] + + var startDate: LocalDateTime? = null + var endDate: LocalDateTime? = null + + try { + if (startDateParam != null) { + startDate = LocalDateTime.parse(startDateParam) + } + if (endDateParam != null) { + endDate = LocalDateTime.parse(endDateParam) + } + } catch (e: Exception) { + return@get call.respond( + HttpStatusCode.BadRequest, + ApiResponse(success = false, message = "Некорректный формат даты. Используйте формат ISO: YYYY-MM-DDTHH:mm:ss") + ) + } + val dav = Dav(username, password, calendarId) val eventManager = dav.getEventManager() - eventManager.getAllEvents().fold( - onSuccess = { events -> - val eventResponses = events.map { event -> - EventResponse( - uid = event.uid, - summary = event.summary, - description = event.description, - startDateTime = event.startDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), - endDateTime = event.endDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), - location = event.location + // Получаем события с учетом фильтрации по датам + val events = when { + startDate != null && endDate != null -> { + eventManager.getEventsByDateRange(startDate, endDate) + } + else -> { + eventManager.getAllEvents().getOrElse { + return@get call.respond( + HttpStatusCode.InternalServerError, + ApiResponse(success = false, message = it.message) ) } - call.respond(ApiResponse(success = true, data = eventResponses)) - }, - onFailure = { error -> - call.respond( - HttpStatusCode.InternalServerError, - ApiResponse(success = false, message = error.message) - ) } - ) + } + + val eventResponses = events.map { event -> + EventResponse( + uid = event.uid, + summary = event.summary, + description = event.description, + startDateTime = event.startDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), + endDateTime = event.endDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), + location = event.location + ) + } + call.respond(ApiResponse(success = true, data = eventResponses)) } catch (e: Exception) { call.respond( HttpStatusCode.InternalServerError,