Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Swamy/28dec2020 small refactoring #1564

2 changes: 1 addition & 1 deletion src/Services/Catalog/Catalog.API/CatalogSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class CatalogSettings
{
public string PicBaseUrl { get;set;}
public string PicBaseUrl { get; set; }

public string EventBusConnection { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public CatalogController(CatalogContext context, IOptionsSnapshot<CatalogSetting
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(IEnumerable<CatalogItem>), (int)HttpStatusCode.OK)]
[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))
{
Expand Down Expand Up @@ -126,7 +126,7 @@ public async Task<ActionResult<CatalogItem>> ItemByIdAsync(int id)
[HttpGet]
[Route("items/withname/{name:minlength(1)}")]
[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
.Where(c => c.Name.StartsWith(name))
Expand All @@ -147,7 +147,7 @@ public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsWithN
[HttpGet]
[Route("items/type/{catalogTypeId}/brand/{catalogBrandId:int?}")]
[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;

Expand Down Expand Up @@ -175,7 +175,7 @@ public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsByTyp
[HttpGet]
[Route("items/type/all/brand/{catalogBrandId:int?}")]
[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;

Expand Down Expand Up @@ -220,7 +220,7 @@ public async Task<ActionResult<List<CatalogBrand>>> CatalogBrandsAsync()
[HttpPut]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[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);

Expand Down Expand Up @@ -259,7 +259,7 @@ public async Task<ActionResult> UpdateProductAsync([FromBody]CatalogItem product
[Route("items")]
[HttpPost]
[ProducesResponseType((int)HttpStatusCode.Created)]
public async Task<ActionResult> CreateProductAsync([FromBody]CatalogItem product)
public async Task<ActionResult> CreateProductAsync([FromBody] CatalogItem product)
{
var item = new CatalogItem
{
Expand Down
1 change: 1 addition & 0 deletions src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CatalogService : CatalogBase
private readonly CatalogContext _catalogContext;
private readonly CatalogSettings _settings;
private readonly ILogger _logger;

public CatalogService(CatalogContext dbContext, IOptions<CatalogSettings> settings, ILogger<CatalogService> logger)
{
_settings = settings.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ protected override void OnModelCreating(ModelBuilder builder)
builder.ApplyConfiguration(new CatalogBrandEntityTypeConfiguration());
builder.ApplyConfiguration(new CatalogTypeEntityTypeConfiguration());
builder.ApplyConfiguration(new CatalogItemEntityTypeConfiguration());
}
}
}


public class CatalogContextDesignFactory : IDesignTimeDbContextFactory<CatalogContext>
{
public CatalogContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<CatalogContext>()
var optionsBuilder = new DbContextOptionsBuilder<CatalogContext>()
.UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;Integrated Security=true");

return new CatalogContext(optionsBuilder.Options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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));

Expand Down Expand Up @@ -73,7 +73,7 @@ private IEnumerable<CatalogBrand> GetCatalogBrandsFromFile(string contentRootPat
try
{
string[] requiredHeaders = { "catalogbrand" };
csvheaders = GetHeaders( csvFileCatalogBrands, requiredHeaders );
csvheaders = GetHeaders(csvFileCatalogBrands, requiredHeaders);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -128,7 +128,7 @@ private IEnumerable<CatalogType> GetCatalogTypesFromFile(string contentRootPath,
try
{
string[] requiredHeaders = { "catalogtype" };
csvheaders = GetHeaders( csvFileCatalogTypes, requiredHeaders );
csvheaders = GetHeaders(csvFileCatalogTypes, requiredHeaders);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -183,7 +183,7 @@ private IEnumerable<CatalogItem> GetCatalogItemsFromFile(string contentRootPath,
{
string[] requiredHeaders = { "catalogtypename", "catalogbrandname", "description", "name", "price", "picturefilename" };
string[] optionalheaders = { "availablestock", "restockthreshold", "maxstockthreshold", "onreorder" };
csvheaders = GetHeaders(csvFileCatalogItems, requiredHeaders, optionalheaders );
csvheaders = GetHeaders(csvFileCatalogItems, requiredHeaders, optionalheaders);
}
catch (Exception ex)
{
Expand All @@ -196,7 +196,7 @@ private IEnumerable<CatalogItem> GetCatalogItemsFromFile(string contentRootPath,

return File.ReadAllLines(csvFileCatalogItems)
.Skip(1) // skip header row
.Select(row => Regex.Split(row, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)") )
.Select(row => Regex.Split(row, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"))
.SelectTry(column => CreateCatalogItem(column, csvheaders, catalogTypeIdLookup, catalogBrandIdLookup))
.OnCaughtException(ex => { logger.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); return null; })
.Where(x => x != null);
Expand Down Expand Up @@ -243,7 +243,7 @@ private CatalogItem CreateCatalogItem(string[] column, string[] headers, Diction
string availableStockString = column[availableStockIndex].Trim('"').Trim();
if (!String.IsNullOrEmpty(availableStockString))
{
if ( int.TryParse(availableStockString, out int availableStock))
if (int.TryParse(availableStockString, out int availableStock))
{
catalogItem.AvailableStock = availableStock;
}
Expand Down Expand Up @@ -370,7 +370,7 @@ private void GetCatalogItemPictures(string contentRootPath, string picturePath)
}
}

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>().
WaitAndRetryAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Catalog.API.IntegrationEvents
{
public class CatalogIntegrationEventService : ICatalogIntegrationEventService,IDisposable
public class CatalogIntegrationEventService : ICatalogIntegrationEventService, IDisposable
{
private readonly Func<DbConnection, IIntegrationEventLogService> _integrationEventLogServiceFactory;
private readonly IEventBus _eventBus;
Expand Down Expand Up @@ -73,7 +73,7 @@ protected virtual void Dispose(bool disposing)
{
(_eventLogService as IDisposable)?.Dispose();
}

disposedValue = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Linq;
using System.Threading.Tasks;

public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler :
public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler :
IIntegrationEventHandler<OrderStatusChangedToAwaitingValidationIntegrationEvent>
{
private readonly CatalogContext _catalogContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Serilog.Context;
using System.Threading.Tasks;

public class OrderStatusChangedToPaidIntegrationEventHandler :
public class OrderStatusChangedToPaidIntegrationEventHandler :
IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>
{
private readonly CatalogContext _catalogContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// An Event is “something that has happened in the past”, therefore its name has to be past tense
// An Integration Event is an event that can cause side effects to other microservices, Bounded-Contexts or external systems.
public class ProductPriceChangedIntegrationEvent : IntegrationEvent
{
{
public int ProductId { get; private set; }

public decimal NewPrice { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Catalog/Catalog.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
{
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Catalog.API V1");
});

app.UseRouting();
app.UseCors("CorsPolicy");
app.UseEndpoints(endpoints =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class PaginatedItemsViewModel<TEntity> where TEntity : class

public PaginatedItemsViewModel(int pageIndex, int pageSize, long count, IEnumerable<TEntity> data)
{
this.PageIndex = pageIndex;
this.PageSize = pageSize;
this.Count = count;
this.Data = data;
PageIndex = pageIndex;
PageSize = pageSize;
Count = count;
Data = data;
}
}
}