From 89aeb1df6ebf32b72d419e3c6a2328c89f6f0303 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Fri, 1 Nov 2024 09:21:30 -0700 Subject: [PATCH] fix empty content --- gradle.properties | 2 +- .../presentation/SignalRouteRegistry.kt | 42 ++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index abfa41d..c77d1b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.parallel=true makeevrserg.project.name=IRDBBackend makeevrserg.project.url=https://github.com/flipperdevices/IRDB-Backend makeevrserg.project.group=com.flipperdevices.ifrmvp.backend -makeevrserg.project.version.string=0.7.1 +makeevrserg.project.version.string=0.7.2 makeevrserg.project.description=Api for IfrSample makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com # Java diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt index 6ae2be3..9ab55ff 100644 --- a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt +++ b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt @@ -18,7 +18,6 @@ import com.flipperdevices.ifrmvp.backend.model.SignalResponse import com.flipperdevices.ifrmvp.backend.model.SignalResponseModel import com.flipperdevices.ifrmvp.backend.route.signal.data.CategoryConfigRepository import com.flipperdevices.ifrmvp.backend.route.signal.data.IRDBCategoryConfigRepository -import com.flipperdevices.ifrmvp.generator.config.device.api.DeviceKeyNamesProvider import com.flipperdevices.ifrmvp.generator.config.device.api.DeviceKeyNamesProvider.Companion.getKey import com.flipperdevices.ifrmvp.generator.config.device.api.any.AnyDeviceKeyNamesProvider import com.flipperdevices.ifrmvp.model.IfrKeyIdentifier @@ -302,7 +301,46 @@ internal class SignalRouteRegistry( println("#root includedInfraredFilesCount=$includedInfraredFilesCount") when (includedInfraredFilesCount) { 0L -> { - context.respond(HttpStatusCode.NoContent) + if (signalRequestModel.failedResults.isEmpty() + .and(signalRequestModel.successResults.isEmpty()) + .and(signalRequestModel.skippedResults.isEmpty()) + ) { + println("#root everything is empty") + context.respond(HttpStatusCode.NoContent) + } else { + val fallbackIncludedFileId = transaction(database) { + getIncludedFileIds( + signalRequestModel = when { + signalRequestModel.skippedResults.isNotEmpty() -> { + signalRequestModel.copy( + skippedResults = signalRequestModel.skippedResults.dropLast(1) + ) + } + + signalRequestModel.failedResults.isNotEmpty() -> { + signalRequestModel.copy( + failedResults = signalRequestModel.failedResults.dropLast(1) + ) + } + + else -> { + signalRequestModel.copy( + successResults = signalRequestModel.successResults.dropLast(1) + ) + } + }, + brandId = brand.id + ).map { it[InfraredFileTable.id] }.firstOrNull()?.value + } + println("#root fallbackIncludedFileId is $fallbackIncludedFileId") + if (fallbackIncludedFileId == null) { + context.respond(HttpStatusCode.NoContent) + } else { + val response = + SignalResponseModel(ifrFileModel = tableDao.ifrFileById(fallbackIncludedFileId)) + context.respond(response) + } + } return@post }