Skip to content

Commit

Permalink
Spring event 적용 (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hank-Choi authored Sep 13, 2024
1 parent 5b600a0 commit 443a1dc
Show file tree
Hide file tree
Showing 185 changed files with 5,047 additions and 3,158 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
insert_final_newline = true

[*.{kt,kts}]
ktlint_code_style = ktlint_official
ktlint_standard_function-naming = disabled
20 changes: 11 additions & 9 deletions api/src/main/kotlin/filter/ErrorWebFilter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ class ErrorWebFilter(
) : WebFilter {
private val log = LoggerFactory.getLogger(javaClass)

override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
override fun filter(
exchange: ServerWebExchange,
chain: WebFilterChain,
): Mono<Void> {
return chain.filter(exchange)
.onErrorResume { throwable ->
val errorBody: ErrorBody
Expand All @@ -32,9 +35,10 @@ class ErrorWebFilter(
}
is ResponseStatusException -> {
httpStatusCode = throwable.statusCode
errorBody = makeErrorBody(
Snu4tException(errorMessage = throwable.body.title ?: ErrorType.DEFAULT_ERROR.errorMessage)
)
errorBody =
makeErrorBody(
Snu4tException(errorMessage = throwable.body.title ?: ErrorType.DEFAULT_ERROR.errorMessage),
)
}
else -> {
log.error(throwable.message, throwable)
Expand All @@ -49,15 +53,13 @@ class ErrorWebFilter(
Mono.just(
exchange.response
.bufferFactory()
.wrap(objectMapper.writeValueAsBytes(errorBody))
)
.wrap(objectMapper.writeValueAsBytes(errorBody)),
),
)
}
}

private fun makeErrorBody(
exception: Snu4tException,
): ErrorBody {
private fun makeErrorBody(exception: Snu4tException): ErrorBody {
return ErrorBody(exception.error.errorCode, exception.errorMessage, exception.displayMessage, exception.detail, exception.ext)
}
}
Expand Down
120 changes: 64 additions & 56 deletions api/src/main/kotlin/handler/AdminHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,60 +26,68 @@ class AdminHandler(
private val popupService: PopupService,
snuttRestAdminApiMiddleware: SnuttRestAdminApiMiddleware,
) : ServiceHandler(snuttRestAdminApiMiddleware) {
suspend fun insertNotification(req: ServerRequest) = handle(req) {
val body = req.awaitBody<InsertNotificationRequest>()
notificationAdminService.insertNotification(body)

OkResponse()
}

suspend fun postConfig(req: ServerRequest) = handle(req) {
val name = req.pathVariable("name")
val body = req.awaitBody<PostConfigRequest>()

val config = configService.postConfig(name, body)
ConfigResponse.from(config)
}

suspend fun getConfigs(req: ServerRequest) = handle(req) {
val name = req.pathVariable("name")

val configs = configService.getConfigsByName(name)
configs.map { ConfigResponse.from(it) }
}

suspend fun deleteConfig(req: ServerRequest) = handle(req) {
val name = req.pathVariable("name")
val configId = req.pathVariable("id")

configService.deleteConfig(name, configId)
}

suspend fun patchConfig(req: ServerRequest) = handle(req) {
val name = req.pathVariable("name")
val configId = req.pathVariable("id")
val body = req.awaitBody<PatchConfigRequest>()

val config = configService.patchConfig(name, configId, body)
ConfigResponse.from(config)
}

suspend fun getUploadSignedUris(req: ServerRequest) = handle(req) {
val source = StorageSource.from(req.pathVariable("source")) ?: throw ServerWebInputException("Invalid source")
val count = req.parseQueryParam<Int>("count") ?: 1

storageService.getUploadSignedUris(source, count)
}

suspend fun postPopup(req: ServerRequest) = handle(req) {
val body = req.awaitBody<PostPopupRequest>()

popupService.postPopup(body).let(::PopupResponse)
}

suspend fun deletePopup(req: ServerRequest) = handle(req) {
val popupId = req.pathVariable("id")

popupService.deletePopup(popupId)
}
suspend fun insertNotification(req: ServerRequest) =
handle(req) {
val body = req.awaitBody<InsertNotificationRequest>()
notificationAdminService.insertNotification(body)

OkResponse()
}

suspend fun postConfig(req: ServerRequest) =
handle(req) {
val name = req.pathVariable("name")
val body = req.awaitBody<PostConfigRequest>()

val config = configService.postConfig(name, body)
ConfigResponse.from(config)
}

suspend fun getConfigs(req: ServerRequest) =
handle(req) {
val name = req.pathVariable("name")

val configs = configService.getConfigsByName(name)
configs.map { ConfigResponse.from(it) }
}

suspend fun deleteConfig(req: ServerRequest) =
handle(req) {
val name = req.pathVariable("name")
val configId = req.pathVariable("id")

configService.deleteConfig(name, configId)
}

suspend fun patchConfig(req: ServerRequest) =
handle(req) {
val name = req.pathVariable("name")
val configId = req.pathVariable("id")
val body = req.awaitBody<PatchConfigRequest>()

val config = configService.patchConfig(name, configId, body)
ConfigResponse.from(config)
}

suspend fun getUploadSignedUris(req: ServerRequest) =
handle(req) {
val source = StorageSource.from(req.pathVariable("source")) ?: throw ServerWebInputException("Invalid source")
val count = req.parseQueryParam<Int>("count") ?: 1

storageService.getUploadSignedUris(source, count)
}

suspend fun postPopup(req: ServerRequest) =
handle(req) {
val body = req.awaitBody<PostPopupRequest>()

popupService.postPopup(body).let(::PopupResponse)
}

suspend fun deletePopup(req: ServerRequest) =
handle(req) {
val popupId = req.pathVariable("id")

popupService.deletePopup(popupId)
}
}
120 changes: 66 additions & 54 deletions api/src/main/kotlin/handler/AuthHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,70 +25,82 @@ class AuthHandler(
private val userService: UserService,
snuttRestApiNoAuthMiddleware: SnuttRestApiNoAuthMiddleware,
) : ServiceHandler(snuttRestApiNoAuthMiddleware) {
suspend fun registerLocal(req: ServerRequest): ServerResponse = handle(req) {
val localRegisterRequest: LocalRegisterRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.registerLocal(localRegisterRequest)
}
suspend fun registerLocal(req: ServerRequest): ServerResponse =
handle(req) {
val localRegisterRequest: LocalRegisterRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.registerLocal(localRegisterRequest)
}

suspend fun loginLocal(req: ServerRequest): ServerResponse = handle(req) {
val localLoginRequest: LocalLoginRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.loginLocal(localLoginRequest)
}
suspend fun loginLocal(req: ServerRequest): ServerResponse =
handle(req) {
val localLoginRequest: LocalLoginRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.loginLocal(localLoginRequest)
}

suspend fun loginFacebookLegacy(req: ServerRequest): ServerResponse = handle(req) {
val facebookLoginRequest: FacebookLoginRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.loginFacebook(SocialLoginRequest(facebookLoginRequest.fbToken))
}
suspend fun loginFacebookLegacy(req: ServerRequest): ServerResponse =
handle(req) {
val facebookLoginRequest: FacebookLoginRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.loginFacebook(SocialLoginRequest(facebookLoginRequest.fbToken))
}

suspend fun loginFacebook(req: ServerRequest): ServerResponse = handle(req) {
val socialLoginRequest: SocialLoginRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.loginFacebook(socialLoginRequest)
}
suspend fun loginFacebook(req: ServerRequest): ServerResponse =
handle(req) {
val socialLoginRequest: SocialLoginRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.loginFacebook(socialLoginRequest)
}

suspend fun loginGoogle(req: ServerRequest): ServerResponse = handle(req) {
val socialLoginRequest: SocialLoginRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.loginGoogle(socialLoginRequest)
}
suspend fun loginGoogle(req: ServerRequest): ServerResponse =
handle(req) {
val socialLoginRequest: SocialLoginRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.loginGoogle(socialLoginRequest)
}

suspend fun loginKakao(req: ServerRequest): ServerResponse = handle(req) {
val socialLoginRequest: SocialLoginRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.loginKakao(socialLoginRequest)
}
suspend fun loginKakao(req: ServerRequest): ServerResponse =
handle(req) {
val socialLoginRequest: SocialLoginRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.loginKakao(socialLoginRequest)
}

suspend fun logout(req: ServerRequest): ServerResponse = handle(req) {
val userId = req.userId
val logoutRequest: LogoutRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.logout(userId, logoutRequest)
suspend fun logout(req: ServerRequest): ServerResponse =
handle(req) {
val userId = req.userId
val logoutRequest: LogoutRequest = req.awaitBodyOrNull() ?: throw ServerWebInputException("Invalid body")
userService.logout(userId, logoutRequest)

OkResponse()
}
OkResponse()
}

suspend fun findId(req: ServerRequest): ServerResponse = handle(req) {
val email = req.awaitBody<SendEmailRequest>().email
userService.sendLocalIdToEmail(email)
OkResponse()
}
suspend fun findId(req: ServerRequest): ServerResponse =
handle(req) {
val email = req.awaitBody<SendEmailRequest>().email
userService.sendLocalIdToEmail(email)
OkResponse()
}

suspend fun sendResetPasswordCode(req: ServerRequest): ServerResponse = handle(req) {
val email = req.awaitBody<SendEmailRequest>().email
userService.sendResetPasswordCode(email)
OkResponse()
}
suspend fun sendResetPasswordCode(req: ServerRequest): ServerResponse =
handle(req) {
val email = req.awaitBody<SendEmailRequest>().email
userService.sendResetPasswordCode(email)
OkResponse()
}

suspend fun verifyResetPasswordCode(req: ServerRequest): ServerResponse = handle(req) {
val body = req.awaitBody<VerificationCodeRequest>()
userService.verifyResetPasswordCode(body.userId!!, body.code)
OkResponse()
}
suspend fun verifyResetPasswordCode(req: ServerRequest): ServerResponse =
handle(req) {
val body = req.awaitBody<VerificationCodeRequest>()
userService.verifyResetPasswordCode(body.userId!!, body.code)
OkResponse()
}

suspend fun getMaskedEmail(req: ServerRequest): ServerResponse = handle(req) {
val id = req.awaitBody<GetMaskedEmailRequest>().userId
EmailResponse(userService.getMaskedEmail(id))
}
suspend fun getMaskedEmail(req: ServerRequest): ServerResponse =
handle(req) {
val id = req.awaitBody<GetMaskedEmailRequest>().userId
EmailResponse(userService.getMaskedEmail(id))
}

suspend fun resetPassword(req: ServerRequest): ServerResponse = handle(req) {
val body = req.awaitBody<PasswordResetRequest>()
userService.resetPassword(body.userId, body.password, body.code)
OkResponse()
}
suspend fun resetPassword(req: ServerRequest): ServerResponse =
handle(req) {
val body = req.awaitBody<PasswordResetRequest>()
userService.resetPassword(body.userId, body.password, body.code)
OkResponse()
}
}
67 changes: 35 additions & 32 deletions api/src/main/kotlin/handler/BookmarkHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,43 @@ class BookmarkHandler(
private val bookmarkService: BookmarkService,
snuttRestApiDefaultMiddleware: SnuttRestApiDefaultMiddleware,
) : ServiceHandler(handlerMiddleware = snuttRestApiDefaultMiddleware) {
suspend fun getBookmarks(req: ServerRequest) =
handle(req) {
val userId: String = req.userId
val year: Int = req.parseRequiredQueryParam("year")
val semester: Semester = req.parseRequiredQueryParam("semester") { Semester.getOfValue(it.toInt()) }
val bookmark = bookmarkService.getBookmark(userId, year, semester)
val bookmarkLectureDtos = bookmarkService.convertBookmarkLecturesToBookmarkLectureDtos(bookmark.lectures)

suspend fun getBookmarks(req: ServerRequest) = handle(req) {
val userId: String = req.userId
val year: Int = req.parseRequiredQueryParam("year")
val semester: Semester = req.parseRequiredQueryParam("semester") { Semester.getOfValue(it.toInt()) }
val bookmark = bookmarkService.getBookmark(userId, year, semester)
val bookmarkLectureDtos = bookmarkService.convertBookmarkLecturesToBookmarkLectureDtos(bookmark.lectures)
BookmarkResponse(
year = bookmark.year,
semester = bookmark.semester.value,
lectures = bookmarkLectureDtos,
)
}

BookmarkResponse(
year = bookmark.year,
semester = bookmark.semester.value,
lectures = bookmarkLectureDtos
)
}
suspend fun existsBookmarkLecture(req: ServerRequest) =
handle(req) {
val userId: String = req.userId
val lectureId = req.pathVariable("lectureId")
ExistenceResponse(bookmarkService.existsBookmarkLecture(userId, lectureId))
}

suspend fun existsBookmarkLecture(req: ServerRequest) = handle(req) {
val userId: String = req.userId
val lectureId = req.pathVariable("lectureId")
ExistenceResponse(bookmarkService.existsBookmarkLecture(userId, lectureId))
}
suspend fun addLecture(req: ServerRequest) =
handle(req) {
val userId: String = req.userId
val body = req.awaitBody<BookmarkLectureModifyRequest>()
val lectureId = body.lectureId
bookmarkService.addLecture(userId, lectureId)
null
}

suspend fun addLecture(req: ServerRequest) = handle(req) {
val userId: String = req.userId
val body = req.awaitBody<BookmarkLectureModifyRequest>()
val lectureId = body.lectureId
bookmarkService.addLecture(userId, lectureId)
null
}

suspend fun deleteBookmark(req: ServerRequest) = handle(req) {
val userId: String = req.userId
val body = req.awaitBody<BookmarkLectureModifyRequest>()
val lectureId = body.lectureId
bookmarkService.deleteLecture(userId, lectureId)
null
}
suspend fun deleteBookmark(req: ServerRequest) =
handle(req) {
val userId: String = req.userId
val body = req.awaitBody<BookmarkLectureModifyRequest>()
val lectureId = body.lectureId
bookmarkService.deleteLecture(userId, lectureId)
null
}
}
Loading

0 comments on commit 443a1dc

Please sign in to comment.