-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] #15 : 사용자 등록 / 사용자 조회 로직 구현
- Loading branch information
1 parent
f52cc77
commit 0583a20
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
core/data/src/main/java/com/wap/wapp/core/data/repository/user/UserRepository.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,14 @@ | ||
package com.wap.wapp.core.data.repository.user | ||
|
||
import com.wap.wapp.core.model.user.UserProfile | ||
|
||
interface UserRepository { | ||
suspend fun getUserProfile(userId: String): Result<UserProfile> | ||
|
||
suspend fun postUserProfile( | ||
userId: String, | ||
userName: String, | ||
studentId: String, | ||
registeredAt: String, | ||
): Result<Unit> | ||
} |
32 changes: 32 additions & 0 deletions
32
core/data/src/main/java/com/wap/wapp/core/data/repository/user/UserRepositoryImpl.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,32 @@ | ||
package com.wap.wapp.core.data.repository.user | ||
|
||
import com.wap.wapp.core.model.user.UserProfile | ||
import com.wap.wapp.core.network.model.user.UserProfileRequest | ||
import com.wap.wapp.core.network.source.user.UserDataSource | ||
import javax.inject.Inject | ||
|
||
class UserRepositoryImpl @Inject constructor( | ||
private val userDataSource: UserDataSource, | ||
) : UserRepository { | ||
override suspend fun getUserProfile(userId: String): Result<UserProfile> { | ||
return userDataSource.getUserProfile(userId).mapCatching { response -> | ||
response.toDomain() | ||
} | ||
} | ||
|
||
override suspend fun postUserProfile( | ||
userId: String, | ||
userName: String, | ||
studentId: String, | ||
registeredAt: String, | ||
): Result<Unit> { | ||
return userDataSource.postUserProfile( | ||
UserProfileRequest( | ||
userId = userId, | ||
userName = userName, | ||
studentId = studentId, | ||
registeredAt = registeredAt, | ||
), | ||
) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
core/network/src/main/java/com/wap/wapp/core/network/source/user/UserDataSource.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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package com.wap.wapp.core.network.source.user | ||
|
||
import com.wap.wapp.core.network.model.user.UserProfileRequest | ||
import com.wap.wapp.core.network.model.user.UserProfileResponse | ||
|
||
interface UserDataSource { | ||
suspend fun postUserProfile(userProfileRequest: UserProfileRequest): Result<Unit> | ||
|
||
suspend fun getUserProfile(userId: String): Result<UserProfileResponse> | ||
} |
43 changes: 42 additions & 1 deletion
43
core/network/src/main/java/com/wap/wapp/core/network/source/user/UserDataSourceImpl.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 |
---|---|---|
@@ -1,3 +1,44 @@ | ||
package com.wap.wapp.core.network.source.user | ||
|
||
class UserDataSourceImpl | ||
import com.google.firebase.firestore.FirebaseFirestore | ||
import com.google.firebase.firestore.SetOptions | ||
import com.wap.wapp.core.network.constant.USER_COLLECTION | ||
import com.wap.wapp.core.network.model.user.UserProfileRequest | ||
import com.wap.wapp.core.network.model.user.UserProfileResponse | ||
import com.wap.wapp.core.network.utils.await | ||
import javax.inject.Inject | ||
|
||
class UserDataSourceImpl @Inject constructor( | ||
private val firebaseFirestore: FirebaseFirestore, | ||
) : UserDataSource { | ||
override suspend fun postUserProfile( | ||
userProfileRequest: UserProfileRequest, | ||
): Result<Unit> { | ||
return runCatching { | ||
val userId = userProfileRequest.userId | ||
val setOption = SetOptions.merge() | ||
|
||
firebaseFirestore.collection(USER_COLLECTION) | ||
.document(userId) | ||
.set( | ||
userProfileRequest, | ||
setOption, | ||
) | ||
.await() | ||
} | ||
} | ||
|
||
override suspend fun getUserProfile( | ||
userId: String, | ||
): Result<UserProfileResponse> { | ||
return runCatching { | ||
val result = firebaseFirestore.collection(USER_COLLECTION) | ||
.document(userId) | ||
.get() | ||
.await() | ||
|
||
val userProfile = result.toObject(UserProfileResponse::class.java) | ||
checkNotNull(userProfile) | ||
} | ||
} | ||
} |