From 66209990446fac83846774b7f6c20eb783b7f630 Mon Sep 17 00:00:00 2001 From: MajoritySky2496 Date: Wed, 22 May 2024 23:34:41 +0500 Subject: [PATCH 1/6] 100-Main_Page_Repository 1) Made models 2) Made ApiService --- .../profile/data/api/ProfileInfoApiService.kt | 12 +++ .../dto/response/ProfileAnalyticsResponse.kt | 57 +++++++++++++ .../dto/response/ProfileInfoMoreResponse.kt | 81 +++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileAnalyticsResponse.kt create mode 100644 app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt diff --git a/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoApiService.kt b/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoApiService.kt index c0470cac..ffb479a5 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoApiService.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoApiService.kt @@ -3,6 +3,8 @@ package app.cashadvisor.profile.data.api import app.cashadvisor.profile.data.dto.request.UpdateUserNameRequest import app.cashadvisor.profile.data.dto.response.ConfirmUpdateNameResponse import app.cashadvisor.profile.data.dto.response.ConfirmUpdatePicResponse +import app.cashadvisor.profile.data.dto.response.ProfileAnalyticsResponse +import app.cashadvisor.profile.data.dto.response.ProfileInfoMoreResponse import app.cashadvisor.profile.data.dto.response.ProfileInfoResponse import okhttp3.MultipartBody import retrofit2.http.Body @@ -32,4 +34,14 @@ interface ProfileInfoApiService { @Part part: MultipartBody.Part ): ConfirmUpdatePicResponse + @GET("profile/more/get") + suspend fun getUserInfoMore( + @Header("Profile") accessToken: String + ):ProfileInfoMoreResponse + + @GET("profile/analytics/get") + suspend fun getUserAnalytics( + @Header("Profile") accessToken: String + ):ProfileAnalyticsResponse + } 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 new file mode 100644 index 00000000..9d26dff3 --- /dev/null +++ b/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileAnalyticsResponse.kt @@ -0,0 +1,57 @@ +package app.cashadvisor.profile.data.dto.response + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ProfileAnalyticsResponse ( + @SerialName("status_code") val statusCode: Int, + val message: String, + @SerialName("response_currency") val responseCurrency: String, + @SerialName("profile") val userAnalyticsDto: UserAnalyticsDto +) + +@Serializable +data class UserAnalyticsDto( + @SerialName("income") val incomeDto: List, + @SerialName("expense") val expenseDto: List, + @SerialName("wealth_fund") val wealthFundDto: List +) + +@Serializable +data class IncomeDto( + val amount: Int, + @SerialName("category_id") val categoryId: String, + val date: String, + val id: String, + val planned: Boolean, + @SerialName("user_id") val userId: String, + @SerialName("bank_account") val bankAccount: String, + val sender: String, + val currency: String +) + +@Serializable +data class ExpenseDto( + val amount: Int, + @SerialName("category_id") val categoryId: String, + val date: String, + val id: String, + val planned: Boolean, + @SerialName("user_id") val userId: String, + @SerialName("bank_account") val bankAccount: String, + @SerialName("sent_to") val sentTo: String, + val currency: String +) + +@Serializable +data class WealthFundDto( + val amount: Int, + val date: String, + val id: String, + val planned: Boolean, + @SerialName("user_id") val userId: String, + @SerialName("bank_account") val bankAccount: String, + val currency: String, + @SerialName("category_id") val categoryId: String +) \ No newline at end of file diff --git a/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt b/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt new file mode 100644 index 00000000..355d9d7b --- /dev/null +++ b/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt @@ -0,0 +1,81 @@ +package app.cashadvisor.profile.data.dto.response + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ProfileInfoMoreResponse( + @SerialName("status_code") val statusCode: Int, + val message: String, + @SerialName("profile") val userInfoMoreDto: UserInfoMoreDto, + + ) + +@Serializable +data class UserInfoMoreDto( + @SerialName("app") val appDto: AppDto, + @SerialName("settings") val settingsDto: SettingsDto +) + +@Serializable +data class AppDto( + @SerialName("category_settings") val categorySettingsDto: CategorySettingsDto, + @SerialName("connected_accounts") val connectedAccountsDto: List +) + +@Serializable +data class SettingsDto( + @SerialName("subscriptions") val subscriptionsDto: SubscriptionsDto +) + +@Serializable +data class CategorySettingsDto( + @SerialName("expense_categories") val expenseCategoriesDto: List, + @SerialName("income_categories") val incomeCategories: List, + @SerialName("investment_categories") val investmentCategoriesDto: List +) + +@Serializable +data class ConnectedAccountDto( + val id: String, + @SerialName("user_id") val userId: String, + @SerialName("bank_id") val bankId: String, + @SerialName("account_number") val accountNumber: String, + @SerialName("account_type") val accountType: String +) + +@Serializable +data class ExpenseCategoryDto( + val id: String, + val name: String, + val icon: String, + @SerialName("is_constant") val isConstant: Boolean, + @SerialName("user_id") val userId: String +) + +@Serializable +data class IncomeCategoryDto( + val id: String, + val icon: String, + val name: String, + @SerialName("is_constant") val isConstant: Boolean, + @SerialName("user_id") val userId: String +) + +@Serializable +data class InvestmentCategoryDto( + val id: String, + val name: String, + val icon: String, + @SerialName("is_constant") val isConstant: Boolean, + @SerialName("user_id") val userId: String +) + +@Serializable +data class SubscriptionsDto( + val id: String, + @SerialName("user_id") val userId: String, + @SerialName("start_date") val startDate: String, + @SerialName("end_date") val endDate: String, + @SerialName("is_active") val isActive: Boolean, +) \ No newline at end of file From a23c07cdbcad0f9ea24f662d261cc8cf57bd0e06 Mon Sep 17 00:00:00 2001 From: MajoritySky2496 Date: Sat, 25 May 2024 23:42:32 +0500 Subject: [PATCH 2/6] 1) Made domain models 2) Made mapper --- .../dto/response/ProfileAnalyticsResponse.kt | 8 +- .../dto/response/ProfileInfoMoreResponse.kt | 2 +- .../data/mapper/ProfileAnalyticsMapper.kt | 58 ++++++++++++++ .../profile/data/mapper/UserInfoMoreMapper.kt | 79 +++++++++++++++++++ .../profile/domain/model/ProfileAnalytics.kt | 50 ++++++++++++ .../profile/domain/model/UserInfoMore.kt | 60 ++++++++++++++ 6 files changed, 255 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsMapper.kt create mode 100644 app/src/main/java/app/cashadvisor/profile/data/mapper/UserInfoMoreMapper.kt create mode 100644 app/src/main/java/app/cashadvisor/profile/domain/model/ProfileAnalytics.kt create mode 100644 app/src/main/java/app/cashadvisor/profile/domain/model/UserInfoMore.kt 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 9d26dff3..74782678 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 @@ -4,12 +4,18 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class ProfileAnalyticsResponse ( +data class ProfileAnalyticsResponse( @SerialName("status_code") val statusCode: Int, val message: String, @SerialName("response_currency") val responseCurrency: String, @SerialName("profile") val userAnalyticsDto: UserAnalyticsDto ) +data class ProfileAnalyticsDto( + val statusCode: Int, + val message: String, + val responseCurrency: String, + val userAnalyticsDto: UserAnalyticsDto +) @Serializable data class UserAnalyticsDto( diff --git a/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt b/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt index 355d9d7b..b8eac9ee 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt @@ -31,7 +31,7 @@ data class SettingsDto( @Serializable data class CategorySettingsDto( @SerialName("expense_categories") val expenseCategoriesDto: List, - @SerialName("income_categories") val incomeCategories: List, + @SerialName("income_categories") val incomeCategoriesDto: List, @SerialName("investment_categories") val investmentCategoriesDto: List ) diff --git a/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsMapper.kt b/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsMapper.kt new file mode 100644 index 00000000..51dbbbf6 --- /dev/null +++ b/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsMapper.kt @@ -0,0 +1,58 @@ +package app.cashadvisor.profile.data.mapper + +import app.cashadvisor.profile.data.dto.response.ExpenseDto +import app.cashadvisor.profile.data.dto.response.IncomeDto +import app.cashadvisor.profile.data.dto.response.ProfileAnalyticsDto +import app.cashadvisor.profile.data.dto.response.UserAnalyticsDto +import app.cashadvisor.profile.data.dto.response.WealthFundDto +import app.cashadvisor.profile.domain.model.Expense +import app.cashadvisor.profile.domain.model.Income +import app.cashadvisor.profile.domain.model.ProfileAnalytics +import app.cashadvisor.profile.domain.model.UserAnalytics +import app.cashadvisor.profile.domain.model.WealthFund + +class ProfileAnalyticsMapper { + 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, + date = incomeDto.date, + id = incomeDto.id, + planned = incomeDto.planned, + userId = incomeDto.userId, + bankAccount = incomeDto.bankAccount, + sender = incomeDto.sender, + currency = incomeDto.currency + ) + private fun toExpense(expenseDto: ExpenseDto) = Expense( + amount = expenseDto.amount, + categoryId = expenseDto.categoryId, + date = expenseDto.date, + id = expenseDto.id, + planned = expenseDto.planned, + userId = expenseDto.userId, + bankAccount = expenseDto.bankAccount, + sentTo = expenseDto.sentTo, + currency = expenseDto.currency + ) + private fun toWealthFund(wealthFundDto: WealthFundDto) = WealthFund( + amount = wealthFundDto.amount, + categoryId = wealthFundDto.categoryId, + date = wealthFundDto.date, + id = wealthFundDto.id, + planned = wealthFundDto.planned, + userId = wealthFundDto.userId, + bankAccount = wealthFundDto.bankAccount, + currency = wealthFundDto.currency + ) +} \ No newline at end of file diff --git a/app/src/main/java/app/cashadvisor/profile/data/mapper/UserInfoMoreMapper.kt b/app/src/main/java/app/cashadvisor/profile/data/mapper/UserInfoMoreMapper.kt new file mode 100644 index 00000000..e0132289 --- /dev/null +++ b/app/src/main/java/app/cashadvisor/profile/data/mapper/UserInfoMoreMapper.kt @@ -0,0 +1,79 @@ +package app.cashadvisor.profile.data.mapper + +import app.cashadvisor.profile.data.dto.response.AppDto +import app.cashadvisor.profile.data.dto.response.CategorySettingsDto +import app.cashadvisor.profile.data.dto.response.ConnectedAccountDto +import app.cashadvisor.profile.data.dto.response.ExpenseCategoryDto +import app.cashadvisor.profile.data.dto.response.IncomeCategoryDto +import app.cashadvisor.profile.data.dto.response.InvestmentCategoryDto +import app.cashadvisor.profile.data.dto.response.SettingsDto +import app.cashadvisor.profile.data.dto.response.SubscriptionsDto +import app.cashadvisor.profile.data.dto.response.UserInfoMoreDto +import app.cashadvisor.profile.domain.model.App +import app.cashadvisor.profile.domain.model.CategorySettings +import app.cashadvisor.profile.domain.model.ConnectedAccount +import app.cashadvisor.profile.domain.model.ExpenseCategory +import app.cashadvisor.profile.domain.model.IncomeCategory +import app.cashadvisor.profile.domain.model.InvestmentCategory +import app.cashadvisor.profile.domain.model.Settings +import app.cashadvisor.profile.domain.model.Subscriptions +import app.cashadvisor.profile.domain.model.UserInfoMore +import javax.inject.Inject + +class UserInfoMoreMapper @Inject constructor() { + fun toUserInfoMore(userInfoMoreDto: UserInfoMoreDto) = UserInfoMore( + appDto = toApp(userInfoMoreDto.appDto), + settings = toSettings(userInfoMoreDto.settingsDto) + ) + + private fun toApp(appDto: AppDto) = App( + categorySettings = toCategorySettings(appDto.categorySettingsDto), + connectedAccounts = appDto.connectedAccountsDto.map { toConnectedAccounts(it) } + ) + + 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) } + ) + 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 + ) + + +} diff --git a/app/src/main/java/app/cashadvisor/profile/domain/model/ProfileAnalytics.kt b/app/src/main/java/app/cashadvisor/profile/domain/model/ProfileAnalytics.kt new file mode 100644 index 00000000..80ebec51 --- /dev/null +++ b/app/src/main/java/app/cashadvisor/profile/domain/model/ProfileAnalytics.kt @@ -0,0 +1,50 @@ +package app.cashadvisor.profile.domain.model + +data class ProfileAnalytics( + val statusCode: Int, + val message: String, + val responseCurrency: String, + val userAnalytics: UserAnalytics +) + +data class UserAnalytics( + val income: List, + val expense: List, + val wealthFund: List +) + +data class Income( + val amount: Int, + val categoryId: String, + val date: String, + val id: String, + val planned: Boolean, + val userId: String, + val bankAccount: String, + val sender: String, + val currency: String +) + +data class Expense( + val amount: Int, + val categoryId: String, + val date: String, + val id: String, + val planned: Boolean, + val userId: String, + val bankAccount: String, + val sentTo: String, + val currency: String +) + +data class WealthFund( + val amount: Int, + val date: String, + val id: String, + val planned: Boolean, + val userId: String, + val bankAccount: String, + val currency: String, + val categoryId: String +) + 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 new file mode 100644 index 00000000..bd6bcaa6 --- /dev/null +++ b/app/src/main/java/app/cashadvisor/profile/domain/model/UserInfoMore.kt @@ -0,0 +1,60 @@ +package app.cashadvisor.profile.domain.model + + +data class UserInfoMore( + val appDto: App, + val settings: Settings +) + +data class App( + val categorySettings: CategorySettings, + val connectedAccounts: List +) + +data class Settings( + val subscriptions: Subscriptions +) + +data class CategorySettings( + val expenseCategories: List, + val incomeCategories: List, + val investmentCategories: List +) + +data class ConnectedAccount( + val id: String, + val userId: String, + val bankId: String, + 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, + val startDate: String, + val endDate: String, + val isActive: Boolean, +) + + From c7cda2768985d7725ee9e941d4158474f61908a3 Mon Sep 17 00:00:00 2001 From: MajoritySky2496 Date: Sun, 26 May 2024 20:24:40 +0500 Subject: [PATCH 3/6] 1) Made NetworkToProfileExceptionMapper 2) Made RemoteDataSource 3) Made Repository 4) Made Interactor --- .../data/api/ProfileInfoRemoteDataSource.kt | 5 +++ .../impl/ProfileInfoRemoteDataSourceImpl.kt | 20 +++++++++ .../data/impl/ProfileInfoRepositoryImpl.kt | 38 +++++++++++++++++ .../mapper/NetworkToProfileExceptionMapper.kt | 41 +++++++++++++++++++ .../data/mapper/ProfileAnalyticsDataMapper.kt | 13 ++++++ .../profile/di/ProfileDataModule.kt | 9 ++++ .../domain/api/ProfileInfoInteractor.kt | 6 +++ .../domain/api/ProfileInfoRepository.kt | 6 +++ .../domain/impl/ProfileInfoInteractorImpl.kt | 10 +++++ .../mapper/ProfileAnalyticsDomainMapper.kt} | 4 +- .../mapper/UserInfoMoreDomainMapper.kt} | 4 +- 11 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsDataMapper.kt rename app/src/main/java/app/cashadvisor/profile/{data/mapper/ProfileAnalyticsMapper.kt => domain/mapper/ProfileAnalyticsDomainMapper.kt} (96%) rename app/src/main/java/app/cashadvisor/profile/{data/mapper/UserInfoMoreMapper.kt => domain/mapper/UserInfoMoreDomainMapper.kt} (97%) diff --git a/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoRemoteDataSource.kt b/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoRemoteDataSource.kt index c60b6bb6..1ebc04e0 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoRemoteDataSource.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoRemoteDataSource.kt @@ -4,6 +4,8 @@ import app.cashadvisor.profile.data.dto.request.UpdateProfilePicRequest import app.cashadvisor.profile.data.dto.request.UpdateUserNameRequest import app.cashadvisor.profile.data.dto.response.ConfirmUpdateNameResponse import app.cashadvisor.profile.data.dto.response.ConfirmUpdatePicResponse +import app.cashadvisor.profile.data.dto.response.ProfileAnalyticsResponse +import app.cashadvisor.profile.data.dto.response.ProfileInfoMoreResponse import app.cashadvisor.profile.data.dto.response.ProfileInfoResponse interface ProfileInfoRemoteDataSource { @@ -19,5 +21,8 @@ interface ProfileInfoRemoteDataSource { dto: UpdateProfilePicRequest, accessToken: String ): ConfirmUpdatePicResponse + suspend fun getUserInfoMore(accessToken: String):ProfileInfoMoreResponse + + suspend fun getUserAnalytics(accessToken: String):ProfileAnalyticsResponse } \ No newline at end of file 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 5ca48ed3..d771166c 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 @@ -7,6 +7,8 @@ import app.cashadvisor.profile.data.dto.request.UpdateProfilePicRequest import app.cashadvisor.profile.data.dto.request.UpdateUserNameRequest import app.cashadvisor.profile.data.dto.response.ConfirmUpdateNameResponse import app.cashadvisor.profile.data.dto.response.ConfirmUpdatePicResponse +import app.cashadvisor.profile.data.dto.response.ProfileAnalyticsResponse +import app.cashadvisor.profile.data.dto.response.ProfileInfoMoreResponse import app.cashadvisor.profile.data.dto.response.ProfileInfoResponse import app.cashadvisor.profile.data.mapper.NetworkToProfileExceptionMapper import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -56,4 +58,22 @@ class ProfileInfoRemoteDataSourceImpl @Inject constructor( } } + override suspend fun getUserInfoMore(accessToken: String): ProfileInfoMoreResponse { + return try { + val response = profileInfoApiService.getUserInfoMore(accessToken = accessToken) + response + }catch (exception:NetworkException){ + throw networkToProfileExceptionMapper.handleExceptionGetMoreProfile(exception) + } + } + + override suspend fun getUserAnalytics(accessToken: String): ProfileAnalyticsResponse { + return try { + val response = profileInfoApiService.getUserAnalytics(accessToken) + response + }catch (exception:NetworkException){ + throw networkToProfileExceptionMapper.handleExceptionAnalyticsProfile(exception) + } + } + } \ No newline at end of file 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 508d9cbf..b5372d0b 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 @@ -11,8 +11,13 @@ import app.cashadvisor.profile.data.api.ProfileInfoStorage 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.ProfileInfoMapper 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 import dagger.hilt.android.qualifiers.ApplicationContext import java.io.File @@ -26,6 +31,9 @@ class ProfileInfoRepositoryImpl @Inject constructor( private val remoteDataSource: ProfileInfoRemoteDataSource, private val credentialsRepository: CredentialsRepository, private val mapper: ProfileInfoMapper, + private val analyticsDataMapper: ProfileAnalyticsDataMapper, + private val userInfoMoreMapper:UserInfoMoreDomainMapper, + private val profileAnalyticsDomainMapper: ProfileAnalyticsDomainMapper, private val profileExceptionToErrorMapper: BaseExceptionToErrorMapper ) : ProfileInfoRepository { @@ -99,6 +107,36 @@ class ProfileInfoRepositoryImpl @Inject constructor( } } + override suspend fun getUserInfoMore(): Resource { + + + return try { + val response = userInfoMoreMapper.toUserInfoMore( + remoteDataSource.getUserInfoMore(getAccessToken()).userInfoMoreDto) + Resource.Success(response) + }catch (exception:Exception){ + Resource.Error( + profileExceptionToErrorMapper.handleException(exception) + ) + } + } + + override suspend fun getUserAnalytics(): Resource { + + + return try { + val response = profileAnalyticsDomainMapper.toProfileAnalytics( + analyticsDataMapper.toProfileAnalyticsDto( + remoteDataSource.getUserAnalytics(getAccessToken()) + )) + Resource.Success(response) + }catch (exception:Exception){ + Resource.Error( + profileExceptionToErrorMapper.handleException(exception) + ) + } + } + private fun createTemporaryFile(inputStream: InputStream?): File { val file = File.createTempFile("temp_image", null, context.cacheDir) 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 44f9abf1..d2db42be 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,6 +66,47 @@ class NetworkToProfileExceptionMapper @Inject constructor( } } + fun handleExceptionGetMoreProfile(exception: NetworkException):UserProfileException { + return when(exception){ + is NetworkException.Unauthorized -> { + val errorResponse = handleErrorResponse(exception.errorBody) + UserProfileException.Profile.UnauthorizedUserNotAuthenticated( + message = errorResponse.message, + statusCode = errorResponse.statusCode + ) + } + is NetworkException.InternalServerError -> { + val errorResponse = handleErrorResponse(exception.errorBody) + UserProfileException.Profile.InternalServerErrorFailedToRetrieve( + message = errorResponse.message, + statusCode = errorResponse.statusCode + ) + } + else -> handleCommonException(exception) + } + } + fun handleExceptionAnalyticsProfile(exception: NetworkException):UserProfileException{ + return when(exception){ + is NetworkException.Unauthorized -> { + val errorResponse = handleErrorResponse(exception.errorBody) + UserProfileException.Profile.UnauthorizedUserNotAuthenticated( + message = errorResponse.message, + statusCode = errorResponse.statusCode + ) + } + is NetworkException.InternalServerError -> { + val errorResponse= handleErrorResponse(exception.errorBody) + UserProfileException.Profile.InternalServerErrorFailedToRetrieve( + message = errorResponse.message, + statusCode = errorResponse.statusCode + ) + } + else-> { + handleCommonException(exception) + } + } + } + private fun handleCommonException(exception: NetworkException): UserProfileException { return when (exception) { is NetworkException.NoInternetConnection -> { diff --git a/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsDataMapper.kt b/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsDataMapper.kt new file mode 100644 index 00000000..9246e1e3 --- /dev/null +++ b/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsDataMapper.kt @@ -0,0 +1,13 @@ +package app.cashadvisor.profile.data.mapper + +import app.cashadvisor.profile.data.dto.response.ProfileAnalyticsDto +import app.cashadvisor.profile.data.dto.response.ProfileAnalyticsResponse + +class ProfileAnalyticsDataMapper { + fun toProfileAnalyticsDto(profileAnalyticsResponse: ProfileAnalyticsResponse) = ProfileAnalyticsDto( + statusCode = profileAnalyticsResponse.statusCode, + message = profileAnalyticsResponse.message, + responseCurrency = profileAnalyticsResponse.responseCurrency, + userAnalyticsDto = profileAnalyticsResponse.userAnalyticsDto + ) +} \ No newline at end of file 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 bb0f65a5..4a8d30dc 100644 --- a/app/src/main/java/app/cashadvisor/profile/di/ProfileDataModule.kt +++ b/app/src/main/java/app/cashadvisor/profile/di/ProfileDataModule.kt @@ -7,9 +7,12 @@ import app.cashadvisor.profile.data.api.ProfileInfoRemoteDataSource 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.ProfileExceptionToErrorMapper import app.cashadvisor.profile.data.mapper.ProfileInfoMapper 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 @@ -29,6 +32,9 @@ class ProfileDataModule { storage: ProfileInfoStorage, credentialsRepository: CredentialsRepository, mapper: ProfileInfoMapper, + analyticsDataMapper: ProfileAnalyticsDataMapper, + userInfoMoreDomainMapper: UserInfoMoreDomainMapper, + profileAnalyticsDomainMapper: ProfileAnalyticsDomainMapper, profileExceptionToErrorMapper: ProfileExceptionToErrorMapper ): ProfileInfoRepository = ProfileInfoRepositoryImpl( context = context, @@ -36,6 +42,9 @@ class ProfileDataModule { credentialsRepository = credentialsRepository, storage = storage, mapper = mapper, + analyticsDataMapper = analyticsDataMapper, + userInfoMoreMapper = userInfoMoreDomainMapper, + profileAnalyticsDomainMapper = profileAnalyticsDomainMapper, profileExceptionToErrorMapper = profileExceptionToErrorMapper ) diff --git a/app/src/main/java/app/cashadvisor/profile/domain/api/ProfileInfoInteractor.kt b/app/src/main/java/app/cashadvisor/profile/domain/api/ProfileInfoInteractor.kt index b8d46b2f..101e7972 100644 --- a/app/src/main/java/app/cashadvisor/profile/domain/api/ProfileInfoInteractor.kt +++ b/app/src/main/java/app/cashadvisor/profile/domain/api/ProfileInfoInteractor.kt @@ -2,6 +2,8 @@ package app.cashadvisor.profile.domain.api import android.net.Uri import app.cashadvisor.common.domain.Resource +import app.cashadvisor.profile.domain.model.ProfileAnalytics +import app.cashadvisor.profile.domain.model.UserInfoMore import app.cashadvisor.profile.domain.model.UserProfileInfo interface ProfileInfoInteractor { @@ -15,4 +17,8 @@ interface ProfileInfoInteractor { suspend fun updateProfilePic( profilePicUri: Uri, ): Resource + + suspend fun getUserInfoMore():Resource + + suspend fun getUserAnalytics():Resource } \ No newline at end of file diff --git a/app/src/main/java/app/cashadvisor/profile/domain/api/ProfileInfoRepository.kt b/app/src/main/java/app/cashadvisor/profile/domain/api/ProfileInfoRepository.kt index 843b224c..174e8348 100644 --- a/app/src/main/java/app/cashadvisor/profile/domain/api/ProfileInfoRepository.kt +++ b/app/src/main/java/app/cashadvisor/profile/domain/api/ProfileInfoRepository.kt @@ -2,6 +2,8 @@ package app.cashadvisor.profile.domain.api import android.net.Uri import app.cashadvisor.common.domain.Resource +import app.cashadvisor.profile.domain.model.ProfileAnalytics +import app.cashadvisor.profile.domain.model.UserInfoMore import app.cashadvisor.profile.domain.model.UserProfileInfo interface ProfileInfoRepository { @@ -15,4 +17,8 @@ interface ProfileInfoRepository { suspend fun updateProfilePic( profilePic: Uri ): Resource + + suspend fun getUserInfoMore(): Resource + + suspend fun getUserAnalytics():Resource } \ No newline at end of file diff --git a/app/src/main/java/app/cashadvisor/profile/domain/impl/ProfileInfoInteractorImpl.kt b/app/src/main/java/app/cashadvisor/profile/domain/impl/ProfileInfoInteractorImpl.kt index d66ec04b..1717ee10 100644 --- a/app/src/main/java/app/cashadvisor/profile/domain/impl/ProfileInfoInteractorImpl.kt +++ b/app/src/main/java/app/cashadvisor/profile/domain/impl/ProfileInfoInteractorImpl.kt @@ -4,6 +4,8 @@ import android.net.Uri import app.cashadvisor.common.domain.Resource import app.cashadvisor.profile.domain.api.ProfileInfoInteractor import app.cashadvisor.profile.domain.api.ProfileInfoRepository +import app.cashadvisor.profile.domain.model.ProfileAnalytics +import app.cashadvisor.profile.domain.model.UserInfoMore import app.cashadvisor.profile.domain.model.UserProfileInfo import javax.inject.Inject @@ -22,4 +24,12 @@ class ProfileInfoInteractorImpl @Inject constructor( return profileInfoRepository.updateProfilePic(profilePic) } + override suspend fun getUserInfoMore(): Resource { + return profileInfoRepository.getUserInfoMore() + } + + override suspend fun getUserAnalytics(): Resource { + return profileInfoRepository.getUserAnalytics() + } + } \ No newline at end of file diff --git a/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsMapper.kt b/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt similarity index 96% rename from app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsMapper.kt rename to app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt index 51dbbbf6..7fd640f8 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsMapper.kt +++ b/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt @@ -1,4 +1,4 @@ -package app.cashadvisor.profile.data.mapper +package app.cashadvisor.profile.domain.mapper import app.cashadvisor.profile.data.dto.response.ExpenseDto import app.cashadvisor.profile.data.dto.response.IncomeDto @@ -11,7 +11,7 @@ import app.cashadvisor.profile.domain.model.ProfileAnalytics import app.cashadvisor.profile.domain.model.UserAnalytics import app.cashadvisor.profile.domain.model.WealthFund -class ProfileAnalyticsMapper { +class ProfileAnalyticsDomainMapper { fun toProfileAnalytics(profileAnalyticsDto: ProfileAnalyticsDto) = ProfileAnalytics( statusCode = profileAnalyticsDto.statusCode, message = profileAnalyticsDto.message, diff --git a/app/src/main/java/app/cashadvisor/profile/data/mapper/UserInfoMoreMapper.kt b/app/src/main/java/app/cashadvisor/profile/domain/mapper/UserInfoMoreDomainMapper.kt similarity index 97% rename from app/src/main/java/app/cashadvisor/profile/data/mapper/UserInfoMoreMapper.kt rename to app/src/main/java/app/cashadvisor/profile/domain/mapper/UserInfoMoreDomainMapper.kt index e0132289..070e8651 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/mapper/UserInfoMoreMapper.kt +++ b/app/src/main/java/app/cashadvisor/profile/domain/mapper/UserInfoMoreDomainMapper.kt @@ -1,4 +1,4 @@ -package app.cashadvisor.profile.data.mapper +package app.cashadvisor.profile.domain.mapper import app.cashadvisor.profile.data.dto.response.AppDto import app.cashadvisor.profile.data.dto.response.CategorySettingsDto @@ -20,7 +20,7 @@ import app.cashadvisor.profile.domain.model.Subscriptions import app.cashadvisor.profile.domain.model.UserInfoMore import javax.inject.Inject -class UserInfoMoreMapper @Inject constructor() { +class UserInfoMoreDomainMapper @Inject constructor() { fun toUserInfoMore(userInfoMoreDto: UserInfoMoreDto) = UserInfoMore( appDto = toApp(userInfoMoreDto.appDto), settings = toSettings(userInfoMoreDto.settingsDto) From 204fb0d7de092696195ef990d4c00fb711c88264 Mon Sep 17 00:00:00 2001 From: MajoritySky2496 Date: Sun, 2 Jun 2024 10:40:02 +0500 Subject: [PATCH 4/6] 100-Main_Page_Repository --- .../main/presentation/ui/MainActivity.kt | 3 ++ .../main/presentation/ui/MainViewModel.kt | 31 ++++++++++++++++++- .../profile/data/api/ProfileInfoApiService.kt | 4 +-- .../dto/response/ProfileAnalyticsResponse.kt | 2 +- .../dto/response/ProfileInfoMoreResponse.kt | 2 +- .../data/impl/ProfileInfoRepositoryImpl.kt | 15 ++++++++- .../data/mapper/ProfileAnalyticsDataMapper.kt | 4 ++- .../mapper/ProfileAnalyticsDomainMapper.kt | 3 +- 8 files changed, 56 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/app/cashadvisor/main/presentation/ui/MainActivity.kt b/app/src/main/java/app/cashadvisor/main/presentation/ui/MainActivity.kt index 730ff9c6..17e885fc 100644 --- a/app/src/main/java/app/cashadvisor/main/presentation/ui/MainActivity.kt +++ b/app/src/main/java/app/cashadvisor/main/presentation/ui/MainActivity.kt @@ -37,6 +37,9 @@ class MainActivity : AppCompatActivity() { Timber.tag("MainActivity").w("Warning log") Timber.tag("MainActivity").e("Error log") + viewModel.getUserInfoMore() + viewModel.getUserAnalytics() + binding = ActivityMainBinding.inflate(layoutInflater).also { setContentView(it.root) } setStatusBarColor() val navHostFragment = diff --git a/app/src/main/java/app/cashadvisor/main/presentation/ui/MainViewModel.kt b/app/src/main/java/app/cashadvisor/main/presentation/ui/MainViewModel.kt index f333926e..807b0456 100644 --- a/app/src/main/java/app/cashadvisor/main/presentation/ui/MainViewModel.kt +++ b/app/src/main/java/app/cashadvisor/main/presentation/ui/MainViewModel.kt @@ -5,7 +5,10 @@ import app.cashadvisor.authorization.data.dto.CredentialsDto import app.cashadvisor.authorization.domain.api.AccountInformationInteractor import app.cashadvisor.authorization.domain.api.CredentialsRepository import app.cashadvisor.authorization.domain.models.states.AccountInformation +import app.cashadvisor.common.domain.Resource import app.cashadvisor.common.ui.BaseViewModel +import app.cashadvisor.common.utill.extensions.logDebugMessage +import app.cashadvisor.profile.domain.api.ProfileInfoInteractor import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -16,7 +19,8 @@ import javax.inject.Inject @HiltViewModel class MainViewModel @Inject constructor( private val interactor: AccountInformationInteractor, - private val storage: CredentialsRepository + private val storage: CredentialsRepository, + private val profileInfoInteractor: ProfileInfoInteractor ) : BaseViewModel(){ private val _state = MutableStateFlow(AccountInformation.NotAuthorized) @@ -36,6 +40,31 @@ class MainViewModel @Inject constructor( } } } + fun getUserInfoMore(){ + viewModelScope.launch { + when(val result = profileInfoInteractor.getUserInfoMore()) { + is Resource.Error -> { + logDebugMessage(result.error.message) + } + is Resource.Success -> { + logDebugMessage(result.data.toString()) + } + } + + } + } + fun getUserAnalytics(){ + viewModelScope.launch { + when(val result = profileInfoInteractor.getUserAnalytics()){ + is Resource.Error -> { + logDebugMessage(result.error.message) + } + is Resource.Success -> { + logDebugMessage(result.data.toString()) + } + } + } + } fun saveCredentials(accessToken: String, refreshToken: String) { viewModelScope.launch { diff --git a/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoApiService.kt b/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoApiService.kt index ffb479a5..8e6d987e 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoApiService.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/api/ProfileInfoApiService.kt @@ -36,12 +36,12 @@ interface ProfileInfoApiService { @GET("profile/more/get") suspend fun getUserInfoMore( - @Header("Profile") accessToken: String + @Header("Authorization") accessToken: String ):ProfileInfoMoreResponse @GET("profile/analytics/get") suspend fun getUserAnalytics( - @Header("Profile") accessToken: String + @Header("Authorization") accessToken: String ):ProfileAnalyticsResponse } 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 74782678..8ce6bbaf 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 @@ -8,7 +8,7 @@ data class ProfileAnalyticsResponse( @SerialName("status_code") val statusCode: Int, val message: String, @SerialName("response_currency") val responseCurrency: String, - @SerialName("profile") val userAnalyticsDto: UserAnalyticsDto + @SerialName("analytics") val userAnalyticsDto: UserAnalyticsDto ) data class ProfileAnalyticsDto( val statusCode: Int, diff --git a/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt b/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt index b8eac9ee..89f7efdb 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable data class ProfileInfoMoreResponse( @SerialName("status_code") val statusCode: Int, val message: String, - @SerialName("profile") val userInfoMoreDto: UserInfoMoreDto, + @SerialName("more") val userInfoMoreDto: UserInfoMoreDto, ) 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 b5372d0b..0e302973 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 @@ -37,8 +37,12 @@ class ProfileInfoRepositoryImpl @Inject constructor( private val profileExceptionToErrorMapper: BaseExceptionToErrorMapper ) : ProfileInfoRepository { + + private var userAnalytics:ProfileAnalytics? = null + private var userInfoMore:UserInfoMore? = null + private suspend fun getAccessToken(): String { - return credentialsRepository.getCredentials()?.accessToken ?: "" + return credentialsRepository.getCredentials()?.accessToken ?: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZXZpY2VfaWQiOiJhZWI5NGRkNi0wYTc2LTRjZmUtOWUyMC0xMTI1ODI1N2MzYzAiLCJleHAiOjE3MTcwOTM0NDUsInN1YiI6Ijc2In0.qWawbOvljWwaklSlDsgiNm8dLD_VvwcpYmTp38hIsQ4" } override suspend fun getUserInfo(): Resource { @@ -113,6 +117,7 @@ class ProfileInfoRepositoryImpl @Inject constructor( return try { val response = userInfoMoreMapper.toUserInfoMore( remoteDataSource.getUserInfoMore(getAccessToken()).userInfoMoreDto) + writeUserInfoMoreInStorage(response) Resource.Success(response) }catch (exception:Exception){ Resource.Error( @@ -129,7 +134,9 @@ class ProfileInfoRepositoryImpl @Inject constructor( analyticsDataMapper.toProfileAnalyticsDto( remoteDataSource.getUserAnalytics(getAccessToken()) )) + writeUserAnalyticsInStorage(response) Resource.Success(response) + }catch (exception:Exception){ Resource.Error( profileExceptionToErrorMapper.handleException(exception) @@ -150,6 +157,12 @@ class ProfileInfoRepositoryImpl @Inject constructor( return file } + private fun writeUserInfoMoreInStorage(userInfoMore: UserInfoMore){ + this.userInfoMore = userInfoMore + } + private fun writeUserAnalyticsInStorage(userAnalytics: ProfileAnalytics){ + this.userAnalytics = userAnalytics + } companion object { private const val BLANK_PROFILE_NAME = "Мы тебя не знаем..." diff --git a/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsDataMapper.kt b/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsDataMapper.kt index 9246e1e3..d9348f82 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsDataMapper.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/mapper/ProfileAnalyticsDataMapper.kt @@ -2,8 +2,10 @@ package app.cashadvisor.profile.data.mapper import app.cashadvisor.profile.data.dto.response.ProfileAnalyticsDto import app.cashadvisor.profile.data.dto.response.ProfileAnalyticsResponse +import javax.inject.Inject -class ProfileAnalyticsDataMapper { + +class ProfileAnalyticsDataMapper @Inject constructor(){ fun toProfileAnalyticsDto(profileAnalyticsResponse: ProfileAnalyticsResponse) = ProfileAnalyticsDto( statusCode = profileAnalyticsResponse.statusCode, message = profileAnalyticsResponse.message, diff --git a/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt b/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt index 7fd640f8..acde50b5 100644 --- a/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt +++ b/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt @@ -10,8 +10,9 @@ import app.cashadvisor.profile.domain.model.Income import app.cashadvisor.profile.domain.model.ProfileAnalytics import app.cashadvisor.profile.domain.model.UserAnalytics import app.cashadvisor.profile.domain.model.WealthFund +import javax.inject.Inject -class ProfileAnalyticsDomainMapper { +class ProfileAnalyticsDomainMapper @Inject constructor(){ fun toProfileAnalytics(profileAnalyticsDto: ProfileAnalyticsDto) = ProfileAnalytics( statusCode = profileAnalyticsDto.statusCode, message = profileAnalyticsDto.message, From 8636865fd8faa647cdf9aa8e3b75e7d1206e0426 Mon Sep 17 00:00:00 2001 From: MajoritySky2496 Date: Sun, 2 Jun 2024 12:11:13 +0500 Subject: [PATCH 5/6] 1) Fixed Dto and Models --- .../data/dto/response/ProfileAnalyticsResponse.kt | 12 ++++++------ .../data/dto/response/ProfileInfoMoreResponse.kt | 8 ++++---- .../profile/data/impl/ProfileInfoRepositoryImpl.kt | 2 +- .../domain/mapper/ProfileAnalyticsDomainMapper.kt | 6 +++--- .../domain/mapper/UserInfoMoreDomainMapper.kt | 8 ++++---- .../profile/domain/model/ProfileAnalytics.kt | 12 ++++++------ .../cashadvisor/profile/domain/model/UserInfoMore.kt | 8 ++++---- 7 files changed, 28 insertions(+), 28 deletions(-) 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 8ce6bbaf..cbc6273b 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 @@ -19,14 +19,14 @@ data class ProfileAnalyticsDto( @Serializable data class UserAnalyticsDto( - @SerialName("income") val incomeDto: List, - @SerialName("expense") val expenseDto: List, - @SerialName("wealth_fund") val wealthFundDto: List + @SerialName("income") val incomeDto: List?, + @SerialName("expense") val expenseDto: List?, + @SerialName("wealth_fund") val wealthFundDto: List? ) @Serializable data class IncomeDto( - val amount: Int, + val amount: Double, @SerialName("category_id") val categoryId: String, val date: String, val id: String, @@ -39,7 +39,7 @@ data class IncomeDto( @Serializable data class ExpenseDto( - val amount: Int, + val amount: Double, @SerialName("category_id") val categoryId: String, val date: String, val id: String, @@ -52,7 +52,7 @@ data class ExpenseDto( @Serializable data class WealthFundDto( - val amount: Int, + val amount: Double, val date: String, val id: String, val planned: Boolean, diff --git a/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt b/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt index 89f7efdb..dec7bb5a 100644 --- a/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt +++ b/app/src/main/java/app/cashadvisor/profile/data/dto/response/ProfileInfoMoreResponse.kt @@ -20,7 +20,7 @@ data class UserInfoMoreDto( @Serializable data class AppDto( @SerialName("category_settings") val categorySettingsDto: CategorySettingsDto, - @SerialName("connected_accounts") val connectedAccountsDto: List + @SerialName("connected_accounts") val connectedAccountsDto: List? ) @Serializable @@ -30,9 +30,9 @@ data class SettingsDto( @Serializable data class CategorySettingsDto( - @SerialName("expense_categories") val expenseCategoriesDto: List, - @SerialName("income_categories") val incomeCategoriesDto: List, - @SerialName("investment_categories") val investmentCategoriesDto: List + @SerialName("expense_categories") val expenseCategoriesDto: List?, + @SerialName("income_categories") val incomeCategoriesDto: List?, + @SerialName("investment_category") val investmentCategoriesDto: List? ) @Serializable 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 0e302973..7efbcc33 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 @@ -42,7 +42,7 @@ class ProfileInfoRepositoryImpl @Inject constructor( private var userInfoMore:UserInfoMore? = null private suspend fun getAccessToken(): String { - return credentialsRepository.getCredentials()?.accessToken ?: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZXZpY2VfaWQiOiJhZWI5NGRkNi0wYTc2LTRjZmUtOWUyMC0xMTI1ODI1N2MzYzAiLCJleHAiOjE3MTcwOTM0NDUsInN1YiI6Ijc2In0.qWawbOvljWwaklSlDsgiNm8dLD_VvwcpYmTp38hIsQ4" + return credentialsRepository.getCredentials()?.accessToken ?: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZXZpY2VfaWQiOiI2MjFjOTc1OS05ZmY5LTRhNjUtYjI4Mi1hMmEwYmRkYjUxM2IiLCJleHAiOjE3MTczMTA0NjgsInN1YiI6Ijc2In0.enVexw46lCNoIHdu-wkaIbAUjuY4pdd-QszTDCBheGE" } override suspend fun getUserInfo(): Resource { diff --git a/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt b/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt index acde50b5..3aa457bc 100644 --- a/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt +++ b/app/src/main/java/app/cashadvisor/profile/domain/mapper/ProfileAnalyticsDomainMapper.kt @@ -20,9 +20,9 @@ class ProfileAnalyticsDomainMapper @Inject constructor(){ 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) } + 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, diff --git a/app/src/main/java/app/cashadvisor/profile/domain/mapper/UserInfoMoreDomainMapper.kt b/app/src/main/java/app/cashadvisor/profile/domain/mapper/UserInfoMoreDomainMapper.kt index 070e8651..f74b6c27 100644 --- a/app/src/main/java/app/cashadvisor/profile/domain/mapper/UserInfoMoreDomainMapper.kt +++ b/app/src/main/java/app/cashadvisor/profile/domain/mapper/UserInfoMoreDomainMapper.kt @@ -28,16 +28,16 @@ class UserInfoMoreDomainMapper @Inject constructor() { private fun toApp(appDto: AppDto) = App( categorySettings = toCategorySettings(appDto.categorySettingsDto), - connectedAccounts = appDto.connectedAccountsDto.map { toConnectedAccounts(it) } + connectedAccounts = appDto.connectedAccountsDto?.map { toConnectedAccounts(it) } ) 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) } + expenseCategories = categorySettingsDto.expenseCategoriesDto?.map { toExpenseCategories(it) }, + incomeCategories = categorySettingsDto.incomeCategoriesDto?.map { toIncomeCategories(it) }, + investmentCategories = categorySettingsDto.investmentCategoriesDto?.map { toInvestmentCategories(it) } ) private fun toConnectedAccounts(connectedAccountDto: ConnectedAccountDto) = ConnectedAccount( id = connectedAccountDto.id, diff --git a/app/src/main/java/app/cashadvisor/profile/domain/model/ProfileAnalytics.kt b/app/src/main/java/app/cashadvisor/profile/domain/model/ProfileAnalytics.kt index 80ebec51..4330aa8c 100644 --- a/app/src/main/java/app/cashadvisor/profile/domain/model/ProfileAnalytics.kt +++ b/app/src/main/java/app/cashadvisor/profile/domain/model/ProfileAnalytics.kt @@ -8,13 +8,13 @@ data class ProfileAnalytics( ) data class UserAnalytics( - val income: List, - val expense: List, - val wealthFund: List + val income: List?, + val expense: List?, + val wealthFund: List? ) data class Income( - val amount: Int, + val amount: Double, val categoryId: String, val date: String, val id: String, @@ -26,7 +26,7 @@ data class Income( ) data class Expense( - val amount: Int, + val amount: Double, val categoryId: String, val date: String, val id: String, @@ -38,7 +38,7 @@ data class Expense( ) data class WealthFund( - val amount: Int, + val amount: Double, val date: String, val id: String, val planned: Boolean, 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 bd6bcaa6..6ebf092b 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 @@ -8,7 +8,7 @@ data class UserInfoMore( data class App( val categorySettings: CategorySettings, - val connectedAccounts: List + val connectedAccounts: List? ) data class Settings( @@ -16,9 +16,9 @@ data class Settings( ) data class CategorySettings( - val expenseCategories: List, - val incomeCategories: List, - val investmentCategories: List + val expenseCategories: List?, + val incomeCategories: List?, + val investmentCategories: List? ) data class ConnectedAccount( From fe5022502a5be9f7d11157d71ee32c00871bace9 Mon Sep 17 00:00:00 2001 From: MajoritySky2496 Date: Mon, 3 Jun 2024 22:35:42 +0500 Subject: [PATCH 6/6] 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 cbc6273b..dbf72281 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 d771166c..e4408cd3 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 7efbcc33..2c165bd2 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 d2db42be..40cb7e71 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 3aa457bc..952bf47d 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 f74b6c27..35b3a04c 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 4a8d30dc..ba2e8f2f 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 6ebf092b..df2a98f1 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,