I am applying Clean Architecture, but actually still have many questions about it.
Suppose, my API @POST fun createJob(@Body request: JobRequest)
. And the params are provided from UI. So,
- In
data
: I have created aJobRequest
like below:
data class JobRequest(
@Expose @SerializedName("p1") val p1: String?,
...
@Expose @SerializedName("p7") val p7: String?
)
- In
domain
: I create aCreateJobUseCase
like below:
class CreateJobUseCase(private val userRepository: UserRepository) :
BaseUseCase<CreateJobUseCase.Input, Job>() {
override suspend fun execute(input: Input): Job {
return userRepository.createJob(input.p1, ...input.p7)
}
data class Input(
val p1: String,
....
val p7: String,
) : BaseInput()
}
- In
presentation
: I will call fromViewModel
like:
createJobUseCase.execute(CreateJobUseCase.Input(p1, p2...p7)) {
//handle output
}
My question is:
In domain
, should my UserRepository
interface like A or B?
A: suspend fun createJob(input: CreateJobUseCase.Input) : Job
or
B: suspend fun createJob(p1: String,... p7: String) : Job
In many projects, I saw them use B
, it seems the repository function is cleared. But, I think A
still ok, because it's still flow the dependency rule, and CreateJobUseCase.Input
already contains what we need for createJob
function. Am I wrong ?
Aucun commentaire:
Enregistrer un commentaire