-
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
20 changed files
with
415 additions
and
11 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
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
36 changes: 29 additions & 7 deletions
36
...ce-app-spring/src/main/kotlin/ru/otus/otuskotlin/markeplace/springapp/config/CorConfig.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 |
---|---|---|
@@ -1,35 +1,57 @@ | ||
package ru.otus.otuskotlin.markeplace.springapp.config | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import ru.otus.otuskotlin.marketplace.app.common.MkplAppSettings | ||
import ru.otus.otuskotlin.marketplace.backend.repo.sql.RepoAdSQL | ||
import ru.otus.otuskotlin.marketplace.backend.repo.sql.SqlProperties | ||
import ru.otus.otuskotlin.marketplace.backend.repository.inmemory.AdRepoStub | ||
import ru.otus.otuskotlin.marketplace.biz.MkplAdProcessor | ||
import ru.otus.otuskotlin.marketplace.common.MkplCorSettings | ||
import ru.otus.otuskotlin.marketplace.common.repo.IAdRepository | ||
import ru.otus.otuskotlin.marketplace.logging.common.MpLoggerProvider | ||
import ru.otus.otuskotlin.marketplace.logging.jvm.mpLoggerLogback | ||
import ru.otus.otuskotlin.marketplace.repo.inmemory.AdRepoInMemory | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(SqlPropertiesEx::class) | ||
class CorConfig { | ||
@Bean | ||
fun loggerProvider(): MpLoggerProvider = MpLoggerProvider { mpLoggerLogback(it) } | ||
|
||
@Bean | ||
fun processor() = MkplAdProcessor(corSettings()) | ||
fun processor(corSettings: MkplCorSettings) = MkplAdProcessor(corSettings) | ||
|
||
|
||
@Bean | ||
fun corSettings(): MkplCorSettings = MkplCorSettings( | ||
fun corSettings( | ||
@Qualifier("prodRepository") prodRepository: IAdRepository?, | ||
@Qualifier("testRepository") testRepository: IAdRepository, | ||
@Qualifier("stubRepository") stubRepository: IAdRepository, | ||
): MkplCorSettings = MkplCorSettings( | ||
loggerProvider = loggerProvider(), | ||
repoStub = AdRepoStub(), | ||
repoProd = AdRepoInMemory(), | ||
repoTest = AdRepoInMemory(), | ||
repoStub = stubRepository, | ||
repoTest = testRepository, | ||
repoProd = prodRepository ?: testRepository, | ||
) | ||
|
||
@Bean | ||
fun appSettings(corSettings: MkplCorSettings) = MkplAppSettings( | ||
processor = processor(), | ||
fun appSettings(corSettings: MkplCorSettings, processor: MkplAdProcessor) = MkplAppSettings( | ||
processor = processor, | ||
logger = loggerProvider(), | ||
corSettings = corSettings | ||
) | ||
|
||
@Bean(name = ["prodRepository"]) | ||
@ConditionalOnProperty(value = ["prod-repository"], havingValue = "sql") | ||
fun prodRepository(sqlProperties: SqlProperties) = RepoAdSQL(sqlProperties) | ||
|
||
@Bean | ||
fun testRepository() = AdRepoInMemory() | ||
|
||
@Bean | ||
fun stubRepository() = AdRepoStub() | ||
} |
15 changes: 15 additions & 0 deletions
15
...-spring/src/main/kotlin/ru/otus/otuskotlin/markeplace/springapp/config/SqlPropertiesEx.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,15 @@ | ||
package ru.otus.otuskotlin.markeplace.springapp.config | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.context.properties.bind.ConstructorBinding | ||
import ru.otus.otuskotlin.marketplace.backend.repo.sql.SqlProperties | ||
|
||
//Annotation @ConstructorBinding is needed, it cannot be placed over the c @Bean method, one way as workaround | ||
@ConfigurationProperties("sql") | ||
class SqlPropertiesEx @ConstructorBinding constructor( | ||
url: String, | ||
user: String, | ||
password: String, | ||
schema: String, | ||
dropDatabase: Boolean | ||
) : SqlProperties(url, user, password, schema, dropDatabase) |
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
4 changes: 4 additions & 0 deletions
4
...ce-app-spring/src/test/kotlin/ru/otus/otuskotlin/markeplace/springapp/ApplicationTests.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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
kotlin("jvm") | ||
} | ||
|
||
dependencies { | ||
val exposedVersion: String by project | ||
val postgresDriverVersion: String by project | ||
val kmpUUIDVersion: String by project | ||
val testContainersVersion: String by project | ||
|
||
implementation(kotlin("stdlib")) | ||
|
||
implementation(project(":ok-marketplace-common")) | ||
|
||
implementation("org.postgresql:postgresql:$postgresDriverVersion") | ||
|
||
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion") | ||
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion") | ||
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion") | ||
implementation("com.benasher44:uuid:$kmpUUIDVersion") | ||
|
||
|
||
testImplementation("org.testcontainers:postgresql:$testContainersVersion") | ||
testImplementation(project(":ok-marketplace-repo-tests")) | ||
} |
50 changes: 50 additions & 0 deletions
50
...epo-postgresql/src/main/kotlin/ru/otus/otuskotlin/marketplace/backend/repo/sql/AdTable.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,50 @@ | ||
package ru.otus.otuskotlin.marketplace.backend.repo.sql | ||
|
||
import org.jetbrains.exposed.sql.ResultRow | ||
import org.jetbrains.exposed.sql.Table | ||
import org.jetbrains.exposed.sql.statements.InsertStatement | ||
import org.jetbrains.exposed.sql.statements.UpdateBuilder | ||
import ru.otus.otuskotlin.marketplace.common.models.* | ||
|
||
object AdTable : Table("ad") { | ||
val id = varchar("id", 128) | ||
val title = varchar("title", 128) | ||
val description = varchar("description", 512) | ||
val owner = varchar("owner", 128) | ||
val visibility = enumeration("visibility", MkplVisibility::class) | ||
val dealSide = enumeration("deal_side", MkplDealSide::class) | ||
val lock = varchar("lock", 50) | ||
|
||
override val primaryKey = PrimaryKey(id) | ||
|
||
fun from(res: InsertStatement<Number>) = MkplAd( | ||
id = MkplAdId(res[id].toString()), | ||
title = res[title], | ||
description = res[description], | ||
ownerId = MkplUserId(res[owner].toString()), | ||
visibility = res[visibility], | ||
adType = res[dealSide], | ||
lock = MkplAdLock(res[lock]) | ||
) | ||
|
||
fun from(res: ResultRow) = MkplAd( | ||
id = MkplAdId(res[id].toString()), | ||
title = res[title], | ||
description = res[description], | ||
ownerId = MkplUserId(res[owner].toString()), | ||
visibility = res[visibility], | ||
adType = res[dealSide], | ||
lock = MkplAdLock(res[lock]) | ||
) | ||
|
||
fun to(it: UpdateBuilder<*>, ad: MkplAd, randomUuid: () -> String) { | ||
it[id] = ad.id.takeIf { it != MkplAdId.NONE }?.asString() ?: randomUuid() | ||
it[title] = ad.title | ||
it[description] = ad.description | ||
it[owner] = ad.ownerId.asString() | ||
it[visibility] = ad.visibility | ||
it[dealSide] = ad.adType | ||
it[lock] = ad.lock.takeIf { it != MkplAdLock.NONE }?.asString() ?: randomUuid() | ||
} | ||
|
||
} |
Oops, something went wrong.