-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Domain logic bug in the models #73
Conversation
@@ -1,8 +1,9 @@ | |||
package com.stepango.blockme.feature.characters.favorite.api.domain.usecase | |||
|
|||
import com.stepango.blockme.feature.characters.favorite.api.domain.model.ICharacterFavorite | |||
import com.stepango.blockme.feature.characters.core.api.domain.model.ICharacter | |||
|
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.
redundant space
|
||
@Entity(tableName = "character_favorite") | ||
data class CharacterFavorite( | ||
@PrimaryKey override val id: Long, | ||
@ColumnInfo(name = "name") override val name: String, | ||
@ColumnInfo(name = "description") override val description: String, |
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.
Did you forgot to add this new field within MIGRATION_1_2
?
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.
I just drop table in MIGRATION_1_2
|
||
interface ICharacterItem { | ||
interface ICharacter { |
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.
Good improvement!
Now we have only 3 types of "Character"!
But we can do more, what do you think, if we'll remove CharacterItem
and CharacterDetail
? I think about added single entity implementation of ICharacter
into core:impl, for example
class Character : ICharacter
And other domains Character Details/Items/Favorites
will use only ICharacter type with default core implementation under hood.
In that case, will be only one Character
single entity with unique structure placed in the core target.
What do you think?
@@ -21,6 +21,6 @@ import androidx.sqlite.db.SupportSQLiteDatabase | |||
|
|||
val MIGRATION_1_2: Migration = object : Migration(1, 2) { |
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.
Lack of tests
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.
May be need another issue for that
import com.stepango.blockme.feature.characters.core.api.domain.model.ICharacter | ||
|
||
interface ICharacterDetail : ICharacter |
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.
For details we can use ICharacter type too, cause it doesn't have unique entity logic.
(it will be not scalable if details will be extended, but for our sample it doesn't need)
|
||
interface IGetCharacterFavoriteUseCase { | ||
|
||
suspend operator fun invoke(characterFavoriteId: Long): ICharacterFavorite? | ||
suspend operator fun invoke(characterFavoriteId: Long): ICharacter? |
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.
I think usecase shouldn't throw nullable behavior for "clients", but for improving that need another issue)
@@ -21,6 +21,6 @@ import androidx.sqlite.db.SupportSQLiteDatabase | |||
|
|||
val MIGRATION_1_2: Migration = object : Migration(1, 2) { |
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.
May be need another issue for that
@@ -41,14 +41,14 @@ const val PAGE_MAX_ELEMENTS = 50 | |||
open class CharacterPageDataSource @Inject constructor( | |||
private val repository: MarvelRepository, |
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.
I think MarvelRepository should use ICharacter
type too.
And CharacterMapper
we can move into core part.
5f1ccac
to
05cf3bd
Compare
import com.stepango.blockme.feature.characters.core.api.data.response.CharacterResponse | ||
import com.stepango.blockme.feature.characters.core.api.domain.model.ICharacter | ||
|
||
interface ICharacterMapper { |
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.
I can't use Mapper<> from :common.utils in this api module
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.
What is the purpose of exposing the mapper in API module?
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.
You shouldn't use CharacterMapper as additional interface for api target. This logic need to place in the impl target as "inner" behavior for converting models.
In the api targets better provide for outer dependecies:
- interfaces for domain models
- interfaces for UseCase's
- interfaces for Repositories
@@ -48,7 +48,7 @@ class CharacterDetailViewModel @Inject constructor( | |||
viewModelScope.launch { | |||
try { | |||
val result = marvelRepository.getCharacter(characterId) |
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.
You should use call UseCase here, instead directly call to data layer
05cf3bd
to
79babb4
Compare
79babb4
to
d327c8a
Compare
#60
For now:
core.api.domain.model.ICharacter - core character entity
detail.api.domain.model.ICharacterDetail - extension for ICharacter
favorite.impl.data.model.CharacterFavorite - DB entitiy