|
| 1 | +package com.dkhalife.tasks.data.db |
| 2 | + |
| 3 | +import com.dkhalife.tasks.data.db.entity.LabelEntity |
| 4 | +import com.dkhalife.tasks.data.db.entity.TaskEntity |
| 5 | +import com.dkhalife.tasks.data.db.entity.TaskWithLabels |
| 6 | +import com.dkhalife.tasks.model.Label |
| 7 | +import com.dkhalife.tasks.model.Task |
| 8 | + |
| 9 | +fun TaskWithLabels.toDomain(): Task = Task( |
| 10 | + id = task.id, |
| 11 | + title = task.title, |
| 12 | + nextDueDate = task.nextDueDate, |
| 13 | + endDate = task.endDate, |
| 14 | + isRolling = task.isRolling, |
| 15 | + frequency = task.frequency, |
| 16 | + notification = task.notification, |
| 17 | + labels = labels.map { it.toDomain() }, |
| 18 | + createdAt = task.createdAt, |
| 19 | + updatedAt = task.updatedAt, |
| 20 | +) |
| 21 | + |
| 22 | +fun LabelEntity.toDomain(): Label = Label( |
| 23 | + id = id, |
| 24 | + name = name, |
| 25 | + color = color, |
| 26 | + createdAt = createdAt, |
| 27 | + updatedAt = updatedAt, |
| 28 | +) |
| 29 | + |
| 30 | +fun Task.toEntity( |
| 31 | + localId: String? = null, |
| 32 | + localState: String = LocalState.SYNCED, |
| 33 | +): TaskEntity = TaskEntity( |
| 34 | + id = id, |
| 35 | + localId = localId, |
| 36 | + title = title, |
| 37 | + nextDueDate = nextDueDate, |
| 38 | + endDate = endDate, |
| 39 | + isRolling = isRolling, |
| 40 | + frequency = frequency, |
| 41 | + notification = notification, |
| 42 | + createdAt = createdAt, |
| 43 | + updatedAt = updatedAt, |
| 44 | + localState = localState, |
| 45 | +) |
| 46 | + |
| 47 | +fun Label.toEntity( |
| 48 | + localId: String? = null, |
| 49 | + localState: String = LocalState.SYNCED, |
| 50 | +): LabelEntity = LabelEntity( |
| 51 | + id = id, |
| 52 | + localId = localId, |
| 53 | + name = name, |
| 54 | + color = color, |
| 55 | + createdAt = createdAt, |
| 56 | + updatedAt = updatedAt, |
| 57 | + localState = localState, |
| 58 | +) |
0 commit comments