-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7f245f1
[TNT-114] fix: RoleState 수정
SeonJeongk 6c0a7e2
[TNT-114] feat: 역할 선택 -> 회원가입 네비게이션 연결
SeonJeongk 071a69f
[TNT-114] feat: 트레이너 회원가입 사진, 이름 state로 관리
SeonJeongk 9c37378
[TNT-114] feat: 트레이너 회원가입 사진, 이름 state로 관리
SeonJeongk 8ff993a
[TNT-114] fix: 불필요한 코드 삭제 및 정렬 수정
SeonJeongk c2d814b
[TNT-114] refactor: 트레이너 이름, 사진 설정 관련 이름 수정
SeonJeongk eb79aca
[TNT-114] feat: 트레이니 회원가입 데이터 state로 관리
SeonJeongk bb6d29e
[TNT-114] feat: 회원가입 API 구현
SeonJeongk f942102
[TNT-114] feat: 트레이너 회원가입 API 연결
SeonJeongk e6a14b9
[TNT-114] refactor: 회원가입 주의사항 입력 에러 문구 추가
SeonJeongk b9d0ba9
[TNT-114] feat: 트레이너 회원가입 API 연결
SeonJeongk f3263f6
[TNT-114] fix: 이미지 File을 넘겨주도록 수정 및 state 수정
SeonJeongk a3274b6
[TNT-114] fix: 연결 화면들 preview 오류 수정
SeonJeongk 6201215
[TNT-114] fix: SignUpRequest 매핑 수정
SeonJeongk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package co.kr.tnt.ui.util | ||
|
||
import android.content.Context | ||
import android.database.Cursor | ||
import android.net.Uri | ||
import android.provider.MediaStore | ||
import android.util.Log | ||
import java.io.File | ||
|
||
fun Uri.toFile(context: Context): File? { | ||
return getRealPathFromUri(this, context)?.let { filePath -> | ||
File(filePath) | ||
} ?: run { | ||
Log.e("toFile", "Error creating file for URI: $this") | ||
null | ||
} | ||
} | ||
|
||
fun getRealPathFromUri(uri: Uri, context: Context): String? { | ||
val projection = arrayOf(MediaStore.Images.Media.DATA) | ||
val cursor: Cursor? = context.contentResolver.query(uri, projection, null, null, null) | ||
cursor?.use { | ||
if (it.moveToFirst()) { | ||
val columnIndex = it.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) | ||
return it.getString(columnIndex) | ||
} | ||
} | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
data/network/src/main/java/co/kr/data/network/model/SignUpRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package co.kr.data.network.model | ||
|
||
import co.kr.tnt.domain.model.UserType | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SignUpRequest( | ||
val socialType: String, | ||
val socialId: String, | ||
val fcmToken: String, | ||
val serviceAgreement: Boolean, | ||
val collectionAgreement: Boolean, | ||
val advertisementAgreement: Boolean, | ||
val socialEmail: String, | ||
val memberType: String, | ||
val name: String, | ||
val birthday: String? = null, | ||
val height: Double? = null, | ||
val weight: Double? = null, | ||
val goalContents: List<String>? = null, | ||
val cautionNote: String? = "", | ||
) | ||
|
||
fun UserType.toSignUpRequest( | ||
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 = 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, | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
data/network/src/main/java/co/kr/data/network/model/SignUpResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package co.kr.data.network.model | ||
|
||
import co.kr.tnt.domain.model.SignUpResult | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SignUpResponse( | ||
val memberType: String, | ||
val sessionId: String, | ||
val name: String, | ||
val profileImageUrl: String, | ||
) | ||
|
||
fun SignUpResponse.toDomain(): SignUpResult { | ||
return SignUpResult( | ||
memberType = memberType, | ||
sessionId = sessionId, | ||
name = name, | ||
profileImageUrl = profileImageUrl, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,24 @@ package co.kr.data.network.service | |
|
||
import co.kr.data.network.model.LoginRequest | ||
import co.kr.data.network.model.LoginResponse | ||
import co.kr.data.network.model.SignUpResponse | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody | ||
import retrofit2.http.Body | ||
import retrofit2.http.Multipart | ||
import retrofit2.http.POST | ||
import retrofit2.http.Part | ||
|
||
interface ApiService { | ||
@POST("/login") | ||
suspend fun postLogin( | ||
@Body request: LoginRequest, | ||
): LoginResponse | ||
|
||
@Multipart | ||
@POST("/members/sign-up") | ||
suspend fun postSignUp( | ||
@Part profileImage: MultipartBody.Part?, | ||
@Part("request") request: RequestBody, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
): SignUpResponse | ||
} |
21 changes: 21 additions & 0 deletions
21
data/network/src/main/java/co/kr/data/network/source/SignUpRemoteDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package co.kr.data.network.source | ||
|
||
import co.kr.data.network.model.SignUpResponse | ||
import co.kr.data.network.service.ApiService | ||
import co.kr.data.network.util.networkHandler | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class SignUpRemoteDataSource @Inject constructor( | ||
private val apiService: ApiService, | ||
) { | ||
suspend fun postSignUp( | ||
profileImage: MultipartBody.Part?, | ||
request: RequestBody, | ||
): SignUpResponse = networkHandler { | ||
apiService.postSignUp(profileImage, request) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
data/repository/src/main/java/co/kr/data/repository/SignUpRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package co.kr.data.repository | ||
|
||
import co.kr.data.network.model.SignUpRequest | ||
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 | ||
import co.kr.tnt.domain.model.UserType | ||
import co.kr.tnt.domain.repository.SignUpRepository | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody | ||
import okhttp3.RequestBody.Companion.asRequestBody | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import java.io.File | ||
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?, | ||
userType: UserType, | ||
socialId: String, | ||
socialType: String, | ||
email: String, | ||
): SignUpResult { | ||
val profileImagePart = profileImage?.let { | ||
val requestFile = it.asRequestBody("image/*".toMediaTypeOrNull()) | ||
MultipartBody.Part.createFormData("profileImage", it.name, requestFile) | ||
} | ||
|
||
// TODO FCM token | ||
val signUpRequest = userType.toSignUpRequest( | ||
socialId = socialId, | ||
socialType = socialType, | ||
email = email, | ||
fcmToken = "EMPTY", | ||
) | ||
val requestBody = signUpRequest.toRequestBody(Json) | ||
|
||
val response = signupRemoteDataSource.postSignUp( | ||
profileImage = profileImagePart, | ||
request = requestBody, | ||
) | ||
|
||
sessionLocalDataSource.updateSessionId(response.sessionId) | ||
|
||
return response.toDomain() | ||
} | ||
|
||
private fun SignUpRequest.toRequestBody(json: Json): RequestBody { | ||
val jsonString = json.encodeToString(this) | ||
return jsonString.toRequestBody("application/json".toMediaTypeOrNull()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package co.kr.tnt.domain.model | ||
|
||
data class SignUpResult( | ||
val memberType: String, | ||
val sessionId: String, | ||
val name: String, | ||
val profileImageUrl: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
package co.kr.tnt.domain.model | ||
|
||
import java.time.LocalDate | ||
|
||
sealed class UserType { | ||
abstract val id: String | ||
abstract val name: String | ||
abstract val image: String? | ||
|
||
data class Trainer( | ||
override val id: String = "", | ||
override val name: String = "", | ||
override val image: String? = null, | ||
override val id: String, | ||
override val name: String, | ||
override val image: String?, | ||
) : UserType() | ||
|
||
data class Trainee( | ||
override val id: String = "", | ||
override val name: String = "", | ||
override val image: String? = null, | ||
val age: Int = 0, | ||
val weight: Float = 0f, | ||
val height: Int = 0, | ||
val ptPurpose: List<String> = emptyList(), | ||
val caution: String? = null, | ||
override val id: String, | ||
override val name: String, | ||
override val image: String?, | ||
val birthday: LocalDate?, | ||
val age: Int?, | ||
val weight: Double, | ||
val height: Int, | ||
val ptPurpose: List<String>, | ||
val caution: String?, | ||
) : UserType() | ||
} |
15 changes: 15 additions & 0 deletions
15
domain/src/main/java/co/kr/tnt/domain/repository/SignUpRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package co.kr.tnt.domain.repository | ||
|
||
import co.kr.tnt.domain.model.SignUpResult | ||
import co.kr.tnt.domain.model.UserType | ||
import java.io.File | ||
|
||
interface SignUpRepository { | ||
suspend fun signUp( | ||
profileImage: File?, | ||
userType: UserType, | ||
socialId: String, | ||
socialType: String, | ||
email: String, | ||
): SignUpResult | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
과 같은 형태가 맞는 것 같아요!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵..! 다시 수정해보겠습니다
There was a problem hiding this comment.
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
을 구현하는건 안 될까요?😨There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
얽 이거
Request
인데 제가 놓쳤네요 '-' ;;혼동드려서 죄송합니다 ㅜㅜ
수정해주신대로 진행해도 될 것 같습니다ㅠㅠㅠ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그럼 지금 코드대로 머지하겠습니다!!