Small-Formatting-Refactoring
This commit is contained in:
parent
21cde1b005
commit
032a21e3fc
@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
public class CatalogSettings
|
public class CatalogSettings
|
||||||
{
|
{
|
||||||
public string PicBaseUrl { get;set;}
|
public string PicBaseUrl { get; set; }
|
||||||
|
|
||||||
public string EventBusConnection { get; set; }
|
public string EventBusConnection { get; set; }
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
|||||||
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||||
[ProducesResponseType(typeof(IEnumerable<CatalogItem>), (int)HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||||
public async Task<IActionResult> ItemsAsync([FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0, string ids = null)
|
public async Task<IActionResult> ItemsAsync([FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0, string ids = null)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(ids))
|
if (!string.IsNullOrEmpty(ids))
|
||||||
{
|
{
|
||||||
@ -126,7 +126,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("items/withname/{name:minlength(1)}")]
|
[Route("items/withname/{name:minlength(1)}")]
|
||||||
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||||
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsWithNameAsync(string name, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsWithNameAsync(string name, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0)
|
||||||
{
|
{
|
||||||
var totalItems = await _catalogContext.CatalogItems
|
var totalItems = await _catalogContext.CatalogItems
|
||||||
.Where(c => c.Name.StartsWith(name))
|
.Where(c => c.Name.StartsWith(name))
|
||||||
@ -147,7 +147,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("items/type/{catalogTypeId}/brand/{catalogBrandId:int?}")]
|
[Route("items/type/{catalogTypeId}/brand/{catalogBrandId:int?}")]
|
||||||
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||||
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsByTypeIdAndBrandIdAsync(int catalogTypeId, int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsByTypeIdAndBrandIdAsync(int catalogTypeId, int? catalogBrandId, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0)
|
||||||
{
|
{
|
||||||
var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems;
|
var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems;
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("items/type/all/brand/{catalogBrandId:int?}")]
|
[Route("items/type/all/brand/{catalogBrandId:int?}")]
|
||||||
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||||
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsByBrandIdAsync(int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsByBrandIdAsync(int? catalogBrandId, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0)
|
||||||
{
|
{
|
||||||
var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems;
|
var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems;
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
|||||||
[HttpPut]
|
[HttpPut]
|
||||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||||
[ProducesResponseType((int)HttpStatusCode.Created)]
|
[ProducesResponseType((int)HttpStatusCode.Created)]
|
||||||
public async Task<ActionResult> UpdateProductAsync([FromBody]CatalogItem productToUpdate)
|
public async Task<ActionResult> UpdateProductAsync([FromBody] CatalogItem productToUpdate)
|
||||||
{
|
{
|
||||||
var catalogItem = await _catalogContext.CatalogItems.SingleOrDefaultAsync(i => i.Id == productToUpdate.Id);
|
var catalogItem = await _catalogContext.CatalogItems.SingleOrDefaultAsync(i => i.Id == productToUpdate.Id);
|
||||||
|
|
||||||
@ -259,7 +259,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
|||||||
[Route("items")]
|
[Route("items")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ProducesResponseType((int)HttpStatusCode.Created)]
|
[ProducesResponseType((int)HttpStatusCode.Created)]
|
||||||
public async Task<ActionResult> CreateProductAsync([FromBody]CatalogItem product)
|
public async Task<ActionResult> CreateProductAsync([FromBody] CatalogItem product)
|
||||||
{
|
{
|
||||||
var item = new CatalogItem
|
var item = new CatalogItem
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,7 @@ namespace Catalog.API.Grpc
|
|||||||
private readonly CatalogContext _catalogContext;
|
private readonly CatalogContext _catalogContext;
|
||||||
private readonly CatalogSettings _settings;
|
private readonly CatalogSettings _settings;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public CatalogService(CatalogContext dbContext, IOptions<CatalogSettings> settings, ILogger<CatalogService> logger)
|
public CatalogService(CatalogContext dbContext, IOptions<CatalogSettings> settings, ILogger<CatalogService> logger)
|
||||||
{
|
{
|
||||||
_settings = settings.Value;
|
_settings = settings.Value;
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
public class CatalogContextSeed
|
public class CatalogContextSeed
|
||||||
{
|
{
|
||||||
public async Task SeedAsync(CatalogContext context,IWebHostEnvironment env,IOptions<CatalogSettings> settings,ILogger<CatalogContextSeed> logger)
|
public async Task SeedAsync(CatalogContext context, IWebHostEnvironment env, IOptions<CatalogSettings> settings, ILogger<CatalogContextSeed> logger)
|
||||||
{
|
{
|
||||||
var policy = CreatePolicy(logger, nameof(CatalogContextSeed));
|
var policy = CreatePolicy(logger, nameof(CatalogContextSeed));
|
||||||
|
|
||||||
@ -73,7 +73,7 @@
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string[] requiredHeaders = { "catalogbrand" };
|
string[] requiredHeaders = { "catalogbrand" };
|
||||||
csvheaders = GetHeaders( csvFileCatalogBrands, requiredHeaders );
|
csvheaders = GetHeaders(csvFileCatalogBrands, requiredHeaders);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -128,7 +128,7 @@
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string[] requiredHeaders = { "catalogtype" };
|
string[] requiredHeaders = { "catalogtype" };
|
||||||
csvheaders = GetHeaders( csvFileCatalogTypes, requiredHeaders );
|
csvheaders = GetHeaders(csvFileCatalogTypes, requiredHeaders);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -183,7 +183,7 @@
|
|||||||
{
|
{
|
||||||
string[] requiredHeaders = { "catalogtypename", "catalogbrandname", "description", "name", "price", "picturefilename" };
|
string[] requiredHeaders = { "catalogtypename", "catalogbrandname", "description", "name", "price", "picturefilename" };
|
||||||
string[] optionalheaders = { "availablestock", "restockthreshold", "maxstockthreshold", "onreorder" };
|
string[] optionalheaders = { "availablestock", "restockthreshold", "maxstockthreshold", "onreorder" };
|
||||||
csvheaders = GetHeaders(csvFileCatalogItems, requiredHeaders, optionalheaders );
|
csvheaders = GetHeaders(csvFileCatalogItems, requiredHeaders, optionalheaders);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -196,7 +196,7 @@
|
|||||||
|
|
||||||
return File.ReadAllLines(csvFileCatalogItems)
|
return File.ReadAllLines(csvFileCatalogItems)
|
||||||
.Skip(1) // skip header row
|
.Skip(1) // skip header row
|
||||||
.Select(row => Regex.Split(row, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)") )
|
.Select(row => Regex.Split(row, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"))
|
||||||
.SelectTry(column => CreateCatalogItem(column, csvheaders, catalogTypeIdLookup, catalogBrandIdLookup))
|
.SelectTry(column => CreateCatalogItem(column, csvheaders, catalogTypeIdLookup, catalogBrandIdLookup))
|
||||||
.OnCaughtException(ex => { logger.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); return null; })
|
.OnCaughtException(ex => { logger.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); return null; })
|
||||||
.Where(x => x != null);
|
.Where(x => x != null);
|
||||||
@ -243,7 +243,7 @@
|
|||||||
string availableStockString = column[availableStockIndex].Trim('"').Trim();
|
string availableStockString = column[availableStockIndex].Trim('"').Trim();
|
||||||
if (!String.IsNullOrEmpty(availableStockString))
|
if (!String.IsNullOrEmpty(availableStockString))
|
||||||
{
|
{
|
||||||
if ( int.TryParse(availableStockString, out int availableStock))
|
if (int.TryParse(availableStockString, out int availableStock))
|
||||||
{
|
{
|
||||||
catalogItem.AvailableStock = availableStock;
|
catalogItem.AvailableStock = availableStock;
|
||||||
}
|
}
|
||||||
@ -370,7 +370,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private AsyncRetryPolicy CreatePolicy( ILogger<CatalogContextSeed> logger, string prefix,int retries = 3)
|
private AsyncRetryPolicy CreatePolicy(ILogger<CatalogContextSeed> logger, string prefix, int retries = 3)
|
||||||
{
|
{
|
||||||
return Policy.Handle<SqlException>().
|
return Policy.Handle<SqlException>().
|
||||||
WaitAndRetryAsync(
|
WaitAndRetryAsync(
|
||||||
|
@ -12,7 +12,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Catalog.API.IntegrationEvents
|
namespace Catalog.API.IntegrationEvents
|
||||||
{
|
{
|
||||||
public class CatalogIntegrationEventService : ICatalogIntegrationEventService,IDisposable
|
public class CatalogIntegrationEventService : ICatalogIntegrationEventService, IDisposable
|
||||||
{
|
{
|
||||||
private readonly Func<DbConnection, IIntegrationEventLogService> _integrationEventLogServiceFactory;
|
private readonly Func<DbConnection, IIntegrationEventLogService> _integrationEventLogServiceFactory;
|
||||||
private readonly IEventBus _eventBus;
|
private readonly IEventBus _eventBus;
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
|
|
||||||
public PaginatedItemsViewModel(int pageIndex, int pageSize, long count, IEnumerable<TEntity> data)
|
public PaginatedItemsViewModel(int pageIndex, int pageSize, long count, IEnumerable<TEntity> data)
|
||||||
{
|
{
|
||||||
this.PageIndex = pageIndex;
|
PageIndex = pageIndex;
|
||||||
this.PageSize = pageSize;
|
PageSize = pageSize;
|
||||||
this.Count = count;
|
Count = count;
|
||||||
this.Data = data;
|
Data = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user