Removed image upload functionality
This commit is contained in:
@@ -19,13 +19,11 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
{
|
||||
private readonly IAsyncRepository<CatalogItem> _itemRepository;
|
||||
private readonly IUriComposer _uriComposer;
|
||||
private readonly IFileSystem _webFileSystem;
|
||||
|
||||
public Create(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer, IFileSystem webFileSystem)
|
||||
public Create(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer)
|
||||
{
|
||||
_itemRepository = itemRepository;
|
||||
_uriComposer = uriComposer;
|
||||
_webFileSystem = webFileSystem;
|
||||
}
|
||||
|
||||
[HttpPost("api/catalog-items")]
|
||||
@@ -45,12 +43,15 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
|
||||
if (newItem.Id != 0)
|
||||
{
|
||||
var picName = $"{newItem.Id}{Path.GetExtension(request.PictureName)}";
|
||||
if (await _webFileSystem.SavePicture(picName, request.PictureBase64, cancellationToken))
|
||||
{
|
||||
newItem.UpdatePictureUri(picName);
|
||||
await _itemRepository.UpdateAsync(newItem, cancellationToken);
|
||||
}
|
||||
// At this point time, the Admin application uses the default catalog item image for any new product item.
|
||||
// But in the actual production scenario, you'll implement the image file upload mechanism in your application and set the image
|
||||
// file the Uri accordingly. You can refer to fewlines of the boilerplate code are commented out and kept it in the following files.
|
||||
// - BlazorAdmin project -> Create.razor and Edit.razor.
|
||||
// - Infrastructure project -> Services/WebFileSystem.cs
|
||||
|
||||
var picName = "eCatalog-item-default.png";
|
||||
newItem.UpdatePictureUri(picName);
|
||||
await _itemRepository.UpdateAsync(newItem, cancellationToken);
|
||||
}
|
||||
|
||||
var dto = new CatalogItemDto
|
||||
|
||||
@@ -17,15 +17,12 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
.WithResponse<UpdateCatalogItemResponse>
|
||||
{
|
||||
private readonly IAsyncRepository<CatalogItem> _itemRepository;
|
||||
private readonly IUriComposer _uriComposer;
|
||||
private readonly IFileSystem _webFileSystem;
|
||||
private readonly IUriComposer _uriComposer;
|
||||
|
||||
public Update(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer, IFileSystem webFileSystem)
|
||||
public Update(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer)
|
||||
{
|
||||
_itemRepository = itemRepository;
|
||||
_uriComposer = uriComposer;
|
||||
_webFileSystem = webFileSystem;
|
||||
|
||||
_uriComposer = uriComposer;
|
||||
}
|
||||
|
||||
[HttpPut("api/catalog-items")]
|
||||
@@ -43,20 +40,7 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
|
||||
existingItem.UpdateDetails(request.Name, request.Description, request.Price);
|
||||
existingItem.UpdateBrand(request.CatalogBrandId);
|
||||
existingItem.UpdateType(request.CatalogTypeId);
|
||||
|
||||
if (string.IsNullOrEmpty(request.PictureBase64) && string.IsNullOrEmpty(request.PictureUri))
|
||||
{
|
||||
existingItem.UpdatePictureUri(string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
var picName = $"{existingItem.Id}{Path.GetExtension(request.PictureName)}";
|
||||
if (await _webFileSystem.SavePicture($"{picName}", request.PictureBase64, cancellationToken))
|
||||
{
|
||||
existingItem.UpdatePictureUri(picName);
|
||||
}
|
||||
}
|
||||
existingItem.UpdateType(request.CatalogTypeId);
|
||||
|
||||
await _itemRepository.UpdateAsync(existingItem, cancellationToken);
|
||||
|
||||
|
||||
@@ -95,8 +95,7 @@ namespace Microsoft.eShopWeb.PublicApi
|
||||
services.AddScoped<ITokenClaimsService, IdentityTokenClaimService>();
|
||||
|
||||
var baseUrlConfig = new BaseUrlConfiguration();
|
||||
Configuration.Bind(BaseUrlConfiguration.CONFIG_NAME, baseUrlConfig);
|
||||
services.AddScoped<IFileSystem, WebFileSystem>(x => new WebFileSystem($"{baseUrlConfig.WebBase}File"));
|
||||
Configuration.Bind(BaseUrlConfiguration.CONFIG_NAME, baseUrlConfig);
|
||||
|
||||
services.AddMemoryCache();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user