I'm currently all about separating things where it makes sense. We've come to conclusion that small, slim, only-what-really-need models are the only one accepeatable.
How about this scenario?
public class EmailModel
{
public int Id {get; set;}
public string Subject {get; set;}
public string Body {get; set;}
public List<AttachmentModel> Attachments {get; set;}
...
}
To create a new email, user makes HTTP POST request:
POST api/v1/emails
{
"subject": "email subject",
"body": "some email content .. "
}
There is additional api for atttachments ofcourse api/v1/emails/attachments with POST to upload attachment and GET to retrieve email attachments.
GET email returns something like this:
GET api/v1/emails/1
{
"id": "1",
"subject": "email subject",
"body": "some email content .. "
"attachments": []
}
Is it better to have two models then?
public class CreateEmailModel // for http post
{
public string Subject {get; set;}
public string Body {get; set;}
}
public class EmailModel : CreateEmailModel // for http get
{
public int Id {get; set;}
public List<AttachmentModel> Attachments {get; set;}
}
Or is this complicating things for no reason, but still when another developer sees the code it's immediately clear what the model does. No model property is unneccessary.