I have a question cause I've been in this situation before and I want to know best practice.
Lets say you want these three endpoints.
host:port/api/movies/published/2012
returns all from '2012' sorted by published_date (M13, M1)
host:port/api/movies/published/2012/8
returns all from '2012-08' sorted by published_date (M1)
host:port/api/movies/published/2012/8/15
returns all from '2012-08-15' sorted by published_date (M1)
Would you have done a generic endpoint like this or what is best practice in these situations? How would you solve it?
[HttpGet("published/{year:int}/{month:int?}/{day:int?}/")]
public void GetMoviesSortedByPublishedDateAsync(int year, int month = 0, int day = 0)
{
if (month == 0)
{
var date = new DateTime(year, 1, 1);
await _cosmosDbService.GetMoviesByYear(date.Year);
}
else if(day == 0)
{
var date = new DateTime(year, month, 1);
await _cosmosDbService.GetMoviesByYearAndMonth(date.Year, date.Month);
}
else
{
var date = new DateTime(year, month, day);
await _cosmosDbService.GetMoviesByPublishedDate(date);
}
}