I'm working on a API built using service repository pattern. For example when a request gets received , the controller passes data to service , then the service passes data to repository and repository gets data from database and sends it back to service and service returns data to controller, Here is the controller code :
[HttpGet("LatestNAV")]
public IActionResult GetLatestNAV()
{
return Ok(_service.GetLastDailyNAV());
}
service:
public LastDailyNAVDto GetLastDailyNAV()
{
var result = _repository.GetLastDailyNAV();
return result.Adapt<LastDailyNAVDto>();
}
repository:
public LastDailyNAV GetLastDailyNAV()
{
return _db.LastDailyNAV.OrderByDescending(n => n.date).FirstOrDefault();
}
I want to change the date retrieved from database in LastDailyNAV because its unformatted. My question is where is the best place to modify the date. I know that its not in repository cause its not repositories concern. But my problem is formatting data in service cause skinny controller and fat service and vice versa.
CodePudding user response:
I hope this link help you at this problem : What layer should a date be formatted?
