lundi 17 avril 2023

Can a usecase have repositories from different domains as dependencies, following the clean architecture principles?

Assume I have two models: Student and Course, so we have a simple many-to-many relationship here, i.e., each student can take many courses and each course has many students.

I also have a usecase for adding a Student to an existing Course, where I receive as input the Student id and the Course id, and add this pair to my Relationship table which is managed by a AddStudentToCourseRepository.

The problem that I'm facing is the following: If the client tries to add a student to a course that does not exist, my application needs to return an error. I though about adding the ReadStudentByIdRepository and the ReadCourseByIdRepository as dependencies of my AddStudentToCourseUsecase, so I can check whether both id's are valid before calling the AddStudentToCourseRepository.

My question is: Am I going against the clean architecture principles by doing that, I mean, is it a bad practice to have a usecase having repositories from multiple domains as dependencies ? And if I am, how would you guys proceed in this situation ?

Aucun commentaire:

Enregistrer un commentaire