From fe5022502a5be9f7d11157d71ee32c00871bace9 Mon Sep 17 00:00:00 2001 From: MajoritySky2496 Date: Mon, 3 Jun 2024 22:35:42 +0500 Subject: [PATCH] 1) Fixed Dto and Models --- .../dto/response/ProfileAnalyticsResponse.kt | 1 + .../impl/ProfileInfoRemoteDataSourceImpl.kt | 4 +-- .../data/impl/ProfileInfoRepositoryImpl.kt | 30 +++++++++++-------- .../mapper/NetworkToProfileExceptionMapper.kt | 17 +++++++---- .../mapper/ProfileAnalyticsDomainMapper.kt | 8 +++-- .../mapper/UserInfoMoreDomainMapper.kt | 29 ++++++++++++------ .../profile/di/ProfileDataModule.kt | 4 +-- .../profile/domain/model/UserInfoMore.kt | 4 +++ 8 files changed, 63 insertions(+), 34 deletions(-) rename app/src/main/java/app/cashadvisor/profile/{domain => data}/mapper/ProfileAnalyticsDomainMapper.kt (95%) rename app/src/main/java/app/cashadvisor/profile/{domain => data}/mapper/UserInfoMoreDomainMapper.kt (88%) diff --git a/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileAnalyticsResponse.kt b/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileAnalyticsResponse.kt index cbc6273..dbf7228 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileAnalyticsResponse.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileAnalyticsResponse.kt @@ -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, diff --git a/app/src/main/java/app/cashadvisor/profile/data/impl/ProfileInfoRemoteDataSourceImpl.kt b/app/src/main/java/app/cashadvisor/profile/data/impl/ProfileInfoRemoteDataSourceImpl.kt index d771166..e4408cd 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/impl/ProfileInfoRemoteDataSourceImpl.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/impl/ProfileInfoRemoteDataSourceImpl.kt @@ -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) } } @@ -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) } } diff --git a/app/src/main/java/app/cashadvisor/profile/data/impl/ProfileInfoRepositoryImpl.kt b/app/src/main/java/app/cashadvisor/profile/data/impl/ProfileInfoRepositoryImpl.kt index 7efbcc3..2c165bd 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/impl/ProfileInfoRepositoryImpl.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/impl/ProfileInfoRepositoryImpl.kt @@ -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 @@ -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 { @@ -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) ) @@ -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) ) @@ -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 } diff --git a/app/src/main/java/app/cashadvisor/profile/data/mapper/NetworkToProfileExceptionMapper.kt b/app/src/main/java/app/cashadvisor/profile/data/mapper/NetworkToProfileExceptionMapper.kt index d2db42b..40cb7e7 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/mapper/NetworkToProfileExceptionMapper.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/mapper/NetworkToProfileExceptionMapper.kt @@ -66,8 +66,8 @@ 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(exception.errorBody) UserProfileException.Profile.UnauthorizedUserNotAuthenticated( @@ -75,6 +75,7 @@ class NetworkToProfileExceptionMapper @Inject constructor( statusCode = errorResponse.statusCode ) } + is NetworkException.InternalServerError -> { val errorResponse = handleErrorResponse(exception.errorBody) UserProfileException.Profile.InternalServerErrorFailedToRetrieve( @@ -82,11 +83,13 @@ class NetworkToProfileExceptionMapper @Inject constructor( 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(exception.errorBody) UserProfileException.Profile.UnauthorizedUserNotAuthenticated( @@ -94,14 +97,16 @@ class NetworkToProfileExceptionMapper @Inject constructor( statusCode = errorResponse.statusCode ) } + is NetworkException.InternalServerError -> { - val errorResponse= handleErrorResponse(exception.errorBody) + val errorResponse = handleErrorResponse(exception.errorBody) UserProfileException.Profile.InternalServerErrorFailedToRetrieve( message = errorResponse.message, statusCode = errorResponse.statusCode ) } - else-> { + + else -> { handleCommonException(exception) } } diff --git a/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt b/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsDomainMapper.kt similarity index 95% rename from app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt rename to app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsDomainMapper.kt index 3aa457b..952bf47 100644 --- a/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsDomainMapper.kt @@ -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 @@ -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, @@ -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, @@ -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, diff --git a/app/src/main/java/app/cashadvisor/profile/domain/mapper/UserInfoMoreDomainMapper.kt b/app/src/main/java/app/cashadvisor/profile/data/mapper/UserInfoMoreDomainMapper.kt similarity index 88% rename from app/src/main/java/app/cashadvisor/profile/domain/mapper/UserInfoMoreDomainMapper.kt rename to app/src/main/java/app/cashadvisor/profile/data/mapper/UserInfoMoreDomainMapper.kt index f74b6c2..35b3a04 100644 --- a/app/src/main/java/app/cashadvisor/profile/domain/mapper/UserInfoMoreDomainMapper.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/mapper/UserInfoMoreDomainMapper.kt @@ -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 @@ -34,11 +34,17 @@ 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, @@ -46,6 +52,7 @@ class UserInfoMoreDomainMapper @Inject constructor() { accountNumber = connectedAccountDto.accountNumber, accountType = connectedAccountDto.accountType ) + private fun toSubscription(subscriptionsDto: SubscriptionsDto) = Subscriptions( id = subscriptionsDto.id, userId = subscriptionsDto.userId, @@ -53,6 +60,7 @@ class UserInfoMoreDomainMapper @Inject constructor() { endDate = subscriptionsDto.endDate, isActive = subscriptionsDto.isActive ) + private fun toExpenseCategories(expenseCategoryDto: ExpenseCategoryDto) = ExpenseCategory( id = expenseCategoryDto.id, name = expenseCategoryDto.name, @@ -60,6 +68,7 @@ class UserInfoMoreDomainMapper @Inject constructor() { isConstant = expenseCategoryDto.isConstant, userId = expenseCategoryDto.userId ) + private fun toIncomeCategories(incomeCategoryDto: IncomeCategoryDto) = IncomeCategory( id = incomeCategoryDto.id, name = incomeCategoryDto.name, @@ -67,13 +76,15 @@ class UserInfoMoreDomainMapper @Inject constructor() { 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 + ) } diff --git a/app/src/main/java/app/cashadvisor/profile/di/ProfileDataModule.kt b/app/src/main/java/app/cashadvisor/profile/di/ProfileDataModule.kt index 4a8d30d..ba2e8f2 100644 --- a/app/src/main/java/app/cashadvisor/profile/di/ProfileDataModule.kt +++ b/app/src/main/java/app/cashadvisor/profile/di/ProfileDataModule.kt @@ -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 diff --git a/app/src/main/java/app/cashadvisor/profile/domain/model/UserInfoMore.kt b/app/src/main/java/app/cashadvisor/profile/domain/model/UserInfoMore.kt index 6ebf092..df2a98f 100644 --- a/app/src/main/java/app/cashadvisor/profile/domain/model/UserInfoMore.kt +++ b/app/src/main/java/app/cashadvisor/profile/domain/model/UserInfoMore.kt @@ -28,6 +28,7 @@ data class ConnectedAccount( val accountNumber: String, val accountType: String ) + data class ExpenseCategory( val id: String, val name: String, @@ -35,6 +36,7 @@ data class ExpenseCategory( val isConstant: Boolean, val userId: String ) + data class IncomeCategory( val id: String, val icon: String, @@ -42,6 +44,7 @@ data class IncomeCategory( val isConstant: Boolean, val userId: String ) + data class InvestmentCategory( val id: String, val name: String, @@ -49,6 +52,7 @@ data class InvestmentCategory( val isConstant: Boolean, val userId: String ) + data class Subscriptions( val id: String, val userId: String,