A
A
Alexander2019-09-26 15:20:16
symfony
Alexander, 2019-09-26 15:20:16

Is this architecture correct?

Prompt, please, who understands patterns and DDD.
In the context of Symfony.
situation:
It is necessary to work with comments. Create comments on the API, give on the API
in order to create a comment, you only need the text of the comment, and the id of what we are commenting on, 2 fields.
To do this, I created a model

CommentNew {
    text;
    commentable;
}

After a comment has been created, I want to return information about it. It already contains more fields.
CommentView {
    text;
    commentable;
    id;
    author: UserObject;
    time;
    files: LinksList;
}

At the same time, there is the Comment entity, which has almost all the fields that the CommentView has, but only knows about the associated files (in the database) and not about the generated links.
It turns out that 3 classes are allocated for one object.
In order to give a CommentView to the client, I must convert the Comment into a CommentView (with my own logic). In order to create - must convert CommentNew to Comment (with its own logic)
Questions:
1. Is this the norm?
2. As norms if it's not
3. What pattern (possible with an example) to use to "transform" one object into another.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hack504, 2019-09-26
@hack504

And the symphony has some kind of tactics and it must be followed. ("best practices Symfony API").
CommentNew is not needed at all, according to this ideology, then it will be necessary to create both CommentUpdate and CommentDelete and even CommentLike with CommentDislike - as you can see, these are all API methods, they just need to be validated for the required fields and passed to the required Comment method. And Comment will already return CommentView.
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question