Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "강의 데이터 반환 전에 빌딩 정보 매핑" #239

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions api/src/main/kotlin/handler/LectureSearchHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ package com.wafflestudio.snu4t.handler
import com.fasterxml.jackson.annotation.JsonProperty
import com.wafflestudio.snu4t.common.enum.DayOfWeek
import com.wafflestudio.snu4t.common.enum.Semester
import com.wafflestudio.snu4t.lecturebuildings.data.PlaceInfo
import com.wafflestudio.snu4t.lecturebuildings.service.LectureBuildingService
import com.wafflestudio.snu4t.lectures.dto.LectureDto
import com.wafflestudio.snu4t.lectures.dto.SearchDto
import com.wafflestudio.snu4t.lectures.dto.SearchTimeDto
import com.wafflestudio.snu4t.lectures.service.LectureService
import com.wafflestudio.snu4t.middleware.SnuttRestApiNoAuthMiddleware
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.toList
import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.server.ServerRequest
Expand All @@ -22,28 +17,13 @@ import org.springframework.web.reactive.function.server.awaitBody
@Component
class LectureSearchHandler(
private val lectureService: LectureService,
private val lectureBuildingService: LectureBuildingService,
snuttRestApiNoAuthMiddleware: SnuttRestApiNoAuthMiddleware,
) : ServiceHandler(
handlerMiddleware = snuttRestApiNoAuthMiddleware
) {
suspend fun searchLectures(req: ServerRequest): ServerResponse = handle(req) {
val query: SearchQueryLegacy = req.awaitBody()
lectureService.search(query.toSearchDto()).toList().map { LectureDto(it) }
.map { it.addLectureBuildings() }
}

private suspend fun LectureDto.addLectureBuildings(): LectureDto = coroutineScope {
copy(
classPlaceAndTimes = classPlaceAndTimes.map { classPlaceAndTime ->
async {
classPlaceAndTime.apply {
lectureBuildings =
place?.let { lectureBuildingService.getLectureBuildings(PlaceInfo.getValuesOf(it)) }
}
}
}.awaitAll()
)
}
}

Expand Down
27 changes: 0 additions & 27 deletions api/src/main/kotlin/handler/TimetableHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ package com.wafflestudio.snu4t.handler

import com.wafflestudio.snu4t.common.enum.Semester
import com.wafflestudio.snu4t.common.exception.InvalidPathParameterException
import com.wafflestudio.snu4t.lecturebuildings.data.PlaceInfo
import com.wafflestudio.snu4t.lecturebuildings.service.LectureBuildingService
import com.wafflestudio.snu4t.middleware.SnuttRestApiDefaultMiddleware
import com.wafflestudio.snu4t.timetables.dto.TimetableLegacyDto
import com.wafflestudio.snu4t.timetables.dto.request.TimetableAddRequestDto
import com.wafflestudio.snu4t.timetables.dto.request.TimetableModifyRequestDto
import com.wafflestudio.snu4t.timetables.dto.request.TimetableModifyThemeRequestDto
import com.wafflestudio.snu4t.timetables.service.TimetableService
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.toList
import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.server.ServerRequest
Expand All @@ -23,7 +18,6 @@ import timetables.dto.TimetableBriefDto
@Component
class TimetableHandler(
private val timetableService: TimetableService,
private val lectureBuildingService: LectureBuildingService,
snuttRestApiDefaultMiddleware: SnuttRestApiDefaultMiddleware,
) : ServiceHandler(
handlerMiddleware = snuttRestApiDefaultMiddleware
Expand All @@ -38,7 +32,6 @@ class TimetableHandler(
val userId = req.userId

timetableService.getMostRecentlyUpdatedTimetable(userId).let(::TimetableLegacyDto)
.addLectureBuidlings()
}

suspend fun getTimetablesBySemester(req: ServerRequest): ServerResponse = handle(req) {
Expand All @@ -48,7 +41,6 @@ class TimetableHandler(
Semester.getOfValue(req.pathVariable("semester").toInt()) ?: throw InvalidPathParameterException("semester")

timetableService.getTimetablesBySemester(userId, year, semester).toList().map(::TimetableLegacyDto)
.map { it.addLectureBuidlings() }
}

suspend fun addTimetable(req: ServerRequest): ServerResponse = handle(req) {
Expand All @@ -69,7 +61,6 @@ class TimetableHandler(
val timetableId = req.pathVariable("timetableId")

timetableService.getTimetable(userId, timetableId).let(::TimetableLegacyDto)
.addLectureBuidlings()
}

suspend fun modifyTimetable(req: ServerRequest): ServerResponse = handle(req) {
Expand Down Expand Up @@ -109,7 +100,6 @@ class TimetableHandler(
val body = req.awaitBody<TimetableModifyThemeRequestDto>()

timetableService.modifyTimetableTheme(userId, timetableId, body.theme, body.themeId).let(::TimetableLegacyDto)
.addLectureBuidlings()
}

suspend fun setPrimary(req: ServerRequest): ServerResponse = handle(req) {
Expand All @@ -121,21 +111,4 @@ class TimetableHandler(
val timetableId = req.pathVariable("timetableId")
timetableService.unSetPrimary(req.userId, timetableId)
}

private suspend fun TimetableLegacyDto.addLectureBuidlings(): TimetableLegacyDto = coroutineScope {
copy(
lectures = lectures.map { lecture ->
lecture.apply {
classPlaceAndTimes = classPlaceAndTimes.map { placeAndTime ->
async {
placeAndTime.apply {
lectureBuildings =
place?.let { lectureBuildingService.getLectureBuildings(PlaceInfo.getValuesOf(it)) }
}
}
}.awaitAll()
}
}
)
}
}
2 changes: 0 additions & 2 deletions core/src/main/kotlin/lectures/dto/ClassPlaceAndTimeDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.wafflestudio.snu4t.lectures.dto

import com.fasterxml.jackson.annotation.JsonProperty
import com.wafflestudio.snu4t.common.enum.DayOfWeek
import com.wafflestudio.snu4t.lecturebuildings.data.LectureBuilding
import com.wafflestudio.snu4t.lectures.data.ClassPlaceAndTime
import com.wafflestudio.snu4t.lectures.utils.endPeriod
import com.wafflestudio.snu4t.lectures.utils.minuteToString
Expand Down Expand Up @@ -35,7 +34,6 @@ data class ClassPlaceAndTimeLegacyDto(
val periodLength: Double,
@JsonProperty("start")
val startPeriod: Double,
var lectureBuildings: List<LectureBuilding>? = null,
)

fun ClassPlaceAndTimeLegacyDto(classPlaceAndTime: ClassPlaceAndTime): ClassPlaceAndTimeLegacyDto = ClassPlaceAndTimeLegacyDto(
Expand Down
Loading