Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5834541404 | |||
| 0bf724bc96 |
@@ -5,7 +5,13 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.nano"
|
group = "com.nano"
|
||||||
version = "0.0.2"
|
version = "0.0.3"
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion.set(JavaLanguageVersion.of(17))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
mainClass = "com.nano.ApplicationKt"
|
mainClass = "com.nano.ApplicationKt"
|
||||||
@@ -28,6 +34,7 @@ dependencies {
|
|||||||
implementation("io.ktor:ktor-server-content-negotiation")
|
implementation("io.ktor:ktor-server-content-negotiation")
|
||||||
implementation("io.ktor:ktor-serialization-kotlinx-json")
|
implementation("io.ktor:ktor-serialization-kotlinx-json")
|
||||||
implementation("io.ktor:ktor-server-netty")
|
implementation("io.ktor:ktor-server-netty")
|
||||||
|
implementation("io.ktor:ktor-server-swagger")
|
||||||
implementation("ch.qos.logback:logback-classic:1.5.13")
|
implementation("ch.qos.logback:logback-classic:1.5.13")
|
||||||
implementation("com.github.bitfireAT:dav4jvm:2.2.1")
|
implementation("com.github.bitfireAT:dav4jvm:2.2.1")
|
||||||
implementation("io.ktor:ktor-client-logging:3.2.2")
|
implementation("io.ktor:ktor-client-logging:3.2.2")
|
||||||
@@ -35,3 +42,20 @@ dependencies {
|
|||||||
testImplementation("io.ktor:ktor-server-test-host")
|
testImplementation("io.ktor:ktor-server-test-host")
|
||||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:2.1.10")
|
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:2.1.10")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ktor {
|
||||||
|
fatJar {
|
||||||
|
archiveFileName.set("webdav-service-fat.jar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<Jar> {
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
mapOf(
|
||||||
|
"Main-Class" to application.mainClass.get(),
|
||||||
|
"Implementation-Version" to version
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -67,11 +67,45 @@ fun Application.configureRouting() {
|
|||||||
ApiResponse<String>(success = false, message = "Не найден параметр calendarId")
|
ApiResponse<String>(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<String>(success = false, message = "Некорректный формат даты. Используйте формат ISO: YYYY-MM-DDTHH:mm:ss")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val dav = Dav(username, password, calendarId)
|
val dav = Dav(username, password, calendarId)
|
||||||
val eventManager = dav.getEventManager()
|
val eventManager = dav.getEventManager()
|
||||||
|
|
||||||
eventManager.getAllEvents().fold(
|
// Получаем события с учетом фильтрации по датам
|
||||||
onSuccess = { events ->
|
val events = when {
|
||||||
|
startDate != null && endDate != null -> {
|
||||||
|
eventManager.getEventsByDateRange(startDate, endDate)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
eventManager.getAllEvents().getOrElse {
|
||||||
|
return@get call.respond(
|
||||||
|
HttpStatusCode.InternalServerError,
|
||||||
|
ApiResponse<String>(success = false, message = it.message)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val eventResponses = events.map { event ->
|
val eventResponses = events.map { event ->
|
||||||
EventResponse(
|
EventResponse(
|
||||||
uid = event.uid,
|
uid = event.uid,
|
||||||
@@ -83,14 +117,6 @@ fun Application.configureRouting() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
call.respond(ApiResponse(success = true, data = eventResponses))
|
call.respond(ApiResponse(success = true, data = eventResponses))
|
||||||
},
|
|
||||||
onFailure = { error ->
|
|
||||||
call.respond(
|
|
||||||
HttpStatusCode.InternalServerError,
|
|
||||||
ApiResponse<String>(success = false, message = error.message)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.InternalServerError,
|
HttpStatusCode.InternalServerError,
|
||||||
|
|||||||
13
src/main/kotlin/Swagger.kt
Normal file
13
src/main/kotlin/Swagger.kt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.nano
|
||||||
|
|
||||||
|
import io.ktor.server.application.Application
|
||||||
|
import io.ktor.server.plugins.swagger.swaggerUI
|
||||||
|
import io.ktor.server.routing.routing
|
||||||
|
|
||||||
|
fun Application.configureSwagger() {
|
||||||
|
routing {
|
||||||
|
routing {
|
||||||
|
swaggerUI(path = "swagger", swaggerFile = "openapi.yaml")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ servers:
|
|||||||
paths:
|
paths:
|
||||||
/calendar/{calendarId}/events:
|
/calendar/{calendarId}/events:
|
||||||
get:
|
get:
|
||||||
description: "Получение всех событий"
|
description: "Получение всех событий с возможностью фильтрации по дате"
|
||||||
parameters:
|
parameters:
|
||||||
- name: "Authorization"
|
- name: "Authorization"
|
||||||
in: "header"
|
in: "header"
|
||||||
@@ -21,6 +21,18 @@ paths:
|
|||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: "string"
|
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:
|
responses:
|
||||||
"400":
|
"400":
|
||||||
description: "Bad Request"
|
description: "Bad Request"
|
||||||
Reference in New Issue
Block a user