-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
111 changed files
with
2,682 additions
and
917 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
version: '3' | ||
services: | ||
psql: | ||
image: postgres | ||
container_name: postgresql | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
ports: | ||
- "5432:5432" | ||
expose: | ||
- "5432" | ||
environment: | ||
POSTGRES_PASSWORD: marketplace-pass | ||
POSTGRES_USER: postgres | ||
POSTGRES_DB: marketplace | ||
healthcheck: | ||
test: [ "CMD-SHELL", "pg_isready" ] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
|
||
app: | ||
image: ok-marketplace-app-spring | ||
container_name: app-spring | ||
ports: | ||
- "8080:8080" | ||
expose: | ||
- "8080" | ||
environment: | ||
SQL_URL: jdbc:postgresql://psql:5432/marketplace | ||
depends_on: | ||
psql: | ||
condition: service_healthy | ||
|
||
volumes: | ||
postgres_data: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
ok-marketplace-app-common/src/commonMain/kotlin/ControllerHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ru.otus.otuskotlin.marketplace.app.common | ||
|
||
import kotlinx.datetime.Clock | ||
import ru.otus.otuskotlin.marketplace.api.logs.mapper.toLog | ||
import ru.otus.otuskotlin.marketplace.common.MkplContext | ||
import ru.otus.otuskotlin.marketplace.common.helpers.asMkplError | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplState | ||
import kotlin.reflect.KClass | ||
|
||
suspend inline fun <T> IMkplAppSettings.controllerHelper( | ||
crossinline getRequest: suspend MkplContext.() -> Unit, | ||
crossinline toResponse: suspend MkplContext.() -> T, | ||
clazz: KClass<*>, | ||
logId: String, | ||
): T { | ||
val logger = corSettings.loggerProvider.logger(clazz) | ||
val ctx = MkplContext( | ||
timeStart = Clock.System.now(), | ||
) | ||
return try { | ||
logger.doWithLogging(logId) { | ||
ctx.getRequest() | ||
processor.exec(ctx) | ||
logger.info( | ||
msg = "Request $logId processed for ${clazz.simpleName}", | ||
marker = "BIZ", | ||
data = ctx.toLog(logId) | ||
) | ||
ctx.toResponse() | ||
} | ||
} catch (e: Throwable) { | ||
logger.doWithLogging("$logId-failure") { | ||
ctx.state = MkplState.FAILING | ||
ctx.errors.add(e.asMkplError()) | ||
processor.exec(ctx) | ||
ctx.toResponse() | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
ok-marketplace-app-common/src/commonMain/kotlin/IMkplAppSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ru.otus.otuskotlin.marketplace.app.common | ||
|
||
import ru.otus.otuskotlin.marketplace.biz.MkplAdProcessor | ||
import ru.otus.otuskotlin.marketplace.common.MkplCorSettings | ||
|
||
interface IMkplAppSettings { | ||
val processor: MkplAdProcessor | ||
val corSettings: MkplCorSettings | ||
} |
12 changes: 0 additions & 12 deletions
12
ok-marketplace-app-common/src/commonMain/kotlin/MkplAppSettings.kt
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
ok-marketplace-app-common/src/commonTest/kotlin/ControllerV2Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package ru.otus.otuskotlin.marketplace.app.common | ||
|
||
import kotlinx.coroutines.test.runTest | ||
import ru.otus.otuskotlin.marketplace.api.v2.models.* | ||
import ru.otus.otuskotlin.marketplace.biz.MkplAdProcessor | ||
import ru.otus.otuskotlin.marketplace.common.MkplCorSettings | ||
import ru.otus.otuskotlin.marketplace.mappers.v2.fromTransport | ||
import ru.otus.otuskotlin.marketplace.mappers.v2.toTransportAd | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class ControllerV2Test { | ||
|
||
private val request = AdCreateRequest( | ||
requestType = "create", | ||
requestId = "1234", | ||
ad = AdCreateObject( | ||
title = "some ad", | ||
description = "some description of some ad", | ||
adType = DealSide.DEMAND, | ||
visibility = AdVisibility.PUBLIC, | ||
productId = "some product id", | ||
), | ||
debug = AdDebug(mode = AdRequestDebugMode.STUB, stub = AdRequestDebugStubs.SUCCESS) | ||
) | ||
|
||
private val appSettings: IMkplAppSettings = object : IMkplAppSettings { | ||
override val corSettings: MkplCorSettings = MkplCorSettings() | ||
override val processor: MkplAdProcessor = MkplAdProcessor(corSettings) | ||
} | ||
|
||
private suspend fun createAdSpring(request: AdCreateRequest): AdCreateResponse = | ||
appSettings.controllerHelper( | ||
{ fromTransport(request) }, | ||
{ toTransportAd() as AdCreateResponse }, | ||
this::class, | ||
"createAdSpring" | ||
) | ||
|
||
class TestApplicationCall(private val request: IRequest) { | ||
var res: IResponse? = null | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T : IRequest> receive(): T = request as T | ||
fun respond(res: IResponse) { | ||
this.res = res | ||
} | ||
} | ||
|
||
private suspend fun TestApplicationCall.createAdKtor(appSettings: IMkplAppSettings) { | ||
val resp = appSettings.controllerHelper( | ||
{ fromTransport(receive<AdCreateRequest>()) }, | ||
{ toTransportAd() }, | ||
this::class, | ||
"createAdKtor", | ||
) | ||
respond(resp) | ||
} | ||
|
||
@Test | ||
fun springHelperTest() = runTest { | ||
val res = createAdSpring(request) | ||
assertEquals(ResponseResult.SUCCESS, res.result) | ||
} | ||
|
||
@Test | ||
fun ktorHelperTest() = runTest { | ||
val testApp = TestApplicationCall(request).apply { createAdKtor(appSettings) } | ||
val res = testApp.res as AdCreateResponse | ||
assertEquals(ResponseResult.SUCCESS, res.result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package ru.otus.otuskotlin.marketplace.app.common |
10 changes: 8 additions & 2 deletions
10
...lace-app-kafka/src/main/kotlin/ru/otus/otuskotlin/marketplace/app/kafka/AppKafkaConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...ace-app-kafka/src/main/kotlin/ru/otus/otuskotlin/marketplace/app/kafka/mkplCorSettings.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.