From 41dd92b71e0cfe14ba5aab9837c691ae021d929d Mon Sep 17 00:00:00 2001 From: hhhello Date: Mon, 7 Oct 2024 12:36:53 +0900 Subject: [PATCH] Fix getMeals api --- .../graduatingserver/api/meal/MealController.kt | 5 ++--- .../graduatingserver/api/meal/MealService.kt | 14 ++++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/meal/MealController.kt b/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/meal/MealController.kt index 0323db9..a3e8abf 100644 --- a/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/meal/MealController.kt +++ b/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/meal/MealController.kt @@ -8,7 +8,6 @@ import org.springframework.web.bind.annotation.* class MealController( private val mealService: MealService ) { - @GetMapping("/{schoolId}", "/{schoolId}/") - fun getMeals(@PathVariable("schoolId") schoolId: Long) = - mealService.getMeals(schoolId) + @GetMapping + fun getMeals() = mealService.getMeals() } \ No newline at end of file diff --git a/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/meal/MealService.kt b/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/meal/MealService.kt index dd45fb2..5112d8f 100644 --- a/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/meal/MealService.kt +++ b/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/meal/MealService.kt @@ -5,22 +5,24 @@ import com.bestswlkh0310.graduating.graduatingserver.core.global.safeSaveAll import com.bestswlkh0310.graduating.graduatingserver.core.meal.MealRepository import com.bestswlkh0310.graduating.graduatingserver.core.school.SchoolRepository import com.bestswlkh0310.graduating.graduatingserver.core.school.getBy +import com.bestswlkh0310.graduating.graduatingserver.core.user.UserAuthenticationHolder +import com.bestswlkh0310.graduating.graduatingserver.global.exception.CustomException import com.bestswlkh0310.graduating.graduatingserver.infra.neis.meal.NeisMealClient +import org.springframework.http.HttpStatus import org.springframework.stereotype.Service import java.time.LocalDate @Service class MealService( private val mealRepository: MealRepository, - private val schoolRepository: SchoolRepository, private val neisMealClient: NeisMealClient, + private val sessionHolder: UserAuthenticationHolder ) { - - fun getMeals(schoolId: Long): List { - val school = schoolRepository.getBy(schoolId) + fun getMeals(): List { + val school = sessionHolder.current().school ?: throw CustomException(HttpStatus.NOT_FOUND, "Not found school") val currentTime = LocalDate.now() - val schools = mealRepository.findBySchoolIdAndMealDate(schoolId, currentTime) + val schools = mealRepository.findBySchoolIdAndMealDate(school.id, currentTime) if (schools.isNotEmpty()) { return schools.map { MealRes.of(it) } } @@ -28,7 +30,7 @@ class MealService( val meals = neisMealClient.getMeals(school = school) mealRepository.safeSaveAll(meals) - return mealRepository.findBySchoolIdAndMealDate(schoolId, currentTime) + return mealRepository.findBySchoolIdAndMealDate(school.id, currentTime) .map { MealRes.of(it) } }