Skip to content

Commit

Permalink
Issue GDSC-PKNU-Official#51 feat: Add mapping todo entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Cha-Ji committed Apr 3, 2022
1 parent d607542 commit 57784f6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
21 changes: 21 additions & 0 deletions app/src/main/java/com/gdsc/todo/data/entity/ToDo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.gdsc.todo.data.entity

import android.os.Build
import androidx.annotation.RequiresApi
import java.time.LocalDateTime
import java.time.ZoneOffset

@RequiresApi(Build.VERSION_CODES.O)
data class ToDo (
val id: Long = 0,
val title: String,
val contents: String,
val date: LocalDateTime = LocalDateTime.now()
) {
fun to() = ToDoEntity(
id = id,
title = title,
contents = contents,
date = date.toEpochSecond(ZoneOffset.UTC)
)
}
14 changes: 11 additions & 3 deletions app/src/main/java/com/gdsc/todo/data/entity/ToDoEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ import androidx.annotation.RequiresApi
import androidx.room.Entity
import androidx.room.PrimaryKey
import java.time.LocalDateTime
import java.time.ZoneOffset

@Entity
@RequiresApi(Build.VERSION_CODES.O)
data class ToDo (
data class ToDoEntity (
@PrimaryKey(autoGenerate = true) val id: Long = 0,
val title: String,
val contents: String,
val date: LocalDateTime = LocalDateTime.now()
)
val date: Long
) {
fun to() = ToDo(
id = id,
title = title,
contents = contents,
date = LocalDateTime.ofEpochSecond(date, 0, ZoneOffset.UTC)
)
}

0 comments on commit 57784f6

Please sign in to comment.