Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 라벨 추가 #63

Merged
merged 1 commit into from
Nov 6, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "99fe4ad42dc76bf2ace29255e371e197",
"identityHash": "55c710c5b13d4a5c2c7517208401c5e1",
"entities": [
{
"tableName": "diary",
Expand Down Expand Up @@ -47,12 +47,32 @@
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "label",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`label` TEXT NOT NULL, PRIMARY KEY(`label`))",
"fields": [
{
"fieldPath": "label",
"columnName": "label",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"label"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"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, '99fe4ad42dc76bf2ace29255e371e197')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '55c710c5b13d4a5c2c7517208401c5e1')"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.boostcamp.dreamteam.dreamdiary.core.data.database.dao.DreamDiaryDao
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.DreamDiaryEntity
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.LabelEntity

@Database(entities = [DreamDiaryEntity::class], version = 1)
@Database(entities = [DreamDiaryEntity::class, LabelEntity::class], version = 1)
@TypeConverters(value = [InstantTypeConverter::class])
internal abstract class DreamDiaryDatabase : RoomDatabase() {
abstract fun dreamDiaryDao(): DreamDiaryDao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package com.boostcamp.dreamteam.dreamdiary.core.data.database.dao
import androidx.room.Dao
import androidx.room.Insert
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.DreamDiaryEntity
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.LabelEntity

@Dao
interface DreamDiaryDao {
@Insert
suspend fun insertDreamDiary(dreamDiaryEntity: DreamDiaryEntity)

@Insert
suspend fun insertLabel(labelEntity: LabelEntity)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.boostcamp.dreamteam.dreamdiary.core.data.database.model

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(
tableName = "label",
)
data class LabelEntity(
@PrimaryKey
val label: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.boostcamp.dreamteam.dreamdiary.core.data.repository

import com.boostcamp.dreamteam.dreamdiary.core.data.database.dao.DreamDiaryDao
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.DreamDiaryEntity
import com.boostcamp.dreamteam.dreamdiary.core.data.database.model.LabelEntity
import java.time.Instant
import java.util.UUID
import javax.inject.Inject
Expand All @@ -23,4 +24,12 @@ internal class DefaultDreamDiaryRepository @Inject constructor(
),
)
}

override suspend fun addLabel(label: String) {
dreamDiaryDao.insertLabel(
LabelEntity(
label = label,
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ interface DreamDiaryRepository {
title: String,
body: String,
)

suspend fun addLabel(label: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.boostcamp.dreamteam.dreamdiary.core.domain.usecase

import com.boostcamp.dreamteam.dreamdiary.core.data.repository.DreamDiaryRepository
import javax.inject.Inject

class AddLabelUseCase @Inject constructor(
private val diaryRepository: DreamDiaryRepository,
) {
suspend operator fun invoke(label: String) {
return diaryRepository.addLabel(label)
}
}