Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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 @@ -40,6 +40,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 Down Expand Up @@ -168,7 +169,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 +208,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 @@ -297,22 +297,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 +327,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 +388,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
Original file line number Diff line number Diff line change
@@ -1,74 +1,106 @@
@file:Suppress("AddExplicitTargetToParameterAnnotation")

package com.cornellappdev.android.eatery.data.models

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class User(
@Json(name = "id") val id: String? = null,
@Json(name = "userName") val userName: String? = null,
@Json(name = "firstName") val firstName: String? = null,
@Json(name = "middleName") val middleName: String? = null,
@Json(name = "lastName") val lastName: String? = null,
@Json(name = "email") val email: String? = null,
@Json(name = "phone") val phone: String? = null,
var accounts: List<Account>? = null,
var transactions: List<Transaction>? = listOf()
@Json(name = "favorite_eateries") val favoriteEateries: List<Int> = emptyList(),
@Json(name = "favorite_items") val favoriteItems: List<String> = emptyList(),
@Json(name = "brb_balance") val brbBalance: Double = 0.0,
@Json(name = "city_bucks_balance") val cityBucksBalance: Double = 0.0,
@Json(name = "laundry_balance") val laundryBalance: Double = 0.0,
@Json(name = "transactions") val transactions: List<Transaction>? = listOf(),
@Json(name = "meal_swipes") val mealSwipes: Int? = null // todo - backend should make this
)

@JsonClass(generateAdapter = true)
data class LoginRequest(
@Json(name = "device_id") val deviceId: String = "",
@Json(name = "fcm_token") val fcmToken: String = "",
@Json(name = "pin") val pin: Int = 0
)

@JsonClass(generateAdapter = true)
data class AuthorizedUser(
@Json(name = "id") val id: Long = 0,
@Json(name = "device_id") val deviceId: String = "",
@Json(name = "fcm_token") val fcmToken: String = "",
@Json(name = "pin") val pin: Int = 0
)

@JsonClass(generateAdapter = true)
data class AccountsResponse(
@Json(name = "accounts") val accounts: List<Account>? = null
data class Accounts(
@Json(name = "brb") val brbBalance: Account? = null,
@Json(name = "city_bucks") val cityBucksBalance: Account? = null,
@Json(name = "laundry") val laundryBalance: Account? = null
)

@JsonClass(generateAdapter = true)
data class Account(
@Json(name = "accountDisplayName") val type: AccountType? = null,
@Json(name = "balance") val balance: Double? = null
@Json(name = "name") val name: String = "",
@Json(name = "balance") val balance: Double = 0.0
)

@JsonClass(generateAdapter = true)
data class TransactionsResponse(
@Json(name = "totalCount") val totalCount: Int? = null,
@Json(name = "returnCapped") val returnCapped: Boolean? = null,
@Json(name = "transactions") val transactions: List<Transaction>? = null
data class Transactions(
@Json(name = "transactions") val transactions: List<Transaction> = emptyList()
)

@JsonClass(generateAdapter = true)
data class Transaction(
@Json(name = "transactionId") val id: String? = null,
@Json(name = "amount") val amount: Double? = null,
@Json(name = "resultingBalance") val resultingBalance: Double? = null,
@Json(name = "postedDate") val date: String? = null,
// make this TransactionType later
@Json(name = "transactionType") val transactionType: Int? = null,
@Json(name = "accountName") val accountType: AccountType? = null,
@Json(name = "locationName") val location: String? = null,
@Json(name = "amount") val amount: Double = 0.0,
@Json(name = "accountName") val accountType: AccountType = AccountType.OTHER,
@Json(name = "date") val date: String = "",
@Json(name = "location") val location: String = "",
@Json(name = "transactionType") val transactionType: TransactionType = TransactionType.NOOP // todo - backend should give this
)

/**
* Categories for transactions used for filtering. More general than AccountType.
*/
enum class TransactionAccountType {
MEAL_SWIPES,
BRBS,
CITY_BUCKS,
LAUNDRY
}

/**
* Specific account types as they show up in the backend.
*/
enum class AccountType {
// MEALSWIPES is used for transaction history filtering, only. For anything else, use the actual
// meal plan types in the block below (OFF_CAMPUS, BEAR_TRADITIONAL, etc.).
LAUNDRY,
MEALSWIPES,
BRBS,
CITYBUCKS,
CITY_BUCKS,
OFF_CAMPUS,
BEAR_TRADITIONAL,
UNLIMITED,
BEAR_BASIC,
BEAR_CHOICE,
HOUSE_MEALPLAN,
HOUSE_MEAL_PLAN,
HOUSE_AFFILIATE,
FLEX,
JUST_BUCKS,
OTHER
// todo - are there more?
}

fun AccountType.toTransactionAccountType(): TransactionAccountType {
return when (this) {
AccountType.BRBS -> TransactionAccountType.BRBS
AccountType.CITY_BUCKS -> TransactionAccountType.CITY_BUCKS
AccountType.LAUNDRY -> TransactionAccountType.LAUNDRY
else -> TransactionAccountType.MEAL_SWIPES
}
}

enum class TransactionType(val value: Int) {
DEPOSIT(3), SPEND(1), NOOP(0), MISC(2);

companion object {
fun fromInt(value: Int) = values().first { it.value == value }
fun fromInt(value: Int) = TransactionType.entries.first { it.value == value }
}
}
Loading
Loading