Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("unused")

package com.cornellappdev.android.eatery.data

import com.cornellappdev.android.eatery.data.models.AccountType
Expand Down Expand Up @@ -116,18 +118,14 @@ class AccountTypeAdapter {
"brb"
}

AccountType.CITYBUCKS -> {
AccountType.CITY_BUCKS -> {
"city bucks"
}

AccountType.LAUNDRY -> {
"laundry"
}

AccountType.MEALSWIPES -> {
"meal plan"
}

else -> {
"other"
}
Expand Down Expand Up @@ -155,7 +153,7 @@ class AccountTypeAdapter {
return if (accountName.contains("brb", ignoreCase = true)) {
AccountType.BRBS
} else if (accountName.contains("city bucks", ignoreCase = true)) {
AccountType.CITYBUCKS
AccountType.CITY_BUCKS
} else if (accountName.contains("laundry", ignoreCase = true)) {
AccountType.LAUNDRY
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@
package com.cornellappdev.android.eatery.data

import com.cornellappdev.android.eatery.data.models.AccountsResponse
import com.cornellappdev.android.eatery.data.models.ApiResponse
import com.cornellappdev.android.eatery.data.models.Accounts
import com.cornellappdev.android.eatery.data.models.AuthorizedUser
import com.cornellappdev.android.eatery.data.models.Eatery
import com.cornellappdev.android.eatery.data.models.Event
import com.cornellappdev.android.eatery.data.models.GetApiAccountsParams
import com.cornellappdev.android.eatery.data.models.GetApiRequestBody
import com.cornellappdev.android.eatery.data.models.GetApiResponse
import com.cornellappdev.android.eatery.data.models.GetApiTransactionHistoryParams
import com.cornellappdev.android.eatery.data.models.GetApiUserParams
import com.cornellappdev.android.eatery.data.models.LoginRequest
import com.cornellappdev.android.eatery.data.models.ReportSendBody
import com.cornellappdev.android.eatery.data.models.TransactionsResponse
import com.cornellappdev.android.eatery.data.models.Transactions
import com.cornellappdev.android.eatery.data.models.User
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Url

interface NetworkApi {
@POST()
suspend fun fetchUser(
@Url url: String,
@Body body: GetApiRequestBody<GetApiUserParams>
): GetApiResponse<User>

@POST()
suspend fun fetchAccounts(
@Url url: String,
@Body body: GetApiRequestBody<GetApiAccountsParams>
): GetApiResponse<AccountsResponse>

@POST()
suspend fun fetchTransactionHistory(
@Url url: String,
@Body body: GetApiRequestBody<GetApiTransactionHistoryParams>
): GetApiResponse<TransactionsResponse>

@GET("/eatery/")
suspend fun fetchEateries(): List<Eatery>

Expand All @@ -46,12 +24,31 @@ interface NetworkApi {
@GET("/eatery/simple")
suspend fun fetchHomeEateries(): List<Eatery>

@GET("/event")
suspend fun fetchEvents(): ApiResponse<List<Event>>


@POST("/report/")
suspend fun sendReport(
@Body report: ReportSendBody
): GetApiResponse<ReportSendBody>

@POST("/user/authorize/")
suspend fun authorizeUser(
@Header("Authorization") sessionId: String,
@Body loginRequest: LoginRequest
): AuthorizedUser

@POST("/user/accounts/")
suspend fun getUserAccounts(
@Header("Authorization") sessionId: String,
@Body user: AuthorizedUser
): Accounts

@POST("/user/transactions/")
suspend fun getUserTransactions(
@Header("Authorization") sessionId: String,
@Body user: AuthorizedUser
): Transactions

@GET("/user/{id}/")
suspend fun getUserData(
@Path("id") id: Long
): User
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.cornellappdev.android.eatery.data.models

data class AccountBalances(
val brbBalance: Double? = null,
val cityBucksBalance: Double? = null,
val laundryBalance: Double? = null,
val mealSwipes: Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,15 @@ package com.cornellappdev.android.eatery.data.models
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class ApiResponse<T>(
@Json(name = "success") val success: Boolean,
@Json(name = "data") val data: T? = null,
@Json(name = "error") val error: String? = null
)

// todo - update these
@JsonClass(generateAdapter = true)
data class GetApiResponse<T>(
@Json(name = "response") val response: T? = null,
@Json(name = "exception") val exception: String? = null
)

@JsonClass(generateAdapter = true)
data class GetApiRequestBody<T>(
val version: String,
val method: String,
val params: T
)

@JsonClass(generateAdapter = true)
data class GetApiUserParams(
val sessionId: String
)

@JsonClass(generateAdapter = true)
data class GetApiAccountsParams(
val sessionId: String,
val userId: String
)

@JsonClass(generateAdapter = true)
data class GetApiTransactionHistoryParams(
val paymentSystemType: Int,
val sessionId: String,
val queryCriteria: GetApiTransactionHistoryQueryCriteria
)

@JsonClass(generateAdapter = true)
data class GetApiTransactionHistoryQueryCriteria(
val endDate: String,
val institutionId: String,
val maxReturn: Int,
val startDate: String,
val userId: String
)

@JsonClass(generateAdapter = true)
data class ReportSendBody(
@Json(name = "eatery") val eatery: Int?,
@Json(name = "content") val content: String
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import java.time.Duration
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import java.util.Date

@JsonClass(generateAdapter = true)
Expand All @@ -40,6 +39,7 @@ data class Eatery(
@Json(name = "wait_times") val waitTimes: List<WaitTimeDay>? = null,
@Json(name = "alerts") val alerts: List<Alert>? = null,
) {
// todo - investigate unused methods
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are methods that are completely unused, we can just get rid of them

fun getWalkTimes(): Int? {
val currentLocation = LocationHandler.currentLocation.value
val results = floatArrayOf(0f)
Expand All @@ -56,29 +56,6 @@ data class Eatery(
return ((results[0] / AVERAGE_WALK_SPEED) / 60).toInt()
}

fun getWaitTimes(): String? {
if (waitTimes.isNullOrEmpty())
return null

val waitTimeDay = waitTimes.find { waitTimeDay ->
// checks if today is the right day
waitTimeDay.canonicalDate
?.toInstant()
?.truncatedTo(ChronoUnit.DAYS)
?.equals(Date().toInstant().truncatedTo(ChronoUnit.DAYS)) ?: true
}?.data

val waitTimes: WaitTimeData? = waitTimeDay?.find { waitTimeData ->
waitTimeData.timestamp?.isBefore(LocalDateTime.now()) == true
}

return if (waitTimes != null) {
"${waitTimes.waitTimeLow?.div(60)}-${waitTimes.waitTimeHigh?.div(60)}"
} else {
null
}
}


private fun getTodaysEvents(): List<Event> {
val currentTime = LocalDateTime.now()
Expand Down Expand Up @@ -111,18 +88,6 @@ data class Eatery(
return todayEvents
}

/**
* Returns the currently active event, or null if no event is active.
*
* Example: At 1 PM, Morrison will return the lunch event.
*/
fun getCurrentEvent(): Event? {
return getTodaysEvents().find {
it.startTime?.isBefore(LocalDateTime.now()) ?: true
&& it.endTime?.isAfter(LocalDateTime.now()) ?: true
}
}

/**
* Returns the event that should be displayed at the Ithaca local time
* If there is currently a meal going on, that is displayed
Expand Down Expand Up @@ -168,7 +133,7 @@ data class Eatery(
* for louies, it returns [("General",some string duration)]
* Note, string duration are in the format "11:00 AM - 2:30 PM"
*/
fun getTypeMeal(currSelectedDay: DayOfWeek): List<Pair<String, String>>? {
fun getTypeMeal(currSelectedDay: DayOfWeek): List<Pair<String, String>> {
val timeFormatter = DateTimeFormatter.ofPattern("h:mm a")

val uniqueMeals = LinkedHashMap<String, String>()
Expand Down Expand Up @@ -207,7 +172,6 @@ data class Eatery(
fun getSelectedDayMeal(meal: MealFilter, day: Int): List<Event>? {
var currentDay = LocalDate.now()
currentDay = currentDay.plusDays(day.toLong())
// Log.d(name, events?.filter { currentDay.dayOfYear == it.startTime?.dayOfYear }.toString())
return events?.filter { event ->
currentDay.dayOfYear == event.startTime?.dayOfYear && meal.text.contains(event.description)
}
Expand Down Expand Up @@ -239,16 +203,6 @@ data class Eatery(
return getOpenUntil() == null
}

fun isClosingInTen(): Boolean {
val currentTime = LocalDateTime.now()
val currentEvents = getCurrentEvents()
if (currentEvents.isEmpty())
return false

val endTime = currentEvents.first().endTime ?: return false
return currentTime.plusMinutes(10).isAfter(endTime)
}

/**
* Returns true if the eatery has a current event and that event is ending within [minutes].
*/
Expand Down Expand Up @@ -297,22 +251,20 @@ data class Eatery(
* e.g. For Oken, {Monday -> ["11:00 AM - 2:30 PM", "4:30 PM - 9:00 PM"], Sunday -> "Closed"}
*/
private fun operatingHours(): Map<DayOfWeek, MutableList<String>> {
var dailyHours = mutableMapOf<DayOfWeek, MutableList<String>>()
val dailyHours = mutableMapOf<DayOfWeek, MutableList<String>>()

events?.forEach { event ->
val dayOfWeek = event.startTime?.dayOfWeek
val openTime = event.startTime?.format(DateTimeFormatter.ofPattern("h:mm a"))
val closeTime = event.endTime?.format(DateTimeFormatter.ofPattern("h:mm a"))
// Log.d("event", event.toString())

val timeString = "$openTime - $closeTime"

if (dayOfWeek != null && dailyHours[dayOfWeek]?.none { it.contains(timeString) } != false) {
dailyHours.computeIfAbsent(dayOfWeek) { mutableListOf() }.add(timeString)
}
}

DayOfWeek.values().forEach { dayOfWeek ->
DayOfWeek.entries.forEach { dayOfWeek ->
dailyHours.computeIfAbsent(dayOfWeek) { mutableListOf("Closed") }
}

Expand All @@ -329,7 +281,7 @@ data class Eatery(
* day(s) mapped to opening hours.
*/
fun formatOperatingHours(): List<Pair<String, List<String>>> {
var dailyHours = operatingHours()
val dailyHours = operatingHours()

val groupedHours = dailyHours.entries.groupBy({ it.value }, { it.key })

Expand Down Expand Up @@ -390,7 +342,7 @@ data class Eatery(
}
}

var formattedHoursList = formattedHours.toList().sortedBy { entry ->
val formattedHoursList = formattedHours.toList().sortedBy { entry ->
val firstDay = entry.first.split(" to ", " ", limit = 2).first()
dayOrder[firstDay] ?: Int.MAX_VALUE
}
Expand Down
Loading
Loading