src/Web/WebMVC/Services/CatalogService.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
namespace Microsoft.eShopOnContainers.WebMVC.Services;
public class CatalogService : ICatalogService
{
private readonly IOptions<AppSettings> _settings;
private readonly HttpClient _httpClient;
private readonly ILogger<CatalogService> _logger;
private readonly string _remoteServiceBaseUrl;
public CatalogService(HttpClient httpClient, ILogger<CatalogService> logger, IOptions<AppSettings> settings)
{
_httpClient = httpClient;
_settings = settings;
_logger = logger;
_remoteServiceBaseUrl = $"{_settings.Value.PurchaseUrl}/c/api/v1/catalog/";
}
public async Task<Catalog> GetCatalogItems(int page, int take, int? brand, int? type)
{
var uri = API.Catalog.GetAllCatalogItems(_remoteServiceBaseUrl, page, take, brand, type);
var responseString = await _httpClient.GetStringAsync(uri);
var catalog = JsonSerializer.Deserialize<Catalog>(responseString, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
return catalog;
}
public async Task<IEnumerable<SelectListItem>> GetBrands()
{
var uri = API.Catalog.GetAllBrands(_remoteServiceBaseUrl);
var responseString = await _httpClient.GetStringAsync(uri);
var items = new List<SelectListItem>();
items.Add(new SelectListItem() { Value = null, Text = "All", Selected = true });
using var brands = JsonDocument.Parse(responseString);
foreach (JsonElement brand in brands.RootElement.EnumerateArray())
{
items.Add(new SelectListItem()
{
Value = brand.GetProperty("id").ToString(),
Text = brand.GetProperty("brand").ToString()
});
}
return items;
}
public async Task<IEnumerable<SelectListItem>> GetTypes()
{
var uri = API.Catalog.GetAllTypes(_remoteServiceBaseUrl);
后面还有 20 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。