Skip to content

Commit 451822e

Browse files
committed
Refactor Firestore response handling and remove unused strings
1 parent 4631445 commit 451822e

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Access the latest APK for Kotlin Dictionary from the link below.
3535
- [x] Add code block for syntax display on the `Detail Screen`
3636
- [ ] Implement caching on the `Detail Screen` to store previously viewed topic data
3737
- [x] Implement dynamic topic loading in `TopicRepository` to support scalability
38-
- [ ] Integrate Room database to persist bookmark states
38+
- [ ] Add bookmark feature for topic cards to allow users to save and revisit important topics
3939
- [ ] Add a `Home Page` for navigation
4040
- [ ] Add a `Quiz Page` to host topic-based quizzes
4141
- [ ] Add a button in `DetailScreen` to attempt a quiz for that topic

composeApp/src/commonMain/composeResources/values/string.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
<string name="topics">Topics</string>
2424
<string name="description_subtitle">Description need to be added</string>
2525
<string name="icon">Icon</string>
26-
<string name="remove_bookmark">Remove bookmark</string>
27-
<string name="add_bookmark">Add bookmark</string>
2826
<string name="search_kotlin_terms">Search Kotlin terms...</string>
2927
<string name="search">Search</string>
3028
</resources>
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,30 @@ package com.developersbreach.kotlindictionarymultiplatform.data.topic.model
33
import kotlinx.serialization.SerialName
44
import kotlinx.serialization.Serializable
55

6+
@Serializable
7+
data class TopicResponse(
8+
@SerialName("documents") val topics: List<RawTopic>,
9+
)
10+
611
@Serializable
712
data class RawTopic(
8-
@SerialName("fields") val fields: Map<String, RawField>,
13+
@SerialName("fields") val fields: TopicFields,
914
)
1015

1116
@Serializable
12-
data class RawField(
13-
@SerialName("stringValue") val value: String,
17+
data class TopicFields(
18+
@SerialName("name") val name: RawField,
19+
@SerialName("description") val description: RawField,
1420
)
1521

1622
@Serializable
17-
data class Response(
18-
@SerialName("documents") val topics: List<RawTopic>,
23+
data class RawField(
24+
@SerialName("stringValue") val value: String,
1925
)
2026

2127
fun RawTopic.toTopic(): Topic {
2228
return Topic(
23-
name = fields["name"]?.value.orEmpty(),
24-
description = fields["description"]?.value.orEmpty(),
29+
name = fields.name.value,
30+
description = fields.description.value,
2531
)
2632
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.developersbreach.kotlindictionarymultiplatform.data.topic.repository
22

33
import arrow.core.Either
4-
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Response
4+
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.TopicResponse
55
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Topic
66
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.toTopic
77
import com.developersbreach.kotlindictionarymultiplatform.core.network.topicSource.FirestoreConstants
@@ -14,8 +14,8 @@ class TopicRepository(
1414
) {
1515
suspend fun getTopics(): Either<Throwable, List<Topic>> {
1616
return Either.catch {
17-
val response: Response = httpClient.get(FirestoreConstants.TOPICS_URL).body()
18-
response.topics.map { it.toTopic() }
17+
val topicResponse: TopicResponse = httpClient.get(FirestoreConstants.TOPICS_URL).body()
18+
topicResponse.topics.map { it.toTopic() }
1919
}
2020
}
2121
}

0 commit comments

Comments
 (0)