-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GetDayLogList Usecase and it's viewModel Impelementation.
This commit includes, 1. Fix some directory hierarchy according to clean architecture. 2. Add GetDayLogList usecase. 3. Implement FakeDataRepository to test usecaes before implementing create dayLog usecase. 4. Link usecase with DayLogListViewModel for front page. TODO: - Need to implement navhost. - Need to implement deletion action for listview. Signed-off-by: Hyukjoong Kim <wangmir@gmail.com>
- Loading branch information
Showing
26 changed files
with
292 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/src/androidTest/java/com/wangmir/calliope/UseCasesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.wangmir.calliope | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import com.wangmir.calliope.adapters.data.FakeDataRepository | ||
import com.wangmir.calliope.domain.usecases.GetDayLogList | ||
import com.wangmir.calliope.domain.util.DayLogFilter | ||
import com.wangmir.calliope.domain.util.OrderType | ||
import com.wangmir.calliope.testutils.getOrAwaitValue | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.jupiter.api.Test | ||
|
||
@ExperimentalCoroutinesApi | ||
class UseCasesTest { | ||
|
||
private val getDayLogList get() = GetDayLogList(FakeDataRepository()) | ||
|
||
@Test | ||
fun testGetDayLogListByYear() = runBlocking { | ||
val uc = getDayLogList | ||
var filter = DayLogFilter.Year(OrderType.Ascending, 2021) | ||
var result = uc(filter).getOrAwaitValue(this, dispatcher = Dispatchers.IO) | ||
assertThat(result).isNotNull() | ||
result.forEach { | ||
assertThat(it.date.year).isEqualTo(2021) | ||
} | ||
|
||
assertThat(result[0].date.toInt()).isLessThan(result[1].date.toInt()) | ||
|
||
filter = DayLogFilter.Year(OrderType.Descending, 2021) | ||
result = uc(filter).getOrAwaitValue(this, dispatcher = Dispatchers.IO) | ||
result.forEach { | ||
assertThat(it.date.year).isEqualTo(2021) | ||
} | ||
|
||
assertThat(result[0].date.toInt()).isGreaterThan(result[1].date.toInt()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...r/calliope/model/adapters/data/BaseDao.kt → ...wangmir/calliope/adapters/data/BaseDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...model/adapters/data/DataRepositoryImpl.kt → ...liope/adapters/data/DataRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...calliope/model/adapters/data/DayLogDao.kt → ...ngmir/calliope/adapters/data/DayLogDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/main/java/com/wangmir/calliope/adapters/data/FakeDataRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.wangmir.calliope.adapters.data | ||
|
||
import com.wangmir.calliope.domain.entities.Date | ||
import com.wangmir.calliope.domain.entities.DayLog | ||
import com.wangmir.calliope.domain.entities.EmotionLog | ||
import com.wangmir.calliope.domain.entities.TextLog | ||
import com.wangmir.calliope.domain.repositories.DataRepository | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.datetime.LocalDate | ||
|
||
class FakeDataRepository : DataRepository { | ||
|
||
companion object { | ||
const val MOCK_KEYWORD = "MOCK_KEYWORD" | ||
} | ||
|
||
val list = mutableListOf<DayLog>() | ||
val mockData = DayLog.getMockDayLog() | ||
|
||
init { | ||
// year 2021 | ||
list.add(mockData.copy(date = Date(2021, 10, 30))) | ||
list.add(mockData.copy(date = Date(2021, 9, 28))) | ||
|
||
// year 2022 | ||
list.add(mockData.copy(date = Date(2022, 1, 21))) | ||
list.add(mockData.copy(date = Date(2022, 2, 28))) | ||
|
||
// keyword has "MOCK_KEYWORD" | ||
list.add(mockData.copy(textLog = TextLog(MOCK_KEYWORD))) | ||
list.add(mockData.copy(textLog = TextLog(MOCK_KEYWORD + "tail misc text"))) | ||
|
||
// emotion is Fear | ||
list.add(mockData.copy(emotionLog = EmotionLog.Fear)) | ||
} | ||
|
||
override suspend fun insertDayLog(dayLog: DayLog) { | ||
list.add(dayLog) | ||
} | ||
|
||
override suspend fun getDayLog(date: LocalDate): DayLog { | ||
return list.find { it.date == Date(date) }!! | ||
} | ||
|
||
override suspend fun deleteDayLog(date: LocalDate) { | ||
list.removeIf { it.date == Date(date) } | ||
} | ||
|
||
override fun getDayLogsByYear(year: Int): Flow<List<DayLog>> { | ||
return flowOf(list.filter { it.date.year == year }) | ||
} | ||
|
||
override fun getDayLogsByKeyword(keyword: String): Flow<List<DayLog>> { | ||
return flowOf(list.filter { it.textLog.text.contains(keyword) }) | ||
} | ||
|
||
override fun getDayLogsByEmotion(emotionLog: EmotionLog): Flow<List<DayLog>> { | ||
return flowOf(list.filter { it.emotionLog == emotionLog }) | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...iope/model/adapters/data/LocalDatabase.kt → ...r/calliope/adapters/data/LocalDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mir/calliope/model/entities/EmotionLog.kt → ...ir/calliope/domain/entities/EmotionLog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...wangmir/calliope/model/entities/SttLog.kt → ...angmir/calliope/domain/entities/SttLog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...angmir/calliope/model/entities/TextLog.kt → ...ngmir/calliope/domain/entities/TextLog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ngmir/calliope/model/entities/VoiceLog.kt → ...gmir/calliope/domain/entities/VoiceLog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
.../wangmir/calliope/model/DataRepository.kt → ...ope/domain/repositories/DataRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/wangmir/calliope/domain/usecases/GetDayLogList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.wangmir.calliope.domain.usecases | ||
|
||
import com.wangmir.calliope.domain.entities.DayLog | ||
import com.wangmir.calliope.domain.repositories.DataRepository | ||
import com.wangmir.calliope.domain.util.DayLogFilter | ||
import com.wangmir.calliope.domain.util.OrderType | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
class GetDayLogList( | ||
private val dataRepository: DataRepository | ||
) { | ||
operator fun invoke(filter: DayLogFilter): Flow<List<DayLog>> { | ||
val logs = when (filter) { | ||
is DayLogFilter.Year -> dataRepository.getDayLogsByYear(filter.year) | ||
is DayLogFilter.Keyword -> dataRepository.getDayLogsByKeyword(filter.keyword) | ||
is DayLogFilter.Emotion -> dataRepository.getDayLogsByEmotion(filter.emotion) | ||
} | ||
return logs.map { dayLogs -> | ||
when (filter.orderType) { | ||
is OrderType.Ascending -> dayLogs.sortedBy { it.date.toInt() } | ||
is OrderType.Descending -> dayLogs.sortedByDescending { it.date.toInt() } | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/wangmir/calliope/domain/util/DayLogFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.wangmir.calliope.domain.util | ||
|
||
import com.wangmir.calliope.domain.entities.EmotionLog | ||
|
||
sealed class DayLogFilter(val orderType: OrderType) { | ||
class Year(orderType: OrderType, val year: Int): DayLogFilter(orderType) | ||
class Keyword(orderType: OrderType, val keyword: String): DayLogFilter(orderType) | ||
class Emotion(orderType: OrderType, val emotion: EmotionLog): DayLogFilter(orderType) | ||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/wangmir/calliope/domain/util/OrderType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.wangmir.calliope.domain.util | ||
|
||
sealed class OrderType { | ||
object Ascending: OrderType() | ||
object Descending: OrderType() | ||
} |
6 changes: 0 additions & 6 deletions
6
app/src/main/java/com/wangmir/calliope/model/events/UiEvent.kt
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ir/calliope/viewmodels/SampleViewModel.kt → .../calliope/presentation/SampleViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/wangmir/calliope/presentation/list/DayLogListEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.wangmir.calliope.presentation.list | ||
|
||
import com.wangmir.calliope.domain.entities.DayLog | ||
import com.wangmir.calliope.domain.util.DayLogFilter | ||
|
||
sealed class DayLogListEvent { | ||
data class Filter(val dayLogFilter: DayLogFilter): DayLogListEvent() | ||
data class DeleteNote(val dayLog: DayLog): DayLogListEvent() | ||
object RestoreNote: DayLogListEvent() | ||
object ToggleOrderSection: DayLogListEvent() | ||
} |
Oops, something went wrong.