Skip to content

Commit cceca0e

Browse files
authored
Implemented comments parser (#3)
1 parent 51be3a5 commit cceca0e

File tree

37 files changed

+483
-51
lines changed

37 files changed

+483
-51
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.shifthackz.joyreactor.data.datasource.remote
2+
3+
import com.shifthackz.joyreactor.domain.datasource.CommentsDataSource
4+
import com.shifthackz.joyreactor.entity.Comment
5+
import com.shifthackz.joyreactor.network.parser.CommentsParser
6+
7+
class CommentsRemoteDataSource(
8+
private val commentsParser: CommentsParser,
9+
) : CommentsDataSource.Remote {
10+
11+
override suspend fun fetchComments(postId: String): List<Comment> {
12+
return commentsParser.fetchComments(postId)
13+
}
14+
}

data/src/main/java/com/shifthackz/joyreactor/data/di/Modules.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
package com.shifthackz.joyreactor.data.di
22

33
import com.shifthackz.joyreactor.data.datasource.local.PostsLocalDataSource
4+
import com.shifthackz.joyreactor.data.datasource.remote.CommentsRemoteDataSource
45
import com.shifthackz.joyreactor.data.datasource.remote.PostsRemoteDataSource
6+
import com.shifthackz.joyreactor.data.repository.CommentsRepositoryImpl
57
import com.shifthackz.joyreactor.data.repository.PostsRepositoryImpl
8+
import com.shifthackz.joyreactor.domain.datasource.CommentsDataSource
69
import com.shifthackz.joyreactor.domain.datasource.PostsDataSource
10+
import com.shifthackz.joyreactor.domain.repository.CommentsRepository
711
import com.shifthackz.joyreactor.domain.repository.PostsRepository
812
import org.koin.core.module.dsl.factoryOf
913
import org.koin.dsl.bind
1014
import org.koin.dsl.module
1115

1216
internal val remoteDataSourceModule = module {
1317
factoryOf(::PostsRemoteDataSource) bind PostsDataSource.Remote::class
18+
factoryOf(::CommentsRemoteDataSource) bind CommentsDataSource.Remote::class
1419
}
1520

1621
internal val localDataSourceModule = module {
@@ -19,6 +24,7 @@ internal val localDataSourceModule = module {
1924

2025
internal val repositoryModule = module {
2126
factoryOf(::PostsRepositoryImpl) bind PostsRepository::class
27+
factoryOf(::CommentsRepositoryImpl) bind CommentsRepository::class
2228
}
2329

2430
val dataModule = (remoteDataSourceModule + localDataSourceModule + repositoryModule).toTypedArray()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ fun FullPostDto.toDomain(): Post = with(this) {
3636
contents = contents.map(ContentEntity::toDomain),
3737
tags = tags.map(TagEntity::toDomain),
3838
rating = post.rating,
39+
comments = emptyList(),
3940
)
4041
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.shifthackz.joyreactor.data.repository
2+
3+
import com.shifthackz.joyreactor.domain.datasource.CommentsDataSource
4+
import com.shifthackz.joyreactor.domain.repository.CommentsRepository
5+
import com.shifthackz.joyreactor.entity.Comment
6+
7+
internal class CommentsRepositoryImpl(
8+
private val commendsRds: CommentsDataSource.Remote,
9+
) : CommentsRepository {
10+
11+
override suspend fun fetchComments(postId: String): List<Comment> {
12+
return commendsRds.fetchComments(postId)
13+
}
14+
}

dependencies.gradle

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ ext {
1111
koinVersion = '3.4.3'
1212
koinComposeVersion = '3.4.6'
1313
coilComposeVersion = '2.4.0'
14-
// retrofitVersion = '2.9.0'
15-
// okHttpVersion = '5.0.0-alpha.11'
14+
retrofitVersion = '2.9.0'
15+
okHttpVersion = '5.0.0-alpha.11'
1616
roomVersion = '2.5.2'
1717
jsoupVersion = '1.16.1'
1818
coroutinesVersion = '1.7.3'
@@ -63,15 +63,14 @@ ext {
6363
coilGif : "io.coil-kt:coil-gif:$coilComposeVersion",
6464
zoomable: "net.engawapg.lib:zoomable:$zoomableVersion"
6565
]
66-
// retrofit = [
67-
// core : "com.squareup.retrofit2:retrofit:$retrofitVersion",
68-
// converterGson: "com.squareup.retrofit2:converter-gson:$retrofitVersion",
69-
// adapterRx : "com.squareup.retrofit2:adapter-rxjava3:$retrofitVersion",
70-
// ]
71-
// okhttp = [
72-
// core : "com.squareup.okhttp3:okhttp:$okHttpVersion",
73-
// logging: "com.squareup.okhttp3:logging-interceptor:$okHttpVersion",
74-
// ]
66+
retrofit = [
67+
core : "com.squareup.retrofit2:retrofit:$retrofitVersion",
68+
converterGson: "com.squareup.retrofit2:converter-gson:$retrofitVersion",
69+
]
70+
okhttp = [
71+
core : "com.squareup.okhttp3:okhttp:$okHttpVersion",
72+
logging: "com.squareup.okhttp3:logging-interceptor:$okHttpVersion",
73+
]
7574
database = [
7675
roomRuntime : "androidx.room:room-runtime:$roomVersion",
7776
roomKtx : "androidx.room:room-ktx:$roomVersion",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.shifthackz.joyreactor.domain.datasource
2+
3+
import com.shifthackz.joyreactor.entity.Comment
4+
5+
sealed interface CommentsDataSource {
6+
7+
interface Remote {
8+
suspend fun fetchComments(postId: String): List<Comment>
9+
}
10+
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.shifthackz.joyreactor.domain.di
22

3-
import com.shifthackz.joyreactor.domain.usecase.FetchPostsPageUseCase
4-
import com.shifthackz.joyreactor.domain.usecase.FetchPostsPageUseCaseImpl
5-
import com.shifthackz.joyreactor.domain.usecase.GetFullPostUseCase
6-
import com.shifthackz.joyreactor.domain.usecase.GetFullPostUseCaseImpl
3+
import com.shifthackz.joyreactor.domain.usecase.comment.FetchPostCommentsUseCase
4+
import com.shifthackz.joyreactor.domain.usecase.comment.FetchPostCommentsUseCaseImpl
5+
import com.shifthackz.joyreactor.domain.usecase.post.FetchPostsPageUseCase
6+
import com.shifthackz.joyreactor.domain.usecase.post.FetchPostsPageUseCaseImpl
7+
import com.shifthackz.joyreactor.domain.usecase.post.GetFullPostUseCase
8+
import com.shifthackz.joyreactor.domain.usecase.post.GetFullPostUseCaseImpl
79
import org.koin.core.module.dsl.factoryOf
810
import org.koin.dsl.bind
911
import org.koin.dsl.module
1012

1113
val domainModule = module {
1214
factoryOf(::FetchPostsPageUseCaseImpl) bind FetchPostsPageUseCase::class
1315
factoryOf(::GetFullPostUseCaseImpl) bind GetFullPostUseCase::class
16+
factoryOf(::FetchPostCommentsUseCaseImpl) bind FetchPostCommentsUseCase::class
1417
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.shifthackz.joyreactor.domain.repository
2+
3+
import com.shifthackz.joyreactor.entity.Comment
4+
5+
interface CommentsRepository {
6+
suspend fun fetchComments(postId: String): List<Comment>
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.shifthackz.joyreactor.domain.usecase.comment
2+
3+
import com.shifthackz.joyreactor.entity.Comment
4+
5+
interface FetchPostCommentsUseCase {
6+
suspend operator fun invoke(postId: String): List<Comment>
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.shifthackz.joyreactor.domain.usecase.comment
2+
3+
import com.shifthackz.joyreactor.domain.repository.CommentsRepository
4+
import com.shifthackz.joyreactor.entity.Comment
5+
6+
internal class FetchPostCommentsUseCaseImpl(
7+
private val commentsRepository: CommentsRepository,
8+
) : FetchPostCommentsUseCase {
9+
10+
override suspend fun invoke(postId: String): List<Comment> {
11+
return commentsRepository.fetchComments(postId)
12+
}
13+
}

0 commit comments

Comments
 (0)