C
C#2y ago
bookuha

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
Angius
Angius2y ago
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
bookuha
bookuha2y ago
So when creating a book, I only pass an author ID to it, if there is any associated
Angius
Angius2y ago
Yeah
bookuha
bookuha2y ago
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<
bookuha
bookuha2y ago
how do I correctly map this?
bookuha
bookuha2y ago
Is it normal to call EF in my mapster config?
Angius
Angius2y ago
I usually just map my things manually, inside of .Select() Never used Mapster, so I won't be of much help there
bookuha
bookuha2y ago
Like 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