Skip to content

[DPMBE-55] feat : 회원가입,로그인 및 fcm 토큰 업데이트 기능 추가 #76

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

Merged
merged 9 commits into from
Jun 12, 2023

Conversation

ImNM
Copy link
Member

@ImNM ImNM commented Jun 11, 2023

개요

작업사항

  • fcm 토큰 업데이트 관련 기능 추가했습니다.
  • 앱 알림 껏다키는 토글 기능 만들었습니다.

변경로직

  • fcmNotificationVo 만들어서 알림관련한 fcmToken, appAlarm 묶어줬어용
  • login user refresh user 도메인 메소드 나눠줬습니다.
  • 리프레쉬할때 fcm 토큰 업데이트 할 필요가없어서!

Kotlin Result 관련

// case 1
 return userRepository.findByOauthInfo(oauthInfo) ?: run {
            val newUser = userRepository.save(User(oauthInfo, username, profileImage, defaultImage))
// case2
 val user = userRepository.findByOauthInfo(oauthInfo) ?: run { throw UserNotFoundException.EXCEPTION }

위처럼 2가지 결과값은 같은데 에러처리를 할 때 대응할 때 달라져서 그냥
repository 에서 받아오고 있었는데

이거 없애고 싶어서

userAdapter 에

  fun queryByOauthInfo(oauthInfo: OauthInfo): User {
        return userRepository.findByOauthInfo(oauthInfo) ?: run { throw UserNotFoundException.EXCEPTION }
    }

위에걸 기본으로 대고

    fun resultQueryByOauthInfo(oauthInfo: OauthInfo): Result<User> {
        return runCatching { // runCatching 으로 감쌈
            userAdapter.queryByOauthInfo(oauthInfo)
        }
    }

위처럼 userDomain 서비스에서 한 번 Kotlin Result 로 래핑해서 쓰기로 했더니
좀 더 깔끔해졌어요 소스가 ㅎㅎ

@ImNM ImNM added the function 특정 기능 추가 label Jun 11, 2023
@ImNM ImNM requested a review from BlackBean99 as a code owner June 11, 2023 14:30
@ImNM ImNM self-assigned this Jun 11, 2023
@ImNM ImNM requested a review from kdomo as a code owner June 11, 2023 14:30
Comment on lines +10 to +31

fun user_id_1_fixture(): User {
return User(
oauthInfo_kakao_1_fixture(),
"유저1",
"url1",
true,
fcmNotificationVo_fixture(),
LocalDateTime.now(),
UserStatus.NORMAL,
AccountRole.USER,
1,
)
}

fun oauthInfo_kakao_1_fixture(): OauthInfo {
return OauthInfo("1", OauthProvider.KAKAO)
}

fun fcmNotificationVo_fixture(): FcmNotificationVo {
return FcmNotificationVo("fcmToken", true)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이번에 새롭게 픽스쳐 한번 가져와봤는데...
이형식이 맞을란가 모르겠네요

픽스쳐관련해선 우테캠쪽 레포보면 종종 나오는데
테스트 할 때 객체생성 매번 해주기 귀찮으니 이렇게
만들어서 쓰더라고요

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제꺼 테스트에도 이런식으로 적어놓긴 했는데 이거 보고 조금 수정해야겠네요

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

37.4% 37.4% Coverage
0.0% 0.0% Duplication

package com.depromeet.whatnow.api.user.dto.request

data class UpdateFcmTokenRequest(
val fcmToken: String,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Valid 넣어주셨는데 나중에 fcm Constraint 생기면 어노테이션으로 추가하면 되겠네요 (참고 )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예압

}

fun updateFcmToken(updateTokenRequest: UpdateFcmTokenRequest): User {
val currentUserId: Long = SecurityUtils.currentUserId
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다시봐도 이거 진짜 개꿀임..

@@ -14,4 +15,12 @@ class UserAdapter(
fun queryUser(userId: Long): User {
return userRepository.findByIdOrNull(userId) ?: run { throw UserNotFoundException.EXCEPTION }
}

fun queryByOauthInfo(oauthInfo: OauthInfo): User {
return userRepository.findByOauthInfo(oauthInfo) ?: run { throw UserNotFoundException.EXCEPTION }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 runCatching 하면 좋지 않을까요? 우리 컨벤션 이야기 해보면 좋을 것 같아요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runCatching 은 한번 감싸는 용도로 쓸 때만 적음 좋을것같아요
Adapter의 경우
query 가 NotFound 오류 디폴트로 하기로 했으니 이대로가고

그 쿼리메서드에 관련한 에러처리를 result로 래핑해서 전략을 짜는 책임은
도메인 서비스에 있다고 봐유!

Copy link
Member

@kdomo kdomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ImNM ImNM merged commit c639735 into develop Jun 12, 2023
@ImNM ImNM deleted the feature/DPMBE-55 branch June 12, 2023 04:57
kdomo pushed a commit that referenced this pull request Jun 16, 2023
* feat : fcmvo

* feat : register fcmtoken appalram add

* refactor : refresh , login 메소드 분리

* feat : toggle AppAlarm

* feat : fcm token 업데이트 기능 추가

* feat : query By result 로 리팩토링

* style : spotless

* test : result 회원가입 래핑 테스트 추가

* refactor : readUserusecase query user 사용
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
function 특정 기능 추가
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DPMBE-55] 회원가입, 로그인간 FCM 토큰 업데이트 기능, 알림 허용 기능을 만든다
3 participants