Skip to content

Commit

Permalink
#1 jpa 모듈 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
Qbeom0925 committed Aug 18, 2024
1 parent f34be09 commit ea32a17
Show file tree
Hide file tree
Showing 26 changed files with 100 additions and 83 deletions.
13 changes: 10 additions & 3 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ plugins {
idea
}


dependencies {
implementation(project(":jpa"))

implementation("org.springframework.boot:spring-boot-starter-data-jpa")
//mysql
implementation("mysql:mysql-connector-java:8.0.33")
//swagger
implementation ("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2")
}

tasks.register("prepareKotlinBuildScriptModel") {}

configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
3 changes: 1 addition & 2 deletions core/src/main/kotlin/com/core/CoreApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package com.core
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
@SpringBootApplication(scanBasePackages = ["com.core", "com.jpa"])
class CoreApplication

fun main(args: Array<String>) {
runApplication<CoreApplication>(*args)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.core.adapter.`in`.web.dto

import com.core.application.domain.meal.model.Meal
import com.jpa.domain.model.Meal
import java.math.BigDecimal
import java.time.LocalDate

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.core.application.domain.meal.service

import com.core.application.domain.meal.model.Meal
import com.core.application.port.`in`.GetWeekMealUseCase
import com.core.application.port.out.GetWeekMealPort
import com.jpa.domain.MealPersistenceAdapter
import com.jpa.domain.model.Meal
import org.springframework.stereotype.Service
import java.time.DayOfWeek
import java.time.LocalDate

@Service
class MealReadService(
private val getWeekMealPort: GetWeekMealPort
private val mealPersistenceAdapter: MealPersistenceAdapter
) : GetWeekMealUseCase {

/**
* 주간 식단 조회
* @param restaurantName
* @return List<ApplicationMealDto.GetWeekMealRes>
*/
override fun invoke(restaurantIdx: Long): List<Meal> {
override operator fun invoke(restaurantIdx: Long): List<Meal> {
val (startDay, endDay) = getWeekRange()
val meals = getWeekMealPort(restaurantIdx, startDay, endDay)
val meals = mealPersistenceAdapter.getWeekMeals(restaurantIdx, startDay, endDay)
return meals
}

Expand All @@ -31,7 +31,6 @@ class MealReadService(
val today = LocalDate.now()
val startOfWeek = today.minusDays((today.dayOfWeek.value % 7).toLong()).with(DayOfWeek.SUNDAY)
val endOfWeek = startOfWeek.plusDays(6)

return Pair(startOfWeek, endOfWeek)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.core.application.port.`in`

import com.core.application.domain.meal.model.Meal
import com.jpa.domain.model.Meal


interface GetWeekMealUseCase {

Expand Down

This file was deleted.

13 changes: 3 additions & 10 deletions core/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ server:
port: 8080

spring:
jpa:
show_sql: true
hibernate:
ddl-auto: none
properties:
hibernate:
format_sql: true
highlight_sql: true
default_batch_fetch_size: 20
open-in-view: false
profiles:
include:
- jpa

springdoc:
swagger-ui:
Expand Down
19 changes: 19 additions & 0 deletions jpa/src/main/kotlin/com/jpa/domain/MealPersistenceAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.jpa.domain

import com.jpa.domain.mapper.MealMapper
import com.jpa.domain.repository.MealRepository
import com.jpa.domain.model.Meal
import org.springframework.stereotype.Component
import java.time.LocalDate

@Component
class MealPersistenceAdapter(
private val mealRepository: MealRepository,
private val mealMapper: MealMapper
) {
fun getWeekMeals(restaurantIdx: Long, start: LocalDate, end: LocalDate): List<Meal> {
val weekMeal = mealRepository.getWeekMeal(restaurantIdx, start, end)
val applicationMeals = mealMapper.toDomain(weekMeal);
return applicationMeals
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.core.common
package com.jpa.domain.common

import jakarta.persistence.Column
import jakarta.persistence.EntityListeners
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.core.adapter.out.persistence.entity
package com.jpa.domain.entity

import com.core.common.BaseEntity
import com.jpa.domain.common.BaseEntity
import jakarta.persistence.*

@Entity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.core.adapter.out.persistence.entity
package com.jpa.domain.entity

import com.core.adapter.out.persistence.enumerate.MealStatus
import com.core.adapter.out.persistence.enumerate.MealType
import com.core.common.BaseEntity
import com.jpa.domain.common.BaseEntity
import com.jpa.domain.enumerate.MealStatus
import com.jpa.domain.enumerate.MealType
import jakarta.persistence.*
import org.hibernate.annotations.Comment
import java.math.BigDecimal
import java.time.LocalDate
import java.time.LocalDateTime

@Entity
@Table(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.core.adapter.out.persistence.entity
package com.jpa.domain.entity

import com.core.common.BaseEntity
import com.jpa.domain.common.BaseEntity
import jakarta.persistence.*

@Entity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.core.adapter.out.persistence.entity
package com.jpa.domain.entity

import jakarta.persistence.*
import org.hibernate.annotations.Comment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.core.adapter.out.persistence.entity
package com.jpa.domain.entity

import jakarta.persistence.*
import org.hibernate.annotations.Comment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.core.adapter.out.persistence.entity
package com.jpa.domain.entity

import jakarta.persistence.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.core.adapter.out.persistence.enumerate
package com.jpa.domain.enumerate

enum class MealStatus(val value: String) {
OPEN("운영중"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.core.adapter.out.persistence.enumerate
package com.jpa.domain.enumerate

enum class MealType(val value: String) {
BREAKFAST("조식"),
Expand Down
11 changes: 11 additions & 0 deletions jpa/src/main/kotlin/com/jpa/domain/global/config/JpaConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jpa.domain.global.config

import org.springframework.boot.autoconfigure.domain.EntityScan
import org.springframework.context.annotation.Configuration
import org.springframework.data.jpa.repository.config.EnableJpaRepositories

@Configuration
@EnableJpaRepositories(basePackages = ["com.jpa.domain.repository"])
@EntityScan(basePackages = ["com.jpa"])
class JpaConfig {
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.core.adapter.out.persistence.mapper
package com.jpa.domain.mapper

import com.core.adapter.out.persistence.entity.MealJpaEntity
import com.core.adapter.out.persistence.enumerate.MealStatus
import com.core.adapter.out.persistence.enumerate.MealType
import com.core.application.domain.meal.model.Meal
import com.jpa.domain.entity.MealJpaEntity
import com.jpa.domain.enumerate.MealStatus
import com.jpa.domain.enumerate.MealType
import com.jpa.domain.model.Meal
import org.springframework.stereotype.Component
import java.math.BigDecimal
import java.time.LocalDateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.core.application.domain.meal.model
package com.jpa.domain.model

import java.time.LocalDateTime

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.core.application.domain.meal.model
package com.jpa.domain.model

import com.core.adapter.out.persistence.enumerate.MealStatus
import com.core.adapter.out.persistence.enumerate.MealType
import com.jpa.domain.enumerate.MealStatus
import com.jpa.domain.enumerate.MealType
import java.math.BigDecimal
import java.time.LocalDate
import java.time.LocalDateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.core.application.domain.meal.model
package com.jpa.domain.model

import java.time.LocalDateTime

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.core.adapter.out.persistence.repository
package com.jpa.domain.repository

import com.core.adapter.out.persistence.entity.MealJpaEntity
import com.jpa.domain.entity.MealJpaEntity
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
import java.time.LocalDate
import java.time.LocalDateTime

@Repository
interface MealRepository: JpaRepository<MealJpaEntity, Long> {
Expand Down
20 changes: 20 additions & 0 deletions jpa/src/main/resources/application-jpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306/myongsik?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 1q2w3e4r!
jpa:
hibernate:
ddl-auto: update
show_sql: true
properties:
hibernate:
format_sql: true
highlight_sql: true

logging:
level:
org:
hibernate:
SQL: debug
orm.jdbc.bind: trace
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ plugins {
}
rootProject.name = "Server-v2"
include("core")
include("admin")
include("admin")
include("jpa")

0 comments on commit ea32a17

Please sign in to comment.