Fix requesting recipe summary errors due to time types
This commit is contained in:
@@ -1,12 +1,22 @@
|
||||
package gq.kirmanak.mealie.data
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.datetime.*
|
||||
|
||||
object RoomTypeConverters {
|
||||
@TypeConverter
|
||||
fun instantToTimestamp(instant: Instant) = instant.toEpochMilliseconds()
|
||||
fun localDateTimeToTimestamp(localDateTime: LocalDateTime) =
|
||||
localDateTime.toInstant(TimeZone.UTC).toEpochMilliseconds()
|
||||
|
||||
@TypeConverter
|
||||
fun timestampToInstant(timestamp: Long) = Instant.fromEpochMilliseconds(timestamp)
|
||||
fun timestampToLocalDateTime(timestamp: Long) =
|
||||
Instant.fromEpochMilliseconds(timestamp).toLocalDateTime(TimeZone.UTC)
|
||||
|
||||
@TypeConverter
|
||||
fun localDateToTimeStamp(date: LocalDate) =
|
||||
localDateTimeToTimestamp(date.atTime(0, 0))
|
||||
|
||||
@TypeConverter
|
||||
fun timestampToLocalDate(timestamp: Long) =
|
||||
timestampToLocalDateTime(timestamp).date
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
|
||||
@Entity(tableName = "recipes", indices = [Index(value = ["remote_id"], unique = true)])
|
||||
data class RecipeEntity(
|
||||
@@ -15,6 +16,6 @@ data class RecipeEntity(
|
||||
@ColumnInfo(name = "image") val image: String,
|
||||
@ColumnInfo(name = "description") val description: String,
|
||||
@ColumnInfo(name = "rating") val rating: Int?,
|
||||
@ColumnInfo(name = "date_added") val dateAdded: Instant,
|
||||
@ColumnInfo(name = "date_updated") val dateUpdated: Instant
|
||||
@ColumnInfo(name = "date_added") val dateAdded: LocalDate,
|
||||
@ColumnInfo(name = "date_updated") val dateUpdated: LocalDateTime
|
||||
)
|
||||
@@ -1,6 +1,7 @@
|
||||
package gq.kirmanak.mealie.data.recipes.network
|
||||
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@@ -14,6 +15,6 @@ data class GetRecipeSummaryResponse(
|
||||
@SerialName("recipeCategory") val recipeCategories: List<String>,
|
||||
@SerialName("tags") val tags: List<String>,
|
||||
@SerialName("rating") val rating: Int?,
|
||||
@SerialName("dateAdded") val dateAdded: Instant,
|
||||
@SerialName("dateUpdated") val dateUpdated: Instant
|
||||
@SerialName("dateAdded") val dateAdded: LocalDate,
|
||||
@SerialName("dateUpdated") val dateUpdated: LocalDateTime
|
||||
)
|
||||
Reference in New Issue
Block a user