diff --git a/build.gradle.kts b/build.gradle.kts index 5e320b3..763f93c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,8 +45,8 @@ subprojects{ testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") testRuntimeOnly("org.junit.platform:junit-platform-launcher") + implementation("io.github.oshai:kotlin-logging-jvm:5.1.1") - implementation("org.springframework.boot:spring-boot-starter-data-jpa") } } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index ae4bf12..8cea017 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -4,5 +4,7 @@ plugins { dependencies { - + implementation("org.springframework.boot:spring-boot-starter-data-jpa") + //mysql + implementation("mysql:mysql-connector-java:8.0.33") } diff --git a/core/src/main/kotlin/com/core/adapter/in/web/MealController.kt b/core/src/main/kotlin/com/core/adapter/in/web/MealController.kt index 937762c..6a7acfb 100644 --- a/core/src/main/kotlin/com/core/adapter/in/web/MealController.kt +++ b/core/src/main/kotlin/com/core/adapter/in/web/MealController.kt @@ -1,20 +1,22 @@ package com.core.adapter.`in`.web import com.core.adapter.`in`.web.dto.AdapterMealDto -import com.core.application.port.`in`.GetMealUseCase +import com.core.application.port.`in`.GetWeekMealUseCase import com.core.common.response.ApplicationResponse import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController +@RestController +class MealController(val getWeekMealUseCase: GetWeekMealUseCase) { -@RestController("/api/v1/meals") -class MealController(private val getMealUseCase: GetMealUseCase) { - - @GetMapping - fun getMeal() : ApplicationResponse> { - val data = getMealUseCase.execute() - val toResponse = AdapterMealDto.GetMealRes.toResponse(data) + @GetMapping("/api/v1/meals/week") + fun getWeekMeal( + @RequestParam("restaurantName") restaurantName: String + ) : ApplicationResponse> { + val data = getWeekMealUseCase(restaurantName) + val toResponse = AdapterMealDto.GetWeekMealRes.from(data) return ApplicationResponse.ok(toResponse) } -} \ No newline at end of file +} diff --git a/core/src/main/kotlin/com/core/adapter/in/web/dto/AdapterMealDto.kt b/core/src/main/kotlin/com/core/adapter/in/web/dto/AdapterMealDto.kt index bd204bb..522eea8 100644 --- a/core/src/main/kotlin/com/core/adapter/in/web/dto/AdapterMealDto.kt +++ b/core/src/main/kotlin/com/core/adapter/in/web/dto/AdapterMealDto.kt @@ -1,23 +1,28 @@ package com.core.adapter.`in`.web.dto -import com.core.application.port.`in`.dto.ApplicationMealDto +import com.core.application.domain.meal.model.Meal +import java.math.BigDecimal +import java.time.LocalDate class AdapterMealDto { - - data class GetMealRes( + data class GetWeekMealRes( val idx: Long, val type: String, val status: String, - val meals: String + val offeredAt: LocalDate, + val price: BigDecimal, + val meals: List ) { companion object { - fun toResponse(data: List) : List{ + fun from(data: List): List { return data.map { - GetMealRes( + GetWeekMealRes( idx = it.idx, - type = it.type, - status = it.status, - meals = it.meals + type = it.type.value, + status = it.status.value, + offeredAt = it.offeredAt, + price = it.price, + meals = it.meals.split(",") ) } } diff --git a/core/src/main/kotlin/com/core/adapter/out/persistence/MealPersistenceAdapter.kt b/core/src/main/kotlin/com/core/adapter/out/persistence/MealPersistenceAdapter.kt new file mode 100644 index 0000000..49ff10b --- /dev/null +++ b/core/src/main/kotlin/com/core/adapter/out/persistence/MealPersistenceAdapter.kt @@ -0,0 +1,20 @@ +package com.core.adapter.out.persistence + +import com.core.adapter.out.persistence.mapper.MealMapper +import com.core.adapter.out.persistence.repository.MealRepository +import com.core.application.domain.meal.model.Meal +import com.core.application.port.out.GetWeekMealPort +import org.springframework.stereotype.Component +import java.time.LocalDate + +@Component +class MealPersistenceAdapter( + private val mealRepository: MealRepository, + private val mealMapper: MealMapper +) : GetWeekMealPort { + override fun invoke(restaurantName: String, start: LocalDate, end: LocalDate): List { + val weekMeal = mealRepository.getWeekMeal(restaurantName, start, end) + val applicationMeals = mealMapper.toDomain(weekMeal); + return applicationMeals + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/adapter/out/persistence/entity/CampusJpaEntity.kt b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/CampusJpaEntity.kt new file mode 100644 index 0000000..ecbe01a --- /dev/null +++ b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/CampusJpaEntity.kt @@ -0,0 +1,23 @@ +package com.core.adapter.out.persistence.entity + +import com.core.common.BaseEntity +import jakarta.persistence.* + +@Entity +@Table(name = "campus", indexes = [ + Index(name = "campus_idx_name", columnList = "name"), +]) +class CampusJpaEntity : BaseEntity() { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val idx: Long = 0 + + @Column(name = "name") + val name: String = "DEFAULT" + + @Column(name = "address") + val address: String = "DEFAULT" + + @Column(name = "is_deleted") + val isDeleted: Boolean = false +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/adapter/out/persistence/entity/MealJpaEntity.kt b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/MealJpaEntity.kt index 6c26bcd..5937017 100644 --- a/core/src/main/kotlin/com/core/adapter/out/persistence/entity/MealJpaEntity.kt +++ b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/MealJpaEntity.kt @@ -2,36 +2,46 @@ package com.core.adapter.out.persistence.entity import com.core.adapter.out.persistence.enumerate.MealStatus import com.core.adapter.out.persistence.enumerate.MealType +import com.core.common.BaseEntity import jakarta.persistence.* import org.hibernate.annotations.Comment import java.math.BigDecimal +import java.time.LocalDate +import java.time.LocalDateTime @Entity @Table( - name = "meal", - indexes = [Index(name = "meal_name_index", columnList = "name")] - + name = "meals", + indexes = [Index(name = "meal_restaurant_idx", columnList = "restaurant_id")] ) -class MealJpaEntity { +class MealJpaEntity : BaseEntity(){ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var idx: Long = 0 + @Column(name = "meals") + var meals: String = "" + @Column(name = "type", length = 20) @Enumerated(EnumType.STRING) - var type: MealType? = MealType.LUNCH + var type: MealType = MealType.LUNCH @Column(name = "status", length = 20) @Enumerated(EnumType.STRING) - var status: MealStatus? = MealStatus.OPEN + var status: MealStatus = MealStatus.OPEN - @Comment("식사 가격") @Column(name = "price") var price: BigDecimal = BigDecimal.ZERO + @Column(name = "offered_at") + var offeredAt: LocalDate = LocalDate.now() + + @Column(name = "is_deleted") + val isDeleted: Boolean = false + @ManyToOne - @JoinColumn(name = "meal_id") - var restaurantJpaEntity: RestaurantJpaEntity? = null + @JoinColumn(name = "restaurant_id") + var restaurantJpaEntity: RestaurantJpaEntity = RestaurantJpaEntity() } \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/adapter/out/persistence/entity/RestaurantJpaEntity.kt b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/RestaurantJpaEntity.kt index ae30b6b..e976535 100644 --- a/core/src/main/kotlin/com/core/adapter/out/persistence/entity/RestaurantJpaEntity.kt +++ b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/RestaurantJpaEntity.kt @@ -1,12 +1,13 @@ package com.core.adapter.out.persistence.entity +import com.core.common.BaseEntity import jakarta.persistence.* @Entity @Table(name = "restaurant", indexes = [ - Index(name = "idx_name", columnList = "name"), + Index(name = "restaurant_idx_name", columnList = "name"), ]) -class RestaurantJpaEntity { +class RestaurantJpaEntity : BaseEntity(){ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -18,9 +19,11 @@ class RestaurantJpaEntity { @Column(name = "address") val address: String = "DEFAULT" - @ManyToOne - @JoinColumn(name = "category_id") - val universityJpaEntity: UniversityJpaEntity? = null + @Column(name = "is_deleted") + val isDeleted: Boolean = false + @ManyToOne + @JoinColumn(name = "campus_id") + val campusJpaEntity: CampusJpaEntity = CampusJpaEntity() } \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/adapter/out/persistence/entity/ScrapJpaEntity.kt b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/ScrapJpaEntity.kt new file mode 100644 index 0000000..095f189 --- /dev/null +++ b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/ScrapJpaEntity.kt @@ -0,0 +1,4 @@ +package com.core.adapter.out.persistence.entity + +class ScrapJpaEntity { +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/adapter/out/persistence/entity/StoreJpaEntity.kt b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/StoreJpaEntity.kt new file mode 100644 index 0000000..4265d06 --- /dev/null +++ b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/StoreJpaEntity.kt @@ -0,0 +1,4 @@ +package com.core.adapter.out.persistence.entity + +class StoreJpaEntity { +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/adapter/out/persistence/entity/UniversityJpaEntity.kt b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/UniversityJpaEntity.kt deleted file mode 100644 index e02d27e..0000000 --- a/core/src/main/kotlin/com/core/adapter/out/persistence/entity/UniversityJpaEntity.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.core.adapter.out.persistence.entity - -import jakarta.persistence.* - -@Entity -@Table(name = "university", indexes = [ - Index(name = "idx_name", columnList = "name"), -]) -class UniversityJpaEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - val idx: Long? = null - - @Column(name = "name") - val name: String = "DEFAULT" - - @Column(name = "campus_name") - val campusName: String = "DEFAULT" - - @Column(name = "is_deleted") - val isDeleted: Boolean = true -} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/adapter/out/persistence/entity/UserJpaEntity.kt b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/UserJpaEntity.kt new file mode 100644 index 0000000..ae640f5 --- /dev/null +++ b/core/src/main/kotlin/com/core/adapter/out/persistence/entity/UserJpaEntity.kt @@ -0,0 +1,4 @@ +package com.core.adapter.out.persistence.entity + +class UserJpaEntity { +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/adapter/out/persistence/mapper/MealMapper.kt b/core/src/main/kotlin/com/core/adapter/out/persistence/mapper/MealMapper.kt new file mode 100644 index 0000000..07ec972 --- /dev/null +++ b/core/src/main/kotlin/com/core/adapter/out/persistence/mapper/MealMapper.kt @@ -0,0 +1,40 @@ +package com.core.adapter.out.persistence.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 org.springframework.stereotype.Component +import java.math.BigDecimal +import java.time.LocalDateTime + +@Component +data class MealMapper( + var idx: Long = 0, + var meals: String = "", + var type: MealType = MealType.LUNCH, + var status: MealStatus = MealStatus.OPEN, + var price: BigDecimal = BigDecimal.ZERO, + var offeredAt: LocalDateTime = LocalDateTime.now(), + val isDeleted: Boolean = false, + val updatedAt: LocalDateTime = LocalDateTime.now(), + val createdAt: LocalDateTime = LocalDateTime.now(), + var restaurantName: String = "DEFAULT", +) { + fun toDomain(mealJpaEntities: List): List { + return mealJpaEntities.map { + Meal( + idx = it.idx, + meals = it.meals, + type = it.type, + status = it.status, + price = it.price, + offeredAt = it.offeredAt, + isDeleted = it.isDeleted, + restaurantName = it.restaurantJpaEntity.name, + updatedAt = it.updatedAt, + createdAt = it.createdAt, + ) + } + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/adapter/out/persistence/repository/MealRepository.kt b/core/src/main/kotlin/com/core/adapter/out/persistence/repository/MealRepository.kt index a0e4d7e..69f8ac2 100644 --- a/core/src/main/kotlin/com/core/adapter/out/persistence/repository/MealRepository.kt +++ b/core/src/main/kotlin/com/core/adapter/out/persistence/repository/MealRepository.kt @@ -1,4 +1,20 @@ package com.core.adapter.out.persistence.repository -interface MealRepository { +import com.core.adapter.out.persistence.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 { + + @Query(""" + SELECT m + FROM MealJpaEntity m + left join RestaurantJpaEntity r on r.name = :restaurantName + WHERE m.isDeleted = false and m.offeredAt between :start and :end + """) + fun getWeekMeal(restaurantName: String, start: LocalDate, end: LocalDate): List } \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/application/domain/meal/model/Campus.kt b/core/src/main/kotlin/com/core/application/domain/meal/model/Campus.kt new file mode 100644 index 0000000..aac5a44 --- /dev/null +++ b/core/src/main/kotlin/com/core/application/domain/meal/model/Campus.kt @@ -0,0 +1,13 @@ +package com.core.application.domain.meal.model + +import java.time.LocalDateTime + +data class Campus( + val idx: Long = 0, + val name: String = "DEFAULT", + val address: String = "DEFAULT", + val isDeleted: Boolean = false, + val updatedDate: LocalDateTime = LocalDateTime.now(), + val createdDate: LocalDateTime = LocalDateTime.now(), +) { +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/application/domain/meal/model/Meal.kt b/core/src/main/kotlin/com/core/application/domain/meal/model/Meal.kt index 5537585..2e041df 100644 --- a/core/src/main/kotlin/com/core/application/domain/meal/model/Meal.kt +++ b/core/src/main/kotlin/com/core/application/domain/meal/model/Meal.kt @@ -1,14 +1,23 @@ package com.core.application.domain.meal.model -import jakarta.annotation.Generated -import jakarta.persistence.* +import com.core.adapter.out.persistence.enumerate.MealStatus +import com.core.adapter.out.persistence.enumerate.MealType +import java.math.BigDecimal +import java.time.LocalDate +import java.time.LocalDateTime data class Meal( - val idx: Long, - val type: String, - val status: String, - val meals: String + var idx: Long = 0, + var meals: String = "제공된 학식 정보가 없습니다.", + var type: MealType = MealType.LUNCH, + var status: MealStatus = MealStatus.OPEN, + var price: BigDecimal = BigDecimal.ZERO, + var offeredAt: LocalDate = LocalDate.now(), + val isDeleted: Boolean = false, + var restaurantName: String = "DEFAULT", + val updatedAt: LocalDateTime = LocalDateTime.now(), + val createdAt: LocalDateTime = LocalDateTime.now(), ) { diff --git a/core/src/main/kotlin/com/core/application/domain/meal/model/Restaurant.kt b/core/src/main/kotlin/com/core/application/domain/meal/model/Restaurant.kt new file mode 100644 index 0000000..b3d31cc --- /dev/null +++ b/core/src/main/kotlin/com/core/application/domain/meal/model/Restaurant.kt @@ -0,0 +1,14 @@ +package com.core.application.domain.meal.model + +import java.time.LocalDateTime + +data class Restaurant( + val idx: Long = 0, + val name: String = "DEFAULT", + val address: String = "DEFAULT", + val isDeleted: Boolean = false, + val campusJpaEntity: Campus = Campus(), + val updatedDate: LocalDateTime = LocalDateTime.now(), + val createdDate: LocalDateTime = LocalDateTime.now(), +) { +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/application/domain/meal/service/MealReadService.kt b/core/src/main/kotlin/com/core/application/domain/meal/service/MealReadService.kt index 241fee1..8cfb681 100644 --- a/core/src/main/kotlin/com/core/application/domain/meal/service/MealReadService.kt +++ b/core/src/main/kotlin/com/core/application/domain/meal/service/MealReadService.kt @@ -1,14 +1,38 @@ package com.core.application.domain.meal.service -import com.core.application.port.`in`.GetMealUseCase -import com.core.application.port.`in`.dto.ApplicationMealDto +import com.core.application.domain.meal.model.Meal +import com.core.application.port.`in`.GetWeekMealUseCase +import com.core.application.port.out.GetWeekMealPort import org.springframework.stereotype.Service +import java.time.DayOfWeek +import java.time.LocalDate @Service -class MealReadService : GetMealUseCase { +class MealReadService( + private val getWeekMealPort: GetWeekMealPort +) : GetWeekMealUseCase { - override fun execute(): List { - TODO("Not yet implemented") + /** + * 주간 식단 조회 + * @param restaurantName + * @return List + */ + override fun invoke(restaurantName: String): List { + val (startDay, endDay) = getWeekRange() + val meals = getWeekMealPort(restaurantName, startDay, endDay) + return meals + } + + /** + * 주간 날짜 범위 조회 + * @return Pair + */ + fun getWeekRange(): Pair { + 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) } diff --git a/core/src/main/kotlin/com/core/application/port/in/GetMealUseCase.kt b/core/src/main/kotlin/com/core/application/port/in/GetMealUseCase.kt deleted file mode 100644 index e750e1b..0000000 --- a/core/src/main/kotlin/com/core/application/port/in/GetMealUseCase.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.core.application.port.`in` - -import com.core.application.port.`in`.dto.ApplicationMealDto - -interface GetMealUseCase { - - fun execute(): List - -} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/application/port/in/GetWeekMealUseCase.kt b/core/src/main/kotlin/com/core/application/port/in/GetWeekMealUseCase.kt new file mode 100644 index 0000000..3d457f7 --- /dev/null +++ b/core/src/main/kotlin/com/core/application/port/in/GetWeekMealUseCase.kt @@ -0,0 +1,8 @@ +package com.core.application.port.`in` + +import com.core.application.domain.meal.model.Meal + +interface GetWeekMealUseCase { + + operator fun invoke(campusName: String): List +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/application/port/in/dto/ApplicationMealDto.kt b/core/src/main/kotlin/com/core/application/port/in/dto/ApplicationMealDto.kt deleted file mode 100644 index 370597d..0000000 --- a/core/src/main/kotlin/com/core/application/port/in/dto/ApplicationMealDto.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.core.application.port.`in`.dto - -data class ApplicationMealDto ( - val name: String, - val price: Int, - val description: String -) { - data class GetMealRes( - val idx: Long, - val type: String, - val status: String, - val meals: String - ) { - } -} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/application/port/out/GetMealPort.kt b/core/src/main/kotlin/com/core/application/port/out/GetMealPort.kt deleted file mode 100644 index fc011fd..0000000 --- a/core/src/main/kotlin/com/core/application/port/out/GetMealPort.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.core.application.port.out - -interface GetMealPort { - - fun getMeal(): List - - data class MealDto( - val name: String, - val price: Int, - val description: String - ) -} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/application/port/out/GetWeekMealPort.kt b/core/src/main/kotlin/com/core/application/port/out/GetWeekMealPort.kt new file mode 100644 index 0000000..ed4dd0d --- /dev/null +++ b/core/src/main/kotlin/com/core/application/port/out/GetWeekMealPort.kt @@ -0,0 +1,11 @@ +package com.core.application.port.out + +import com.core.application.domain.meal.model.Meal +import java.time.LocalDate + +interface GetWeekMealPort { + + operator fun invoke(restaurantName: String, + start: LocalDate, + end: LocalDate): List +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/common/excpetion/ExceptionAdvice.kt b/core/src/main/kotlin/com/core/common/excpetion/ExceptionAdvice.kt new file mode 100644 index 0000000..9eb3c8f --- /dev/null +++ b/core/src/main/kotlin/com/core/common/excpetion/ExceptionAdvice.kt @@ -0,0 +1,24 @@ +package com.core.common.excpetion + +import com.core.common.response.ApplicationResponse +import io.github.oshai.kotlinlogging.KotlinLogging +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.ExceptionHandler +import org.springframework.web.bind.annotation.RestControllerAdvice +import kotlin.math.log + +private val logger = KotlinLogging.logger {} + +@RestControllerAdvice +class ExceptionAdvice { + + @ExceptionHandler(Exception::class) + fun handleException(e: Exception): ResponseEntity> { + logger.error { + "error : ${e.message}" + e.printStackTrace() + } + return ResponseEntity.status(ExceptionList.SERVER_ERROR.status) + .body(ApplicationResponse.error(ExceptionList.SERVER_ERROR)) + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/common/excpetion/ExceptionList.kt b/core/src/main/kotlin/com/core/common/excpetion/ExceptionList.kt new file mode 100644 index 0000000..6c8733c --- /dev/null +++ b/core/src/main/kotlin/com/core/common/excpetion/ExceptionList.kt @@ -0,0 +1,12 @@ +package com.core.common.excpetion + +import org.springframework.http.HttpStatus + +enum class ExceptionList( + val code: String, + val status: HttpStatus, + val message: String +) { + SERVER_ERROR("SE0001",HttpStatus.INTERNAL_SERVER_ERROR, "서버 에러가 발생하였습니다") + +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/core/common/response/ApplicationResponse.kt b/core/src/main/kotlin/com/core/common/response/ApplicationResponse.kt index 09d39cc..a57097e 100644 --- a/core/src/main/kotlin/com/core/common/response/ApplicationResponse.kt +++ b/core/src/main/kotlin/com/core/common/response/ApplicationResponse.kt @@ -1,8 +1,10 @@ package com.core.common.response +import com.core.common.excpetion.ExceptionList + data class ApplicationResponse( val meta: Meta, - val data: T, + val data: T?, val error: Error? ){ companion object { @@ -11,6 +13,12 @@ data class ApplicationResponse( data = data, error = null ) + + fun error(error: ExceptionList): ApplicationResponse = ApplicationResponse( + meta = Meta().error(error.code, error.message), + data = null, + error = Error(error.code, error.message) + ) } } diff --git a/core/src/main/kotlin/com/core/common/response/Meta.kt b/core/src/main/kotlin/com/core/common/response/Meta.kt index 7036a2b..33aa567 100644 --- a/core/src/main/kotlin/com/core/common/response/Meta.kt +++ b/core/src/main/kotlin/com/core/common/response/Meta.kt @@ -19,9 +19,9 @@ data class Meta( ) } - fun error(error: Error): Meta = Meta( - result = "ERROR", - errorCode = error.code, - message = error.message + fun error(errorCode: String, message: String): Meta = Meta( + result = "FAIL", + errorCode = errorCode, + message = message ) } diff --git a/core/src/main/resources/application.yml b/core/src/main/resources/application.yml index 47fbb02..4024760 100644 --- a/core/src/main/resources/application.yml +++ b/core/src/main/resources/application.yml @@ -1,2 +1,25 @@ server: - port: 8080 \ No newline at end of file + port: 8080 + +spring: + datasource: + url: jdbc:mysql://localhost:3306/myongsik?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true + username: root + password: 1q2w3e4r! + + jpa: + show_sql: true + hibernate: + ddl-auto: update + properties: + hibernate: + format_sql: true + highlight_sql: true + default_batch_fetch_size: 20 + open-in-view: false +logging: + level: + org: + hibernate: + SQL: debug + orm.jdbc.bind: trace \ No newline at end of file diff --git a/core/src/main/resources/db/data.sql b/core/src/main/resources/db/data.sql new file mode 100644 index 0000000..1090394 --- /dev/null +++ b/core/src/main/resources/db/data.sql @@ -0,0 +1,78 @@ +-- Campus 데이터 삽입 +INSERT INTO campus (is_deleted, created_at, updated_at, name) +SELECT false, NOW(6), NOW(6), '서울대학교' + WHERE NOT EXISTS (SELECT 1 FROM campus WHERE name = '서울대학교'); + +INSERT INTO campus (is_deleted, created_at, updated_at, name) +SELECT false, NOW(6), NOW(6), '부산대학교' + WHERE NOT EXISTS (SELECT 1 FROM campus WHERE name = '부산대학교'); + +INSERT INTO campus (is_deleted, created_at, updated_at, name) +SELECT false, NOW(6), NOW(6), '명지대학교 자연캠퍼스' + WHERE NOT EXISTS (SELECT 1 FROM campus WHERE name = '명지대학교 자연캠퍼스'); + +INSERT INTO campus (is_deleted, created_at, updated_at, name) +SELECT false, NOW(6), NOW(6), '명지대학교 인문캠퍼스' + WHERE NOT EXISTS (SELECT 1 FROM campus WHERE name = '명지대학교 인문캠퍼스'); + +-- Restaurant 데이터 삽입 +INSERT INTO restaurant (campus_id, is_deleted, created_at, updated_at, address, name) +SELECT c.idx, false, NOW(6), NOW(6), '123 Seoul Street', '교직원식당' +FROM campus c +WHERE c.name = '명지대학교 자연캠퍼스' AND NOT EXISTS (SELECT 1 FROM restaurant WHERE name = '교직원식당'); + +INSERT INTO restaurant (campus_id, is_deleted, created_at, updated_at, address, name) +SELECT c.idx, false, NOW(6), NOW(6), '456 Busan Street', 'MCC식당' +FROM campus c +WHERE c.name = '명지대학교 인문캠퍼스' AND NOT EXISTS (SELECT 1 FROM restaurant WHERE name = 'MCC식당'); + +INSERT INTO restaurant (campus_id, is_deleted, created_at, updated_at, address, name) +SELECT c.idx, false, NOW(6), NOW(6), '456 Busan Street', '생활관식당' +FROM campus c +WHERE c.name = '명지대학교 자연캠퍼스' AND NOT EXISTS (SELECT 1 FROM restaurant WHERE name = '생활관식당'); + +-- Meals 데이터 삽입 +INSERT INTO meals (price, is_deleted, created_at, offered_at, restaurant_id, updated_at, meals, status, type) +SELECT 4500, false, NOW(6), NOW(6), r.idx, NOW(6), '밥, 콩나물국, 계란말이, 김치', 'OPEN', 'BREAKFAST' +FROM restaurant r +WHERE r.name = 'MCC식당' AND NOT EXISTS (SELECT 1 FROM meals WHERE meals = '밥, 콩나물국, 계란말이, 김치' AND type = 'BREAKFAST' AND restaurant_id = r.idx); + +INSERT INTO meals (price, is_deleted, created_at, offered_at, restaurant_id, updated_at, meals, status, type) +SELECT 7500, false, NOW(6), NOW(6), r.idx, NOW(6), '밥, 된장찌개, 제육볶음, 깍두기', 'OPEN', 'LUNCH' +FROM restaurant r +WHERE r.name = 'MCC식당' AND NOT EXISTS (SELECT 1 FROM meals WHERE meals = '밥, 된장찌개, 제육볶음, 깍두기' AND type = 'LUNCH' AND restaurant_id = r.idx); + +INSERT INTO meals (price, is_deleted, created_at, offered_at, restaurant_id, updated_at, meals, status, type) +SELECT 9500, false, NOW(6), NOW(6), r.idx, NOW(6), '밥, 북어국, 생선구이, 배추김치', 'OPEN', 'DINNER' +FROM restaurant r +WHERE r.name = 'MCC식당' AND NOT EXISTS (SELECT 1 FROM meals WHERE meals = '밥, 북어국, 생선구이, 배추김치' AND type = 'DINNER' AND restaurant_id = r.idx); + +INSERT INTO meals (price, is_deleted, created_at, offered_at, restaurant_id, updated_at, meals, status, type) +SELECT 4000, false, NOW(6), NOW(6), r.idx, NOW(6), '밥, 미소된장국, 햄구이, 김치', 'OPEN', 'BREAKFAST' +FROM restaurant r +WHERE r.name = '생활관식당' AND NOT EXISTS (SELECT 1 FROM meals WHERE meals = '밥, 미소된장국, 햄구이, 김치' AND type = 'BREAKFAST' AND restaurant_id = r.idx); + +INSERT INTO meals (price, is_deleted, created_at, offered_at, restaurant_id, updated_at, meals, status, type) +SELECT 7000, false, NOW(6), NOW(6), r.idx, NOW(6), '밥, 감자탕, 오징어볶음, 깍두기', 'OPEN', 'LUNCH' +FROM restaurant r +WHERE r.name = '생활관식당' AND NOT EXISTS (SELECT 1 FROM meals WHERE meals = '밥, 감자탕, 오징어볶음, 깍두기' AND type = 'LUNCH' AND restaurant_id = r.idx); + +INSERT INTO meals (price, is_deleted, created_at, offered_at, restaurant_id, updated_at, meals, status, type) +SELECT 9000, false, NOW(6), NOW(6), r.idx, NOW(6), '밥, 김치수제비, 불고기, 나물', 'OPEN', 'DINNER' +FROM restaurant r +WHERE r.name = '생활관식당' AND NOT EXISTS (SELECT 1 FROM meals WHERE meals = '밥, 김치수제비, 불고기, 나물' AND type = 'DINNER' AND restaurant_id = r.idx); + +INSERT INTO meals (price, is_deleted, created_at, offered_at, restaurant_id, updated_at, meals, status, type) +SELECT 5000, false, NOW(6), NOW(6), r.idx, NOW(6), '밥, 된장국, 불고기, 배추김치', 'OPEN', 'BREAKFAST' +FROM restaurant r +WHERE r.name = '교직원식당' AND NOT EXISTS (SELECT 1 FROM meals WHERE meals = '밥, 된장국, 불고기, 배추김치' AND type = 'BREAKFAST' AND restaurant_id = r.idx); + +INSERT INTO meals (price, is_deleted, created_at, offered_at, restaurant_id, updated_at, meals, status, type) +SELECT 8000, false, NOW(6), NOW(6), r.idx, NOW(6), '밥, 김치찌개, 돈까스, 나물', 'OPEN', 'LUNCH' +FROM restaurant r +WHERE r.name = '교직원식당' AND NOT EXISTS (SELECT 1 FROM meals WHERE meals = '밥, 김치찌개, 돈까스, 나물' AND type = 'LUNCH' AND restaurant_id = r.idx); + +INSERT INTO meals (price, is_deleted, created_at, offered_at, restaurant_id, updated_at, meals, status, type) +SELECT 10000, false, NOW(6), NOW(6), r.idx, NOW(6), '밥, 소고기미역국, 닭갈비, 깍두기', 'OPEN', 'DINNER' +FROM restaurant r +WHERE r.name = '교직원식당' AND NOT EXISTS (SELECT 1 FROM meals WHERE meals = '밥, 소고기미역국, 닭갈비, 깍두기' AND type = 'DINNER' AND restaurant_id = r.idx);