If I had to create some sort of API with a MVC architechture, I would have to decide a naming convention for DTOs that the controller receive and those DTOs that the controller produces I'm right?
For example, given the following code:
public class InStudentDTO
{
public int Id { get; set; }
public List<int> Grades { get; set; }
}
public class OutStudentDTO
{
public int Id { get; set; }
public bool HasApprovedCourse { get; set; }
}
[HttpPost]
public OutStudentDto StudentHasApprovedCourse(InStudentDto dto)
{
OutStudentDto outStudentDto = _someService.CalculateStudentApprovedCourse(dto);
return outStudentDto;
}
This is just a silly example, but the point is that I want to perform some calculation inside a service with the property List<int> Grades
and not showing it later on the output of the controller. Thus, as far as I understand I should create a brand new DTO only that doesn't expose the List<int> Grades
property, right? If so, how is the right naming convention to this "produced DTOs¨? or should just name those as Viewmodels?
Thanks!
GET
action have a DTO? GET actions should only have scalar parameters, not complex-types or objects. Otherwise make it a POST action. – MandarinStudentGetResponse
,StudentPutRequest
, ` orStudentPostRequest
andStudentPostResponse
. It's very easy to know then for example in testing when to use what object and what properties to fill or expect. – Croatia