using DomainResults.Common;
using DataProviders.Collections;
using WeatherForecast.Models.Responses;
namespace WeatherForecast.Services {
///
///
///
public interface IContentService {
///
///
///
///
///
///
(ContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale);
}
///
///
///
public class ContentService : IContentService {
private readonly ILogger _logger;
private readonly IContentDataProvider _contentDataProvider;
///
///
///
///
///
public ContentService(
ILogger logger,
IContentDataProvider contentDataprovider
) {
_logger = logger;
_contentDataProvider = contentDataprovider;
}
///
///
///
///
///
///
public (ContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale) {
try {
var (content, result) = _contentDataProvider.Get(siteId);
if (!result.IsSuccess || content == null)
return (null, result);
return IDomainResult.Success(new ContentResponseModel(content.Single(x => x.Localization.Locale == locale)));
}
catch (Exception ex) {
_logger.LogError(ex, "Unhandled exception");
return IDomainResult.Failed(ex.Message);
}
}
}
}