Skip to content

Commit

Permalink
Make if there is no record id, the id would be -1
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanLiou committed Jun 24, 2023
1 parent 246d7df commit b7884ef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import app.cash.sqldelight.coroutines.asFlow
import app.cash.sqldelight.coroutines.mapToList
import com.rayliu.commonmain.data.database.AppDatabase
import com.rayliu.commonmain.data.database.RecordDetails
import com.rayliu.commonmain.domain.model.RECORD_EMPTY_ID
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -38,6 +39,10 @@ class WorkoutRecordDataSourceImpl(
}

override suspend fun updateRecordDetails(recordDetails: RecordDetails) = withContext(ioDispatcher) {
if (recordDetails.id == RECORD_EMPTY_ID.toLong()) {
return@withContext
}

detailsQueries.updateRecord(
id = recordDetails.id,
lastModified = recordDetails.lastModified,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RecordDetailsMapper : Mapper<Record, RecordDetails> {
}

return RecordDetails(
id = -1,
id = input.id.toLong(),
workoutId = input.workoutId.toLong(),
createAt = input.createdAt.toString(),
lastModified = input.lastModified.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.rayliu.commonmain.domain.model

import kotlinx.datetime.LocalDateTime

const val RECORD_EMPTY_ID = -1

interface Record {
val id: Int
val workoutId: Int
Expand All @@ -11,7 +13,7 @@ interface Record {
}

data class WeightRepsRecord(
override val id: Int,
override val id: Int = RECORD_EMPTY_ID,
override val workoutId: Int,
override val sportRecordType: SportRecordType,
override val createdAt: LocalDateTime,
Expand All @@ -21,7 +23,7 @@ data class WeightRepsRecord(
) : Record

data class WeightTimeRecord(
override val id: Int,
override val id: Int = RECORD_EMPTY_ID,
override val workoutId: Int,
override val sportRecordType: SportRecordType,
override val createdAt: LocalDateTime,
Expand All @@ -31,7 +33,7 @@ data class WeightTimeRecord(
) : Record

data class DistanceTimeRecord(
override val id: Int,
override val id: Int = RECORD_EMPTY_ID,
override val workoutId: Int,
override val sportRecordType: SportRecordType,
override val createdAt: LocalDateTime,
Expand All @@ -41,7 +43,7 @@ data class DistanceTimeRecord(
) : Record

data class UnknownRecord(
override val id: Int,
override val id: Int = RECORD_EMPTY_ID,
override val workoutId: Int,
override val sportRecordType: SportRecordType,
override val createdAt: LocalDateTime,
Expand Down

0 comments on commit b7884ef

Please sign in to comment.