-
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.
Merge pull request #94 from YAPP-Github/feature/MZ-129-my-statistics
Feature/mz 129 my statistics
- Loading branch information
Showing
26 changed files
with
978 additions
and
20 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
core/model/src/main/java/com/susu/core/model/MyStatistics.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 com.susu.core.model | ||
|
||
import androidx.compose.runtime.Stable | ||
|
||
@Stable | ||
data class MyStatistics( | ||
val highestAmountReceived: StatisticsElement = StatisticsElement(), | ||
val highestAmountSent: StatisticsElement = StatisticsElement(), | ||
val mostCategory: StatisticsElement = StatisticsElement(), | ||
val mostRelationship: StatisticsElement = StatisticsElement(), | ||
val mostSpentMonth: Int = 0, | ||
val recentSpent: List<StatisticsElement> = emptyList(), | ||
val recentTotalSpent: Int = 0, | ||
val recentMaximumSpent: Int = 0, | ||
) |
9 changes: 9 additions & 0 deletions
9
core/model/src/main/java/com/susu/core/model/StatisticsElement.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,9 @@ | ||
package com.susu.core.model | ||
|
||
import androidx.compose.runtime.Stable | ||
|
||
@Stable | ||
data class StatisticsElement( | ||
val title: String = "", | ||
val value: Int = 0, | ||
) |
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
29 changes: 29 additions & 0 deletions
29
data/src/main/java/com/susu/data/data/repository/StatisticsRepositoryImpl.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,29 @@ | ||
package com.susu.data.data.repository | ||
|
||
import com.susu.core.model.MyStatistics | ||
import com.susu.core.model.StatisticsElement | ||
import com.susu.data.remote.api.StatisticsService | ||
import com.susu.data.remote.model.response.toModel | ||
import com.susu.domain.repository.StatisticsRepository | ||
import javax.inject.Inject | ||
|
||
class StatisticsRepositoryImpl @Inject constructor( | ||
private val statisticsService: StatisticsService, | ||
) : StatisticsRepository { | ||
override suspend fun getMyStatistics(): MyStatistics { | ||
val originalStatistic = statisticsService.getMyStatistics().getOrThrow().toModel() | ||
val sortedRecentSpent = originalStatistic.recentSpent.sortedBy { it.title.toInt() } | ||
.map { StatisticsElement(title = it.title.substring(it.title.length - 2).toInt().toString(), value = it.value) } | ||
|
||
return MyStatistics( | ||
highestAmountReceived = originalStatistic.highestAmountReceived, | ||
highestAmountSent = originalStatistic.highestAmountSent, | ||
mostCategory = originalStatistic.mostCategory, | ||
mostRelationship = originalStatistic.mostRelationship, | ||
mostSpentMonth = originalStatistic.mostSpentMonth % 100, | ||
recentSpent = sortedRecentSpent, | ||
recentTotalSpent = originalStatistic.recentTotalSpent, | ||
recentMaximumSpent = originalStatistic.recentMaximumSpent, | ||
) | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
data/src/main/java/com/susu/data/remote/api/StatisticsService.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,10 @@ | ||
package com.susu.data.remote.api | ||
|
||
import com.susu.data.remote.model.response.MyStatisticsResponse | ||
import com.susu.data.remote.retrofit.ApiResult | ||
import retrofit2.http.GET | ||
|
||
interface StatisticsService { | ||
@GET("statistics/mine") | ||
suspend fun getMyStatistics(): ApiResult<MyStatisticsResponse> | ||
} |
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
36 changes: 36 additions & 0 deletions
36
data/src/main/java/com/susu/data/remote/model/response/MyStatisticsResponse.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,36 @@ | ||
package com.susu.data.remote.model.response | ||
|
||
import com.susu.core.model.MyStatistics | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class MyStatisticsResponse( | ||
val highestAmountReceived: StatisticsElement, | ||
val highestAmountSent: StatisticsElement, | ||
val mostCategory: StatisticsElement, | ||
val mostRelationship: StatisticsElement, | ||
val mostSpentMonth: Int, | ||
val recentSpent: List<StatisticsElement>, | ||
) | ||
|
||
@Serializable | ||
data class StatisticsElement( | ||
val title: String, | ||
val value: Int, | ||
) | ||
|
||
fun MyStatisticsResponse.toModel() = MyStatistics( | ||
highestAmountReceived = highestAmountReceived.toModel(), | ||
highestAmountSent = highestAmountSent.toModel(), | ||
mostCategory = mostCategory.toModel(), | ||
mostRelationship = mostRelationship.toModel(), | ||
mostSpentMonth = mostSpentMonth, | ||
recentSpent = recentSpent.map { it.toModel() }, | ||
recentMaximumSpent = recentSpent.maxOfOrNull { it.value } ?: 0, | ||
recentTotalSpent = recentSpent.sumOf { it.value }, | ||
) | ||
|
||
fun StatisticsElement.toModel() = com.susu.core.model.StatisticsElement( | ||
title = title, | ||
value = value, | ||
) |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/com/susu/domain/repository/StatisticsRepository.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,7 @@ | ||
package com.susu.domain.repository | ||
|
||
import com.susu.core.model.MyStatistics | ||
|
||
interface StatisticsRepository { | ||
suspend fun getMyStatistics(): MyStatistics | ||
} |
14 changes: 14 additions & 0 deletions
14
domain/src/main/java/com/susu/domain/usecase/statistics/CheckAdditionalUserInfoUseCase.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.susu.domain.usecase.statistics | ||
|
||
import com.susu.core.common.runCatchingIgnoreCancelled | ||
import com.susu.domain.repository.UserRepository | ||
import javax.inject.Inject | ||
|
||
class CheckAdditionalUserInfoUseCase @Inject constructor( | ||
private val userRepository: UserRepository, | ||
) { | ||
suspend operator fun invoke() = runCatchingIgnoreCancelled { | ||
val userInfo = userRepository.getUserInfo() | ||
userInfo.birth in 1930..2030 && (userInfo.gender == "M" || userInfo.gender == "F") | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
domain/src/main/java/com/susu/domain/usecase/statistics/GetMyStatisticsUseCase.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,13 @@ | ||
package com.susu.domain.usecase.statistics | ||
|
||
import com.susu.core.common.runCatchingIgnoreCancelled | ||
import com.susu.domain.repository.StatisticsRepository | ||
import javax.inject.Inject | ||
|
||
class GetMyStatisticsUseCase @Inject constructor( | ||
private val statisticsRepository: StatisticsRepository, | ||
) { | ||
suspend operator fun invoke() = runCatchingIgnoreCancelled { | ||
statisticsRepository.getMyStatistics() | ||
} | ||
} |
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
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
21 changes: 21 additions & 0 deletions
21
feature/statistics/src/main/java/com/susu/feature/statistics/StatisticsContract.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 com.susu.feature.statistics | ||
|
||
import androidx.annotation.StringRes | ||
import com.susu.core.ui.base.SideEffect | ||
import com.susu.core.ui.base.UiState | ||
|
||
enum class StatisticsTab(@StringRes val stringId: Int) { | ||
MY(R.string.statistics_tab_my), | ||
AVERAGE(R.string.statistics_tab_average), | ||
} | ||
|
||
data class StatisticsState( | ||
val isLoading: Boolean = false, | ||
val isBlind: Boolean = true, | ||
val currentTab: StatisticsTab = StatisticsTab.MY, | ||
) : UiState | ||
|
||
sealed interface StatisticsEffect : SideEffect { | ||
data object ShowAdditionalInfoDialog : StatisticsEffect | ||
data class HandleException(val throwable: Throwable, val retry: () -> Unit) : StatisticsEffect | ||
} |
Oops, something went wrong.