Skip to content

Commit bd85fab

Browse files
committed
Refactor TopicRepository to use constructor injection for HttpClient.
1 parent fa724f5 commit bd85fab

File tree

1 file changed

+5
-22
lines changed
  • composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/topic/repository

1 file changed

+5
-22
lines changed

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/topic/repository/TopicRepository.kt

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,14 @@ import com.developersbreach.kotlindictionarymultiplatform.core.network.topicSour
88
import io.ktor.client.HttpClient
99
import io.ktor.client.call.body
1010
import io.ktor.client.request.get
11-
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
12-
import io.ktor.serialization.kotlinx.json.json
13-
import kotlinx.serialization.json.Json
14-
15-
//object TopicRepository {
16-
//
17-
// private val client = HttpClient {
18-
// install(ContentNegotiation) {
19-
// json(Json { ignoreUnknownKeys = true })
20-
// }
21-
// }
22-
//
23-
// suspend fun getTopics(): Either<Throwable, List<Topic>> {
24-
// return Either.catch {
25-
// val response: Response = client.get(FirestoreConstants.TOPICS_URL).body()
26-
// response.topics.map { it.toTopic() }
27-
// }
28-
// }
29-
//}
3011

3112
class TopicRepository(
32-
private val httpClient: HttpClient
33-
){
34-
suspend fun getTopics(): Either<Throwable, List<Topic>> = Either.catch {
13+
private val httpClient: HttpClient,
14+
) {
15+
suspend fun getTopics(): Either<Throwable, List<Topic>> {
16+
return Either.catch {
3517
val response: Response = httpClient.get(FirestoreConstants.TOPICS_URL).body()
3618
response.topics.map { it.toTopic() }
19+
}
3720
}
3821
}

0 commit comments

Comments
 (0)