Skip to content

Commit a6e7c52

Browse files
committed
refactor(details): use domain model for profile caching and cleanup DTOs
This commit simplifies the user profile data handling by using the `GithubUserProfile` domain model directly for caching and removing redundant DTOs and mappers. - **refactor(details)**: Removed `GithubUserProfileDto` and its associated mapper. - **refactor(details)**: Updated `DetailsRepositoryImpl` to cache and retrieve `GithubUserProfile` directly instead of using a DTO. - **feat(core)**: Added `@Serializable` to `GithubUserProfile` and `PaginatedDiscoveryRepositories` to support serialization/caching. - **chore**: Cleaned up unused imports in `ProfileRepositoryImpl` and `DetailsRepositoryImpl`.
1 parent cd41c1f commit a6e7c52

6 files changed

Lines changed: 12 additions & 51 deletions

File tree

core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/GithubUserProfile.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package zed.rainxch.core.domain.model
22

3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
36
data class GithubUserProfile(
47
val id: Long,
58
val login: String,

core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/PaginatedDiscoveryRepositories.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package zed.rainxch.core.domain.model
22

3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
36
data class PaginatedDiscoveryRepositories(
47
val repos: List<GithubRepoSummary>,
58
val hasMore: Boolean,

feature/details/data/src/commonMain/kotlin/zed/rainxch/details/data/mappers/GithubUserProfileMapper.kt

Lines changed: 0 additions & 22 deletions
This file was deleted.

feature/details/data/src/commonMain/kotlin/zed/rainxch/details/data/model/GithubUserProfileDto.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

feature/details/data/src/commonMain/kotlin/zed/rainxch/details/data/repository/DetailsRepositoryImpl.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import zed.rainxch.core.data.dto.UserProfileNetwork
2828
import zed.rainxch.core.domain.logging.GitHubStoreLogger
2929
import zed.rainxch.core.data.mappers.toDomain
3030
import zed.rainxch.core.domain.model.GithubUserProfile
31-
import zed.rainxch.details.data.mappers.toDomain
32-
import zed.rainxch.details.data.model.GithubUserProfileDto
3331
import zed.rainxch.details.data.utils.ReadmeLocalizationHelper
3432
import zed.rainxch.details.data.utils.preprocessMarkdown
3533
import zed.rainxch.details.domain.model.RepoStats
@@ -419,9 +417,9 @@ class DetailsRepositoryImpl(
419417
override suspend fun getUserProfile(username: String): GithubUserProfile {
420418
val cacheKey = "details:profile:$username"
421419

422-
cacheManager.get<GithubUserProfileDto>(cacheKey)?.let { cached ->
420+
cacheManager.get<GithubUserProfile>(cacheKey)?.let { cached ->
423421
logger.debug("Cache hit for user profile $username")
424-
return cached.toDomain()
422+
return cached
425423
}
426424

427425
return try {
@@ -431,7 +429,7 @@ class DetailsRepositoryImpl(
431429
}
432430
}.getOrThrow()
433431

434-
val result = GithubUserProfileDto(
432+
val result = GithubUserProfile(
435433
id = user.id,
436434
login = user.login,
437435
name = user.name,
@@ -445,14 +443,14 @@ class DetailsRepositoryImpl(
445443
company = user.company,
446444
blog = user.blog,
447445
twitterUsername = user.twitterUsername
448-
).toDomain()
446+
)
449447

450448
cacheManager.put(cacheKey, result, USER_PROFILE)
451449
result
452450
} catch (e: Exception) {
453-
cacheManager.getStale<GithubUserProfileDto>(cacheKey)?.let { stale ->
451+
cacheManager.getStale<GithubUserProfile>(cacheKey)?.let { stale ->
454452
logger.debug("Network error, using stale cache for profile $username")
455-
return stale.toDomain()
453+
return stale
456454
}
457455
throw e
458456
}

feature/profile/data/src/commonMain/kotlin/zed/rainxch/profile/data/repository/ProfileRepositoryImpl.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import kotlinx.coroutines.flow.flow
1010
import kotlinx.coroutines.flow.flowOn
1111
import zed.rainxch.core.data.cache.CacheManager
1212
import zed.rainxch.core.data.cache.CacheManager.CacheTtl.USER_PROFILE
13-
import zed.rainxch.core.data.cache.CacheTtl
1413
import zed.rainxch.core.data.data_source.TokenStore
1514
import zed.rainxch.core.data.dto.UserProfileNetwork
1615
import zed.rainxch.core.data.network.executeRequest

0 commit comments

Comments
 (0)