Skip to content

Commit

Permalink
디바이스 정보 등록 시에 유저 정보에 닉네임이 없는 경우 채워줌
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhvictor4 committed Jul 30, 2023
1 parent 31a82f4 commit 2b46e14
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api/src/main/kotlin/handler/DeviceHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package com.wafflestudio.snu4t.handler
import com.wafflestudio.snu4t.common.dto.OkResponse
import com.wafflestudio.snu4t.middleware.SnuttRestApiDefaultMiddleware
import com.wafflestudio.snu4t.notification.service.DeviceService
import com.wafflestudio.snu4t.users.data.User
import com.wafflestudio.snu4t.users.service.UserNicknameGenerateService
import com.wafflestudio.snu4t.users.service.UserService
import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.server.ServerRequest

@Component
class DeviceHandler(
private val deviceService: DeviceService,
private val userService: UserService,
private val userNicknameGenerateService: UserNicknameGenerateService,
snuttRestApiDefaultMiddleware: SnuttRestApiDefaultMiddleware,
) : ServiceHandler(snuttRestApiDefaultMiddleware) {
suspend fun addRegistrationId(req: ServerRequest) = handle(req) {
Expand All @@ -18,9 +23,19 @@ class DeviceHandler(
val registrationId = req.pathVariable("id")
deviceService.addRegistrationId(userId, registrationId, clientInfo)

updateIfUserNicknameNull(req.getContext().user!!)
OkResponse()
}

// TODO 회원가입 API (SNUTT -> SNU4T) 마이그레이션 완료 이후 삭제
// context: https://wafflestudio.slack.com/archives/C0PAVPS5T/p1690711859658779
private suspend fun updateIfUserNicknameNull(user: User) {
if (user.nickname == null) {
val nickname = userNicknameGenerateService.generateUniqueRandomNickname()
userService.update(user.copy(nickname = nickname))
}
}

suspend fun removeRegistrationId(req: ServerRequest) = handle(req) {
val userId = req.userId

Expand Down

0 comments on commit 2b46e14

Please sign in to comment.