diff --git a/DBTApp/app/build.gradle.kts b/DBTApp/app/build.gradle.kts index 6a7b1a4..067653a 100644 --- a/DBTApp/app/build.gradle.kts +++ b/DBTApp/app/build.gradle.kts @@ -38,6 +38,9 @@ android { buildFeatures { compose = true } + ksp { + arg("room.schemaLocation", "$projectDir/schemas") + } } dependencies { diff --git a/DBTApp/app/schemas/de.cdaut.dbtapp.model.AppDatabase/1.json b/DBTApp/app/schemas/de.cdaut.dbtapp.model.AppDatabase/1.json new file mode 100644 index 0000000..41d6ad0 --- /dev/null +++ b/DBTApp/app/schemas/de.cdaut.dbtapp.model.AppDatabase/1.json @@ -0,0 +1,43 @@ +{ + "formatVersion": 1, + "database": { + "version": 1, + "identityHash": "9293dc46eca03d297eae6183174db499", + "entities": [ + { + "tableName": "Skill", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`identifier` BLOB NOT NULL, `title` TEXT NOT NULL, `description` TEXT NOT NULL, PRIMARY KEY(`identifier`))", + "fields": [ + { + "fieldPath": "identifier", + "columnName": "identifier", + "affinity": "BLOB", + "notNull": true + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "identifier" + ] + } + } + ], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '9293dc46eca03d297eae6183174db499')" + ] + } +} \ No newline at end of file diff --git a/DBTApp/app/src/main/java/de/cdaut/dbtapp/model/AppDatabase.kt b/DBTApp/app/src/main/java/de/cdaut/dbtapp/model/AppDatabase.kt new file mode 100644 index 0000000..241064d --- /dev/null +++ b/DBTApp/app/src/main/java/de/cdaut/dbtapp/model/AppDatabase.kt @@ -0,0 +1,9 @@ +package de.cdaut.dbtapp.model + +import androidx.room.Database +import androidx.room.RoomDatabase + +@Database(entities = [Skill::class], version = 1) +abstract class AppDatabase : RoomDatabase() { + abstract fun skillDao() : SkillDao +} \ No newline at end of file diff --git a/DBTApp/app/src/main/java/de/cdaut/dbtapp/model/Skill.kt b/DBTApp/app/src/main/java/de/cdaut/dbtapp/model/Skill.kt index 612c86a..0528f62 100644 --- a/DBTApp/app/src/main/java/de/cdaut/dbtapp/model/Skill.kt +++ b/DBTApp/app/src/main/java/de/cdaut/dbtapp/model/Skill.kt @@ -1,24 +1,56 @@ package de.cdaut.dbtapp.model -class Skill(val title: String, val description: String) { +import androidx.room.ColumnInfo +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Entity +import androidx.room.Insert +import androidx.room.PrimaryKey +import androidx.room.Query +import java.util.UUID + +@Entity +class Skill( + @PrimaryKey val identifier: UUID, + @ColumnInfo(name = "title") val title: String, + @ColumnInfo(name = "description") val description: String +) { companion object { fun mockSkills(): List { return listOf( Skill( + identifier = UUID.randomUUID(), title = "Test Hallo :3", description = "lorem ipsum dolor sid amnet consequetur blabla yada yada" ), Skill( + identifier = UUID.randomUUID(), title = "5-4-3-2-1", description = "Hier kurz beschreiben wie die Übung funktioniert. Ggf. mehrere Zeilen aber nicht super lang" ), Skill( + identifier = UUID.randomUUID(), title = "UwU UwU awawawa", description = "Just arf a little like the good fopsgirl you are :3" ) ) } } +} + +@Dao +interface SkillDao { + @Query("SELECT * FROM Skill") + fun getAll(): List + + @Query("SELECT * FROM Skill WHERE title LIKE :title LIMIT 1") + fun findByName(title: String): Skill + + @Insert + fun insertAll(vararg skills: Skill) + + @Delete + fun delete(skill: Skill) } \ No newline at end of file