Skip to content

Commit

Permalink
1) Fixed Dto and Models
Browse files Browse the repository at this point in the history
  • Loading branch information
MajoritySky2496 committed Jun 3, 2024
1 parent 8636865 commit fe50225
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data class ProfileAnalyticsResponse(
@SerialName("response_currency") val responseCurrency: String,
@SerialName("analytics") val userAnalyticsDto: UserAnalyticsDto
)

data class ProfileAnalyticsDto(
val statusCode: Int,
val message: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ProfileInfoRemoteDataSourceImpl @Inject constructor(
return try {
val response = profileInfoApiService.getUserInfoMore(accessToken = accessToken)
response
}catch (exception:NetworkException){
} catch (exception: NetworkException) {
throw networkToProfileExceptionMapper.handleExceptionGetMoreProfile(exception)
}
}
Expand All @@ -71,7 +71,7 @@ class ProfileInfoRemoteDataSourceImpl @Inject constructor(
return try {
val response = profileInfoApiService.getUserAnalytics(accessToken)
response
}catch (exception:NetworkException){
} catch (exception: NetworkException) {
throw networkToProfileExceptionMapper.handleExceptionAnalyticsProfile(exception)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import app.cashadvisor.profile.data.dto.UserInfoDto
import app.cashadvisor.profile.data.dto.request.UpdateProfilePicRequest
import app.cashadvisor.profile.data.dto.request.UpdateUserNameRequest
import app.cashadvisor.profile.data.mapper.ProfileAnalyticsDataMapper
import app.cashadvisor.profile.data.mapper.ProfileAnalyticsDomainMapper
import app.cashadvisor.profile.data.mapper.ProfileInfoMapper
import app.cashadvisor.profile.data.mapper.UserInfoMoreDomainMapper
import app.cashadvisor.profile.domain.api.ProfileInfoRepository
import app.cashadvisor.profile.domain.mapper.ProfileAnalyticsDomainMapper
import app.cashadvisor.profile.domain.mapper.UserInfoMoreDomainMapper
import app.cashadvisor.profile.domain.model.ProfileAnalytics
import app.cashadvisor.profile.domain.model.UserInfoMore
import app.cashadvisor.profile.domain.model.UserProfileInfo
Expand All @@ -32,17 +32,17 @@ class ProfileInfoRepositoryImpl @Inject constructor(
private val credentialsRepository: CredentialsRepository,
private val mapper: ProfileInfoMapper,
private val analyticsDataMapper: ProfileAnalyticsDataMapper,
private val userInfoMoreMapper:UserInfoMoreDomainMapper,
private val userInfoMoreMapper: UserInfoMoreDomainMapper,
private val profileAnalyticsDomainMapper: ProfileAnalyticsDomainMapper,
private val profileExceptionToErrorMapper: BaseExceptionToErrorMapper
) : ProfileInfoRepository {


private var userAnalytics:ProfileAnalytics? = null
private var userInfoMore:UserInfoMore? = null
private var userAnalytics: ProfileAnalytics? = null
private var userInfoMore: UserInfoMore? = null

private suspend fun getAccessToken(): String {
return credentialsRepository.getCredentials()?.accessToken ?: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZXZpY2VfaWQiOiI2MjFjOTc1OS05ZmY5LTRhNjUtYjI4Mi1hMmEwYmRkYjUxM2IiLCJleHAiOjE3MTczMTA0NjgsInN1YiI6Ijc2In0.enVexw46lCNoIHdu-wkaIbAUjuY4pdd-QszTDCBheGE"
return credentialsRepository.getCredentials()?.accessToken ?: ""
}

override suspend fun getUserInfo(): Resource<UserProfileInfo> {
Expand Down Expand Up @@ -116,10 +116,11 @@ class ProfileInfoRepositoryImpl @Inject constructor(

return try {
val response = userInfoMoreMapper.toUserInfoMore(
remoteDataSource.getUserInfoMore(getAccessToken()).userInfoMoreDto)
remoteDataSource.getUserInfoMore(getAccessToken()).userInfoMoreDto
)
writeUserInfoMoreInStorage(response)
Resource.Success(response)
}catch (exception:Exception){
} catch (exception: Exception) {
Resource.Error(
profileExceptionToErrorMapper.handleException(exception)
)
Expand All @@ -132,12 +133,13 @@ class ProfileInfoRepositoryImpl @Inject constructor(
return try {
val response = profileAnalyticsDomainMapper.toProfileAnalytics(
analyticsDataMapper.toProfileAnalyticsDto(
remoteDataSource.getUserAnalytics(getAccessToken())
))
remoteDataSource.getUserAnalytics(getAccessToken())
)
)
writeUserAnalyticsInStorage(response)
Resource.Success(response)

}catch (exception:Exception){
} catch (exception: Exception) {
Resource.Error(
profileExceptionToErrorMapper.handleException(exception)
)
Expand All @@ -157,10 +159,12 @@ class ProfileInfoRepositoryImpl @Inject constructor(

return file
}
private fun writeUserInfoMoreInStorage(userInfoMore: UserInfoMore){

private fun writeUserInfoMoreInStorage(userInfoMore: UserInfoMore) {
this.userInfoMore = userInfoMore
}
private fun writeUserAnalyticsInStorage(userAnalytics: ProfileAnalytics){

private fun writeUserAnalyticsInStorage(userAnalytics: ProfileAnalytics) {
this.userAnalytics = userAnalytics
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,42 +66,47 @@ class NetworkToProfileExceptionMapper @Inject constructor(
}
}

fun handleExceptionGetMoreProfile(exception: NetworkException):UserProfileException {
return when(exception){
fun handleExceptionGetMoreProfile(exception: NetworkException): UserProfileException {
return when (exception) {
is NetworkException.Unauthorized -> {
val errorResponse = handleErrorResponse<ErrorResponse>(exception.errorBody)
UserProfileException.Profile.UnauthorizedUserNotAuthenticated(
message = errorResponse.message,
statusCode = errorResponse.statusCode
)
}

is NetworkException.InternalServerError -> {
val errorResponse = handleErrorResponse<ErrorResponse>(exception.errorBody)
UserProfileException.Profile.InternalServerErrorFailedToRetrieve(
message = errorResponse.message,
statusCode = errorResponse.statusCode
)
}

else -> handleCommonException(exception)
}
}
fun handleExceptionAnalyticsProfile(exception: NetworkException):UserProfileException{
return when(exception){

fun handleExceptionAnalyticsProfile(exception: NetworkException): UserProfileException {
return when (exception) {
is NetworkException.Unauthorized -> {
val errorResponse = handleErrorResponse<ErrorResponse>(exception.errorBody)
UserProfileException.Profile.UnauthorizedUserNotAuthenticated(
message = errorResponse.message,
statusCode = errorResponse.statusCode
)
}

is NetworkException.InternalServerError -> {
val errorResponse= handleErrorResponse<ErrorResponse>(exception.errorBody)
val errorResponse = handleErrorResponse<ErrorResponse>(exception.errorBody)
UserProfileException.Profile.InternalServerErrorFailedToRetrieve(
message = errorResponse.message,
statusCode = errorResponse.statusCode
)
}
else-> {

else -> {
handleCommonException(exception)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.cashadvisor.profile.domain.mapper
package app.cashadvisor.profile.data.mapper

import app.cashadvisor.profile.data.dto.response.ExpenseDto
import app.cashadvisor.profile.data.dto.response.IncomeDto
Expand All @@ -12,18 +12,20 @@ import app.cashadvisor.profile.domain.model.UserAnalytics
import app.cashadvisor.profile.domain.model.WealthFund
import javax.inject.Inject

class ProfileAnalyticsDomainMapper @Inject constructor(){
class ProfileAnalyticsDomainMapper @Inject constructor() {
fun toProfileAnalytics(profileAnalyticsDto: ProfileAnalyticsDto) = ProfileAnalytics(
statusCode = profileAnalyticsDto.statusCode,
message = profileAnalyticsDto.message,
responseCurrency = profileAnalyticsDto.responseCurrency,
userAnalytics = toUserAnalytics(profileAnalyticsDto.userAnalyticsDto)
)

private fun toUserAnalytics(userAnalyticsDto: UserAnalyticsDto) = UserAnalytics(
income = userAnalyticsDto.incomeDto?.map { toIncome(it) },
expense = userAnalyticsDto.expenseDto?.map { toExpense(it) },
wealthFund = userAnalyticsDto.wealthFundDto?.map { toWealthFund(it) }
)

private fun toIncome(incomeDto: IncomeDto) = Income(
amount = incomeDto.amount,
categoryId = incomeDto.categoryId,
Expand All @@ -35,6 +37,7 @@ class ProfileAnalyticsDomainMapper @Inject constructor(){
sender = incomeDto.sender,
currency = incomeDto.currency
)

private fun toExpense(expenseDto: ExpenseDto) = Expense(
amount = expenseDto.amount,
categoryId = expenseDto.categoryId,
Expand All @@ -46,6 +49,7 @@ class ProfileAnalyticsDomainMapper @Inject constructor(){
sentTo = expenseDto.sentTo,
currency = expenseDto.currency
)

private fun toWealthFund(wealthFundDto: WealthFundDto) = WealthFund(
amount = wealthFundDto.amount,
categoryId = wealthFundDto.categoryId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.cashadvisor.profile.domain.mapper
package app.cashadvisor.profile.data.mapper

import app.cashadvisor.profile.data.dto.response.AppDto
import app.cashadvisor.profile.data.dto.response.CategorySettingsDto
Expand Down Expand Up @@ -34,46 +34,57 @@ class UserInfoMoreDomainMapper @Inject constructor() {
private fun toSettings(settingsDto: SettingsDto) = Settings(
subscriptions = toSubscription(settingsDto.subscriptionsDto)
)

private fun toCategorySettings(categorySettingsDto: CategorySettingsDto) = CategorySettings(
expenseCategories = categorySettingsDto.expenseCategoriesDto?.map { toExpenseCategories(it) },
incomeCategories = categorySettingsDto.incomeCategoriesDto?.map { toIncomeCategories(it) },
investmentCategories = categorySettingsDto.investmentCategoriesDto?.map { toInvestmentCategories(it) }
investmentCategories = categorySettingsDto.investmentCategoriesDto?.map {
toInvestmentCategories(
it
)
}
)

private fun toConnectedAccounts(connectedAccountDto: ConnectedAccountDto) = ConnectedAccount(
id = connectedAccountDto.id,
userId = connectedAccountDto.userId,
bankId = connectedAccountDto.bankId,
accountNumber = connectedAccountDto.accountNumber,
accountType = connectedAccountDto.accountType
)

private fun toSubscription(subscriptionsDto: SubscriptionsDto) = Subscriptions(
id = subscriptionsDto.id,
userId = subscriptionsDto.userId,
startDate = subscriptionsDto.startDate,
endDate = subscriptionsDto.endDate,
isActive = subscriptionsDto.isActive
)

private fun toExpenseCategories(expenseCategoryDto: ExpenseCategoryDto) = ExpenseCategory(
id = expenseCategoryDto.id,
name = expenseCategoryDto.name,
icon = expenseCategoryDto.icon,
isConstant = expenseCategoryDto.isConstant,
userId = expenseCategoryDto.userId
)

private fun toIncomeCategories(incomeCategoryDto: IncomeCategoryDto) = IncomeCategory(
id = incomeCategoryDto.id,
name = incomeCategoryDto.name,
icon = incomeCategoryDto.icon,
isConstant = incomeCategoryDto.isConstant,
userId = incomeCategoryDto.userId
)
private fun toInvestmentCategories(investmentCategoryDto: InvestmentCategoryDto) = InvestmentCategory(
id = investmentCategoryDto.id,
name = investmentCategoryDto.name,
icon = investmentCategoryDto.icon,
isConstant = investmentCategoryDto.isConstant,
userId = investmentCategoryDto.userId
)

private fun toInvestmentCategories(investmentCategoryDto: InvestmentCategoryDto) =
InvestmentCategory(
id = investmentCategoryDto.id,
name = investmentCategoryDto.name,
icon = investmentCategoryDto.icon,
isConstant = investmentCategoryDto.isConstant,
userId = investmentCategoryDto.userId
)


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import app.cashadvisor.profile.data.api.ProfileInfoStorage
import app.cashadvisor.profile.data.impl.ProfileInfoRepositoryImpl
import app.cashadvisor.profile.data.impl.ProfileInfoStorageImpl
import app.cashadvisor.profile.data.mapper.ProfileAnalyticsDataMapper
import app.cashadvisor.profile.data.mapper.ProfileAnalyticsDomainMapper
import app.cashadvisor.profile.data.mapper.ProfileExceptionToErrorMapper
import app.cashadvisor.profile.data.mapper.ProfileInfoMapper
import app.cashadvisor.profile.data.mapper.UserInfoMoreDomainMapper
import app.cashadvisor.profile.domain.api.ProfileInfoRepository
import app.cashadvisor.profile.domain.mapper.ProfileAnalyticsDomainMapper
import app.cashadvisor.profile.domain.mapper.UserInfoMoreDomainMapper
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,31 @@ data class ConnectedAccount(
val accountNumber: String,
val accountType: String
)

data class ExpenseCategory(
val id: String,
val name: String,
val icon: String,
val isConstant: Boolean,
val userId: String
)

data class IncomeCategory(
val id: String,
val icon: String,
val name: String,
val isConstant: Boolean,
val userId: String
)

data class InvestmentCategory(
val id: String,
val name: String,
val icon: String,
val isConstant: Boolean,
val userId: String
)

data class Subscriptions(
val id: String,
val userId: String,
Expand Down

0 comments on commit fe50225

Please sign in to comment.