I'm building a Use Case for creating blog posts, this Use Case has its own "DTO", which is basically a parameter object with only primitive data, as follows:
Use Case's DTO (Parameter Object):
export class CreatePostInput {
public id: string;
public slug: string;
public title: string;
public authorId: string;
public platform: string;
public tags: string[];
public images: string[];
public content: string;
public createdAt: string;
}
inside my Use Case, I have to create an entity that is built with most of the data of the Use Case's DTO, the "problem" is that most of the entity's properties are typed with Value Object's, for example:
Post Entity
export class Post {
private id: PostId;
private slug: Slug;
private title: Title;
private authorId: AuthorId;
private platform: Platform;
private tags: Tag[];
private images: Image[];
private content: string;
private createdAt: Date;
}
Use Case:
export class CreatePost {
public async create(CreatePostInput: CreatePostInput): Promise<CreatePostOutput> {
if (CreatePostInput.images.length > 0) {
// do something...
}
// some more logic using typed data
const PostEntity = new Post(CreatePostInput);
// ...
// return CreatePostOutput
}
}
Should the Use Case be responsible for creating the entity's Value Objects or transforming its primitive data into something else? if so, is there a problem with instantiating the Value Objects inside the Use Case?
If I happen to have more entities and more Value Objects in this use case, how should i organize all this creation? builder pattern?