Skip to content
This repository was archived by the owner on Mar 30, 2025. It is now read-only.
Merged

Jooq #707

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ target
/spring-boot-migrator.log
/.run/RsapiApplication.run.xml
/.kotlin/sessions/
/db-migration/jooq-src/main/
9 changes: 3 additions & 6 deletions adapter/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
plugins {
alias(libs.plugins.kotlin.spring)
alias(libs.plugins.kotlin.kapt)
id("java-library")
id("java-test-fixtures")
}

dependencies {
implementation(project("::openapi"))
implementation(project("::db-migration"))
implementation(project("::core"))
implementation("org.springframework.boot:spring-boot-starter-mail")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-jdbc")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-jooq")
implementation(libs.swagger.annotations)
implementation("jakarta.validation:jakarta.validation-api")
implementation(libs.spring.security.oauth2.authorization.server)
implementation("org.flywaydb:flyway-core")
implementation("org.flywaydb:flyway-database-postgresql")
implementation(libs.jdbi3.spring5)
implementation(libs.jdbi3.kotlin)
implementation(libs.jdbi3.kotlin.sqlobject)
implementation(libs.jooq.core)
implementation(libs.lazysodium.java)
implementation(libs.jna)
implementation("commons-codec:commons-codec")
Expand All @@ -30,8 +29,6 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation(libs.bootstrap)

kapt("org.springframework.boot:spring-boot-configuration-processor")

runtimeOnly("org.postgresql:postgresql")
runtimeOnly("org.webjars:webjars-locator-lite")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.railwaystations.rsapi.adapter.db

import org.jooq.DSLContext
import org.jooq.Record2
import org.jooq.Result
import org.jooq.SelectJoinStep
import org.jooq.impl.DSL.multiset
import org.jooq.impl.DSL.noCondition
import org.jooq.impl.DSL.selectFrom
import org.railwaystations.rsapi.adapter.db.jooq.tables.records.CountryRecord
import org.railwaystations.rsapi.adapter.db.jooq.tables.records.ProviderappRecord
import org.railwaystations.rsapi.adapter.db.jooq.tables.references.CountryTable
import org.railwaystations.rsapi.adapter.db.jooq.tables.references.ProviderappTable
import org.railwaystations.rsapi.core.model.Country
import org.railwaystations.rsapi.core.model.License
import org.railwaystations.rsapi.core.model.ProviderApp
import org.railwaystations.rsapi.core.ports.outbound.CountryPort
import org.springframework.stereotype.Component

@Component
class CountryAdapter(private val dsl: DSLContext) : CountryPort {

override fun findById(id: String) =
selectCountriesWithProviderApps()
.where(CountryTable.id.eq(id))
.fetchOne { record -> record.component1().toCountry(record.component2()) }

private fun selectCountriesWithProviderApps(): SelectJoinStep<Record2<CountryRecord, Result<ProviderappRecord>>> =
dsl.select(
CountryTable,
multiset(
selectFrom(ProviderappTable)
.where(ProviderappTable.countrycode.eq(CountryTable.id))
)
).from(CountryTable)

private fun CountryRecord.toCountry(providerAppRecords: Result<ProviderappRecord>) = Country(
code = id,
name = name,
_email = email,
timetableUrlTemplate = timetableurltemplate,
overrideLicense = overridelicense?.let { License.valueOf(it) },
active = active == true,
providerApps = providerAppRecords.map { it.toProviderApp() }
)

private fun ProviderappRecord.toProviderApp() = ProviderApp(
type = type,
name = name,
url = url
)

override fun list(onlyActive: Boolean): Set<Country> {
val condition = if (onlyActive) CountryTable.active.eq(true) else noCondition()
return selectCountriesWithProviderApps()
.where(condition)
.fetch { record -> record.component1().toCountry(record.component2()) }
.toSet()
}

}

This file was deleted.

Loading
Loading