diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 8cea017..7bf23a0 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -7,4 +7,6 @@ dependencies { 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") } 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 6a7acfb..b821bb1 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 @@ -3,6 +3,7 @@ package com.core.adapter.`in`.web import com.core.adapter.`in`.web.dto.AdapterMealDto import com.core.application.port.`in`.GetWeekMealUseCase import com.core.common.response.ApplicationResponse +import io.swagger.v3.oas.annotations.Operation import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController @@ -10,11 +11,13 @@ import org.springframework.web.bind.annotation.RestController @RestController class MealController(val getWeekMealUseCase: GetWeekMealUseCase) { + @GetMapping("/api/v1/meals/week") + @Operation(summary = "주간 식단 조회") fun getWeekMeal( - @RequestParam("restaurantName") restaurantName: String - ) : ApplicationResponse> { - val data = getWeekMealUseCase(restaurantName) + @RequestParam("restaurantIdx") restaurantIdx: Long + ) : ApplicationResponse> { + val data = getWeekMealUseCase(restaurantIdx) val toResponse = AdapterMealDto.GetWeekMealRes.from(data) return ApplicationResponse.ok(toResponse) } 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 522eea8..b44d85b 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 @@ -5,6 +5,11 @@ import java.math.BigDecimal import java.time.LocalDate class AdapterMealDto { + data class GroupedWeekMealRes( + val offeredAt: LocalDate, + val getWeekMealRes: List + ) + data class GetWeekMealRes( val idx: Long, val type: String, @@ -14,19 +19,24 @@ class AdapterMealDto { val meals: List ) { companion object { - fun from(data: List): List { - return data.map { + fun from(data: List): List { + val groupedData = data.map { GetWeekMealRes( idx = it.idx, type = it.type.value, status = it.status.value, offeredAt = it.offeredAt, price = it.price, - meals = it.meals.split(",") + meals = it.meals.split(",").map { meal -> meal.trim() } + ) + }.groupBy { it.offeredAt } + return groupedData.map { (date, meals) -> + GroupedWeekMealRes( + offeredAt = date, + getWeekMealRes = meals ) } } } } - } \ No newline at end of file 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 index 49ff10b..6449ca6 100644 --- a/core/src/main/kotlin/com/core/adapter/out/persistence/MealPersistenceAdapter.kt +++ b/core/src/main/kotlin/com/core/adapter/out/persistence/MealPersistenceAdapter.kt @@ -7,13 +7,12 @@ import com.core.application.port.out.GetWeekMealPort import org.springframework.stereotype.Component import java.time.LocalDate -@Component -class MealPersistenceAdapter( +@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) + override fun invoke(restaurantIdx: Long, start: LocalDate, end: LocalDate): List { + val weekMeal = mealRepository.getWeekMeal(restaurantIdx, start, end) val applicationMeals = mealMapper.toDomain(weekMeal); return applicationMeals } 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 69f8ac2..8a17184 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 @@ -13,8 +13,7 @@ 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 + WHERE m.isDeleted = false and m.offeredAt between :start and :end and m.restaurantJpaEntity.idx = :restaurantIdx """) - fun getWeekMeal(restaurantName: String, start: LocalDate, end: LocalDate): List + fun getWeekMeal(restaurantIdx: Long, start: LocalDate, end: LocalDate): List } \ 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 8cfb681..6cf6273 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 @@ -17,9 +17,9 @@ class MealReadService( * @param restaurantName * @return List */ - override fun invoke(restaurantName: String): List { + override fun invoke(restaurantIdx: Long): List { val (startDay, endDay) = getWeekRange() - val meals = getWeekMealPort(restaurantName, startDay, endDay) + val meals = getWeekMealPort(restaurantIdx, startDay, endDay) return meals } 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 index 3d457f7..79dcd88 100644 --- a/core/src/main/kotlin/com/core/application/port/in/GetWeekMealUseCase.kt +++ b/core/src/main/kotlin/com/core/application/port/in/GetWeekMealUseCase.kt @@ -4,5 +4,5 @@ import com.core.application.domain.meal.model.Meal interface GetWeekMealUseCase { - operator fun invoke(campusName: String): List + operator fun invoke(restaurantIdx: Long): List } \ 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 index ed4dd0d..7220fa2 100644 --- a/core/src/main/kotlin/com/core/application/port/out/GetWeekMealPort.kt +++ b/core/src/main/kotlin/com/core/application/port/out/GetWeekMealPort.kt @@ -5,7 +5,7 @@ import java.time.LocalDate interface GetWeekMealPort { - operator fun invoke(restaurantName: String, + operator fun invoke(restaurantIdx: Long, start: LocalDate, end: LocalDate): List } \ No newline at end of file diff --git a/core/src/main/resources/application-local.yml b/core/src/main/resources/application-local.yml new file mode 100644 index 0000000..8a4f952 --- /dev/null +++ b/core/src/main/resources/application-local.yml @@ -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 \ No newline at end of file diff --git a/core/src/main/resources/application.yml b/core/src/main/resources/application.yml index 4024760..ec4973f 100644 --- a/core/src/main/resources/application.yml +++ b/core/src/main/resources/application.yml @@ -2,24 +2,13 @@ server: 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 + ddl-auto: none 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