Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
feat: app - Tag
  • Loading branch information
taetae98coding committed Nov 19, 2024
1 parent 516be6c commit 2044f11
Show file tree
Hide file tree
Showing 55 changed files with 1,448 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public fun DiaryTheme(
onSurface = colorScheme.onSurface,
),
LocalDiaryTypography provides DiaryTypography(
headlineMedium = MaterialTheme.typography.headlineMedium,
labelSmall = MaterialTheme.typography.labelSmall,
labelMedium = MaterialTheme.typography.labelMedium,
labelLarge = MaterialTheme.typography.labelLarge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.taetae98coding.diary.core.design.system.typography
import androidx.compose.ui.text.TextStyle

public data class DiaryTypography(
val headlineMedium: TextStyle,
val labelSmall: TextStyle,
val labelMedium: TextStyle,
val labelLarge: TextStyle,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "8e6b08fa78bcbc993963c679fe1d6ce9",
"entities": [
{
"tableName": "MemoEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL DEFAULT '', `title` TEXT NOT NULL DEFAULT '', `description` TEXT NOT NULL DEFAULT '', `start` TEXT DEFAULT null, `endInclusive` TEXT DEFAULT null, `color` INTEGER NOT NULL DEFAULT -16777216, `isFinish` INTEGER NOT NULL DEFAULT 0, `isDelete` INTEGER NOT NULL DEFAULT 0, `owner` TEXT DEFAULT null, `updateAt` INTEGER NOT NULL DEFAULT 0, `serverUpdateAt` INTEGER DEFAULT null, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "description",
"columnName": "description",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "start",
"columnName": "start",
"affinity": "TEXT",
"defaultValue": "null"
},
{
"fieldPath": "endInclusive",
"columnName": "endInclusive",
"affinity": "TEXT",
"defaultValue": "null"
},
{
"fieldPath": "color",
"columnName": "color",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "-16777216"
},
{
"fieldPath": "isFinish",
"columnName": "isFinish",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "isDelete",
"columnName": "isDelete",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "owner",
"columnName": "owner",
"affinity": "TEXT",
"defaultValue": "null"
},
{
"fieldPath": "updateAt",
"columnName": "updateAt",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "serverUpdateAt",
"columnName": "serverUpdateAt",
"affinity": "INTEGER",
"defaultValue": "null"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
},
{
"tableName": "TagEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL DEFAULT '', `title` TEXT NOT NULL DEFAULT '', `description` TEXT NOT NULL DEFAULT '', `color` INTEGER NOT NULL DEFAULT -16777216, `isFinish` INTEGER NOT NULL DEFAULT 0, `isDelete` INTEGER NOT NULL DEFAULT 0, `owner` TEXT DEFAULT null, `updateAt` INTEGER NOT NULL DEFAULT 0, `serverUpdateAt` INTEGER DEFAULT null, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "description",
"columnName": "description",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "color",
"columnName": "color",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "-16777216"
},
{
"fieldPath": "isFinish",
"columnName": "isFinish",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "isDelete",
"columnName": "isDelete",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "owner",
"columnName": "owner",
"affinity": "TEXT",
"defaultValue": "null"
},
{
"fieldPath": "updateAt",
"columnName": "updateAt",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "serverUpdateAt",
"columnName": "serverUpdateAt",
"affinity": "INTEGER",
"defaultValue": "null"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
},
{
"tableName": "MemoBackupEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` TEXT NOT NULL, `memoId` TEXT NOT NULL, PRIMARY KEY(`uid`, `memoId`), FOREIGN KEY(`memoId`) REFERENCES `MemoEntity`(`id`) ON UPDATE CASCADE ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "uid",
"columnName": "uid",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "memoId",
"columnName": "memoId",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"uid",
"memoId"
]
},
"foreignKeys": [
{
"table": "MemoEntity",
"onDelete": "CASCADE",
"onUpdate": "CASCADE",
"columns": [
"memoId"
],
"referencedColumns": [
"id"
]
}
]
}
],
"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, '8e6b08fa78bcbc993963c679fe1d6ce9')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import io.github.taetae98coding.diary.core.diary.database.room.dao.MemoBackupEntityDao
import io.github.taetae98coding.diary.core.diary.database.room.dao.MemoEntityDao
import io.github.taetae98coding.diary.core.diary.database.room.dao.TagEntityDao
import io.github.taetae98coding.diary.core.diary.database.room.entity.MemoBackupEntity
import io.github.taetae98coding.diary.core.diary.database.room.entity.MemoEntity
import io.github.taetae98coding.diary.core.diary.database.room.entity.TagEntity
import io.github.taetae98coding.diary.core.diary.database.room.internal.DiaryDatabaseConstructor
import io.github.taetae98coding.diary.library.room.InstantConverter
import io.github.taetae98coding.diary.library.room.LocalDataConverter

@Database(
entities = [
MemoEntity::class,
TagEntity::class,
MemoBackupEntity::class,
],
version = 1
version = 2,
)
@ConstructedBy(DiaryDatabaseConstructor::class)
@TypeConverters(
Expand All @@ -26,5 +29,7 @@ import io.github.taetae98coding.diary.library.room.LocalDataConverter
)
internal abstract class DiaryDatabase : RoomDatabase() {
abstract fun memo(): MemoEntityDao
abstract fun tag(): TagEntityDao

abstract fun memoBackup(): MemoBackupEntityDao
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.github.taetae98coding.diary.core.diary.database.room.dao

import androidx.room.Dao
import androidx.room.Query
import io.github.taetae98coding.diary.core.diary.database.room.entity.TagEntity
import kotlinx.coroutines.flow.Flow

@Dao
internal abstract class TagEntityDao : EntityDao<TagEntity>() {
@Query(
"""
SELECT *
FROM TagEntity
WHERE id = :tagId
""",
)
abstract fun find(tagId: String): Flow<TagEntity?>

@Query(
"""
SELECT *
FROM TagEntity
WHERE isDelete = 0
AND (owner = :owner OR (owner IS NULL AND :owner IS NULL))
ORDER BY title
""",
)
abstract fun page(owner: String?): Flow<List<TagEntity>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.taetae98coding.diary.core.diary.database.room.dao

import io.github.taetae98coding.diary.core.diary.database.TagDao
import io.github.taetae98coding.diary.core.diary.database.room.DiaryDatabase
import io.github.taetae98coding.diary.core.diary.database.room.entity.TagEntity
import io.github.taetae98coding.diary.core.diary.database.room.mapper.toDto
import io.github.taetae98coding.diary.core.diary.database.room.mapper.toEntity
import io.github.taetae98coding.diary.core.model.tag.TagDto
import io.github.taetae98coding.diary.library.coroutines.mapCollectionLatest
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.mapLatest
import org.koin.core.annotation.Factory

@OptIn(ExperimentalCoroutinesApi::class)
@Factory
internal class TagRoomDao(
private val database: DiaryDatabase,
) : TagDao {
override suspend fun upsert(tag: TagDto) {
database.tag().upsert(tag.toEntity())
}

override fun find(tagId: String): Flow<TagDto?> {
return database.tag().find(tagId).mapLatest { it?.toDto() }
}

override fun page(owner: String?): Flow<List<TagDto>> {
return database.tag().page(owner)
.mapCollectionLatest(TagEntity::toDto)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.github.taetae98coding.diary.core.diary.database.room.entity

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.datetime.Instant

@Entity
internal data class TagEntity(
@PrimaryKey
@ColumnInfo(defaultValue = "")
val id: String,
@ColumnInfo(defaultValue = "")
val title: String,
@ColumnInfo(defaultValue = "")
val description: String,
@ColumnInfo(defaultValue = "-16777216")
val color: Int,
@ColumnInfo(defaultValue = "0")
val isFinish: Boolean,
@ColumnInfo(defaultValue = "0")
val isDelete: Boolean,
@ColumnInfo(defaultValue = "null")
val owner: String?,
@ColumnInfo(defaultValue = "0")
val updateAt: Instant,
@ColumnInfo(defaultValue = "null")
val serverUpdateAt: Instant?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.taetae98coding.diary.core.diary.database.room.mapper

import io.github.taetae98coding.diary.core.diary.database.room.entity.MemoEntity
import io.github.taetae98coding.diary.core.diary.database.room.entity.TagEntity
import io.github.taetae98coding.diary.core.model.memo.MemoDetail
import io.github.taetae98coding.diary.core.model.memo.MemoDto
import io.github.taetae98coding.diary.core.model.tag.TagDetail
import io.github.taetae98coding.diary.core.model.tag.TagDto

internal fun TagDto.toEntity(): TagEntity {
return TagEntity(
id = id,
title = detail.title,
description = detail.description,
color = detail.color,
isFinish = isFinish,
isDelete = isDelete,
owner = owner,
updateAt = updateAt,
serverUpdateAt = serverUpdateAt,
)
}

internal fun TagEntity.toDto(): TagDto {
return TagDto(
id = id,
detail = TagDetail(
title = title,
description = description,
color = color,
),
owner = owner,
isFinish = isFinish,
isDelete = isDelete,
updateAt = updateAt,
serverUpdateAt = serverUpdateAt,
)
}
Loading

0 comments on commit 2044f11

Please sign in to comment.