JeeferSan
JeeferSan

Reputation: 21

How to structure DTO class in a clean architecture project with parcelize?

I'm working on an Android app in Kotlin and am trying to implement Clean Architecture with viewmodels, repositories, datasources, interfaces etc.

Right now I have a DTO class that I'm parsing with Retrofit:

@Parcelize
data class NewsArticleDto(
    val author: String, val title: String, val description: String,
    val url: String, val urlToImage: String, val publishedAt: String, val content: String
) : Parcelable

I would like to have an interactor called "GetNews" get the data from NewsRepository which in turn gets it from the datasource (retrofit), map it to NewsArticle entities and send a list of NewsArticles back to the viewmodel.

The data layer is inside a different module("core"), which is a java library. The repository/interactors dont know about the DTO class since it's in the "app" module.

The core module isn't supposed to know about the "app" module. It's also not supposed to have SDK-logic, as I understand it.

So the problem here is that the interactor doesn't know about a DTO class and if I move it altogether to the "core" module, Android Studio can't handle the @parcelize and parcelable.

How do I structure my project or am I overengineering things and should I leave the DTO altogether in the "app" module? If so, I still won't be able to use a "GetNews" interactor.

This is the GetNews interactor:

class GetNews(private val newsRepository: NewsRepository) {
    suspend operator fun invoke(keyword: String, apiKey: String): Result<List<NewsArticle>> =
        try {
            newsRepository.getNews(keyword, apiKey) as Result<List<NewsArticle>>
        } catch (throwable: Throwable) {
            Result.Failure(throwable)
        }
}

What I have tried:

This is my project structure:

Text](https://imgur.com/eQ14M7H)[![enter image description here]1

Any help is appreciated.

Upvotes: 1

Views: 1934

Answers (0)

Related Questions