Skip to content

Commit

Permalink
[Refactor/#468] 라이브러리성 모듈 라이브러리 모듈 밑으로 수정 (#469)
Browse files Browse the repository at this point in the history
* refactor: 라이브러리성 모듈 라이브러리 모듈 밑으로 수정

* refactor: repo, data 모듈 삭제 반영

* refactor: 테스크 수정
  • Loading branch information
belljun3395 authored Dec 23, 2024
1 parent 9df6081 commit 49068de
Show file tree
Hide file tree
Showing 221 changed files with 551 additions and 550 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/code-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ jobs:
java-version: '18'
distribution: 'temurin'

- name: Jooq Code Generation
- name: Jooq Code Generation for API Module
run: |
./gradlew jooqCodegenAll
./gradlew api:jooqCodegen
- name: Build with Gradle
run: |
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Jooq Code Generation
- name: Jooq Code Generation for API Module
run: |
./gradlew jooqCodegenAll
./gradlew api:jooqCodegen
- name: Generate Allure Results
run: ./gradlew api:test
run: ./gradlew test

- name: Load test report history
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ecs-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Jooq Code Generation
- name: Jooq Code Generation for API Module
run: |
./gradlew jooqCodegenAll
./gradlew api:jooqCodegen
- name: Generate OpenAPI3
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ecs-dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Jooq Code Generation
- name: Jooq Code Generation for API Module
run: |
./gradlew jooqCodegenAll
./gradlew api:jooqCodegen
- name: Generate OpenAPI3
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/validate-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Jooq Code Generation
- name: Jooq Code Generation for API Module
run: |
./gradlew jooqCodegenAll
./gradlew api:jooqCodegen
- name: API Test with Gradle
- name: Test with Gradle
run: |
./gradlew api:test
./gradlew test
92 changes: 84 additions & 8 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@ tasks.withType(BootJar::class.java) {

dependencies {
/** module */
implementation(project(":repo"))
implementation(project(":email"))
implementation(project(":storage"))
implementation(project(":web"))
testImplementation(testFixtures(project(":web")))
implementation(project(":library:email"))
implementation(project(":library:storage"))
implementation(project(":library:web"))
testImplementation(testFixtures(project(":library:web")))

/** spring starter */
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-aop")
implementation("org.springframework.boot:spring-boot-starter-cache")

/** jooq */
jooqCodegen("org.jooq:jooq-meta-extensions:${DependencyVersion.JOOQ}")

/** Local Cache **/
implementation("org.ehcache:ehcache:${DependencyVersion.EHCACHE}")

Expand All @@ -45,6 +41,86 @@ dependencies {

/** jsoup - html parser */
implementation("org.jsoup:jsoup:1.15.3")

/** mysql */
implementation("com.mysql:mysql-connector-j")

/** jooq */
jooqCodegen("org.jooq:jooq-meta-extensions:${DependencyVersion.JOOQ}")
implementation("org.springframework.boot:spring-boot-starter-jooq")

/** flyway */
implementation("org.flywaydb:flyway-core:${DependencyVersion.FLYWAY}")
implementation("org.flywaydb:flyway-mysql")
}

jooq {
configuration {
generator {
database {
name = "org.jooq.meta.extensions.ddl.DDLDatabase"
properties {
// Specify the location of your SQL script.
// You may use ant-style file matching, e.g. /path/**/to/*.sql
//
// Where:
// - ** matches any directory subtree
// - * matches any number of characters in a directory / file name
// - ? matches a single character in a directory / file name
property {
key = "scripts"
value = "src/main/resources/db/migration/**/*.sql"
}

// The sort order of the scripts within a directory, where:
//
// - semantic: sorts versions, e.g. v-3.10.0 is after v-3.9.0 (default)
// - alphanumeric: sorts strings, e.g. v-3.10.0 is before v-3.9.0
// - flyway: sorts files the same way as flyway does
// - none: doesn't sort directory contents after fetching them from the directory
property {
key = "sort"
value = "flyway"
}

// The default schema for unqualified objects:
//
// - public: all unqualified objects are located in the PUBLIC (upper case) schema
// - none: all unqualified objects are located in the default schema (default)
//
// This configuration can be overridden with the schema mapping feature
property {
key = "unqualifiedSchema"
value = "none"
}

// The default name case for unquoted objects:
//
// - as_is: unquoted object names are kept unquoted
// - upper: unquoted object names are turned into upper case (most databases)
// - lower: unquoted object names are turned into lower case (e.g. PostgreSQL)
property {
key = "defaultNameCase"
value = "as_is"
}
}
}

generate {
isDeprecated = false
isRecords = true
isImmutablePojos = true
isFluentSetters = true
isJavaTimeTypes = true
}

target {
packageName = "jooq.jooq_dsl"
directory = "src/generated"
encoding = "UTF-8"
}
}
}
}

tasks.withType(OpenApi3Task::class.java) {
Expand Down
2 changes: 0 additions & 2 deletions api/src/main/kotlin/com/few/api/config/ApiConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
import repo.config.RepoConfig
import security.config.SecurityConfig
import storage.document.config.DocumentStorageConfig
import storage.image.config.ImageStorageConfig
Expand All @@ -14,7 +13,6 @@ import web.config.WebConfig
@Configuration
@ComponentScan(basePackages = [ApiConfig.BASE_PACKAGE])
@Import(
RepoConfig::class,
MailConfig::class,
ImageStorageConfig::class,
DocumentStorageConfig::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package repo.config
package com.few.api.config

import com.zaxxer.hikari.HikariDataSource
import org.springframework.boot.context.properties.ConfigurationProperties
Expand All @@ -8,12 +8,12 @@ import org.springframework.context.annotation.Configuration
import javax.sql.DataSource

@Configuration
class DataSourceConfig {
class ApiDataSourceConfig {
companion object {
const val DATASOURCE = RepoConfig.BEAN_NAME_PREFIX + "DataSource"
const val DATASOURCE = ApiConfig.BEAN_NAME_PREFIX + "DataSource"
}

@Bean(name = [DATASOURCE])
@ConfigurationProperties(prefix = "spring.datasource.hikari")
@ConfigurationProperties(prefix = "spring.api.datasource.hikari")
fun dataSource(): DataSource = DataSourceBuilder.create().type(HikariDataSource::class.java).build()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package repo.config
package com.few.api.config

import org.flywaydb.core.Flyway
import org.flywaydb.core.api.configuration.FluentConfiguration
Expand All @@ -14,14 +14,14 @@ import java.util.function.Consumer
import javax.sql.DataSource

@Configuration
@Import(DataSourceConfig::class)
class FlywayConfig {
@Import(ApiDataSourceConfig::class)
class ApiFlywayConfig {
companion object {
const val FLYWAY = RepoConfig.BEAN_NAME_PREFIX + "Flyway"
const val FLYWAY_VALIDATE_INITIALIZER = RepoConfig.BEAN_NAME_PREFIX + "FlywayValidateInitializer"
const val FLYWAY_MIGRATION_INITIALIZER = RepoConfig.BEAN_NAME_PREFIX + "FlywayMigrationInitializer"
const val FLYWAY_PROPERTIES = RepoConfig.BEAN_NAME_PREFIX + "FlywayProperties"
const val FLYWAY_CONFIGURATION = RepoConfig.BEAN_NAME_PREFIX + "FlywayConfiguration"
const val FLYWAY = ApiConfig.BEAN_NAME_PREFIX + "Flyway"
const val FLYWAY_VALIDATE_INITIALIZER = ApiConfig.BEAN_NAME_PREFIX + "FlywayValidateInitializer"
const val FLYWAY_MIGRATION_INITIALIZER = ApiConfig.BEAN_NAME_PREFIX + "FlywayMigrationInitializer"
const val FLYWAY_PROPERTIES = ApiConfig.BEAN_NAME_PREFIX + "FlywayProperties"
const val FLYWAY_CONFIGURATION = ApiConfig.BEAN_NAME_PREFIX + "FlywayConfiguration"
}

@Bean(name = [FLYWAY])
Expand All @@ -37,12 +37,12 @@ class FlywayConfig {
FlywayMigrationInitializer(flyway) { obj: Flyway -> obj.migrate() }

@Bean(name = [FLYWAY_PROPERTIES])
@ConfigurationProperties(prefix = "spring.flyway")
@ConfigurationProperties(prefix = "spring.flyway.api")
fun flywayProperties(): FlywayProperties = FlywayProperties()

@Bean(name = [FLYWAY_CONFIGURATION])
fun configuration(
@Qualifier(DataSourceConfig.DATASOURCE) dataSource: DataSource,
@Qualifier(ApiDataSourceConfig.DATASOURCE) dataSource: DataSource,
): org.flywaydb.core.api.configuration.Configuration {
val configuration = FluentConfiguration()
configuration.dataSource(dataSource)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package repo.config
package com.few.api.config

import com.few.api.config.ApiDataSourceConfig.Companion.DATASOURCE
import com.few.api.config.ApiTxConfig.Companion.DATASOURCE_TX
import com.few.api.config.jooq.ApiExceptionTranslator
import com.few.api.config.jooq.ApiNativeSQLLogger
import com.few.api.config.jooq.ApiPerformanceListener
import org.jooq.SQLDialect
import org.jooq.impl.DataSourceConnectionProvider
import org.jooq.impl.DefaultConfiguration
Expand All @@ -12,24 +17,19 @@ import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator
import org.springframework.transaction.PlatformTransactionManager
import repo.config.DataSourceConfig.Companion.DATASOURCE
import repo.config.TxConfig.Companion.DATASOURCE_TX
import repo.flyway.support.ExceptionTranslator
import repo.flyway.support.NativeSQLLogger
import repo.flyway.support.PerformanceListener
import javax.sql.DataSource

@Configuration
@Import(DataSourceConfig::class, TxConfig::class)
class JooqConfig(
@Import(ApiDataSourceConfig::class, ApiTxConfig::class)
class ApiJooqConfig(
@Qualifier(DATASOURCE) private val dataSource: DataSource,
@Qualifier(DATASOURCE_TX) private val txManager: PlatformTransactionManager,
private val applicationEventPublisher: ApplicationEventPublisher,
) {
companion object {
const val DSL = RepoConfig.BEAN_NAME_PREFIX + "Dsl"
const val JOOQ_CONFIGURATION = RepoConfig.BEAN_NAME_PREFIX + "JooqConfiguration"
const val JOOQ_CONNECTION_PROVIDER = RepoConfig.BEAN_NAME_PREFIX + "JooqConnectionProvider"
const val DSL = ApiConfig.BEAN_NAME_PREFIX + "Dsl"
const val JOOQ_CONFIGURATION = ApiConfig.BEAN_NAME_PREFIX + "JooqConfiguration"
const val JOOQ_CONNECTION_PROVIDER = ApiConfig.BEAN_NAME_PREFIX + "JooqConnectionProvider"
}

@Bean(name = [DSL])
Expand All @@ -41,7 +41,7 @@ class JooqConfig(
jooqConfiguration.set(connectionProvider())
val translator =
SQLErrorCodeSQLExceptionTranslator(SQLDialect.MYSQL.name)
jooqConfiguration.set(ExceptionTranslator(translator), NativeSQLLogger(), PerformanceListener(applicationEventPublisher))
jooqConfiguration.set(ApiExceptionTranslator(translator), ApiNativeSQLLogger(), ApiPerformanceListener(applicationEventPublisher))
jooqConfiguration.set(SQLDialect.MYSQL)
return jooqConfiguration
}
Expand Down
8 changes: 0 additions & 8 deletions api/src/main/kotlin/com/few/api/config/ApiJpaConfig.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
package repo.config
package com.few.api.config

import jakarta.persistence.EntityManagerFactory
import com.few.api.config.ApiDataSourceConfig.Companion.DATASOURCE
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
import org.springframework.jdbc.datasource.DataSourceTransactionManager
import org.springframework.orm.jpa.JpaTransactionManager
import org.springframework.transaction.PlatformTransactionManager
import org.springframework.transaction.TransactionManager
import org.springframework.transaction.annotation.EnableTransactionManagement
import org.springframework.transaction.annotation.TransactionManagementConfigurer
import repo.config.DataSourceConfig.Companion.DATASOURCE
import javax.sql.DataSource

@Import(JpaConfig::class, DataSourceConfig::class)
@Import(ApiConfig::class, ApiDataSourceConfig::class)
@Configuration
@EnableTransactionManagement
class TxConfig(
private val emf: EntityManagerFactory,
class ApiTxConfig(
@Qualifier(DATASOURCE) private val dataSource: DataSource,
) : TransactionManagementConfigurer {
companion object {
const val JPA_TX = RepoConfig.BEAN_NAME_PREFIX + "JpaTransactionManager"
const val DATASOURCE_TX = RepoConfig.BEAN_NAME_PREFIX + "DataSourceTransactionManager"
const val DATASOURCE_TX = ApiConfig.BEAN_NAME_PREFIX + "DataSourceTransactionManager"
}

@Bean(name = [JPA_TX])
fun jpaTransactionManager(): PlatformTransactionManager = JpaTransactionManager(emf)

@Bean(name = [DATASOURCE_TX])
fun dataSourceTransactionManager(): PlatformTransactionManager = DataSourceTransactionManager(dataSource)

override fun annotationDrivenTransactionManager(): TransactionManager = jpaTransactionManager()
override fun annotationDrivenTransactionManager(): TransactionManager = dataSourceTransactionManager()
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package repo.flyway.support
package com.few.api.config.jooq

import org.jooq.ExecuteContext
import org.jooq.ExecuteListener
import org.springframework.jdbc.support.SQLExceptionTranslator

class ExceptionTranslator(
class ApiExceptionTranslator(
private val translator: SQLExceptionTranslator,
) : ExecuteListener {
override fun exception(context: ExecuteContext) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package repo.flyway.support
package com.few.api.config.jooq

import io.github.oshai.kotlinlogging.KotlinLogging
import org.jooq.ExecuteContext
import org.jooq.ExecuteListener
import org.jooq.impl.DSL

class NativeSQLLogger : ExecuteListener {
class ApiNativeSQLLogger : ExecuteListener {
private val log = KotlinLogging.logger {}

override fun executeEnd(ctx: ExecuteContext) {
Expand Down
Loading

0 comments on commit 49068de

Please sign in to comment.