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

Domain logic bug in the models #73

Merged
merged 7 commits into from
Jan 25, 2021
Merged

Domain logic bug in the models #73

merged 7 commits into from
Jan 25, 2021

Conversation

ntnsmirnov
Copy link
Collaborator

@ntnsmirnov ntnsmirnov commented Dec 29, 2020

#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

@ntnsmirnov ntnsmirnov linked an issue Dec 29, 2020 that may be closed by this pull request
@@ -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

Copy link
Collaborator

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,
Copy link

@b1n0m13 b1n0m13 Jan 6, 2021

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?

Copy link
Collaborator Author

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 {
Copy link
Collaborator

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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lack of tests

Copy link
Collaborator

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
Copy link
Collaborator

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?
Copy link
Collaborator

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) {
Copy link
Collaborator

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,
Copy link
Collaborator

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.

import com.stepango.blockme.feature.characters.core.api.data.response.CharacterResponse
import com.stepango.blockme.feature.characters.core.api.domain.model.ICharacter

interface ICharacterMapper {
Copy link
Collaborator Author

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

Copy link
Collaborator

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?

Copy link
Collaborator

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)
Copy link
Collaborator

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

@ntnsmirnov ntnsmirnov merged commit 5ae58ce into master Jan 25, 2021
@ntnsmirnov ntnsmirnov deleted the characters_hell branch January 25, 2021 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Domain logic bug in the models
4 participants