Skip to content

Commit

Permalink
Merge pull request #304 from Nexters/feature/Boolti-301
Browse files Browse the repository at this point in the history
Feature/boolti 301 타인의 프로필 구현
  • Loading branch information
mangbaam authored Oct 8, 2024
2 parents 3f85a7a + 13ff6d7 commit 85c2587
Show file tree
Hide file tree
Showing 25 changed files with 241 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nexters.boolti.data.datasource

import com.nexters.boolti.data.network.api.MemberService
import com.nexters.boolti.data.network.response.MemberResponse
import javax.inject.Inject

internal class MemberDataSource @Inject constructor(
private val memberService: MemberService,
) {
suspend fun getMember(userCode: String): MemberResponse = memberService.getMember(userCode)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.nexters.boolti.data.network.api.FileService
import com.nexters.boolti.data.network.api.GiftService
import com.nexters.boolti.data.network.api.HostService
import com.nexters.boolti.data.network.api.LoginService
import com.nexters.boolti.data.network.api.MemberService
import com.nexters.boolti.data.network.api.ReservationService
import com.nexters.boolti.data.network.api.ShowService
import com.nexters.boolti.data.network.api.SignUpService
Expand Down Expand Up @@ -139,6 +140,10 @@ internal object NetworkModule {
@Provides
fun provideFileService(@Named("non-auth") retrofit: Retrofit): FileService = retrofit.create()

@Singleton
@Provides
fun provideMemberService(@Named("non-auth") retrofit: Retrofit): MemberService = retrofit.create()

@Singleton
@Provides
@Named("auth")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.nexters.boolti.data.repository.ConfigRepositoryImpl
import com.nexters.boolti.data.repository.FileRepositoryImpl
import com.nexters.boolti.data.repository.GiftRepositoryImpl
import com.nexters.boolti.data.repository.HostRepositoryImpl
import com.nexters.boolti.data.repository.MemberRepositoryImpl
import com.nexters.boolti.data.repository.ReservationRepositoryImpl
import com.nexters.boolti.data.repository.ShowRepositoryImpl
import com.nexters.boolti.data.repository.TicketRepositoryImpl
Expand All @@ -14,6 +15,7 @@ import com.nexters.boolti.domain.repository.ConfigRepository
import com.nexters.boolti.domain.repository.FileRepository
import com.nexters.boolti.domain.repository.GiftRepository
import com.nexters.boolti.domain.repository.HostRepository
import com.nexters.boolti.domain.repository.MemberRepository
import com.nexters.boolti.domain.repository.ReservationRepository
import com.nexters.boolti.domain.repository.ShowRepository
import com.nexters.boolti.domain.repository.TicketRepository
Expand Down Expand Up @@ -52,4 +54,7 @@ internal abstract class RepositoryModule {

@Binds
abstract fun bindFileRepository(repository: FileRepositoryImpl): FileRepository

@Binds
abstract fun bindMemberRepository(repository: MemberRepositoryImpl): MemberRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.nexters.boolti.data.network.api

import com.nexters.boolti.data.network.response.MemberResponse
import retrofit2.http.GET
import retrofit2.http.Path

internal interface MemberService {
@GET("/app/papi/v1/users/{userCode}")
suspend fun getMember(
@Path("userCode") userCode: String,
): MemberResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.nexters.boolti.data.network.response

import com.nexters.boolti.domain.model.User
import com.nexters.boolti.domain.request.EditProfileRequest
import kotlinx.serialization.Serializable

@Serializable
internal data class MemberResponse(
val nickname: String = "",
val userCode: String = "",
val imgPath: String = "",
val introduction: String = "",
val link: List<EditProfileRequest.LinkDto> = emptyList(),
) {
fun toDomain(): User.Others = User.Others(
nickname = nickname,
photo = imgPath,
userCode = userCode,
introduction = introduction,
link = link.map { it.toDomain() },
)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.nexters.boolti.data.network.response

import com.nexters.boolti.domain.model.Link
import com.nexters.boolti.domain.model.User
import com.nexters.boolti.domain.request.EditProfileRequest
import kotlinx.serialization.Serializable
import java.util.UUID

@Serializable
internal data class UserResponse(
Expand All @@ -16,15 +14,15 @@ internal data class UserResponse(
val introduction: String = "",
val link: List<EditProfileRequest.LinkDto> = emptyList(),
) {
fun toDomain(): User {
return User(
fun toDomain(): User.My {
return User.My(
id = id,
nickname = nickname ?: "",
email = email ?: "",
photo = imgPath,
userCode = userCode ?: "",
introduction = introduction,
link = link.map { Link(id = UUID.randomUUID().toString(), it.title, it.link) },
link = link.map { it.toDomain() },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class AuthRepositoryImpl @Inject constructor(
override val loggedIn: Flow<Boolean>
get() = authDataSource.loggedIn

override val cachedUser: Flow<User?>
override val cachedUser: Flow<User.My?>
get() = authDataSource.user.map { it?.toDomain() }

override suspend fun kakaoLogin(request: LoginRequest): Result<LoginUserState> {
Expand All @@ -55,7 +55,7 @@ internal class AuthRepositoryImpl @Inject constructor(
authDataSource.localLogout()
}

override fun getUserAndCache(): Flow<User?> = flow {
override fun getUserAndCache(): Flow<User.My?> = flow {
val response = userDateSource.getUser()
response?.let {
authDataSource.updateUser(it)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nexters.boolti.data.repository

import com.nexters.boolti.data.datasource.MemberDataSource
import com.nexters.boolti.domain.model.User
import com.nexters.boolti.domain.repository.MemberRepository
import javax.inject.Inject

internal class MemberRepositoryImpl @Inject constructor(
private val memberDataSource: MemberDataSource,
) : MemberRepository {
override suspend fun getMember(userCode: String): Result<User.Others> = runCatching {
memberDataSource.getMember(userCode).toDomain()
}
}
34 changes: 25 additions & 9 deletions domain/src/main/java/com/nexters/boolti/domain/model/User.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package com.nexters.boolti.domain.model

data class User(
val id: String,
val nickname: String = "",
val email: String = "",
val photo: String? = null,
val userCode: String = "",
val introduction: String = "",
val link: List<Link> = emptyList(),
)
sealed interface User {
val nickname: String
val photo: String?
val userCode: String
val introduction: String
val link: List<Link>

class My(
val id: String,
override val nickname: String = "",
val email: String = "",
override val photo: String? = null,
override val userCode: String = "",
override val introduction: String = "",
override val link: List<Link> = emptyList(),
) : User

class Others(
override val nickname: String = "",
override val photo: String? = null,
override val userCode: String = "",
override val introduction: String = "",
override val link: List<Link> = emptyList(),
) : User
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ interface AuthRepository {
suspend fun logout(): Result<Unit>
suspend fun signUp(signUpRequest: SignUpRequest): Result<Unit>
suspend fun signout(request: SignoutRequest): Result<Unit>
fun getUserAndCache(): Flow<User?>
fun getUserAndCache(): Flow<User.My?>
suspend fun sendFcmToken(): Result<Unit>

val loggedIn: Flow<Boolean>
val cachedUser: Flow<User?>
val cachedUser: Flow<User.My?>

suspend fun editProfile(editProfileRequest: EditProfileRequest): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.nexters.boolti.domain.repository

import com.nexters.boolti.domain.model.User

interface MemberRepository {
suspend fun getMember(userCode: String): Result<User.Others>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.nexters.boolti.domain.request

import com.nexters.boolti.domain.model.Link
import kotlinx.serialization.Serializable
import java.util.UUID

@Serializable
data class EditProfileRequest(
Expand All @@ -14,7 +15,9 @@ data class EditProfileRequest(
data class LinkDto(
val title: String,
val link: String,
)
) {
fun toDomain(): Link = Link(id = UUID.randomUUID().toString(), title, link)
}
}

fun Link.toDto(): EditProfileRequest.LinkDto = EditProfileRequest.LinkDto(name, url)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import javax.inject.Inject
class GetUserUsecase @Inject constructor(
private val authRepository: AuthRepository,
) {
operator fun invoke(): User? = runBlocking { authRepository.getUserAndCache().first() }
operator fun invoke(): User.My? = runBlocking { authRepository.getUserAndCache().first() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ sealed class MainDestination(val route: String) {
data object Login : MainDestination(route = "login")
data object Business : MainDestination(route = "business")
data object AccountSetting : MainDestination(route = "accountSetting")
data object Profile : MainDestination(route = "profile?id={$userId}") {
data object Profile : MainDestination(route = "profile?userCode={$userCode}") {
val arguments = listOf(
navArgument(userId) {
navArgument(userCode) {
type = NavType.StringType
nullable = true
},
)

fun createRoute(id: String? = null): String =
fun createRoute(userCode: String? = null): String =
StringBuilder("profile").apply {
id?.let { append("?id=$id") }
userCode?.let { append("?userCode=$it") }
}.toString()
}

Expand Down Expand Up @@ -137,7 +137,7 @@ const val reservationId = "reservationId"
const val salesTicketId = "salesTicketId"
const val ticketCount = "ticketCount"
const val isInviteTicket = "isInviteTicket"
const val userId = "userId"
const val userCode = "userCode"
const val linkId = "linkId"
const val linkTitle = "linkTitle"
const val url = "url"
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fun MyScreen(
@Composable
fun MyScreen(
modifier: Modifier = Modifier,
user: User? = null,
user: User.My? = null,
onClickHeaderButton: () -> Unit = {},
onClickAccountSetting: () -> Unit = {},
onClickReservations: () -> Unit = {},
Expand Down Expand Up @@ -176,7 +176,7 @@ fun MyScreen(
@Composable
private fun MyHeader(
modifier: Modifier = Modifier,
user: User? = null,
user: User.My? = null,
onClickButton: () -> Unit,
) {
val shape = RoundedCornerShape(
Expand Down Expand Up @@ -255,7 +255,7 @@ private fun MyMenu(
@Preview("로그인 한 유저 헤더")
@Composable
private fun MyHeaderUserPreview() {
val user = User(
val user = User.My(
id = "",
nickname = "일이삼사오육칠팔구십",
email = "[email protected]",
Expand All @@ -278,7 +278,7 @@ private fun MyHeaderGuestPreview() {
@Preview
@Composable
private fun MyScreenPreview() {
val user = User(
val user = User.My(
id = "",
nickname = "불티유저",
email = "[email protected]",
Expand All @@ -295,7 +295,7 @@ private fun MyScreenPreview() {
@Preview(device = "spec:parent=pixel_5,orientation=landscape")
@Composable
private fun MyScreenLandscapePreview() {
val user = User(
val user = User.My(
id = "",
nickname = "불티유저",
email = "[email protected]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import com.nexters.boolti.domain.model.User

sealed interface MyUiState {
data object Loading: MyUiState
data class Success(val user: User): MyUiState
data class Success(val user: User.My): MyUiState
data object Failure: MyUiState
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.nexters.boolti.presentation.screen.profile

sealed interface ProfileEvent {
data object Invalid : ProfileEvent
data object WithdrawUser : ProfileEvent
}
Loading

0 comments on commit 85c2587

Please sign in to comment.