During my first attempt of implementing a project with the "Clean Architecture" I try to implementation a job portal where I came across a problem concerning the communication between (hopefully) two loosely coupled modules.
The two modules are:
Identity
- responsible for user operations like registerCatalog
- responsible for job operations like find
The Problem
When searching for one or more jobs, information about the employer should be sent along with the job information.
Brief Architect Description
A Job
(inside Catalog
) references an User
(inside Identity
) by an id called employee
:
class Job {
private Identifier id;
private Identifier employee;
/* ... */
}
First Attempt
My first idea was to query the information inside a Use Case but this would couple the two modules:
class FindJobByIdUseCase {
private final FindUserByIdUseCase findUserById; // from Identity module
/* ... */
JobResponse execute(FindJobInput input) {
User employee = findUserById.execute(input.employee);
Job job = /* ... */;
/* ... */
return new JobResponse(jobDTO, employeeDTO);
}
}
Second Attempt
I thought I could create a third module coupled to Identity
and Catalog
to aggregate the required data:
Identity
<----- Identity-Catalog-Aggregat
-------> Catalog
// in Identity-Catalog-Module
class FindJobAndEmployeeUseCase {
private final FindUserByIdUseCase findUserById; // from Identity module
private final FindJobByIdUseCase findJobById; // from Catalog module
/* ... */
Response execute(FindJobAndEmployeeInput input) {
User employee = findUserById.execute(input.employee);
Job job = findJobById.execute(input.job);
/ * ... */
return new Response(jobDTO, employeeDTO);
}
}
Both attempts feel wrong.. Can you advise me on the solution that makes the most sense?
Job
reference aUser
? More to the point, what does registering aUser
have to do with finding aJob
? Hint: Two domain entities can share an identifier.