C
C#3mo ago
cumslvt13

Dealing with sub-models in request endpoint response pattern

I'm using RERP (request endpoint response) pattern to structure my api endpoints. Recently I've noticed that some requests have lots of fields that could be combined into a separate sub-model as example:
public record CreateCustomerRequest
{
// main group of fields that are used t create customer
public required string Name { get; init; }
public required string Identifier { get; init; }
public required bool Active { get; init; }

// logically grouped fields, that are used to create other entity
public required string CompanyName { get; init; }
public required string CompanyEmail { get; init; }
public required string CompanyIndustry { get; init; }
// ... and so on
}
public record CreateCustomerRequest
{
// main group of fields that are used t create customer
public required string Name { get; init; }
public required string Identifier { get; init; }
public required bool Active { get; init; }

// logically grouped fields, that are used to create other entity
public required string CompanyName { get; init; }
public required string CompanyEmail { get; init; }
public required string CompanyIndustry { get; init; }
// ... and so on
}
It seems obvious that those fields could be mapped to separate model, but question is: where should I put it? Currently my folder structure is following:
Endpoints/
EnitityName/
Requests/
Responses/
EndpointExtensions.cs
Endpoints/
EnitityName/
Requests/
Responses/
EndpointExtensions.cs
I don't really like idea of creating a single folder named Common or Shared and dumping all of the similar models there nor I like the idea of keeping that model with requests, because name would be too generic like CompanyInfoModel which doesn't actually say anything about relation to the CreateCustomerRequest when viewed in swagger. What are your approaches/advises in such situations. How you deal with that kind of stuff?
0 Replies
No replies yetBe the first to reply to this messageJoin