Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 347c131fa9 | |||
| e947ae71db |
@@ -5,13 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.nano"
|
group = "com.nano"
|
||||||
version = "0.0.3"
|
version = "0.0.2"
|
||||||
|
|
||||||
java {
|
|
||||||
toolchain {
|
|
||||||
languageVersion.set(JavaLanguageVersion.of(17))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
application {
|
application {
|
||||||
mainClass = "com.nano.ApplicationKt"
|
mainClass = "com.nano.ApplicationKt"
|
||||||
@@ -34,7 +28,6 @@ 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")
|
||||||
@@ -42,20 +35,3 @@ 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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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,18 +21,6 @@ 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"
|
||||||
@@ -67,56 +67,30 @@ 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(
|
||||||
val events = when {
|
onSuccess = { events ->
|
||||||
startDate != null && endDate != null -> {
|
val eventResponses = events.map { event ->
|
||||||
eventManager.getEventsByDateRange(startDate, endDate)
|
EventResponse(
|
||||||
}
|
uid = event.uid,
|
||||||
else -> {
|
summary = event.summary,
|
||||||
eventManager.getAllEvents().getOrElse {
|
description = event.description,
|
||||||
return@get call.respond(
|
startDateTime = event.startDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
|
||||||
HttpStatusCode.InternalServerError,
|
endDateTime = event.endDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
|
||||||
ApiResponse<String>(success = false, message = it.message)
|
location = event.location
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
call.respond(ApiResponse(success = true, data = eventResponses))
|
||||||
|
},
|
||||||
|
onFailure = { error ->
|
||||||
|
call.respond(
|
||||||
|
HttpStatusCode.InternalServerError,
|
||||||
|
ApiResponse<String>(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) {
|
} catch (e: Exception) {
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.InternalServerError,
|
HttpStatusCode.InternalServerError,
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user