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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sampoom.android.feature.dashboard.data.mapper

import com.sampoom.android.feature.dashboard.data.remote.dto.DashboardResponseDto
import com.sampoom.android.feature.dashboard.data.remote.dto.WeeklySummaryResponseDto
import com.sampoom.android.feature.dashboard.domain.model.Dashboard
import com.sampoom.android.feature.dashboard.domain.model.WeeklySummary

fun DashboardResponseDto.toModel(): Dashboard = Dashboard(totalParts, outOfStockParts, lowStockParts, totalQuantity)
fun WeeklySummaryResponseDto.toModel(): WeeklySummary = WeeklySummary(inStockParts, outStockParts, weekPeriod)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sampoom.android.feature.dashboard.data.remote.api

import com.sampoom.android.core.model.ApiResponse
import com.sampoom.android.feature.dashboard.data.remote.dto.DashboardResponseDto
import com.sampoom.android.feature.dashboard.data.remote.dto.WeeklySummaryResponseDto
import retrofit2.http.GET
import retrofit2.http.Path

interface DashboardApi {
// 대시보드 조회
@GET("agency/{agencyId}/dashboard")
suspend fun getDashboard(@Path("agencyId") agencyId: Long): ApiResponse<DashboardResponseDto>

// 주간 히스토리 조회
@GET("agency/{agencyId}/weekly-summary")
suspend fun getWeeklySummary(@Path("agencyId") agencyId: Long): ApiResponse<WeeklySummaryResponseDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sampoom.android.feature.dashboard.data.remote.dto

data class DashboardResponseDto(
val totalParts: Long,
val outOfStockParts: Long,
val lowStockParts: Long,
val totalQuantity: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sampoom.android.feature.dashboard.data.remote.dto

data class WeeklySummaryResponseDto(
val inStockParts: Long,
val outStockParts: Long,
val weekPeriod: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sampoom.android.feature.dashboard.data.repository

import com.sampoom.android.core.preferences.AuthPreferences
import com.sampoom.android.feature.dashboard.data.mapper.toModel
import com.sampoom.android.feature.dashboard.data.remote.api.DashboardApi
import com.sampoom.android.feature.dashboard.domain.model.Dashboard
import com.sampoom.android.feature.dashboard.domain.model.WeeklySummary
import com.sampoom.android.feature.dashboard.domain.repository.DashboardRepository
import javax.inject.Inject

class DashboardRepositoryImpl @Inject constructor(
private val api: DashboardApi,
private val authPreferences: AuthPreferences
) : DashboardRepository {
override suspend fun getDashboard(): Result<Dashboard> {
return runCatching {
val agencyId = authPreferences.getStoredUser()?.agencyId ?: throw Exception()
val dto = api.getDashboard(agencyId)
dto.data.toModel()
}
}

override suspend fun getWeeklySummary(): Result<WeeklySummary> {
return runCatching {
val agencyId = authPreferences.getStoredUser()?.agencyId ?: throw Exception()
val dto = api.getWeeklySummary(agencyId)
dto.data.toModel()
}
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.sampoom.android.feature.dashboard.di

import com.sampoom.android.feature.dashboard.data.remote.api.DashboardApi
import com.sampoom.android.feature.dashboard.data.repository.DashboardRepositoryImpl
import com.sampoom.android.feature.dashboard.domain.repository.DashboardRepository
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class DashboardBinModule {
@Binds @Singleton
abstract fun bindDashboardRepository(impl: DashboardRepositoryImpl): DashboardRepository
}

@Module
@InstallIn(SingletonComponent::class)
object DashboardModule {
@Provides @Singleton
fun provideDashboardApi(retrofit: Retrofit): DashboardApi = retrofit.create(DashboardApi::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sampoom.android.feature.dashboard.domain.model

data class Dashboard(
val totalParts: Long,
val outOfStockParts: Long,
val lowStockParts: Long,
val totalQuantity: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sampoom.android.feature.dashboard.domain.model

data class WeeklySummary(
val inStockParts: Long,
val outStockParts: Long,
val weekPeriod: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sampoom.android.feature.dashboard.domain.repository

import com.sampoom.android.feature.dashboard.domain.model.Dashboard
import com.sampoom.android.feature.dashboard.domain.model.WeeklySummary

interface DashboardRepository {
suspend fun getDashboard(): Result<Dashboard>
suspend fun getWeeklySummary(): Result<WeeklySummary>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sampoom.android.feature.dashboard.domain.usecase

import com.sampoom.android.feature.dashboard.domain.model.Dashboard
import com.sampoom.android.feature.dashboard.domain.repository.DashboardRepository
import javax.inject.Inject

class GetDashboardUseCase @Inject constructor(
private val repository: DashboardRepository
) {
suspend operator fun invoke(): Result<Dashboard> = repository.getDashboard()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sampoom.android.feature.dashboard.domain.usecase

import com.sampoom.android.feature.dashboard.domain.model.WeeklySummary
import com.sampoom.android.feature.dashboard.domain.repository.DashboardRepository
import javax.inject.Inject

class WeeklySummaryUseCase @Inject constructor(
private val repository: DashboardRepository
) {
suspend operator fun invoke(): Result<WeeklySummary> = repository.getWeeklySummary()
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ import com.sampoom.android.R
import com.sampoom.android.core.model.UserPosition
import com.sampoom.android.core.ui.component.EmptyContent
import com.sampoom.android.core.ui.component.ErrorContent
import com.sampoom.android.feature.order.ui.OrderItem
import com.sampoom.android.core.ui.theme.FailRed
import com.sampoom.android.core.ui.theme.Main500
import com.sampoom.android.core.ui.theme.SuccessGreen
import com.sampoom.android.core.ui.theme.backgroundCardColor
import com.sampoom.android.core.ui.theme.textColor
import com.sampoom.android.core.ui.theme.textSecondaryColor
import com.sampoom.android.feature.auth.domain.model.User
import com.sampoom.android.feature.dashboard.domain.model.Dashboard
import com.sampoom.android.feature.dashboard.domain.model.WeeklySummary
import com.sampoom.android.feature.order.domain.model.Order
import com.sampoom.android.feature.order.ui.OrderItem

@Composable
fun DashboardScreen(
Expand Down Expand Up @@ -159,11 +163,10 @@ fun DashboardScreen(
) {
item { TitleSection(user) }

item { ButtonSection(isManager) }
item { ButtonSection(isManager, uiState.dashboard) }

item {
OrderListSection(
viewModel = viewModel,
orderListPaged = orderListPaged,
onNavigateOrderDetail = { order ->
onNavigateOrderDetail(order)
Expand All @@ -174,6 +177,12 @@ fun DashboardScreen(
)
}

item { Spacer(Modifier.height(32.dp)) }

item {
WeeklySummarySection(modifier = Modifier, weeklySummary = uiState.weeklySummary)
}

item { Spacer(Modifier.height(100.dp)) }
}
}
Expand Down Expand Up @@ -225,7 +234,8 @@ fun TitleSection(

@Composable
fun ButtonSection(
isManager: Boolean
isManager: Boolean,
dashboard: Dashboard?
) {
Column(
modifier = Modifier
Expand All @@ -248,48 +258,48 @@ fun ButtonSection(
)
}

// 보유 부품, 진행중 주문
// 부품, 품절 부품
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
ButtonCard(
modifier = Modifier.weight(1f),
painter = painterResource(R.drawable.parts),
painterDescription = stringResource(R.string.dashboard_parts_on_hand),
text = 1234.toString(), // TODO : API 연동
subText = stringResource(R.string.dashboard_parts_on_hand),
painter = painterResource(R.drawable.car),
painterDescription = stringResource(R.string.dashboard_parts_all),
text = (dashboard?.totalParts ?: stringResource(R.string.common_slash)).toString(),
subText = stringResource(R.string.dashboard_parts_all),
onClick = { }
)

ButtonCard(
modifier = Modifier.weight(1f),
painter = painterResource(R.drawable.orders),
painterDescription = stringResource(R.string.dashboard_parts_in_progress),
text = 23.toString(), // TODO : API 연동
subText = stringResource(R.string.dashboard_parts_in_progress),
painter = painterResource(R.drawable.block),
painterDescription = stringResource(R.string.dashboard_parts_out_of_stock),
text = (dashboard?.outOfStockParts ?: stringResource(R.string.common_slash)).toString(),
subText = stringResource(R.string.dashboard_parts_out_of_stock),
onClick = { }
)
}

// 부족 부품, 주문 금액
// 부족 부품, 보유 부품
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
ButtonCard(
modifier = Modifier.weight(1f),
painter = painterResource(R.drawable.warning),
painterDescription = stringResource(R.string.dashboard_shortage_of_parts),
text = 19.toString(), // TODO : API 연동
subText = stringResource(R.string.dashboard_shortage_of_parts),
painterDescription = stringResource(R.string.dashboard_parts_low_stock),
text = (dashboard?.lowStockParts ?: stringResource(R.string.common_slash)).toString(),
subText = stringResource(R.string.dashboard_parts_low_stock),
onClick = { }
)

ButtonCard(
modifier = Modifier.weight(1f),
painter = painterResource(R.drawable.money),
painterDescription = stringResource(R.string.dashboard_order_amount),
text = 4123200.toString(), // TODO : API 연동
subText = stringResource(R.string.dashboard_order_amount),
painter = painterResource(R.drawable.parts),
painterDescription = stringResource(R.string.dashboard_parts_on_hand),
text = (dashboard?.totalQuantity ?: stringResource(R.string.common_slash)).toString(),
subText = stringResource(R.string.dashboard_parts_on_hand),
onClick = { }
)
}
Expand Down Expand Up @@ -349,12 +359,10 @@ fun ButtonCard(

@Composable
fun OrderListSection(
viewModel: DashboardViewModel,
orderListPaged: LazyPagingItems<Order>,
onNavigateOrderDetail: (Order) -> Unit,
onNavigationOrder: () -> Unit
) {

Column(
modifier = Modifier.fillMaxWidth()
) {
Expand Down Expand Up @@ -441,4 +449,71 @@ fun OrderListSection(
}
}
}
}

@Composable
fun WeeklySummarySection(
modifier: Modifier,
weeklySummary: WeeklySummary?
) {
Card(
modifier = modifier
.fillMaxWidth(),
colors = CardDefaults.cardColors(
containerColor = backgroundCardColor()
),
onClick = { },
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
) {
Text(
text = stringResource(R.string.dashboard_weekly_summary_title),
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold,
color = textColor()
)

Row(
modifier = Modifier.fillMaxWidth()
) {
Column(
modifier = Modifier.weight(1f),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = (weeklySummary?.inStockParts ?: stringResource(R.string.common_slash)).toString(),
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold,
color = SuccessGreen
)
Text(
text = stringResource(R.string.dashboard_weekly_summary_in_stock),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.Light,
color = textSecondaryColor()
)
}
Column(
modifier = Modifier.weight(1f),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = (weeklySummary?.outStockParts ?: stringResource(R.string.common_slash)).toString(),
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold,
color = FailRed
)
Text(
text = stringResource(R.string.dashboard_weekly_summary_out_stock),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.Light,
color = textSecondaryColor()
)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.sampoom.android.feature.dashboard.ui

import com.sampoom.android.feature.dashboard.domain.model.Dashboard
import com.sampoom.android.feature.dashboard.domain.model.WeeklySummary
import com.sampoom.android.feature.order.domain.model.Order

data class DashboardUiState(
val orderList: List<Order> = emptyList(),
val dashboard: Dashboard? = null,
val weeklySummary: WeeklySummary? = null,
val dashboardLoading: Boolean = false,
val dashboardError: String? = null,
val weeklySummaryLoading: Boolean = false,
val weeklySummaryError: String? = null,
)
Loading