Image added (#434)
* Image added * ImageMaximumBytes * FileController remove Authorized * ApplicationCore.Constants.AuthorizationConstants.AUTH_KEY * SavePicture in the interface. * IFileSystem in Core * WebFileSystem in Infrastructure * PictureUri removed from UpdateCatalogItemRequest * Modal scroll fix
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
public string Description { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string PictureUri { get; set; }
|
||||
public string PictureBase64 { get; set; }
|
||||
public string PictureName { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Ardalis.ApiEndpoints;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Ardalis.ApiEndpoints;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -16,11 +18,13 @@ 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)
|
||||
public Create(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer, IFileSystem webFileSystem)
|
||||
{
|
||||
_itemRepository = itemRepository;
|
||||
_uriComposer = uriComposer;
|
||||
_webFileSystem = webFileSystem;
|
||||
}
|
||||
|
||||
[HttpPost("api/catalog-items")]
|
||||
@@ -34,10 +38,20 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
{
|
||||
var response = new CreateCatalogItemResponse(request.CorrelationId());
|
||||
|
||||
CatalogItem newItem = new CatalogItem(request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri);
|
||||
var newItem = new CatalogItem(request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri);
|
||||
|
||||
newItem = await _itemRepository.AddAsync(newItem);
|
||||
|
||||
if (newItem.Id != 0)
|
||||
{
|
||||
var picName = $"{newItem.Id}{Path.GetExtension(request.PictureName)}";
|
||||
if (await _webFileSystem.SavePicture(picName, request.PictureBase64))
|
||||
{
|
||||
newItem.UpdatePictureUri(picName);
|
||||
await _itemRepository.UpdateAsync(newItem);
|
||||
}
|
||||
}
|
||||
|
||||
var dto = new CatalogItemDto
|
||||
{
|
||||
Id = newItem.Id,
|
||||
@@ -51,5 +65,7 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
response.CatalogItem = dto;
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
public string Description { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
public string PictureUri { get; set; }
|
||||
public string PictureBase64 { get; set; }
|
||||
public string PictureName { get; set; }
|
||||
[Range(0.01, 10000)]
|
||||
public decimal Price { get; set; }
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Constants;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Exceptions;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
@@ -17,11 +15,13 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
{
|
||||
private readonly IAsyncRepository<CatalogItem> _itemRepository;
|
||||
private readonly IUriComposer _uriComposer;
|
||||
private readonly IFileSystem _webFileSystem;
|
||||
|
||||
public Update(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer)
|
||||
public Update(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer, IFileSystem webFileSystem)
|
||||
{
|
||||
_itemRepository = itemRepository;
|
||||
_uriComposer = uriComposer;
|
||||
_webFileSystem = webFileSystem;
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,19 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
existingItem.UpdateBrand(request.CatalogBrandId);
|
||||
existingItem.UpdateType(request.CatalogTypeId);
|
||||
|
||||
if (string.IsNullOrEmpty(request.PictureBase64))
|
||||
{
|
||||
existingItem.UpdatePictureUri(string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
var picName = $"{existingItem.Id}{Path.GetExtension(request.PictureName)}";
|
||||
if (await _webFileSystem.SavePicture($"{picName}", request.PictureBase64))
|
||||
{
|
||||
existingItem.UpdatePictureUri(picName);
|
||||
}
|
||||
}
|
||||
|
||||
await _itemRepository.UpdateAsync(existingItem);
|
||||
|
||||
var dto = new CatalogItemDto
|
||||
|
||||
Reference in New Issue
Block a user