Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Show only upcoming or ongoing events #1753

Merged
merged 2 commits into from May 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -245,4 +246,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 @@ -95,15 +97,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 @@ -113,6 +123,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 @@ -132,6 +146,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 @@ -159,7 +177,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 @@ -186,7 +208,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 @@ -213,7 +239,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 @@ -240,7 +270,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 @@ -268,7 +302,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