REST? DTOs
I have two entities: Book, Author
And two DTOs for both of them.
I want to receive a BookDTO in my controller action.
Do I want to have AuthorDTO in it,
like, is it normal to create another entities through a Book one?
Or do I separate it with distinct controllers: one for Books, one for Authors.
I get a Book and AuthorID (not an entire object),
or I can access Book Authors via AuthorsConroller
(books/id/authors)
What is a better way? Thank you
8 Replies
Far as creating goes, I would not create an author while creating a book
Far as fetching the data goes, absolutely do include the author with the book, no problem with that
So when creating a book, I only pass an author ID to it, if there is any associated
Yeah
If there is not, I create a new author, retrieve an ID from a created record, and then pass it to the Book
Thank you!!!!!!!!!!!!
Also<
how do I correctly map this?
Is it normal to call EF in my mapster config?
I usually just map my things manually, inside of
.Select()
Never used Mapster, so I won't be of much help thereLike
I want these IDs to be mapped to persistent objects
Find Author by id, add it to "Authors"
and so on
Oh, I see that people use "Converters"
Inject DBContext there, map id to entity, return it
And everything goes well