-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradlew.bat
54 lines (49 loc) · 2.21 KB
/
gradlew.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package ru.home.collaborativeeducation.network
import io.reactivex.Observable
import ru.home.collaborativeeducation.model.*
import ru.home.collaborativeeducation.model.converter.CourseWithMetaConverter
import ru.home.collaborativeeducation.model.database.CourseSourceEntity
import ru.home.collaborativeeducation.network.model.ApiResponse
import ru.home.collaborativeeducation.network.model.CoursePayload
import ru.home.collaborativeeducation.storage.model.CourseWithMetadataAndCommentsEntity
import ru.home.collaborativeeducation.storage.model.ItemMetadataEntity
import ru.home.collaborativeeducation.storage.model.LikesEntity
class NetworkRepository(val api: Api) {
fun getCategoryViewItems(): Observable<List<CategoryViewItem>> {
return api.getAllCategories
.flatMap { it ->
val result = mutableListOf<CategoryViewItem>()
if (it.code != 200) {
// no op
} else {
for (item in it.status.payload) {
val obj = CategoryViewItem(item.uid, item.title)
result.add(obj)
}
}
Observable.just(result)
}
}
fun saveCategoryViewItem(data: CategoryViewItem): Observable<CategoryViewItem> {
return api.create(data)
.flatMap { it ->
lateinit var response: CategoryViewItem
if (it.code != 200) {
response = CategoryViewItem(-1, "")
} else {
val item = it.status.payload[0]
response = CategoryViewItem(item.uid, item.title)
}
Observable.just(response)
}
}
fun getCoursesForCategory(categoryUid: String): Observable<List<CourseViewItem>> {
return api.getAllCoursesForCategory(categoryUid)
.flatMap { it ->
val result = mutableListOf<CourseViewItem>()
if (it.code != 200) {
// no op
} else {
for (item in it.status.payload) {
val obj = CourseViewItem(item.uid, item.title, item.categoryUid)
result.add(obj)