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

[TNT-114] 회원가입 데이터 취합 및 API 연동 #54

Merged
merged 14 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,45 @@ data class SignUpRequest(
val cautionNote: String? = "",
)

object SignUpRequestMapper {
fun fromUserType(
userType: UserType,
socialId: String,
socialType: String,
email: String,
fcmToken: String,
): SignUpRequest {
return when (userType) {
is UserType.Trainer -> SignUpRequest(
memberType = "trainer",
name = userType.name,
birthday = null,
height = null,
weight = null,
goalContents = null,
cautionNote = null,
socialType = socialType,
socialId = socialId,
socialEmail = email,
fcmToken = fcmToken,
serviceAgreement = true,
collectionAgreement = true,
advertisementAgreement = true,
)
fun UserType.toSignUpRequest(
Copy link
Member

Choose a reason for hiding this comment

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

요 클래스에서 UserType 에 대한 확장 함수를 가지고 있는건 너무 어색해보입니다..!

SignUpRequest.fromDomain 이나, SignUpRequest.fromUserType 과 같은 형태가 맞는 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵..! 다시 수정해보겠습니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

지금 제 코드는 UserType을 기반으로 새로운 SignUpRequest 객체를 생성하는 방식이라 SignUpRequest에 대한 확장 함수로 구현하기는 어려울 것 같습니다..!

companion object를 이용해 fromUserType을 구현하는건 안 될까요?😨

Copy link
Member

Choose a reason for hiding this comment

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

얽 이거 Request 인데 제가 놓쳤네요 '-' ;;

혼동드려서 죄송합니다 ㅜㅜ

수정해주신대로 진행해도 될 것 같습니다ㅠㅠㅠ

Copy link
Contributor Author

Choose a reason for hiding this comment

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

그럼 지금 코드대로 머지하겠습니다!!

socialId: String,
socialType: String,
email: String,
fcmToken: String,
): SignUpRequest {
return when (this) {
is UserType.Trainer -> SignUpRequest(
memberType = "trainer",
name = name,
birthday = null,
height = null,
weight = null,
goalContents = null,
cautionNote = null,
socialType = socialType,
socialId = socialId,
socialEmail = email,
fcmToken = fcmToken,
serviceAgreement = true,
collectionAgreement = true,
advertisementAgreement = true,
)

is UserType.Trainee -> SignUpRequest(
memberType = "trainee",
name = userType.name,
birthday = userType.birthday?.toString(),
height = userType.height.toDouble(),
weight = userType.weight,
goalContents = userType.ptPurpose,
cautionNote = userType.caution?.ifBlank { null },
socialType = socialType,
socialId = socialId,
socialEmail = email,
fcmToken = fcmToken,
serviceAgreement = true,
collectionAgreement = true,
advertisementAgreement = true,
)
}
is UserType.Trainee -> SignUpRequest(
memberType = "trainee",
name = name,
birthday = birthday?.toString(),
height = height.toDouble(),
weight = weight,
goalContents = ptPurpose,
cautionNote = caution?.ifBlank { null },
socialType = socialType,
socialId = socialId,
socialEmail = email,
fcmToken = fcmToken,
serviceAgreement = true,
collectionAgreement = true,
advertisementAgreement = true,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package co.kr.data.repository

import co.kr.data.network.model.SignUpRequest
import co.kr.data.network.model.SignUpRequestMapper
import co.kr.data.network.model.toDomain
import co.kr.data.network.model.toSignUpRequest
import co.kr.data.network.source.SignUpRemoteDataSource
import co.kr.data.storage.source.SessionLocalDataSource
import co.kr.tnt.domain.model.SignUpResult
Expand All @@ -21,6 +21,7 @@ import javax.inject.Inject
class SignUpRepositoryImpl @Inject constructor(
private val signupRemoteDataSource: SignUpRemoteDataSource,
private val sessionLocalDataSource: SessionLocalDataSource,
private val json: Json,
) : SignUpRepository {
override suspend fun signUp(
profileImage: File?,
Expand All @@ -35,29 +36,26 @@ class SignUpRepositoryImpl @Inject constructor(
}

// TODO FCM token
val signUpRequest = SignUpRequestMapper.fromUserType(
userType = userType,
val signUpRequest = userType.toSignUpRequest(
socialId = socialId,
socialType = socialType,
email = email,
fcmToken = "EMPTY",
)
val requestBody = prepareJsonRequestBody(signUpRequest)
val requestBody = signUpRequest.toRequestBody(Json)

val response = signupRemoteDataSource.postSignUp(
profileImage = profileImagePart,
request = requestBody,
)

response.sessionId.let { sessionId ->
sessionLocalDataSource.updateSessionId(sessionId)
}
sessionLocalDataSource.updateSessionId(response.sessionId)

return response.toDomain()
}

private fun prepareJsonRequestBody(signUpRequest: SignUpRequest): RequestBody {
val jsonString = Json.encodeToString(signUpRequest)
private fun SignUpRequest.toRequestBody(json: Json): RequestBody {
val jsonString = json.encodeToString(this)
return jsonString.toRequestBody("application/json".toMediaTypeOrNull())
}
}