-
Notifications
You must be signed in to change notification settings - Fork 18
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
Implement adding a Category in CategoriesUseCase #453
Merged
PaulKlauser
merged 2 commits into
main
from
chore/452-abstract-over-saved-preset-categories
Nov 29, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,17 @@ import com.willowtree.vocable.presets.Category | |
import com.willowtree.vocable.presets.IPresetsRepository | ||
import com.willowtree.vocable.presets.PresetCategoriesRepository | ||
import com.willowtree.vocable.presets.asCategory | ||
import com.willowtree.vocable.room.CategoryDto | ||
import com.willowtree.vocable.room.CategorySortOrder | ||
import com.willowtree.vocable.room.StoredCategoriesRepository | ||
import com.willowtree.vocable.utils.DateProvider | ||
import com.willowtree.vocable.utils.UUIDProvider | ||
import com.willowtree.vocable.utils.locale.LocalesWithText | ||
import com.willowtree.vocable.utils.locale.LocaleProvider | ||
import com.willowtree.vocable.utils.locale.LocalesWithText | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
class CategoriesUseCase( | ||
private val presetsRepository: IPresetsRepository, | ||
private val uuidProvider: UUIDProvider, | ||
private val dateProvider: DateProvider, | ||
private val localeProvider: LocaleProvider, | ||
private val storedCategoriesRepository: StoredCategoriesRepository, | ||
private val presetCategoriesRepository: PresetCategoriesRepository | ||
|
@@ -49,10 +46,9 @@ class CategoriesUseCase( | |
} | ||
|
||
override suspend fun addCategory(categoryName: String, sortOrder: Int) { | ||
presetsRepository.addCategory( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great ask, looks like it's not |
||
CategoryDto( | ||
storedCategoriesRepository.addCategory( | ||
Category.StoredCategory( | ||
uuidProvider.randomUUIDString(), | ||
dateProvider.currentTimeMillis(), | ||
null, | ||
LocalesWithText(mapOf(Pair(localeProvider.getDefaultLocaleString(), categoryName))), | ||
false, | ||
|
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: 2 additions & 0 deletions
2
app/src/main/java/com/willowtree/vocable/room/StoredCategoriesRepository.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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package com.willowtree.vocable.room | ||
|
||
import com.willowtree.vocable.presets.Category | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface StoredCategoriesRepository { | ||
fun getAllCategories(): Flow<List<CategoryDto>> | ||
suspend fun addCategory(category: Category.StoredCategory) | ||
} |
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
34 changes: 26 additions & 8 deletions
34
app/src/test/java/com/willowtree/vocable/room/FakeStoredCategoriesRepository.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 |
---|---|---|
@@ -1,21 +1,39 @@ | ||
package com.willowtree.vocable.room | ||
|
||
import com.willowtree.vocable.presets.Category | ||
import com.willowtree.vocable.utils.locale.LocalesWithText | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.update | ||
|
||
class FakeStoredCategoriesRepository : StoredCategoriesRepository { | ||
val _allCategories = MutableStateFlow(listOf(CategoryDto( | ||
"categoryId", | ||
0L, | ||
0, | ||
LocalesWithText( emptyMap()), | ||
false, | ||
0 | ||
val _allCategories = MutableStateFlow( | ||
listOf( | ||
CategoryDto( | ||
"categoryId", | ||
0L, | ||
0, | ||
LocalesWithText(emptyMap()), | ||
false, | ||
0 | ||
) | ||
) | ||
) | ||
)) | ||
|
||
override fun getAllCategories(): Flow<List<CategoryDto>> { | ||
return _allCategories | ||
} | ||
|
||
override suspend fun addCategory(category: Category.StoredCategory) { | ||
_allCategories.update { | ||
it + CategoryDto( | ||
category.categoryId, | ||
0L, | ||
category.resourceId, | ||
category.localizedName, | ||
category.hidden, | ||
category.sortOrder | ||
) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate discussions from your code but I'm curious on your thoughts on these sort of mono use cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaning, use cases that can do more than one thing? I don't have super strong feelings, and I know a lot of folks go with the one-operation use cases, but I find that doesn't buy you a whole lot for the extra verbosity. What are your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't buy you much for sure. It feel like its conflating two patterns but doesn't feel too wrong otherwise.