34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using DataProviders;
|
|
using DomainResults.Common;
|
|
using WeatherForecast.Models;
|
|
using WeatherForecast.Models.Responses;
|
|
|
|
namespace WeatherForecast.Services {
|
|
|
|
public interface IShopItemsService {
|
|
(GetShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? searchText);
|
|
}
|
|
|
|
public class ShopItemsService : IShopItemsService {
|
|
ILogger<ShopItemsService> _logger;
|
|
IShopCatalogDataProvider _shopCatalogDataProvider;
|
|
|
|
public ShopItemsService(
|
|
ILogger<ShopItemsService> logger,
|
|
IShopCatalogDataProvider shopCatalogDataprovider
|
|
) {
|
|
_logger = logger;
|
|
_shopCatalogDataProvider = shopCatalogDataprovider;
|
|
}
|
|
|
|
public (GetShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? searchText) {
|
|
var (items, result) = _shopCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage);
|
|
|
|
if (!result.IsSuccess || items == null)
|
|
return (null, result);
|
|
|
|
return IDomainResult.Success(new GetShopItemsResponseModel(currentPage, 0, items.Select(x => new GetShopItemResponseModel(x)).ToList()));
|
|
}
|
|
}
|
|
}
|