Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sampoom.android.core.util

import java.text.NumberFormat
import java.util.Locale

fun formatWon(value: Long): String =
NumberFormat.getInstance(Locale.KOREA).format(value) + "원"
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.sampoom.android.feature.auth.data.mapper

import com.sampoom.android.core.model.UserPosition
import com.sampoom.android.feature.auth.data.remote.dto.GetProfileResponseDto
import com.sampoom.android.feature.auth.data.remote.dto.GetVendorsResponseDto
import com.sampoom.android.feature.auth.data.remote.dto.LoginResponseDto
import com.sampoom.android.feature.auth.domain.model.User
import com.sampoom.android.feature.auth.domain.model.Vendor

fun LoginResponseDto.toModel(): User = User(
userId = userId,
Expand Down Expand Up @@ -37,15 +39,18 @@ fun GetProfileResponseDto.toModel(): User = User(
endedAt = endedAt
)

fun User.mergeWith(profile: User): User = this.copy(
userName = profile.userName,
position = profile.position,
workspace = profile.workspace,
branch = profile.branch
)

private fun String.toUserPosition(): UserPosition = try {
UserPosition.valueOf(this.uppercase())
} catch (_: IllegalArgumentException) {
UserPosition.STAFF
}
}

fun GetVendorsResponseDto.toModel(): Vendor = Vendor(
id = id,
vendorCode = vendorCode,
name = name,
businessNumber = businessNumber,
ceoName = ceoName,
address = address,
status = status
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.sampoom.android.feature.auth.data.remote.dto.RefreshResponseDto
import com.sampoom.android.feature.auth.data.remote.dto.UpdateProfileRequestDto
import com.sampoom.android.feature.auth.data.remote.dto.UpdateProfileResponseDto
import com.sampoom.android.feature.auth.data.remote.dto.GetProfileResponseDto
import com.sampoom.android.feature.auth.data.remote.dto.GetVendorsResponseDto
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Headers
Expand Down Expand Up @@ -38,4 +39,7 @@ interface AuthApi {

@PATCH("user/profile")
suspend fun updateProfile(@Body body: UpdateProfileRequestDto): ApiResponse<UpdateProfileResponseDto>

@GET("site/vendors")
suspend fun getVendors(): ApiResponse<List<GetVendorsResponseDto>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sampoom.android.feature.auth.data.remote.dto

data class GetVendorsResponseDto(
val id: Long,
val vendorCode: String,
val name: String,
val businessNumber: String,
val ceoName: String,
val address: String,
val status: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import com.sampoom.android.feature.auth.data.remote.dto.LoginRequestDto
import com.sampoom.android.feature.auth.data.remote.dto.RefreshRequestDto
import com.sampoom.android.feature.auth.data.remote.dto.SignUpRequestDto
import com.sampoom.android.feature.auth.domain.model.User
import com.sampoom.android.feature.auth.domain.model.VendorList
import com.sampoom.android.feature.auth.domain.repository.AuthRepository
import com.sampoom.android.feature.outbound.data.mapper.toModel
import kotlinx.coroutines.delay
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
Expand Down Expand Up @@ -36,7 +39,11 @@ class AuthRepositoryImpl @Inject constructor(
)
)
if (!signUpRes.success) throw Exception(signUpRes.message)
signIn(email, password).getOrThrow()

delay(500)
retry(times = 5, initialDelay = 500) {
signIn(email, password).getOrThrow()
}
}
}

Expand Down Expand Up @@ -126,4 +133,13 @@ class AuthRepositoryImpl @Inject constructor(
dto.data.toModel()
}
}

override suspend fun getVendorList(): Result<VendorList> {
return runCatching {
val dto = api.getVendors()
if (!dto.success) throw Exception(dto.message)
val vendorItems = dto.data.map { it.toModel() }
VendorList(items = vendorItems)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sampoom.android.feature.auth.domain.model

data class Vendor(
val id: Long,
val vendorCode: String,
val name: String,
val businessNumber: String,
val ceoName: String,
val address: String,
val status: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sampoom.android.feature.auth.domain.model

data class VendorList(
val items: List<Vendor>,
val totalCount: Int = items.size,
val isEmpty: Boolean = items.isEmpty()
) {
companion object Companion {
fun empty() = VendorList(emptyList())
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sampoom.android.feature.auth.domain.repository

import com.sampoom.android.feature.auth.domain.model.User
import com.sampoom.android.feature.auth.domain.model.VendorList

interface AuthRepository {
suspend fun signUp(
Expand All @@ -18,4 +19,5 @@ interface AuthRepository {
suspend fun clearTokens(): Result<Unit>
suspend fun isSignedIn(): Boolean
suspend fun getProfile(workspace: String): Result<User>
suspend fun getVendorList(): Result<VendorList>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sampoom.android.feature.auth.domain.usecase

import com.sampoom.android.feature.auth.domain.model.VendorList
import com.sampoom.android.feature.auth.domain.repository.AuthRepository
import javax.inject.Inject

class GetVendorUseCase @Inject constructor(
private val repository: AuthRepository
) {
suspend operator fun invoke(): Result<VendorList> = repository.getVendorList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fun SignUpScreen(

val positionItems = remember { UserPosition.entries }
var positionMenuExpanded by remember { mutableStateOf(false) }
var vendorMenuExpanded by remember { mutableStateOf(false) }

Scaffold(
topBar = {
Expand Down Expand Up @@ -144,16 +145,50 @@ fun SignUpScreen(
text = stringResource(R.string.signup_title_branch),
fontSize = labelTextSize
)
CommonTextField(
modifier = Modifier.fillMaxWidth().focusRequester(branchFocus),
value = state.branch,
onValueChange = { viewModel.onEvent(SignUpUiEvent.BranchChanged(it)) },
placeholder = stringResource(R.string.signup_placeholder_branch),
isError = state.branchError != null,
errorMessage = state.branchError,
imeAction = ImeAction.Next,
keyboardActions = KeyboardActions(onNext = { positionFocus.requestFocus() })
)
ExposedDropdownMenuBox(
expanded = vendorMenuExpanded,
onExpandedChange = { vendorMenuExpanded = it && !state.vendorsLoading }
) {
CommonTextField(
modifier = Modifier
.menuAnchor(
type = ExposedDropdownMenuAnchorType.PrimaryNotEditable,
enabled = true
)
.fillMaxWidth()
.focusRequester(branchFocus),
readOnly = true,
value = state.selectedVendor?.name ?: "",
onValueChange = {},
placeholder = stringResource(R.string.signup_placeholder_branch),
isError = state.branchError != null,
errorMessage = state.branchError,
singleLine = true,
enabled = !state.vendorsLoading
)
ExposedDropdownMenu(
expanded = vendorMenuExpanded,
onDismissRequest = { vendorMenuExpanded = false }
) {
if (state.vendorsLoading) {
DropdownMenuItem(
text = { Text("로딩 중...") },
onClick = {}
)
} else {
state.vendors.forEach { vendor ->
DropdownMenuItem(
text = { Text(vendor.name) },
onClick = {
viewModel.onEvent(SignUpUiEvent.VendorChanged(vendor))
vendorMenuExpanded = false
positionFocus.requestFocus()
}
)
}
}
}
}
Spacer(Modifier.height(8.dp))
Text(
text = stringResource(R.string.signup_title_position),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.sampoom.android.feature.auth.ui

import com.sampoom.android.core.model.UserPosition
import com.sampoom.android.feature.auth.domain.model.Vendor

sealed interface SignUpUiEvent {
data class NameChanged(val name: String) : SignUpUiEvent
data class BranchChanged(val branch: String) : SignUpUiEvent
// data class BranchChanged(val branch: String) : SignUpUiEvent
data class VendorChanged(val vendor: Vendor) : SignUpUiEvent
data class PositionChanged(val position: UserPosition) : SignUpUiEvent
data class EmailChanged(val email: String) : SignUpUiEvent
data class PasswordChanged(val password: String) : SignUpUiEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sampoom.android.feature.auth.ui

import com.sampoom.android.core.model.UserPosition
import com.sampoom.android.feature.auth.domain.model.Vendor

data class SignUpUiState(
val name: String = "",
Expand All @@ -11,6 +12,11 @@ data class SignUpUiState(
val password: String = "",
val passwordCheck: String = "",

// Vendor
val vendors: List<Vendor> = emptyList(),
val selectedVendor: Vendor? = null,
val vendorsLoading: Boolean = false,

// Error message
val nameError: String? = null,
val branchError: String? = null,
Expand Down
Loading