generated from pricelees/issue-pr-template
[#46] 더미 데이터 생성 및 1개의 슬로우쿼리 개선 #47
@ -121,23 +121,6 @@ class ReservationService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
fun findMostReservedThemeIds(count: Int): MostReservedThemeIdListResponse {
|
|
||||||
log.info { "[ReservationService.findMostReservedThemeIds] 인기 테마 조회 시작: count=$count" }
|
|
||||||
val previousWeekSunday = DateUtils.getSundayOfPreviousWeek(LocalDate.now())
|
|
||||||
val previousWeekSaturday = previousWeekSunday.plusDays(6)
|
|
||||||
|
|
||||||
val themeIds: List<Long> = reservationRepository.findMostReservedThemeIds(
|
|
||||||
dateFrom = previousWeekSunday,
|
|
||||||
dateTo = previousWeekSaturday,
|
|
||||||
count = count
|
|
||||||
)
|
|
||||||
|
|
||||||
return MostReservedThemeIdListResponse(themeIds = themeIds).also {
|
|
||||||
log.info { "[ReservationService.findMostReservedThemeIds] 인기 테마 조회 완료: count=${it.themeIds.size}" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun findOrThrow(id: Long): ReservationEntity {
|
private fun findOrThrow(id: Long): ReservationEntity {
|
||||||
log.info { "[ReservationService.findOrThrow] 예약 조회 시작: reservationId=${id}" }
|
log.info { "[ReservationService.findOrThrow] 예약 조회 시작: reservationId=${id}" }
|
||||||
|
|
||||||
|
|||||||
@ -16,14 +16,6 @@ import roomescape.common.dto.response.CommonApiResponse
|
|||||||
import roomescape.reservation.web.*
|
import roomescape.reservation.web.*
|
||||||
|
|
||||||
interface ReservationAPI {
|
interface ReservationAPI {
|
||||||
|
|
||||||
@Public
|
|
||||||
@Operation(summary = "가장 많이 예약된 테마 ID 조회")
|
|
||||||
@ApiResponses(ApiResponse(responseCode = "200", useReturnTypeSchema = true))
|
|
||||||
fun findMostReservedThemeIds(
|
|
||||||
@RequestParam count: Int
|
|
||||||
): ResponseEntity<CommonApiResponse<MostReservedThemeIdListResponse>>
|
|
||||||
|
|
||||||
@Operation(summary = "결제 전 임시 예약 저장")
|
@Operation(summary = "결제 전 임시 예약 저장")
|
||||||
@ApiResponses(ApiResponse(responseCode = "200", useReturnTypeSchema = true))
|
@ApiResponses(ApiResponse(responseCode = "200", useReturnTypeSchema = true))
|
||||||
fun createPendingReservation(
|
fun createPendingReservation(
|
||||||
|
|||||||
@ -1,27 +1,8 @@
|
|||||||
package roomescape.reservation.infrastructure.persistence
|
package roomescape.reservation.infrastructure.persistence
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
import org.springframework.data.jpa.repository.Query
|
|
||||||
import org.springframework.data.repository.query.Param
|
|
||||||
import java.time.LocalDate
|
|
||||||
|
|
||||||
interface ReservationRepository : JpaRepository<ReservationEntity, Long> {
|
interface ReservationRepository : JpaRepository<ReservationEntity, Long> {
|
||||||
|
|
||||||
fun findAllByUserIdAndStatusIsIn(userId: Long, statuses: List<ReservationStatus>): List<ReservationEntity>
|
fun findAllByUserIdAndStatusIsIn(userId: Long, statuses: List<ReservationStatus>): List<ReservationEntity>
|
||||||
|
|
||||||
@Query("""
|
|
||||||
SELECT s.themeId
|
|
||||||
FROM ReservationEntity r
|
|
||||||
JOIN ScheduleEntity s ON s._id = r.scheduleId
|
|
||||||
WHERE r.status = roomescape.reservation.infrastructure.persistence.ReservationStatus.CONFIRMED
|
|
||||||
AND s.date BETWEEN :dateFrom AND :dateTo
|
|
||||||
GROUP BY s.themeId
|
|
||||||
ORDER BY count(r) DESC
|
|
||||||
LIMIT :count
|
|
||||||
""")
|
|
||||||
fun findMostReservedThemeIds(
|
|
||||||
@Param("dateFrom") dateFrom: LocalDate,
|
|
||||||
@Param("dateTo") dateTo: LocalDate,
|
|
||||||
@Param("count") count: Int
|
|
||||||
): List<Long>
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,16 +14,6 @@ import roomescape.reservation.docs.ReservationAPI
|
|||||||
class ReservationController(
|
class ReservationController(
|
||||||
private val reservationService: ReservationService
|
private val reservationService: ReservationService
|
||||||
) : ReservationAPI {
|
) : ReservationAPI {
|
||||||
|
|
||||||
@GetMapping("/popular-themes")
|
|
||||||
override fun findMostReservedThemeIds(
|
|
||||||
@RequestParam count: Int
|
|
||||||
): ResponseEntity<CommonApiResponse<MostReservedThemeIdListResponse>> {
|
|
||||||
val response = reservationService.findMostReservedThemeIds(count)
|
|
||||||
|
|
||||||
return ResponseEntity.ok(CommonApiResponse(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/pending")
|
@PostMapping("/pending")
|
||||||
override fun createPendingReservation(
|
override fun createPendingReservation(
|
||||||
@User user: CurrentUserContext,
|
@User user: CurrentUserContext,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user