Skip to content

Commit

Permalink
응답의 user_id 사용자 정보로 교체
Browse files Browse the repository at this point in the history
  • Loading branch information
asp345 committed Dec 21, 2024
1 parent 0f00915 commit 774bfa4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
16 changes: 16 additions & 0 deletions core/src/main/kotlin/evaluation/dto/EvUserDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.wafflestudio.snu4t.evaluation.dto

import com.wafflestudio.snu4t.users.data.User

data class EvUserDto(
val id: String?,
val email: String?,
val local_id: String?,
)

fun EvUserDto(user: User) =
EvUserDto(
id = user.id,
email = user.email,
local_id = user.credential.localId,
)
41 changes: 32 additions & 9 deletions core/src/main/kotlin/evaluation/service/EvService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import com.wafflestudio.snu4t.common.util.buildMultiValueMap
import com.wafflestudio.snu4t.config.SnuttEvWebClient
import com.wafflestudio.snu4t.coursebook.service.CoursebookService
import com.wafflestudio.snu4t.evaluation.dto.EvLectureInfoDto
import com.wafflestudio.snu4t.evaluation.dto.EvUserDto
import com.wafflestudio.snu4t.timetables.service.TimetableService
import com.wafflestudio.snu4t.users.service.UserService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.withContext
Expand All @@ -25,26 +27,30 @@ class EvService(
private val snuttEvWebClient: SnuttEvWebClient,
private val timetableService: TimetableService,
private val coursebookService: CoursebookService,
private val userService: UserService,
) {
suspend fun handleRouting(
userId: String,
requestPath: String,
requestQueryParams: MultiValueMap<String, String> = buildMultiValueMap(mapOf()),
originalBody: String,
method: HttpMethod,
): Map<String, Any> =
snuttEvWebClient.method(method)
.uri { builder -> builder.path(requestPath).queryParams(requestQueryParams).build() }
.header("Snutt-User-Id", userId)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body(BodyInserters.fromValue(originalBody))
.retrieve()
.awaitBody()
): Map<String, Any?> {
val result: MutableMap<String, Any?> =
snuttEvWebClient.method(method)
.uri { builder -> builder.path(requestPath).queryParams(requestQueryParams).build() }
.header("Snutt-User-Id", userId)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body(BodyInserters.fromValue(originalBody))
.retrieve()
.awaitBody<MutableMap<String, Any?>>()
return updateUserInfo(result)
}

suspend fun getMyLatestLectures(
userId: String,
requestQueryParams: MultiValueMap<String, String>? = null,
): Map<String, Any> {
): Map<String, Any?> {
val recentLectures: List<EvLectureInfoDto> =
coursebookService.getLastTwoCourseBooksBeforeCurrent().flatMap { coursebook ->
timetableService.getTimetablesBySemester(userId, coursebook.year, coursebook.semester)
Expand Down Expand Up @@ -83,4 +89,21 @@ class EvService(
.retrieve()
.awaitBody()
}

private suspend fun updateUserInfo(data: MutableMap<String, Any?>): MutableMap<String, Any?> {
val updatedMap: MutableMap<String, Any?> = mutableMapOf()
for ((k, v) in data.entries) {
if (k == "user_id") {
val userDto = runCatching { EvUserDto(userService.getUser(v as String)) }.getOrNull()
updatedMap["user"] = userDto
} else {
when (v) {
is List<*> -> updatedMap[k] = v.map { updateUserInfo(it as MutableMap<String, Any?>) }
is MutableMap<*, *> -> updatedMap[k] = updateUserInfo(v as MutableMap<String, Any?>)
else -> updatedMap[k] = v
}
}
}
return updatedMap
}
}

0 comments on commit 774bfa4

Please sign in to comment.