Skip to content

Commit

Permalink
fix: Show only upcoming or ongoing events (#1753)
Browse files Browse the repository at this point in the history
  • Loading branch information
liveHarshit authored and iamareebjamal committed May 17, 2019
1 parent cb3ee5a commit d6b7ead
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
Expand Up @@ -14,7 +14,7 @@ import org.fossasia.openevent.general.event.topic.EventTopicApi
import org.fossasia.openevent.general.event.topic.EventTopicsDao
import org.fossasia.openevent.general.event.types.EventType
import org.fossasia.openevent.general.event.types.EventTypesApi
import java.util.Locale.filter
import java.util.Date

class EventService(
private val eventApi: EventApi,
Expand Down Expand Up @@ -88,7 +88,8 @@ class EventService(
}

fun getEventsByLocation(locationName: String?): Single<List<Event>> {
val query = "[{\"name\":\"location-name\",\"op\":\"ilike\",\"val\":\"%$locationName%\"}]"
val query = "[{\"name\":\"location-name\",\"op\":\"ilike\",\"val\":\"%$locationName%\"}," +
"{\"name\":\"ends-at\",\"op\":\"ge\",\"val\":\"%${EventUtils.getTimeInISO8601(Date())}%\"}]"
return eventApi.searchEvents("name", query).flatMap { apiList ->
val eventIds = apiList.map { it.id }.toList()
eventTopicsDao.insertEventTopics(getEventTopicList(apiList))
Expand Down
Expand Up @@ -22,6 +22,7 @@ import java.io.FileOutputStream
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.TimeZone

object EventUtils {

Expand Down Expand Up @@ -269,4 +270,11 @@ object EventUtils {
bmpUri
}
}

fun getTimeInISO8601(date: Date): String {
val tz = TimeZone.getTimeZone(TimeZone.getDefault().id)
val df = SimpleDateFormat("yyyy-MM-dd'T'HH:mm", Locale.getDefault())
df.timeZone = tz
return df.format(date)
}
}
Expand Up @@ -14,6 +14,7 @@ import org.fossasia.openevent.general.data.Preference
import org.fossasia.openevent.general.data.Resource
import org.fossasia.openevent.general.event.Event
import org.fossasia.openevent.general.event.EventService
import org.fossasia.openevent.general.event.EventUtils
import org.fossasia.openevent.general.event.types.EventType
import org.fossasia.openevent.general.utils.DateTimeUtils.getNextDate
import org.fossasia.openevent.general.utils.DateTimeUtils.getNextMonth
Expand All @@ -22,6 +23,7 @@ import org.fossasia.openevent.general.utils.DateTimeUtils.getNextToNextMonth
import org.fossasia.openevent.general.utils.DateTimeUtils.getNextToWeekendDate
import org.fossasia.openevent.general.utils.DateTimeUtils.getWeekendDate
import timber.log.Timber
import java.util.Date

class SearchViewModel(
private val eventService: EventService,
Expand Down Expand Up @@ -97,15 +99,23 @@ class SearchViewModel(
| 'op':'eq',
| 'val':'0'
| }
|}
|}, {
| 'name':'ends-at',
| 'op':'ge',
| 'val':'%${EventUtils.getTimeInISO8601(Date())}%'
| }
""".trimIndent()
else ""
val query: String = when {
TextUtils.isEmpty(location) -> """[{
| 'name':'name',
| 'op':'ilike',
| 'val':'%$searchEvent%'
|}]""".trimMargin().replace("'", "'")
|}, {
| 'name':'ends-at',
| 'op':'ge',
| 'val':'%${EventUtils.getTimeInISO8601(Date())}%'
| }]""".trimMargin().replace("'", "'")
time == "Anytime" && type == "Anything" -> """[{
| 'and':[{
| 'name':'location-name',
Expand All @@ -115,6 +125,10 @@ class SearchViewModel(
| 'name':'name',
| 'op':'ilike',
| 'val':'%$searchEvent%'
| }, {
| 'name':'ends-at',
| 'op':'ge',
| 'val':'%${EventUtils.getTimeInISO8601(Date())}%'
| }$freeStuffFilter]
|}]""".trimMargin().replace("'", "\"")
time == "Anytime" -> """[{
Expand All @@ -134,6 +148,10 @@ class SearchViewModel(
| 'op':'eq',
| 'val':'$type'
| }
| }, {
| 'name':'ends-at',
| 'op':'ge',
| 'val':'%${EventUtils.getTimeInISO8601(Date())}%'
| }$freeStuffFilter]
|}]""".trimMargin().replace("'", "\"")
time == "Today" -> """[{
Expand Down Expand Up @@ -161,7 +179,11 @@ class SearchViewModel(
| 'op':'eq',
| 'val':'$type'
| }
| }$freeStuffFilter]
| }, {
| 'name':'ends-at',
| 'op':'ge',
| 'val':'%${EventUtils.getTimeInISO8601(Date())}%'
| }$freeStuffFilter]
|}]""".trimMargin().replace("'", "\"")
time == "Tomorrow" -> """[{
| 'and':[{
Expand All @@ -188,7 +210,11 @@ class SearchViewModel(
| 'op':'eq',
| 'val':'$type'
| }
| }$freeStuffFilter]
| }, {
| 'name':'ends-at',
| 'op':'ge',
| 'val':'%${EventUtils.getTimeInISO8601(Date())}%'
| }$freeStuffFilter]
|}]""".trimMargin().replace("'", "\"")
time == "This weekend" -> """[{
| 'and':[{
Expand All @@ -215,7 +241,11 @@ class SearchViewModel(
| 'op':'eq',
| 'val':'$type'
| }
| }$freeStuffFilter]
| }, {
| 'name':'ends-at',
| 'op':'ge',
| 'val':'%${EventUtils.getTimeInISO8601(Date())}%'
| }$freeStuffFilter]
|}]""".trimMargin().replace("'", "\"")
time == "In the next month" -> """[{
| 'and':[{
Expand All @@ -242,7 +272,11 @@ class SearchViewModel(
| 'op':'eq',
| 'val':'$type'
| }
| }$freeStuffFilter]
| }, {
| 'name':'ends-at',
| 'op':'ge',
| 'val':'%${EventUtils.getTimeInISO8601(Date())}%'
| }$freeStuffFilter]
|}]""".trimMargin().replace("'", "\"")

else -> """[{
Expand Down Expand Up @@ -270,7 +304,11 @@ class SearchViewModel(
| 'op':'eq',
| 'val':'$type'
| }
| }$freeStuffFilter]
| }, {
| 'name':'ends-at',
| 'op':'ge',
| 'val':'%${EventUtils.getTimeInISO8601(Date())}%'
| }$freeStuffFilter]
|}]""".trimMargin().replace("'", "\"")
}
compositeDisposable += eventService.getSearchEvents(query, sortBy)
Expand Down

0 comments on commit d6b7ead

Please sign in to comment.