Seeding, cleanup, fix nginx proxying
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using Imprink.Application.Products.Create;
|
||||
using Imprink.Application.Products.Delete;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Application.Products.Query;
|
||||
using MediatR;
|
||||
@@ -8,40 +6,13 @@ using Microsoft.AspNetCore.Mvc;
|
||||
namespace Imprink.WebApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
[Route("api/products/categories")]
|
||||
public class CategoriesController(IMediator mediator) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<CategoryDto>>> GetCategories(
|
||||
[FromQuery] bool? isActive = null,
|
||||
[FromQuery] bool rootCategoriesOnly = false)
|
||||
public async Task<ActionResult<IEnumerable<CategoryDto>>> GetCategories([FromQuery] GetCategoriesQuery query)
|
||||
{
|
||||
var query = new GetCategoriesQuery
|
||||
{
|
||||
IsActive = isActive,
|
||||
RootCategoriesOnly = rootCategoriesOnly
|
||||
};
|
||||
|
||||
var result = await mediator.Send(query);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<CategoryDto>> CreateCategory([FromBody] CreateCategoryCommand command)
|
||||
{
|
||||
var result = await mediator.Send(command);
|
||||
return CreatedAtAction(nameof(CreateCategory), new { id = result.Id }, result);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<ActionResult> DeleteCategory(Guid id)
|
||||
{
|
||||
var command = new DeleteCategoryCommand { Id = id };
|
||||
var result = await mediator.Send(command);
|
||||
|
||||
if (!result)
|
||||
return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
using Imprink.Application.Products.Create;
|
||||
using Imprink.Application.Products.Delete;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Application.Products.Query;
|
||||
using MediatR;
|
||||
@@ -8,42 +6,14 @@ using Microsoft.AspNetCore.Mvc;
|
||||
namespace Imprink.WebApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
[Route("/api/products/variants")]
|
||||
public class ProductVariantsController(IMediator mediator) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ProductVariantDto>>> GetProductVariants(
|
||||
[FromQuery] Guid? productId = null,
|
||||
[FromQuery] bool? isActive = null,
|
||||
[FromQuery] bool inStockOnly = false)
|
||||
[FromQuery] GetProductVariantsQuery query)
|
||||
{
|
||||
var query = new GetProductVariantsQuery
|
||||
{
|
||||
ProductId = productId,
|
||||
IsActive = isActive,
|
||||
InStockOnly = inStockOnly
|
||||
};
|
||||
|
||||
var result = await mediator.Send(query);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<ProductVariantDto>> CreateProductVariant([FromBody] CreateProductVariantCommand command)
|
||||
{
|
||||
var result = await mediator.Send(command);
|
||||
return CreatedAtAction(nameof(CreateProductVariant), new { id = result.Id }, result);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<ActionResult> DeleteProductVariant(Guid id)
|
||||
{
|
||||
var command = new DeleteProductVariantCommand { Id = id };
|
||||
var result = await mediator.Send(command);
|
||||
|
||||
if (!result)
|
||||
return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -1,66 +1,23 @@
|
||||
using Imprink.Application.Products.Create;
|
||||
using Imprink.Application.Products.Delete;
|
||||
using Imprink.Application.Products;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Application.Products.Query;
|
||||
using Imprink.Domain.Common.Models;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Imprink.WebApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
[Route("/api/products")]
|
||||
public class ProductsController(IMediator mediator) : ControllerBase
|
||||
{
|
||||
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<PagedResultDto<ProductDto>>> GetProducts(
|
||||
[FromQuery] int pageNumber = 1,
|
||||
[FromQuery] int pageSize = 10,
|
||||
[FromQuery] string? searchTerm = null,
|
||||
[FromQuery] Guid? categoryId = null,
|
||||
[FromQuery] decimal? minPrice = null,
|
||||
[FromQuery] decimal? maxPrice = null,
|
||||
[FromQuery] bool? isActive = true,
|
||||
[FromQuery] bool? isCustomizable = null,
|
||||
[FromQuery] string sortBy = "Name",
|
||||
[FromQuery] string sortDirection = "ASC")
|
||||
[FromQuery] ProductFilterParameters filterParameters)
|
||||
{
|
||||
var filterParameters = new ProductFilterParameters
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
SearchTerm = searchTerm,
|
||||
CategoryId = categoryId,
|
||||
MinPrice = minPrice,
|
||||
MaxPrice = maxPrice,
|
||||
IsActive = isActive,
|
||||
IsCustomizable = isCustomizable,
|
||||
SortBy = sortBy,
|
||||
SortDirection = sortDirection
|
||||
};
|
||||
|
||||
var query = new GetProductsQuery { FilterParameters = filterParameters };
|
||||
var result = await mediator.Send(query);
|
||||
|
||||
var result = await mediator.Send(new GetProductsQuery { FilterParameters = filterParameters });
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<ProductDto>> CreateProduct([FromBody] CreateProductCommand command)
|
||||
{
|
||||
var result = await mediator.Send(command);
|
||||
return CreatedAtAction(nameof(CreateProduct), new { id = result.Id }, result);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<ActionResult> DeleteProduct(Guid id)
|
||||
{
|
||||
var command = new DeleteProductCommand { Id = id };
|
||||
var result = await mediator.Send(command);
|
||||
|
||||
if (!result)
|
||||
return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
17
src/Imprink.WebApi/Controllers/Products/SeedingController.cs
Normal file
17
src/Imprink.WebApi/Controllers/Products/SeedingController.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Imprink.WebApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("/api/products/seed")]
|
||||
public class SeedingController(Seeder seeder) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public async Task<ActionResult<bool>> Seed()
|
||||
{
|
||||
await seeder.SeedAsync();
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -8,22 +8,22 @@ using Microsoft.AspNetCore.Mvc;
|
||||
namespace Imprink.WebApi.Controllers.Users;
|
||||
|
||||
[ApiController]
|
||||
[Route("/users")]
|
||||
[Route("/api/users")]
|
||||
public class UserController(IMediator mediator) : ControllerBase
|
||||
{
|
||||
[Authorize]
|
||||
[HttpPost("sync")]
|
||||
public async Task<IActionResult> Sync()
|
||||
{
|
||||
var enumerable = User.Claims as Claim[] ?? User.Claims.ToArray();
|
||||
var claims = User.Claims as Claim[] ?? User.Claims.ToArray();
|
||||
|
||||
var auth0User = new Auth0User
|
||||
{
|
||||
Sub = enumerable.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value ?? string.Empty,
|
||||
Name = enumerable.FirstOrDefault(c => c.Type == "name")?.Value ?? string.Empty,
|
||||
Nickname = enumerable.FirstOrDefault(c => c.Type == "nickname")?.Value ?? string.Empty,
|
||||
Email = enumerable.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value ?? string.Empty,
|
||||
EmailVerified = bool.TryParse(enumerable.FirstOrDefault(c => c.Type == "email_verified")?.Value, out var emailVerified) && emailVerified
|
||||
Sub = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value ?? string.Empty,
|
||||
Name = claims.FirstOrDefault(c => c.Type == "name")?.Value ?? string.Empty,
|
||||
Nickname = claims.FirstOrDefault(c => c.Type == "nickname")?.Value ?? string.Empty,
|
||||
Email = claims.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value ?? string.Empty,
|
||||
EmailVerified = bool.TryParse(claims.FirstOrDefault(c => c.Type == "email_verified")?.Value, out var emailVerified) && emailVerified
|
||||
};
|
||||
|
||||
await mediator.Send(new SyncUserCommand(auth0User));
|
||||
|
||||
Reference in New Issue
Block a user