Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VovaStelmashchuk committed Aug 15, 2024
1 parent 4aeddc5 commit d5b6fc7
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 14 deletions.
3 changes: 1 addition & 2 deletions backend/src/main/java/com/nestapp/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ class Configuration(
val accessKey: String,
val secretKey: String,
val mongoUrl: String,
val jaguarUrl: String,
)

const val TOLERANCE = 1e-2
1 change: 1 addition & 0 deletions backend/src/main/java/com/nestapp/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal object Main {
accessKey = config.property("ktor.minio.access_key").getString(),
secretKey = config.property("ktor.minio.secret_key").getString(),
mongoUrl = config.property("ktor.mongo.url").getString(),
jaguarUrl = config.property("ktor.jaguar.url").getString(),
)

val appComponent = AppComponent(
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/java/com/nestapp/RestController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fun Route.setupRouter(
)

nestRestApi(
jaguarRequest = JaguarRequest(client),
jaguarRequest = JaguarRequest(client, appComponent.configuration),
polygonGenerator = PolygonGenerator(),
minioProjectRepository = appComponent.minioProjectRepository,
nestHistoryRepository = appComponent.nestHistoryRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class NestHistoryRepository(
.append("svgPreviewUrl", svgPath)
.append("dxfFileUrl", dxfPath)
)

collection.updateOne(query, update)
}
}

Expand Down
22 changes: 16 additions & 6 deletions backend/src/main/java/com/nestapp/nest/NestRestApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,22 @@ fun Route.nestRestApi(
}

is NestResult.Success -> {
buildResultFiles(
val result = buildResultFiles(
nestedResult = nestedResult,
nestId = nestResultDatabase.id,
minioFileUpload = minioFileUpload,
configuration = configuration,
)

nestHistoryRepository.makeNestFinish(
id = nestResultDatabase.id,
svgPath = result.svg,
dxfPath = result.dxf,
)

NestedOutput(
id = nestResultDatabase.id.toHexString(),
svg = "${configuration.baseUrl}files/${result.svg}",
dxf = "${configuration.baseUrl}files/${result.dxf}",
)
}
}
Expand All @@ -84,8 +95,7 @@ fun Route.nestRestApi(
private fun buildResultFiles(
nestedResult: NestResult.Success,
nestId: ObjectId,
minioFileUpload: MinioFileUpload,
configuration: Configuration
minioFileUpload: MinioFileUpload
): NestedOutput {
val svgPolygons = nestedResult.polygons.flatMap { nestedPolygon ->
PolygonGenerator().convertEntitiesToPolygons(nestedPolygon.closePolygon.entities, 0.1).map {
Expand Down Expand Up @@ -122,8 +132,8 @@ private fun buildResultFiles(

return NestedOutput(
id = nestId.toHexString(),
svg = "${configuration.baseUrl}files/$svgPath",
dxf = "${configuration.baseUrl}files/$dxfPath",
svg = svgPath,
dxf = dxfPath,
)
}

Expand Down
1 change: 0 additions & 1 deletion backend/src/main/java/com/nestapp/nest/Utlis.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nestapp.nest

import com.nestapp.TOLERANCE
import com.nestapp.nest.config.Config
import de.lighti.clipper.Clipper
import de.lighti.clipper.ClipperOffset
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.nestapp.nest.jaguar

import com.nestapp.Configuration
import com.nestapp.nest.ClosePolygon
import com.nestapp.nest.polygonOffset
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.plugins.timeout
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.contentType
import java.util.concurrent.TimeUnit

sealed class NestResult {

Expand Down Expand Up @@ -42,14 +41,16 @@ data class JaguarNestInput(

class JaguarRequest(
private val client: HttpClient,
private val configuration: Configuration,
) {
suspend fun makeNestByJaguar(
jaguarNestInput: JaguarNestInput,
): NestResult {
val request = buildRequest(jaguarNestInput)

return try {
val response = client.post("https://jagua.nest2d.online/run/") {
println("JaguarRequest request $jaguarNestInput")
val response = client.post("${configuration.jaguarUrl}run/") {
contentType(ContentType.Application.Json)
setBody(request)
}.body<Response>()
Expand All @@ -70,7 +71,7 @@ class JaguarRequest(
NestResult.NotFit
}
} catch (e: Exception) {
e.printStackTrace()
System.err.println("JaguarRequest error: $e")
throw e
}
}
Expand Down
3 changes: 3 additions & 0 deletions backend/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ ktor {
mongo {
url = ${NEST2D_MONGO_URL}
}
jaguar {
url = ${NEST2D_JAGUAR_URL}
}
}

0 comments on commit d5b6fc7

Please sign in to comment.