* Added Blazor Client Configured PublicAPI CORS to allow traffic from client * Make admin page home page; remove extra pages Add CatalogType list endpoint * Wired up Types and Brands in the API and the admin list page * Adding a custom HttpClient to talk securely to API * Ardalis/blazor (#419) * Login added * AuthService will handel http request secure and not secure. * Logout added * CatalogBrandService in it is own service * Get token from localstorage when refresh. * used GetAsync * Fixed Login and Logout switch. * CatalogItemService added * CatalogTypeService added & Auth for CatalogType. using not used removed. * Made BlazorComponent and BlazorLayoutComponent for refresh. Index now small enough to be in one file. * Removed the service from program main and use lazy singleton. * used OnInitialized * Refactoring and detecting login status in login.razor * Refactoring login to redirect if user is already logged in * Blazor login with MVC (#420) * Blazor login with MVC * return back the PasswordSignInAsync in Login page * CRUD added (#422) * CRUD added * Unit Test changed to meet new redirect /admin * CreateCatalogItemRequest added. * Action caption added. * Validation added for name and price. * Updated port of api Redirect to returnUrl from login * Add username to /admin; link to my profile * Working on authorization of /admin * Working on custom auth locking down /admin page * Microsoft authorize working.Login.razor removed.Login from SignInMana… (#425) * Microsoft authorize working.Login.razor removed.Login from SignInManager and create token from it.unit test fixed. * GetTokenFromController function used in CustomAuthStateProvider * Cleaned up button styles Refactored to use codebehind for List component Updated Not Authorized view Co-authored-by: Shady Nagy <shadynagi@gmail.com>
56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
using Ardalis.ApiEndpoints;
|
|
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.Interfaces;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
|
{
|
|
|
|
[Authorize(Roles = AuthorizationConstants.Roles.ADMINISTRATORS, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
|
public class Create : BaseAsyncEndpoint<CreateCatalogItemRequest, CreateCatalogItemResponse>
|
|
{
|
|
private readonly IAsyncRepository<CatalogItem> _itemRepository;
|
|
private readonly IUriComposer _uriComposer;
|
|
|
|
public Create(IAsyncRepository<CatalogItem> itemRepository, IUriComposer uriComposer)
|
|
{
|
|
_itemRepository = itemRepository;
|
|
_uriComposer = uriComposer;
|
|
}
|
|
|
|
[HttpPost("api/catalog-items")]
|
|
[SwaggerOperation(
|
|
Summary = "Creates a new Catalog Item",
|
|
Description = "Creates a new Catalog Item",
|
|
OperationId = "catalog-items.create",
|
|
Tags = new[] { "CatalogItemEndpoints" })
|
|
]
|
|
public override async Task<ActionResult<CreateCatalogItemResponse>> HandleAsync(CreateCatalogItemRequest request)
|
|
{
|
|
var response = new CreateCatalogItemResponse(request.CorrelationId());
|
|
|
|
CatalogItem newItem = new CatalogItem(request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri);
|
|
|
|
newItem = await _itemRepository.AddAsync(newItem);
|
|
|
|
var dto = new CatalogItemDto
|
|
{
|
|
Id = newItem.Id,
|
|
CatalogBrandId = newItem.CatalogBrandId,
|
|
CatalogTypeId = newItem.CatalogTypeId,
|
|
Description = newItem.Description,
|
|
Name = newItem.Name,
|
|
PictureUri = _uriComposer.ComposePicUri(newItem.PictureUri),
|
|
Price = newItem.Price
|
|
};
|
|
response.CatalogItem = dto;
|
|
return response;
|
|
}
|
|
}
|
|
}
|