File tree Expand file tree Collapse file tree 2 files changed +21
-14
lines changed
app/src/main/java/org/fossasia/openevent/general/event Expand file tree Collapse file tree 2 files changed +21
-14
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import androidx.room.OnConflictStrategy.REPLACE
6
6
import androidx.room.Query
7
7
import io.reactivex.Flowable
8
8
import io.reactivex.Single
9
+ import org.fossasia.openevent.general.event.topic.EventTopic
9
10
10
11
@Dao
11
12
interface EventDao {
@@ -36,6 +37,9 @@ interface EventDao {
36
37
@Query(" SELECT id from Event WHERE favorite = 1 AND id in (:ids)" )
37
38
fun getFavoriteEventWithinIds (ids : List <Long >): Single <List <Long >>
38
39
39
- @Query(" SELECT * from Event WHERE eventTopic = :topicId" )
40
- fun getAllSimilarEvents (topicId : Long ): Flowable <List <Event >>
40
+ @Query(" SELECT * from Event WHERE eventTopic = :eventTopic" )
41
+ fun getAllSimilarEvents (eventTopic : EventTopic ): Flowable <List <Event >>
42
+
43
+ @Query(" SELECT * FROM EventTopic WHERE id=:topicId" )
44
+ fun getEventTopic (topicId : Long ): Single <EventTopic >
41
45
}
Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ import org.fossasia.openevent.general.event.types.EventType
16
16
import org.fossasia.openevent.general.event.types.EventTypesApi
17
17
import org.fossasia.openevent.general.sessions.Session
18
18
import org.fossasia.openevent.general.sessions.SessionApi
19
- import java.util.Locale.filter
20
19
21
20
class EventService (
22
21
private val eventApi : EventApi ,
@@ -131,20 +130,24 @@ class EventService(
131
130
}
132
131
133
132
fun getSimilarEvents (id : Long ): Flowable <List <Event >> {
134
- val eventsFlowable = eventDao.getAllSimilarEvents(id)
135
- return eventsFlowable.switchMap {
136
- if (it.isNotEmpty())
137
- eventsFlowable
138
- else
139
- eventTopicApi.getEventsUnderTopicId(id)
140
- .toFlowable()
141
- .map {
142
- eventDao.insertEvents(it)
133
+ val eventsFlowable = eventDao.getEventTopic(id)
134
+ .flatMapPublisher {
135
+ eventDao.getAllSimilarEvents(it)
136
+ }
137
+ return eventsFlowable
138
+ .switchMap {
139
+ if (it.isNotEmpty()) {
140
+ eventsFlowable
141
+ } else {
142
+ eventTopicApi.getEventsUnderTopicId(id)
143
+ .map { list ->
144
+ eventDao.insertEvents(list)
143
145
}
144
- .flatMap {
146
+ .flatMapPublisher {
145
147
eventsFlowable
146
148
}
147
- }
149
+ }
150
+ }
148
151
}
149
152
150
153
private fun buildQuery (eventIds : List <Long >): String {
You can’t perform that action at this time.
0 commit comments