Skip to content

Commit 83f228e

Browse files
committed
Update
1 parent cceca0e commit 83f228e

File tree

52 files changed

+1414
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1414
-409
lines changed

data/src/main/java/com/shifthackz/joyreactor/data/datasource/local/PostsLocalDataSource.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ internal class PostsLocalDataSource(
3939
contentDao.upsertList(posts.map(Post::toContentEntities).flatten())
4040
}
4141

42-
override suspend fun getPost(id: String): Post {
43-
return postDao.queryById(id).let(FullPostDto::toDomain)
42+
override suspend fun getPost(id: String): Result<Post> = runCatching {
43+
postDao.queryById(id).let(FullPostDto::toDomain)
4444
}
4545

4646
private suspend fun saveAuthors(authors: List<Author>) {

data/src/main/java/com/shifthackz/joyreactor/data/datasource/remote/CommentsRemoteDataSource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class CommentsRemoteDataSource(
88
private val commentsParser: CommentsParser,
99
) : CommentsDataSource.Remote {
1010

11-
override suspend fun fetchComments(postId: String): List<Comment> {
11+
override suspend fun fetchComments(postId: String): Result<List<Comment>> {
1212
return commentsParser.fetchComments(postId)
1313
}
1414
}

data/src/main/java/com/shifthackz/joyreactor/data/datasource/remote/PostsRemoteDataSource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal class PostsRemoteDataSource(
99
private val postsParser: PostsParser,
1010
) : PostsDataSource.Remote {
1111

12-
override suspend fun fetchPage(url: String): PagePayload<Post> {
12+
override suspend fun fetchPage(url: String): Result<PagePayload<Post>> {
1313
return postsParser.fetchPage(url)
1414
}
1515
}

data/src/main/java/com/shifthackz/joyreactor/data/mappers/PostMappers.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import com.shifthackz.joyreactor.storage.db.dto.FullPostDto
66
import com.shifthackz.joyreactor.storage.db.entity.ContentEntity
77
import com.shifthackz.joyreactor.storage.db.entity.PostEntity
88
import com.shifthackz.joyreactor.storage.db.entity.TagEntity
9+
import java.util.Date
910

1011
fun Post.toEntity(): PostEntity = with(this) {
1112
PostEntity(
1213
id = id,
1314
rating = rating,
1415
authorName = author.name,
16+
estimatedCommentsCount = estimatedCommentsCount,
17+
date = date.time,
18+
url = url,
1519
)
1620
}
1721

@@ -37,5 +41,8 @@ fun FullPostDto.toDomain(): Post = with(this) {
3741
tags = tags.map(TagEntity::toDomain),
3842
rating = post.rating,
3943
comments = emptyList(),
44+
estimatedCommentsCount = post.estimatedCommentsCount,
45+
date = Date(post.date),
46+
url = post.url,
4047
)
4148
}

data/src/main/java/com/shifthackz/joyreactor/data/repository/CommentsRepositoryImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal class CommentsRepositoryImpl(
88
private val commendsRds: CommentsDataSource.Remote,
99
) : CommentsRepository {
1010

11-
override suspend fun fetchComments(postId: String): List<Comment> {
11+
override suspend fun fetchComments(postId: String): Result<List<Comment>> {
1212
return commendsRds.fetchComments(postId)
1313
}
1414
}

data/src/main/java/com/shifthackz/joyreactor/data/repository/PostsRepositoryImpl.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ class PostsRepositoryImpl(
1111
private val postsLds: PostsDataSource.Local,
1212
) : PostsRepository {
1313

14-
override suspend fun fetchPage(url: String): PagePayload<Post> = coroutineScope {
15-
val page = postsRds.fetchPage(url)
16-
postsLds.savePosts(page.data)
17-
return@coroutineScope page
14+
override suspend fun fetchPage(url: String): Result<PagePayload<Post>> = coroutineScope {
15+
return@coroutineScope postsRds.fetchPage(url).getOrNull()?.let {
16+
postsLds.savePosts(it.data)
17+
Result.success(it)
18+
} ?: Result.failure(IllegalStateException())
1819
}
1920

20-
override suspend fun getPost(id: String): Post {
21+
override suspend fun getPost(id: String): Result<Post> {
2122
return postsLds.getPost(id)
2223
}
2324
}

domain/src/main/java/com/shifthackz/joyreactor/domain/datasource/CommentsDataSource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import com.shifthackz.joyreactor.entity.Comment
55
sealed interface CommentsDataSource {
66

77
interface Remote {
8-
suspend fun fetchComments(postId: String): List<Comment>
8+
suspend fun fetchComments(postId: String): Result<List<Comment>>
99
}
1010
}

domain/src/main/java/com/shifthackz/joyreactor/domain/datasource/PostsDataSource.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import com.shifthackz.joyreactor.entity.Post
66
sealed interface PostsDataSource {
77

88
interface Remote : PostsDataSource {
9-
suspend fun fetchPage(url: String): PagePayload<Post>
9+
suspend fun fetchPage(url: String): Result<PagePayload<Post>>
1010
}
1111

1212
interface Local : PostsDataSource {
1313
suspend fun savePosts(posts: List<Post>)
14-
suspend fun getPost(id: String): Post
14+
suspend fun getPost(id: String): Result<Post>
1515
}
1616
}

domain/src/main/java/com/shifthackz/joyreactor/domain/repository/CommentsRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ package com.shifthackz.joyreactor.domain.repository
33
import com.shifthackz.joyreactor.entity.Comment
44

55
interface CommentsRepository {
6-
suspend fun fetchComments(postId: String): List<Comment>
6+
suspend fun fetchComments(postId: String): Result<List<Comment>>
77
}

domain/src/main/java/com/shifthackz/joyreactor/domain/repository/PostsRepository.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import com.shifthackz.joyreactor.entity.PagePayload
44
import com.shifthackz.joyreactor.entity.Post
55

66
interface PostsRepository {
7-
suspend fun fetchPage(url: String): PagePayload<Post>
8-
suspend fun getPost(id: String): Post
7+
suspend fun fetchPage(url: String): Result<PagePayload<Post>>
8+
suspend fun getPost(id: String): Result<Post>
99
}

0 commit comments

Comments
 (0)