Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Android
*.iml
.gradle
/local.properties
/.idea/
.DS_Store
/build
/captures
.externalNativeBuild
.cxx

# Kotlin
*.class
*.log

# Dependency directories
/node_modules/
/app/build/

# Sensitive files
*.env
*.key

# Logs
*.log

# Test coverage
/coverage/
44 changes: 44 additions & 0 deletions app/src/main/java/com/todoapp/data/entity/TodoEntity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.todoapp.data.entity

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import java.time.LocalDateTime

/**
* Represents a Todo item in the Room database.
* Defines the schema for storing todo items with their properties.
*
* @property id Unique identifier for the todo item
* @property title Title of the todo item
* @property description Optional description of the todo item
* @property isCompleted Flag indicating whether the todo item is completed
* @property createdAt Timestamp of when the todo item was created
* @property dueDate Optional due date for the todo item
*/
@Entity(tableName = "todos")
data class TodoEntity(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
val id: Long = 0,

@ColumnInfo(name = "title")
val title: String,

@ColumnInfo(name = "description")
val description: String? = null,

@ColumnInfo(name = "is_completed")
val isCompleted: Boolean = false,

@ColumnInfo(name = "created_at")
val createdAt: LocalDateTime = LocalDateTime.now(),

@ColumnInfo(name = "due_date")
val dueDate: LocalDateTime? = null
) {
// Validate title is not blank during object creation
init {
require(title.isNotBlank()) { "Todo title cannot be blank" }
}
}
43 changes: 43 additions & 0 deletions app/src/test/java/com/todoapp/data/entity/TodoEntityTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.todoapp.data.entity

import org.junit.Assert.*
import org.junit.Test
import java.time.LocalDateTime

class TodoEntityTest {

@Test
fun `create todo item with valid title`() {
val todo = TodoEntity(title = "Test Todo")

assertEquals("Test Todo", todo.title)
assertFalse(todo.isCompleted)
assertNotNull(todo.createdAt)
}

@Test
fun `create todo item with full details`() {
val dueDate = LocalDateTime.now().plusDays(1)
val todo = TodoEntity(
title = "Complete Project",
description = "Finish Android Todo App",
isCompleted = false,
dueDate = dueDate
)

assertEquals("Complete Project", todo.title)
assertEquals("Finish Android Todo App", todo.description)
assertFalse(todo.isCompleted)
assertEquals(dueDate, todo.dueDate)
}

@Test(expected = IllegalArgumentException::class)
fun `create todo item with blank title should throw exception`() {
TodoEntity(title = "")
}

@Test(expected = IllegalArgumentException::class)
fun `create todo item with whitespace title should throw exception`() {
TodoEntity(title = " ")
}
}
13 changes: 13 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Placeholder for dependencies
// In a real project, you would add Room, Kotlin, and testing dependencies here
dependencies {
// Room Database
implementation("androidx.room:room-runtime:2.4.3")
implementation("androidx.room:room-ktx:2.4.3")
kapt("androidx.room:room-compiler:2.4.3")

// Testing
testImplementation("junit:junit:4.13.2")
testImplementation("androidx.arch.core:core-testing:2.1.0")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
}