Dev #7
@@ -1,8 +1,9 @@
|
||||
using Imprink.Application.Categories.Dtos;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Categories;
|
||||
namespace Imprink.Application.Categories.Commands;
|
||||
|
||||
public class CreateCategoryCommand : IRequest<CategoryDto>
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Categories;
|
||||
namespace Imprink.Application.Categories.Commands;
|
||||
|
||||
public class DeleteCategoryCommand : IRequest<bool>
|
||||
{
|
||||
@@ -1,8 +1,9 @@
|
||||
using Imprink.Application.Categories.Dtos;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Categories;
|
||||
namespace Imprink.Application.Categories.Commands;
|
||||
|
||||
public class GetCategoriesQuery : IRequest<IEnumerable<CategoryDto>>
|
||||
{
|
||||
@@ -1,8 +1,9 @@
|
||||
using Imprink.Application.Categories.Dtos;
|
||||
using Imprink.Application.Exceptions;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Categories;
|
||||
namespace Imprink.Application.Categories.Commands;
|
||||
|
||||
public class UpdateCategoryCommand : IRequest<CategoryDto>
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Imprink.Application.Products.Dtos;
|
||||
namespace Imprink.Application.Categories.Dtos;
|
||||
|
||||
public class CategoryDto
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.Categories;
|
||||
using Imprink.Application.Categories.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.Categories;
|
||||
namespace Imprink.Application.Categories.Validation;
|
||||
|
||||
public class CreateCategoryCommandValidator : AbstractValidator<CreateCategoryCommand>
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.Categories;
|
||||
using Imprink.Application.Categories.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.Categories;
|
||||
namespace Imprink.Application.Categories.Validation;
|
||||
|
||||
public class DeleteCategoryCommandValidator : AbstractValidator<DeleteCategoryCommand>
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.Categories;
|
||||
using Imprink.Application.Categories.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.Categories;
|
||||
namespace Imprink.Application.Categories.Validation;
|
||||
|
||||
public class UpdateCategoryCommandValidator : AbstractValidator<UpdateCategoryCommand>
|
||||
{
|
||||
@@ -1,65 +0,0 @@
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.ProductVariants;
|
||||
|
||||
public class CreateProductVariantCommand : IRequest<ProductVariantDto>
|
||||
{
|
||||
public Guid ProductId { get; set; }
|
||||
public string Size { get; set; } = null!;
|
||||
public string? Color { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
public string? ImageUrl { get; set; }
|
||||
public string Sku { get; set; } = null!;
|
||||
public int StockQuantity { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
}
|
||||
|
||||
public class CreateProductVariantHandler(IUnitOfWork unitOfWork)
|
||||
: IRequestHandler<CreateProductVariantCommand, ProductVariantDto>
|
||||
{
|
||||
public async Task<ProductVariantDto> Handle(CreateProductVariantCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await unitOfWork.BeginTransactionAsync(cancellationToken);
|
||||
|
||||
try
|
||||
{
|
||||
var productVariant = new ProductVariant
|
||||
{
|
||||
ProductId = request.ProductId,
|
||||
Size = request.Size,
|
||||
Color = request.Color,
|
||||
Price = request.Price,
|
||||
ImageUrl = request.ImageUrl,
|
||||
Sku = request.Sku,
|
||||
StockQuantity = request.StockQuantity,
|
||||
IsActive = request.IsActive,
|
||||
Product = null!
|
||||
};
|
||||
|
||||
var createdVariant = await unitOfWork.ProductVariantRepository.AddAsync(productVariant, cancellationToken);
|
||||
await unitOfWork.CommitTransactionAsync(cancellationToken);
|
||||
|
||||
return new ProductVariantDto
|
||||
{
|
||||
Id = createdVariant.Id,
|
||||
ProductId = createdVariant.ProductId,
|
||||
Size = createdVariant.Size,
|
||||
Color = createdVariant.Color,
|
||||
Price = createdVariant.Price,
|
||||
ImageUrl = createdVariant.ImageUrl,
|
||||
Sku = createdVariant.Sku,
|
||||
StockQuantity = createdVariant.StockQuantity,
|
||||
IsActive = createdVariant.IsActive,
|
||||
CreatedAt = createdVariant.CreatedAt,
|
||||
ModifiedAt = createdVariant.ModifiedAt
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
await unitOfWork.RollbackTransactionAsync(cancellationToken);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Products;
|
||||
|
||||
public class CreateProductCommand : IRequest<ProductDto>
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
public string? Description { get; set; }
|
||||
public decimal BasePrice { get; set; }
|
||||
public bool IsCustomizable { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
public string? ImageUrl { get; set; }
|
||||
public Guid? CategoryId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateProductHandler(IUnitOfWork unitOfWork) : IRequestHandler<CreateProductCommand, ProductDto>
|
||||
{
|
||||
public async Task<ProductDto> Handle(CreateProductCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await unitOfWork.BeginTransactionAsync(cancellationToken);
|
||||
|
||||
try
|
||||
{
|
||||
var product = new Product
|
||||
{
|
||||
Name = request.Name,
|
||||
Description = request.Description,
|
||||
BasePrice = request.BasePrice,
|
||||
IsCustomizable = request.IsCustomizable,
|
||||
IsActive = request.IsActive,
|
||||
ImageUrl = request.ImageUrl,
|
||||
CategoryId = request.CategoryId,
|
||||
Category = null!
|
||||
};
|
||||
|
||||
var createdProduct = await unitOfWork.ProductRepository.AddAsync(product, cancellationToken);
|
||||
|
||||
var categoryDto = new CategoryDto
|
||||
{
|
||||
Id = createdProduct.Category.Id,
|
||||
Name = createdProduct.Category.Name,
|
||||
Description = createdProduct.Category.Description,
|
||||
ImageUrl = createdProduct.Category.ImageUrl,
|
||||
SortOrder = createdProduct.Category.SortOrder,
|
||||
IsActive = createdProduct.Category.IsActive,
|
||||
ParentCategoryId = createdProduct.Category.ParentCategoryId,
|
||||
CreatedAt = createdProduct.Category.CreatedAt,
|
||||
ModifiedAt = createdProduct.Category.ModifiedAt
|
||||
};
|
||||
|
||||
await unitOfWork.CommitTransactionAsync(cancellationToken);
|
||||
|
||||
return new ProductDto
|
||||
{
|
||||
Id = createdProduct.Id,
|
||||
Name = createdProduct.Name,
|
||||
Description = createdProduct.Description,
|
||||
BasePrice = createdProduct.BasePrice,
|
||||
IsCustomizable = createdProduct.IsCustomizable,
|
||||
IsActive = createdProduct.IsActive,
|
||||
ImageUrl = createdProduct.ImageUrl,
|
||||
CategoryId = createdProduct.CategoryId,
|
||||
Category = categoryDto,
|
||||
CreatedAt = createdProduct.CreatedAt,
|
||||
ModifiedAt = createdProduct.ModifiedAt
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
await unitOfWork.RollbackTransactionAsync(cancellationToken);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,4 @@
|
||||
<ProjectReference Include="..\Imprink.Domain\Imprink.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Domains\Orders\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
5
src/Imprink.Application/MappingProfile.cs
Normal file
5
src/Imprink.Application/MappingProfile.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace Imprink.Application;
|
||||
|
||||
public abstract class MappingProfile : Profile { }
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Domain.Models;
|
||||
|
||||
namespace Imprink.Application.Validation.Models;
|
||||
namespace Imprink.Application.Orders.Validation;
|
||||
|
||||
public class OrderFilterParametersValidator : AbstractValidator<OrderFilterParameters>
|
||||
{
|
||||
@@ -0,0 +1,46 @@
|
||||
using AutoMapper;
|
||||
using Imprink.Application.ProductVariants.Dtos;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.ProductVariants.Commands;
|
||||
|
||||
public class CreateProductVariantCommand : IRequest<ProductVariantDto>
|
||||
{
|
||||
public Guid ProductId { get; set; }
|
||||
public string Size { get; set; } = null!;
|
||||
public string? Color { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
public string? ImageUrl { get; set; }
|
||||
public string Sku { get; set; } = null!;
|
||||
public int StockQuantity { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
}
|
||||
|
||||
public class CreateProductVariantHandler(IUnitOfWork unitOfWork, IMapper mapper)
|
||||
: IRequestHandler<CreateProductVariantCommand, ProductVariantDto>
|
||||
{
|
||||
public async Task<ProductVariantDto> Handle(CreateProductVariantCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await unitOfWork.BeginTransactionAsync(cancellationToken);
|
||||
|
||||
try
|
||||
{
|
||||
var productVariant = mapper.Map<ProductVariant>(request);
|
||||
|
||||
productVariant.Product = null!;
|
||||
|
||||
var createdVariant = await unitOfWork.ProductVariantRepository.AddAsync(productVariant, cancellationToken);
|
||||
|
||||
await unitOfWork.SaveAsync(cancellationToken);
|
||||
await unitOfWork.CommitTransactionAsync(cancellationToken);
|
||||
|
||||
return mapper.Map<ProductVariantDto>(createdVariant);
|
||||
}
|
||||
catch
|
||||
{
|
||||
await unitOfWork.RollbackTransactionAsync(cancellationToken);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.ProductVariants;
|
||||
namespace Imprink.Application.ProductVariants.Commands;
|
||||
|
||||
public class DeleteProductVariantCommand : IRequest<bool>
|
||||
{
|
||||
@@ -16,6 +16,7 @@ public class DeleteProductVariantHandler(IUnitOfWork unitOfWork) : IRequestHandl
|
||||
try
|
||||
{
|
||||
var exists = await unitOfWork.ProductVariantRepository.ExistsAsync(request.Id, cancellationToken);
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
await unitOfWork.RollbackTransactionAsync(cancellationToken);
|
||||
@@ -23,7 +24,10 @@ public class DeleteProductVariantHandler(IUnitOfWork unitOfWork) : IRequestHandl
|
||||
}
|
||||
|
||||
await unitOfWork.ProductVariantRepository.DeleteAsync(request.Id, cancellationToken);
|
||||
|
||||
await unitOfWork.SaveAsync(cancellationToken);
|
||||
await unitOfWork.CommitTransactionAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
@@ -1,8 +1,10 @@
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using AutoMapper;
|
||||
using Imprink.Application.ProductVariants.Dtos;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Imprink.Application.Domains.ProductVariants;
|
||||
namespace Imprink.Application.ProductVariants.Commands;
|
||||
|
||||
public class GetProductVariantsQuery : IRequest<IEnumerable<ProductVariantDto>>
|
||||
{
|
||||
@@ -11,7 +13,7 @@ public class GetProductVariantsQuery : IRequest<IEnumerable<ProductVariantDto>>
|
||||
public bool InStockOnly { get; set; } = false;
|
||||
}
|
||||
|
||||
public class GetProductVariantsHandler(IUnitOfWork unitOfWork)
|
||||
public class GetProductVariantsHandler(IUnitOfWork unitOfWork, IMapper mapper, ILogger<GetProductVariantsHandler> logger)
|
||||
: IRequestHandler<GetProductVariantsQuery, IEnumerable<ProductVariantDto>>
|
||||
{
|
||||
public async Task<IEnumerable<ProductVariantDto>> Handle(GetProductVariantsQuery request, CancellationToken cancellationToken)
|
||||
@@ -38,32 +40,6 @@ public class GetProductVariantsHandler(IUnitOfWork unitOfWork)
|
||||
variants = new List<ProductVariant>();
|
||||
}
|
||||
|
||||
return variants.Select(pv => new ProductVariantDto
|
||||
{
|
||||
Id = pv.Id,
|
||||
ProductId = pv.ProductId,
|
||||
Size = pv.Size,
|
||||
Color = pv.Color,
|
||||
Price = pv.Price,
|
||||
ImageUrl = pv.ImageUrl,
|
||||
Sku = pv.Sku,
|
||||
StockQuantity = pv.StockQuantity,
|
||||
IsActive = pv.IsActive,
|
||||
Product = new ProductDto
|
||||
{
|
||||
Id = pv.Product.Id,
|
||||
Name = pv.Product.Name,
|
||||
Description = pv.Product.Description,
|
||||
BasePrice = pv.Product.BasePrice,
|
||||
IsCustomizable = pv.Product.IsCustomizable,
|
||||
IsActive = pv.Product.IsActive,
|
||||
ImageUrl = pv.Product.ImageUrl,
|
||||
CategoryId = pv.Product.CategoryId,
|
||||
CreatedAt = pv.Product.CreatedAt,
|
||||
ModifiedAt = pv.Product.ModifiedAt
|
||||
},
|
||||
CreatedAt = pv.CreatedAt,
|
||||
ModifiedAt = pv.ModifiedAt
|
||||
});
|
||||
return mapper.Map<IEnumerable<ProductVariantDto>>(variants);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Exceptions;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Application.ProductVariants.Dtos;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.ProductVariants;
|
||||
namespace Imprink.Application.ProductVariants.Commands;
|
||||
|
||||
public class UpdateProductVariantCommand : IRequest<ProductVariantDto>
|
||||
{
|
||||
@@ -17,7 +18,7 @@ public class UpdateProductVariantCommand : IRequest<ProductVariantDto>
|
||||
public bool IsActive { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateProductVariantHandler(IUnitOfWork unitOfWork)
|
||||
public class UpdateProductVariantHandler(IUnitOfWork unitOfWork, IMapper mapper)
|
||||
: IRequestHandler<UpdateProductVariantCommand, ProductVariantDto>
|
||||
{
|
||||
public async Task<ProductVariantDto> Handle(UpdateProductVariantCommand request, CancellationToken cancellationToken)
|
||||
@@ -29,36 +30,16 @@ public class UpdateProductVariantHandler(IUnitOfWork unitOfWork)
|
||||
var existingVariant = await unitOfWork.ProductVariantRepository.GetByIdAsync(request.Id, cancellationToken);
|
||||
|
||||
if (existingVariant == null)
|
||||
{
|
||||
throw new NotFoundException($"Product variant with ID {request.Id} not found.");
|
||||
}
|
||||
|
||||
existingVariant.ProductId = request.ProductId;
|
||||
existingVariant.Size = request.Size;
|
||||
existingVariant.Color = request.Color;
|
||||
existingVariant.Price = request.Price;
|
||||
existingVariant.ImageUrl = request.ImageUrl;
|
||||
existingVariant.Sku = request.Sku;
|
||||
existingVariant.StockQuantity = request.StockQuantity;
|
||||
existingVariant.IsActive = request.IsActive;
|
||||
mapper.Map(request, existingVariant);
|
||||
|
||||
var updatedVariant = await unitOfWork.ProductVariantRepository.UpdateAsync(existingVariant, cancellationToken);
|
||||
|
||||
await unitOfWork.SaveAsync(cancellationToken);
|
||||
await unitOfWork.CommitTransactionAsync(cancellationToken);
|
||||
|
||||
return new ProductVariantDto
|
||||
{
|
||||
Id = updatedVariant.Id,
|
||||
ProductId = updatedVariant.ProductId,
|
||||
Size = updatedVariant.Size,
|
||||
Color = updatedVariant.Color,
|
||||
Price = updatedVariant.Price,
|
||||
ImageUrl = updatedVariant.ImageUrl,
|
||||
Sku = updatedVariant.Sku,
|
||||
StockQuantity = updatedVariant.StockQuantity,
|
||||
IsActive = updatedVariant.IsActive,
|
||||
CreatedAt = updatedVariant.CreatedAt,
|
||||
ModifiedAt = updatedVariant.ModifiedAt
|
||||
};
|
||||
return mapper.Map<ProductVariantDto>(updatedVariant);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Imprink.Application.Products.Dtos;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
|
||||
namespace Imprink.Application.ProductVariants.Dtos;
|
||||
|
||||
public class ProductVariantDto
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.ProductVariants;
|
||||
using Imprink.Application.ProductVariants.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.ProductVariants;
|
||||
namespace Imprink.Application.ProductVariants.Validation;
|
||||
|
||||
public class CreateProductVariantCommandValidator : AbstractValidator<CreateProductVariantCommand>
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.ProductVariants;
|
||||
using Imprink.Application.ProductVariants.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.ProductVariants;
|
||||
namespace Imprink.Application.ProductVariants.Validation;
|
||||
|
||||
public class DeleteProductVariantCommandValidator : AbstractValidator<DeleteProductVariantCommand>
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.ProductVariants;
|
||||
using Imprink.Application.ProductVariants.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.ProductVariants;
|
||||
namespace Imprink.Application.ProductVariants.Validation;
|
||||
|
||||
public class GetProductVariantsQueryValidator : AbstractValidator<GetProductVariantsQuery>
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.ProductVariants;
|
||||
using Imprink.Application.ProductVariants.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.ProductVariants;
|
||||
namespace Imprink.Application.ProductVariants.Validation;
|
||||
|
||||
public class UpdateProductVariantCommandValidator : AbstractValidator<UpdateProductVariantCommand>
|
||||
{
|
||||
@@ -0,0 +1,46 @@
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Products.Commands;
|
||||
|
||||
public class CreateProductCommand : IRequest<ProductDto>
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
public string? Description { get; set; }
|
||||
public decimal BasePrice { get; set; }
|
||||
public bool IsCustomizable { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
public string? ImageUrl { get; set; }
|
||||
public Guid? CategoryId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateProductHandler(IUnitOfWork unitOfWork, IMapper mapper) : IRequestHandler<CreateProductCommand, ProductDto>
|
||||
{
|
||||
public async Task<ProductDto> Handle(CreateProductCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await unitOfWork.BeginTransactionAsync(cancellationToken);
|
||||
|
||||
try
|
||||
{
|
||||
var product = mapper.Map<Product>(request);
|
||||
|
||||
var createdProduct = await unitOfWork.ProductRepository.AddAsync(product, cancellationToken);
|
||||
|
||||
if (createdProduct.CategoryId.HasValue)
|
||||
{
|
||||
createdProduct.Category = (await unitOfWork.CategoryRepository.GetByIdAsync(createdProduct.CategoryId.Value, cancellationToken))!;
|
||||
}
|
||||
|
||||
await unitOfWork.CommitTransactionAsync(cancellationToken);
|
||||
|
||||
return mapper.Map<ProductDto>(createdProduct);
|
||||
}
|
||||
catch
|
||||
{
|
||||
await unitOfWork.RollbackTransactionAsync(cancellationToken);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Products;
|
||||
namespace Imprink.Application.Products.Commands;
|
||||
|
||||
public class DeleteProductCommand : IRequest<bool>
|
||||
{
|
||||
@@ -1,8 +1,9 @@
|
||||
using Imprink.Application.Categories.Dtos;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Domain.Models;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Products;
|
||||
namespace Imprink.Application.Products.Commands;
|
||||
|
||||
public class GetProductsQuery : IRequest<PagedResultDto<ProductDto>>
|
||||
{
|
||||
@@ -1,8 +1,9 @@
|
||||
using Imprink.Application.Categories.Dtos;
|
||||
using Imprink.Application.Exceptions;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Products;
|
||||
namespace Imprink.Application.Products.Commands;
|
||||
|
||||
public class UpdateProductCommand : IRequest<ProductDto>
|
||||
{
|
||||
@@ -1,3 +1,5 @@
|
||||
using Imprink.Application.Categories.Dtos;
|
||||
|
||||
namespace Imprink.Application.Products.Dtos;
|
||||
|
||||
public class ProductDto
|
||||
@@ -0,0 +1,44 @@
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Categories.Dtos;
|
||||
using Imprink.Application.Products.Commands;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Application.ProductVariants.Commands;
|
||||
using Imprink.Application.ProductVariants.Dtos;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
|
||||
namespace Imprink.Application.Products.Mappings;
|
||||
|
||||
public class ProductMappingProfile: Profile
|
||||
{
|
||||
public ProductMappingProfile()
|
||||
{
|
||||
CreateMap<CreateProductVariantCommand, ProductVariant>()
|
||||
.ForMember(dest => dest.Id, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.CreatedAt, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.ModifiedAt, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.CreatedBy, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.ModifiedBy, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Product, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.OrderItems, opt => opt.Ignore());
|
||||
|
||||
CreateMap<ProductVariant, ProductVariantDto>();
|
||||
CreateMap<ProductVariantDto, ProductVariant>()
|
||||
.ForMember(dest => dest.CreatedBy, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.ModifiedBy, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.OrderItems, opt => opt.Ignore());
|
||||
|
||||
CreateMap<Product, ProductDto>();
|
||||
|
||||
CreateMap<CreateProductCommand, Product>()
|
||||
.ForMember(dest => dest.Id, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.CreatedAt, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.ModifiedAt, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.CreatedBy, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.ModifiedBy, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Category, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.ProductVariants, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.OrderItems, opt => opt.Ignore());
|
||||
|
||||
CreateMap<Category, CategoryDto>();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.Products;
|
||||
using Imprink.Application.Products.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.Products;
|
||||
namespace Imprink.Application.Products.Validation;
|
||||
|
||||
public class CreateProductCommandValidator : AbstractValidator<CreateProductCommand>
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.Products;
|
||||
using Imprink.Application.Products.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.Products;
|
||||
namespace Imprink.Application.Products.Validation;
|
||||
|
||||
public class DeleteProductCommandValidator : AbstractValidator<DeleteProductCommand>
|
||||
{
|
||||
@@ -1,8 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.Products;
|
||||
using Imprink.Application.Validation.Models;
|
||||
using Imprink.Application.Products.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.Products;
|
||||
namespace Imprink.Application.Products.Validation;
|
||||
|
||||
public class GetProductsQueryValidator : AbstractValidator<GetProductsQuery>
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Domain.Models;
|
||||
|
||||
namespace Imprink.Application.Validation.Models;
|
||||
namespace Imprink.Application.Products.Validation;
|
||||
|
||||
public class ProductFilterParametersValidator : AbstractValidator<ProductFilterParameters>
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.Products;
|
||||
using Imprink.Application.Products.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.Products;
|
||||
namespace Imprink.Application.Products.Validation;
|
||||
|
||||
public class UpdateProductCommandValidator : AbstractValidator<UpdateProductCommand>
|
||||
{
|
||||
@@ -1,12 +1,13 @@
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Exceptions;
|
||||
using Imprink.Application.Users.Dtos;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Users;
|
||||
namespace Imprink.Application.Users.Commands;
|
||||
|
||||
public record DeleteUserRoleCommand(string Sub, Guid RoleId) : IRequest<UserRoleDto?>;
|
||||
|
||||
public class DeleteUserRoleHandler(IUnitOfWork uw) : IRequestHandler<DeleteUserRoleCommand, UserRoleDto?>
|
||||
public class DeleteUserRoleHandler(IUnitOfWork uw, IMapper mapper) : IRequestHandler<DeleteUserRoleCommand, UserRoleDto?>
|
||||
{
|
||||
public async Task<UserRoleDto?> Handle(DeleteUserRoleCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -27,11 +28,7 @@ public class DeleteUserRoleHandler(IUnitOfWork uw) : IRequestHandler<DeleteUserR
|
||||
await uw.SaveAsync(cancellationToken);
|
||||
await uw.CommitTransactionAsync(cancellationToken);
|
||||
|
||||
return new UserRoleDto
|
||||
{
|
||||
UserId = removedRole.UserId,
|
||||
RoleId = removedRole.RoleId
|
||||
};
|
||||
return mapper.Map<UserRoleDto>(removedRole);
|
||||
}
|
||||
catch
|
||||
{
|
||||
17
src/Imprink.Application/Users/Commands/GetAllRolesHandler.cs
Normal file
17
src/Imprink.Application/Users/Commands/GetAllRolesHandler.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Users.Dtos;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Users.Commands;
|
||||
|
||||
public record GetAllRolesCommand : IRequest<IEnumerable<RoleDto>>;
|
||||
|
||||
public class GetAllRolesHandler(IUnitOfWork uw, IMapper mapper): IRequestHandler<GetAllRolesCommand, IEnumerable<RoleDto>>
|
||||
{
|
||||
public async Task<IEnumerable<RoleDto>> Handle(GetAllRolesCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var roles = await uw.RoleRepository.GetAllRolesAsync(cancellationToken);
|
||||
|
||||
return mapper.Map<IEnumerable<RoleDto>>(roles);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Exceptions;
|
||||
using Imprink.Application.Users.Dtos;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Users;
|
||||
namespace Imprink.Application.Users.Commands;
|
||||
|
||||
public record GetUserRolesCommand(string Sub) : IRequest<IEnumerable<RoleDto>>;
|
||||
|
||||
public class GetUserRolesHandler(IUnitOfWork uw): IRequestHandler<GetUserRolesCommand, IEnumerable<RoleDto>>
|
||||
public class GetUserRolesHandler(IUnitOfWork uw, IMapper mapper): IRequestHandler<GetUserRolesCommand, IEnumerable<RoleDto>>
|
||||
{
|
||||
public async Task<IEnumerable<RoleDto>> Handle(GetUserRolesCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -15,10 +16,6 @@ public class GetUserRolesHandler(IUnitOfWork uw): IRequestHandler<GetUserRolesCo
|
||||
|
||||
var roles = await uw.UserRoleRepository.GetUserRolesAsync(request.Sub, cancellationToken);
|
||||
|
||||
return roles.Select(role => new RoleDto
|
||||
{
|
||||
RoleId = role.Id,
|
||||
RoleName = role.RoleName
|
||||
}).ToList();
|
||||
return mapper.Map<IEnumerable<RoleDto>>(roles);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Exceptions;
|
||||
using Imprink.Application.Services;
|
||||
using Imprink.Application.Users.Dtos;
|
||||
using Imprink.Application.Users.Services;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Users;
|
||||
namespace Imprink.Application.Users.Commands;
|
||||
|
||||
public record SetUserFullNameCommand(string FirstName, string LastName) : IRequest<UserDto?>;
|
||||
|
||||
public class SetUserFullNameHandler(IUnitOfWork uw, ICurrentUserService userService) : IRequestHandler<SetUserFullNameCommand, UserDto?>
|
||||
public class SetUserFullNameHandler(IUnitOfWork uw, IMapper mapper, ICurrentUserService userService) : IRequestHandler<SetUserFullNameCommand, UserDto?>
|
||||
{
|
||||
public async Task<UserDto?> Handle(SetUserFullNameCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -16,28 +17,19 @@ public class SetUserFullNameHandler(IUnitOfWork uw, ICurrentUserService userServ
|
||||
try
|
||||
{
|
||||
var currentUser = userService.GetCurrentUserId();
|
||||
|
||||
if (currentUser == null)
|
||||
throw new NotFoundException("User token could not be accessed.");
|
||||
|
||||
var user = await uw.UserRepository.SetUserFullNameAsync(currentUser, request.FirstName, request.LastName, cancellationToken);
|
||||
|
||||
if (user == null)
|
||||
throw new DataUpdateException("User name could not be updated.");
|
||||
|
||||
await uw.SaveAsync(cancellationToken);
|
||||
await uw.CommitTransactionAsync(cancellationToken);
|
||||
|
||||
return new UserDto
|
||||
{
|
||||
Id = user.Id,
|
||||
Name = user.Name,
|
||||
Nickname = user.Nickname,
|
||||
Email = user.Email,
|
||||
EmailVerified = user.EmailVerified,
|
||||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
PhoneNumber = user.PhoneNumber,
|
||||
IsActive = user.IsActive
|
||||
};
|
||||
return mapper.Map<UserDto>(user);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -1,13 +1,14 @@
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Exceptions;
|
||||
using Imprink.Application.Services;
|
||||
using Imprink.Application.Users.Dtos;
|
||||
using Imprink.Application.Users.Services;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Users;
|
||||
namespace Imprink.Application.Users.Commands;
|
||||
|
||||
public record SetUserPhoneCommand(string PhoneNumber) : IRequest<UserDto?>;
|
||||
|
||||
public class SetUserPhoneHandler(IUnitOfWork uw, ICurrentUserService userService) : IRequestHandler<SetUserPhoneCommand, UserDto?>
|
||||
public class SetUserPhoneHandler(IUnitOfWork uw, IMapper mapper, ICurrentUserService userService) : IRequestHandler<SetUserPhoneCommand, UserDto?>
|
||||
{
|
||||
public async Task<UserDto?> Handle(SetUserPhoneCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -16,28 +17,19 @@ public class SetUserPhoneHandler(IUnitOfWork uw, ICurrentUserService userService
|
||||
try
|
||||
{
|
||||
var currentUser = userService.GetCurrentUserId();
|
||||
|
||||
if (currentUser == null)
|
||||
throw new NotFoundException("User token could not be accessed.");
|
||||
|
||||
var user = await uw.UserRepository.SetUserPhoneAsync(currentUser, request.PhoneNumber, cancellationToken);
|
||||
|
||||
if (user == null)
|
||||
throw new DataUpdateException("User phone could not be updated.");
|
||||
|
||||
await uw.SaveAsync(cancellationToken);
|
||||
await uw.CommitTransactionAsync(cancellationToken);
|
||||
|
||||
return new UserDto
|
||||
{
|
||||
Id = user.Id,
|
||||
Name = user.Name,
|
||||
Nickname = user.Nickname,
|
||||
Email = user.Email,
|
||||
EmailVerified = user.EmailVerified,
|
||||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
PhoneNumber = user.PhoneNumber,
|
||||
IsActive = user.IsActive
|
||||
};
|
||||
return mapper.Map<UserDto>(user);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -1,13 +1,14 @@
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Exceptions;
|
||||
using Imprink.Application.Users.Dtos;
|
||||
using Imprink.Domain.Entities.Users;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Users;
|
||||
namespace Imprink.Application.Users.Commands;
|
||||
|
||||
public record SetUserRoleCommand(string Sub, Guid RoleId) : IRequest<UserRoleDto?>;
|
||||
|
||||
public class SetUserRoleHandler(IUnitOfWork uw) : IRequestHandler<SetUserRoleCommand, UserRoleDto?>
|
||||
public class SetUserRoleHandler(IUnitOfWork uw, IMapper mapper) : IRequestHandler<SetUserRoleCommand, UserRoleDto?>
|
||||
{
|
||||
public async Task<UserRoleDto?> Handle(SetUserRoleCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -29,11 +30,7 @@ public class SetUserRoleHandler(IUnitOfWork uw) : IRequestHandler<SetUserRoleCom
|
||||
await uw.SaveAsync(cancellationToken);
|
||||
await uw.CommitTransactionAsync(cancellationToken);
|
||||
|
||||
return new UserRoleDto
|
||||
{
|
||||
UserId = addedRole.UserId,
|
||||
RoleId = addedRole.RoleId
|
||||
};
|
||||
return mapper.Map<UserRoleDto>(addedRole);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -1,12 +1,13 @@
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Users.Dtos;
|
||||
using Imprink.Domain.Models;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Domains.Users;
|
||||
namespace Imprink.Application.Users.Commands;
|
||||
|
||||
public record SyncUserCommand(Auth0User User) : IRequest<UserDto?>;
|
||||
|
||||
public class SyncUserHandler(IUnitOfWork uw): IRequestHandler<SyncUserCommand, UserDto?>
|
||||
public class SyncUserHandler(IUnitOfWork uw, IMapper mapper): IRequestHandler<SyncUserCommand, UserDto?>
|
||||
{
|
||||
public async Task<UserDto?> Handle(SyncUserCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -16,23 +17,13 @@ public class SyncUserHandler(IUnitOfWork uw): IRequestHandler<SyncUserCommand, U
|
||||
{
|
||||
var user = await uw.UserRepository.UpdateOrCreateUserAsync(request.User, cancellationToken);
|
||||
|
||||
if (user == null) throw new Exception("User exists but could not be updated");
|
||||
if (user == null)
|
||||
throw new Exception("User exists but could not be updated");
|
||||
|
||||
await uw.SaveAsync(cancellationToken);
|
||||
await uw.CommitTransactionAsync(cancellationToken);
|
||||
|
||||
return new UserDto
|
||||
{
|
||||
Id = user.Id,
|
||||
Name = user.Name,
|
||||
Nickname = user.Nickname,
|
||||
Email = user.Email,
|
||||
EmailVerified = user.EmailVerified,
|
||||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
PhoneNumber = user.PhoneNumber,
|
||||
IsActive = user.IsActive
|
||||
};
|
||||
return mapper.Map<UserDto>(user);
|
||||
}
|
||||
catch
|
||||
{
|
||||
42
src/Imprink.Application/Users/Mappings/UserMappingProfile.cs
Normal file
42
src/Imprink.Application/Users/Mappings/UserMappingProfile.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Security.Claims;
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Users.Dtos;
|
||||
using Imprink.Domain.Entities.Users;
|
||||
using Imprink.Domain.Models;
|
||||
|
||||
namespace Imprink.Application.Users.Mappings;
|
||||
|
||||
public class UserMappingProfile: Profile
|
||||
{
|
||||
public UserMappingProfile()
|
||||
{
|
||||
CreateMap<User, UserDto>()
|
||||
.ForMember(dest => dest.DefaultAddress, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Roles, opt => opt.Ignore());
|
||||
|
||||
CreateMap<UserDto, User>()
|
||||
.ForMember(dest => dest.DefaultAddress, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Roles, opt => opt.Ignore());
|
||||
|
||||
CreateMap<UserRole, UserRoleDto>();
|
||||
CreateMap<UserRoleDto, UserRole>();
|
||||
|
||||
CreateMap<Role, RoleDto>()
|
||||
.ForMember(dest => dest.RoleId, opt => opt.MapFrom(src => src.Id));
|
||||
CreateMap<RoleDto, Role>()
|
||||
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.RoleId))
|
||||
.ForMember(dest => dest.UserRoles, opt => opt.Ignore());
|
||||
|
||||
CreateMap<ClaimsPrincipal, Auth0User>()
|
||||
.ForMember(dest => dest.Sub, opt => opt.MapFrom(src =>
|
||||
src.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)!.Value))
|
||||
.ForMember(dest => dest.Name, opt => opt.MapFrom(src =>
|
||||
src.Claims.FirstOrDefault(c => c.Type == "name")!.Value))
|
||||
.ForMember(dest => dest.Nickname, opt => opt.MapFrom(src =>
|
||||
src.Claims.FirstOrDefault(c => c.Type == "nickname")!.Value))
|
||||
.ForMember(dest => dest.Email, opt => opt.MapFrom(src =>
|
||||
src.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email)!.Value))
|
||||
.ForMember(dest => dest.EmailVerified, opt => opt.MapFrom(src =>
|
||||
src.Claims.FirstOrDefault(c => c.Type == "email_verified")!.Value == "true"));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Imprink.Application.Services;
|
||||
namespace Imprink.Application.Users.Services;
|
||||
|
||||
public interface ICurrentUserService
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Domain.Models;
|
||||
|
||||
namespace Imprink.Application.Validation.Models;
|
||||
namespace Imprink.Application.Users.Validation;
|
||||
|
||||
public class Auth0UserValidator : AbstractValidator<Auth0User>
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.Users;
|
||||
using Imprink.Application.Users.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.Users;
|
||||
namespace Imprink.Application.Users.Validation;
|
||||
|
||||
public class SetUserFullNameCommandValidator : AbstractValidator<SetUserFullNameCommand>
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Imprink.Application.Domains.Users;
|
||||
using Imprink.Application.Users.Commands;
|
||||
|
||||
namespace Imprink.Application.Validation.Users;
|
||||
namespace Imprink.Application.Users.Validation;
|
||||
|
||||
public class SetUserPhoneCommandValidator : AbstractValidator<SetUserPhoneCommand>
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
|
||||
namespace Imprink.Domain.Entities.Orders;
|
||||
|
||||
@@ -14,6 +14,6 @@ public class OrderItem : EntityBase
|
||||
public string CustomizationDescription { get; set; } = null!;
|
||||
|
||||
public Order Order { get; set; } = null!;
|
||||
public Product.Product Product { get; set; } = null!;
|
||||
public Product Product { get; set; } = null!;
|
||||
public ProductVariant ProductVariant { get; set; } = null!;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Imprink.Domain.Entities.Product;
|
||||
namespace Imprink.Domain.Entities.Products;
|
||||
|
||||
public class Category : EntityBase
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Imprink.Domain.Entities.Orders;
|
||||
|
||||
namespace Imprink.Domain.Entities.Product;
|
||||
namespace Imprink.Domain.Entities.Products;
|
||||
|
||||
public class Product : EntityBase
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Imprink.Domain.Entities.Orders;
|
||||
|
||||
namespace Imprink.Domain.Entities.Product;
|
||||
namespace Imprink.Domain.Entities.Products;
|
||||
|
||||
public class ProductVariant : EntityBase
|
||||
{
|
||||
@@ -13,6 +13,6 @@ public class ProductVariant : EntityBase
|
||||
public int StockQuantity { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
public virtual required Imprink.Domain.Entities.Product.Product Product { get; set; }
|
||||
public virtual required Product Product { get; set; }
|
||||
public virtual ICollection<OrderItem> OrderItems { get; set; } = new List<OrderItem>();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
|
||||
namespace Imprink.Domain.Repositories.Products;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using Imprink.Domain.Models;
|
||||
|
||||
namespace Imprink.Domain.Repositories.Products;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
|
||||
namespace Imprink.Domain.Repositories.Products;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Imprink.Domain.Entities.Users;
|
||||
|
||||
namespace Imprink.Domain.Repositories;
|
||||
namespace Imprink.Domain.Repositories.Users;
|
||||
|
||||
public interface IRoleRepository
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Imprink.Domain.Entities.Orders;
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using Imprink.Domain.Entities.Users;
|
||||
using Imprink.Infrastructure.Configuration.Orders;
|
||||
using Imprink.Infrastructure.Configuration.Products;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using Imprink.Domain.Repositories.Products;
|
||||
using Imprink.Infrastructure.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using Imprink.Domain.Models;
|
||||
using Imprink.Domain.Repositories.Products;
|
||||
using Imprink.Infrastructure.Database;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using Imprink.Domain.Repositories.Products;
|
||||
using Imprink.Infrastructure.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Imprink.Domain.Entities.Users;
|
||||
using Imprink.Domain.Repositories;
|
||||
using Imprink.Domain.Repositories.Users;
|
||||
using Imprink.Infrastructure.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Security.Claims;
|
||||
using Imprink.Application.Services;
|
||||
using Imprink.Application.Users.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Imprink.Infrastructure.Services;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Imprink.Application.Domains.Categories;
|
||||
using Imprink.Application.Categories.Commands;
|
||||
using Imprink.Application.Categories.Dtos;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Imprink.Application.Domains.ProductVariants;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Application.ProductVariants.Commands;
|
||||
using Imprink.Application.ProductVariants.Dtos;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Imprink.Application.Domains.Products;
|
||||
using Imprink.Application.Products;
|
||||
using Imprink.Application.Products.Commands;
|
||||
using Imprink.Application.Products.Dtos;
|
||||
using Imprink.Domain.Models;
|
||||
using MediatR;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Security.Claims;
|
||||
using Imprink.Application.Domains.Users;
|
||||
using AutoMapper;
|
||||
using Imprink.Application.Users.Commands;
|
||||
using Imprink.Application.Users.Dtos;
|
||||
using Imprink.Domain.Models;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -9,30 +11,21 @@ namespace Imprink.WebApi.Controllers.Users;
|
||||
|
||||
[ApiController]
|
||||
[Route("/api/users")]
|
||||
public class UsersController(IMediator mediator) : ControllerBase
|
||||
public class UsersController(IMediator mediator, IMapper mapper) : ControllerBase
|
||||
{
|
||||
[Authorize]
|
||||
[HttpPost("me/sync")]
|
||||
public async Task<IActionResult> SyncMyProfile()
|
||||
{
|
||||
var claims = User.Claims as Claim[] ?? User.Claims.ToArray();
|
||||
|
||||
var auth0User = new Auth0User
|
||||
{
|
||||
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
|
||||
};
|
||||
var auth0User = mapper.Map<Auth0User>(User);
|
||||
|
||||
await mediator.Send(new SyncUserCommand(auth0User));
|
||||
return Ok("User profile synchronized.");
|
||||
return Ok("Synced");
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet("me/roles")]
|
||||
public async Task<IActionResult> GetMyRoles()
|
||||
public async Task<ActionResult<IEnumerable<RoleDto>>> GetMyRoles()
|
||||
{
|
||||
var sub = User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? string.Empty;
|
||||
return Ok(await mediator.Send(new GetUserRolesCommand(sub)));
|
||||
@@ -40,21 +33,29 @@ public class UsersController(IMediator mediator) : ControllerBase
|
||||
|
||||
[Authorize]
|
||||
[HttpPut("me/phone")]
|
||||
public async Task<IActionResult> UpdateMyPhone([FromBody] SetUserPhoneCommand command)
|
||||
public async Task<ActionResult<UserDto?>> UpdateMyPhone([FromBody] SetUserPhoneCommand command)
|
||||
{
|
||||
return Ok(await mediator.Send(command));
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPut("me/fullname")]
|
||||
public async Task<IActionResult> UpdateMyFullName([FromBody] SetUserFullNameCommand command)
|
||||
public async Task<ActionResult<UserDto?>> UpdateMyFullName([FromBody] SetUserFullNameCommand command)
|
||||
{
|
||||
return Ok(await mediator.Send(command));
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet("roles")]
|
||||
public async Task<ActionResult<UserRoleDto?>> GetAllRoles()
|
||||
{
|
||||
var command = new GetAllRolesCommand();
|
||||
return Ok(await mediator.Send(command));
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPut("{userId}/roles/{roleId:guid}")]
|
||||
public async Task<IActionResult> AddUserRole(string userId, Guid roleId)
|
||||
public async Task<ActionResult<UserRoleDto?>> AddUserRole(string userId, Guid roleId)
|
||||
{
|
||||
var command = new SetUserRoleCommand(userId, roleId);
|
||||
return Ok(await mediator.Send(command));
|
||||
@@ -62,7 +63,7 @@ public class UsersController(IMediator mediator) : ControllerBase
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpDelete("{userId}/roles/{roleId:guid}")]
|
||||
public async Task<IActionResult> RemoveUserRole(string userId, Guid roleId)
|
||||
public async Task<ActionResult<UserRoleDto?>> RemoveUserRole(string userId, Guid roleId)
|
||||
{
|
||||
var command = new DeleteUserRoleCommand(userId, roleId);
|
||||
return Ok(await mediator.Send(command));
|
||||
|
||||
@@ -61,6 +61,7 @@ public class ExceptionHandlingMiddleware(
|
||||
return exception switch
|
||||
{
|
||||
NotFoundException => (HttpStatusCode.NotFound, exception.Message, false),
|
||||
DataUpdateException => (HttpStatusCode.Conflict, exception.Message, false),
|
||||
_ => (HttpStatusCode.InternalServerError, "An internal server error occurred", true)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,5 +13,3 @@ var app = builder.Build();
|
||||
Startup.Configure(app, app.Environment);
|
||||
|
||||
app.Run();
|
||||
|
||||
public partial class Program { }
|
||||
@@ -1,4 +1,4 @@
|
||||
using Imprink.Domain.Entities.Product;
|
||||
using Imprink.Domain.Entities.Products;
|
||||
using Imprink.Infrastructure.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Security.Claims;
|
||||
using FluentValidation;
|
||||
using Imprink.Application;
|
||||
using Imprink.Application.Domains.Products;
|
||||
using Imprink.Application.Products;
|
||||
using Imprink.Application.Services;
|
||||
using Imprink.Application.Validation.Models;
|
||||
using Imprink.Application.Products.Commands;
|
||||
using Imprink.Application.Users.Services;
|
||||
using Imprink.Application.Users.Validation;
|
||||
using Imprink.Domain.Repositories;
|
||||
using Imprink.Domain.Repositories.Orders;
|
||||
using Imprink.Domain.Repositories.Products;
|
||||
@@ -39,9 +39,10 @@ public static class Startup
|
||||
services.AddScoped<IOrderItemRepository, OrderItemRepository>();
|
||||
services.AddScoped<IUnitOfWork, UnitOfWork>();
|
||||
services.AddScoped<ICurrentUserService, CurrentUserService>();
|
||||
|
||||
services.AddScoped<Seeder>();
|
||||
|
||||
services.AddAutoMapper(typeof(MappingProfile).Assembly);
|
||||
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
services.AddDbContext<ApplicationDbContext>(options =>
|
||||
|
||||
@@ -1,423 +1,192 @@
|
||||
'use client'
|
||||
'use client';
|
||||
|
||||
import {useEffect, useState} from 'react';
|
||||
import axios from 'axios';
|
||||
import {
|
||||
Alert,
|
||||
AppBar,
|
||||
Badge,
|
||||
Box,
|
||||
Button,
|
||||
Card,
|
||||
CardActions,
|
||||
CardContent,
|
||||
CardMedia,
|
||||
Chip,
|
||||
Container,
|
||||
Fab,
|
||||
Grid,
|
||||
IconButton,
|
||||
Skeleton,
|
||||
Toolbar,
|
||||
Typography
|
||||
} from '@mui/material';
|
||||
import {createTheme, ThemeProvider} from '@mui/material/styles';
|
||||
import CssBaseline from '@mui/material/CssBaseline';
|
||||
import {Menu, Palette, Search, ShoppingCart} from 'lucide-react';
|
||||
import { useUser } from "@auth0/nextjs-auth0";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
const theme = createTheme({
|
||||
palette: {
|
||||
mode: 'dark',
|
||||
primary: {
|
||||
main: '#D0BCFF',
|
||||
light: '#EADDFF',
|
||||
dark: '#9A82DB',
|
||||
contrastText: '#21005D'
|
||||
},
|
||||
secondary: {
|
||||
main: '#CCC2DC',
|
||||
light: '#E8DEF8',
|
||||
dark: '#A8A2BA',
|
||||
contrastText: '#332D41'
|
||||
},
|
||||
background: {
|
||||
default: '#101418',
|
||||
paper: '#1D1B20'
|
||||
},
|
||||
surface: {
|
||||
main: '#1D1B20',
|
||||
variant: '#49454F'
|
||||
},
|
||||
error: {
|
||||
main: '#F2B8B5',
|
||||
light: '#FFDAD6',
|
||||
dark: '#BA1A1A',
|
||||
contrastText: '#410002'
|
||||
},
|
||||
success: {
|
||||
main: '#A6D4A3',
|
||||
light: '#C4F0B8',
|
||||
dark: '#52B788'
|
||||
},
|
||||
text: {
|
||||
primary: '#E6E0E9',
|
||||
secondary: '#CAC4D0'
|
||||
}
|
||||
},
|
||||
shape: {
|
||||
borderRadius: 16
|
||||
},
|
||||
typography: {
|
||||
fontFamily: '"Google Sans", "Roboto", "Helvetica", "Arial", sans-serif',
|
||||
h4: {
|
||||
fontWeight: 400,
|
||||
fontSize: '2rem'
|
||||
},
|
||||
h6: {
|
||||
fontWeight: 500,
|
||||
fontSize: '1.25rem'
|
||||
},
|
||||
body1: {
|
||||
fontSize: '1rem',
|
||||
lineHeight: 1.5
|
||||
},
|
||||
body2: {
|
||||
fontSize: '0.875rem',
|
||||
lineHeight: 1.43
|
||||
}
|
||||
},
|
||||
components: {
|
||||
MuiCard: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
backgroundImage: 'none',
|
||||
backgroundColor: '#1D1B20',
|
||||
border: '1px solid #49454F',
|
||||
transition: 'all 0.3s ease',
|
||||
'&:hover': {
|
||||
transform: 'translateY(-4px)',
|
||||
borderColor: '#D0BCFF',
|
||||
boxShadow: '0 8px 32px rgba(208, 188, 255, 0.1)'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
MuiButton: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
textTransform: 'none',
|
||||
fontWeight: 500,
|
||||
borderRadius: 20,
|
||||
paddingLeft: 24,
|
||||
paddingRight: 24,
|
||||
height: 40
|
||||
}
|
||||
}
|
||||
},
|
||||
MuiTextField: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
'& .MuiOutlinedInput-root': {
|
||||
borderRadius: 12,
|
||||
backgroundColor: '#1D1B20',
|
||||
'& fieldset': {
|
||||
borderColor: '#49454F'
|
||||
},
|
||||
'&:hover fieldset': {
|
||||
borderColor: '#CAC4D0'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
MuiChip: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
borderRadius: 8
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const ProductCard = ({ product }) => {
|
||||
const [imageLoaded, setImageLoaded] = useState(false);
|
||||
|
||||
return (
|
||||
<Card sx={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
|
||||
<Box sx={{ position: 'relative', overflow: 'hidden' }}>
|
||||
{!imageLoaded && (
|
||||
<Skeleton variant="rectangular" height={200} />
|
||||
)}
|
||||
<CardMedia
|
||||
component="img"
|
||||
height="200"
|
||||
image={product.imageUrl}
|
||||
alt={product.name}
|
||||
onLoad={() => setImageLoaded(true)}
|
||||
sx={{
|
||||
display: imageLoaded ? 'block' : 'none',
|
||||
objectFit: 'cover',
|
||||
transition: 'transform 0.3s ease',
|
||||
'&:hover': {
|
||||
transform: 'scale(1.05)'
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Box sx={{
|
||||
position: 'absolute',
|
||||
top: 12,
|
||||
right: 12,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 1
|
||||
}}>
|
||||
{product.isCustomizable && (
|
||||
<Chip
|
||||
icon={<Palette size={16} />}
|
||||
label="Customizable"
|
||||
size="small"
|
||||
color="primary"
|
||||
sx={{ fontSize: '0.75rem' }}
|
||||
/>
|
||||
)}
|
||||
<Chip
|
||||
label={product.category.name}
|
||||
size="small"
|
||||
variant="outlined"
|
||||
sx={{ fontSize: '0.75rem' }}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<CardContent sx={{ flexGrow: 1, pb: 1 }}>
|
||||
<Typography variant="h6" component="h3" gutterBottom>
|
||||
{product.name}
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary" sx={{ mb: 2 }}>
|
||||
{product.description}
|
||||
</Typography>
|
||||
<Typography variant="h5" color="primary.main" fontWeight="bold">
|
||||
${product.basePrice.toFixed(2)}
|
||||
</Typography>
|
||||
</CardContent>
|
||||
|
||||
<CardActions sx={{ p: 2, pt: 0 }}>
|
||||
<Button
|
||||
variant="contained"
|
||||
fullWidth
|
||||
startIcon={<ShoppingCart size={18} />}
|
||||
sx={{
|
||||
background: 'linear-gradient(45deg, #D0BCFF 30%, #EADDFF 90%)',
|
||||
color: '#21005D'
|
||||
}}
|
||||
>
|
||||
Add to Cart
|
||||
</Button>
|
||||
</CardActions>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
const LoadingSkeleton = () => (
|
||||
<Grid container spacing={3}>
|
||||
{[...Array(8)].map((_, index) => (
|
||||
<Grid item xs={12} sm={6} md={4} lg={3} key={index}>
|
||||
<Card>
|
||||
<Skeleton variant="rectangular" height={200} />
|
||||
<CardContent>
|
||||
<Skeleton variant="text" height={32} />
|
||||
<Skeleton variant="text" height={20} />
|
||||
<Skeleton variant="text" height={20} width="60%" />
|
||||
<Skeleton variant="text" height={28} width="40%" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
);
|
||||
|
||||
const ImprintLanding = () => {
|
||||
const [products, setProducts] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
const [cartCount, setCartCount] = useState(0);
|
||||
export default function Home() {
|
||||
const { user, error, isLoading } = useUser();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchProducts = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await axios.get('https://impr.ink/api/products', {
|
||||
params: {
|
||||
PageNumber: 1,
|
||||
PageSize: 20
|
||||
}
|
||||
});
|
||||
setProducts(response.data.items);
|
||||
} catch (err) {
|
||||
setError('Failed to load products. Please try again later.');
|
||||
console.error('Error fetching products:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
const fetchAccessToken = async () => {
|
||||
if (user) {
|
||||
try {
|
||||
await fetch('/token');
|
||||
} catch (error) {
|
||||
console.error("Error fetching token");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
await fetch('/untoken');
|
||||
} catch (e) {
|
||||
console.error('Error in /api/untoken:', e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fetchProducts().then(r => console.log(r));
|
||||
}, []);
|
||||
fetchAccessToken().then(r => console.log(r));
|
||||
}, [user]);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-purple-900 via-blue-900 to-indigo-900 flex items-center justify-center">
|
||||
<div className="relative">
|
||||
<div className="w-16 h-16 border-4 border-white/20 border-t-white rounded-full animate-spin"></div>
|
||||
<div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2">
|
||||
<div className="w-10 h-10 border-4 border-transparent border-t-purple-400 rounded-full animate-spin"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-red-900 via-pink-900 to-purple-900 flex items-center justify-center p-4">
|
||||
<div className="bg-white/10 backdrop-blur-xl rounded-2xl p-6 border border-white/20 shadow-2xl">
|
||||
<div className="text-white/80 mb-4">{error.message}</div>
|
||||
<div className="text-center">
|
||||
<a
|
||||
href="/auth/login"
|
||||
className="group relative inline-flex items-center gap-2 px-8 py-3 bg-gradient-to-r from-purple-500 to-blue-500 rounded-xl font-bold text-white shadow-2xl hover:shadow-purple-500/25 transition-all duration-300 hover:scale-105 active:scale-95"
|
||||
>
|
||||
<div
|
||||
className="absolute inset-0 bg-gradient-to-r from-purple-600 to-blue-600 rounded-xl opacity-0 group-hover:opacity-100 transition-opacity duration-300"></div>
|
||||
<span className="relative flex items-center gap-2">
|
||||
Sign In
|
||||
</span>
|
||||
</a>
|
||||
<a
|
||||
onClick={() => checkValidity()}
|
||||
className="group relative px-6 py-3 bg-gradient-to-r from-red-500 to-pink-500 rounded-xl font-bold text-white shadow-2xl hover:shadow-red-500/25 transition-all duration-300 hover:scale-105 active:scale-95"
|
||||
>
|
||||
<div
|
||||
className="absolute inset-0 bg-gradient-to-r from-red-600 to-pink-600 rounded-xl opacity-0 group-hover:opacity-100 transition-opacity duration-300"></div>
|
||||
<span className="relative flex items-center gap-2">
|
||||
Check
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const featuredProducts = products.slice(0, 4);
|
||||
return (
|
||||
<ThemeProvider theme={theme}>
|
||||
<CssBaseline />
|
||||
<Box sx={{ flexGrow: 1 }}>
|
||||
{/* App Bar */}
|
||||
<AppBar position="sticky" sx={{ backgroundColor: 'background.paper', borderBottom: '1px solid #49454F' }}>
|
||||
<Toolbar>
|
||||
<IconButton edge="start" color="inherit" sx={{ mr: 2 }}>
|
||||
<Menu />
|
||||
</IconButton>
|
||||
<Typography variant="h6" component="div" sx={{ flexGrow: 1, color: 'primary.main', fontWeight: 'bold' }}>
|
||||
impr.ink
|
||||
</Typography>
|
||||
<IconButton color="inherit" sx={{ mr: 1 }}>
|
||||
<Search />
|
||||
</IconButton>
|
||||
<IconButton color="inherit">
|
||||
<Badge badgeContent={cartCount} color="primary">
|
||||
<ShoppingCart />
|
||||
</Badge>
|
||||
</IconButton>
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
<div
|
||||
className="min-h-screen bg-gradient-to-br from-purple-900 via-blue-900 to-indigo-900 relative overflow-hidden">
|
||||
<div className="relative z-10 min-h-screen flex items-center justify-center p-4">
|
||||
{user ? (
|
||||
<div className="w-full max-w-5xl">
|
||||
<div className="text-center mb-6">
|
||||
<div
|
||||
className="inline-flex items-center justify-center w-16 h-16 bg-gradient-to-r from-purple-500 to-blue-500 rounded-full mb-3 shadow-2xl">
|
||||
{user.picture ? (
|
||||
<img
|
||||
src={user.picture}
|
||||
alt="Profile"
|
||||
className="w-full h-full rounded-full object-cover border-3 border-white/20"
|
||||
/>
|
||||
) : (
|
||||
<div className="text-white text-xl font-bold">
|
||||
{user.name?.charAt(0) || user.email?.charAt(0) || '👤'}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<h1 className="text-2xl pb-1 font-bold bg-gradient-to-r from-white via-purple-200 to-blue-200 bg-clip-text text-transparent">
|
||||
Just testing :P
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Hero Section */}
|
||||
<Box sx={{
|
||||
background: 'linear-gradient(135deg, #1D1B20 0%, #2D1B69 50%, #1D1B20 100%)',
|
||||
py: 8,
|
||||
position: 'relative',
|
||||
overflow: 'hidden'
|
||||
}}>
|
||||
<Container maxWidth="lg">
|
||||
<Box sx={{ textAlign: 'center', position: 'relative', zIndex: 1 }}>
|
||||
<Typography variant="h2" component="h1" gutterBottom sx={{
|
||||
fontWeight: 300,
|
||||
background: 'linear-gradient(45deg, #D0BCFF, #EADDFF)',
|
||||
backgroundClip: 'text',
|
||||
WebkitBackgroundClip: 'text',
|
||||
WebkitTextFillColor: 'transparent',
|
||||
mb: 2
|
||||
}}>
|
||||
Custom Printing Made Beautiful
|
||||
</Typography>
|
||||
<Typography variant="h5" color="text.secondary" sx={{ mb: 4, maxWidth: 600, mx: 'auto' }}>
|
||||
High-quality custom printing solutions for caps, flyers, coasters, and more.
|
||||
Premium materials with excellent print adhesion and longevity.
|
||||
</Typography>
|
||||
<Button
|
||||
variant="contained"
|
||||
size="large"
|
||||
sx={{
|
||||
background: 'linear-gradient(45deg, #D0BCFF 30%, #EADDFF 90%)',
|
||||
color: '#21005D',
|
||||
px: 4,
|
||||
py: 1.5,
|
||||
fontSize: '1.1rem'
|
||||
}}
|
||||
<div className="bg-white/10 backdrop-blur-xl rounded-2xl border border-white/20 shadow-2xl overflow-hidden mb-4">
|
||||
<div className="bg-gradient-to-r from-purple-500/20 to-blue-500/20 p-4 border-b border-white/10">
|
||||
<h2 className="text-xl font-bold text-white flex items-center gap-2">
|
||||
Auth Details
|
||||
</h2>
|
||||
</div>
|
||||
<div className="p-5">
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label
|
||||
className="text-purple-300 text-xs font-semibold uppercase tracking-wider">Name</label>
|
||||
<div
|
||||
className="text-white text-base mt-1 p-2 bg-white/5 rounded-lg border border-white/10">
|
||||
{user.name || 'Not provided'}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
className="text-purple-300 text-xs font-semibold uppercase tracking-wider">Email</label>
|
||||
<div
|
||||
className="text-white text-base mt-1 p-2 bg-white/5 rounded-lg border border-white/10">
|
||||
{user.email || 'Not provided'}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
className="text-purple-300 text-xs font-semibold uppercase tracking-wider">User
|
||||
ID</label>
|
||||
<div
|
||||
className="text-white/80 text-xs mt-1 p-2 bg-white/5 rounded-lg border border-white/10 font-mono break-all">
|
||||
{user.sub || 'Not available'}
|
||||
</div>
|
||||
</div>
|
||||
{user.nickname && (
|
||||
<div>
|
||||
<label
|
||||
className="text-purple-300 text-xs font-semibold uppercase tracking-wider">Nickname</label>
|
||||
<div
|
||||
className="text-white text-base mt-1 p-2 bg-white/5 rounded-lg border border-white/10">
|
||||
{user.nickname}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label
|
||||
className="text-purple-300 text-xs font-semibold uppercase tracking-wider mb-2 block">
|
||||
Raw User Data
|
||||
</label>
|
||||
<div
|
||||
className="bg-black/30 rounded-lg p-3 border border-white/10 h-64 overflow-auto">
|
||||
<pre
|
||||
className="text-green-300 text-xs font-mono leading-tight whitespace-pre-wrap">
|
||||
{JSON.stringify(user, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-center">
|
||||
<a
|
||||
onClick={() => checkValidity()}
|
||||
className="group relative px-6 py-3 bg-gradient-to-r from-red-500 to-pink-500 rounded-xl font-bold text-white shadow-2xl hover:shadow-red-500/25 transition-all duration-300 hover:scale-105 active:scale-95"
|
||||
>
|
||||
Explore Products
|
||||
</Button>
|
||||
</Box>
|
||||
</Container>
|
||||
</Box>
|
||||
|
||||
<Container maxWidth="lg" sx={{ py: 6 }}>
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mb: 4 }}>
|
||||
{error}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{/* Featured Products */}
|
||||
<Box sx={{ mb: 6 }}>
|
||||
<Typography variant="h4" component="h2" gutterBottom sx={{ mb: 4, textAlign: 'center' }}>
|
||||
Featured Products
|
||||
</Typography>
|
||||
{loading ? (
|
||||
<Grid container spacing={3}>
|
||||
{[...Array(4)].map((_, index) => (
|
||||
<Grid item xs={12} sm={6} md={3} key={index}>
|
||||
<Card>
|
||||
<Skeleton variant="rectangular" height={200} />
|
||||
<CardContent>
|
||||
<Skeleton variant="text" height={32} />
|
||||
<Skeleton variant="text" height={20} />
|
||||
<Skeleton variant="text" height={28} width="40%" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
) : (
|
||||
<Grid container spacing={3}>
|
||||
{featuredProducts.map((product) => (
|
||||
<Grid item xs={12} sm={6} md={3} key={product.id}>
|
||||
<ProductCard product={product} />
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
{/* All Products */}
|
||||
<Box>
|
||||
<Typography variant="h4" component="h2" gutterBottom sx={{ mb: 4, textAlign: 'center' }}>
|
||||
All Products
|
||||
</Typography>
|
||||
{loading ? (
|
||||
<LoadingSkeleton />
|
||||
) : (
|
||||
<Grid container spacing={3}>
|
||||
{products.map((product) => (
|
||||
<Grid item xs={12} sm={6} md={4} lg={3} key={product.id}>
|
||||
<ProductCard product={product} />
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
{/* Load More Button */}
|
||||
{!loading && products.length > 0 && (
|
||||
<Box sx={{ textAlign: 'center', mt: 6 }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="large"
|
||||
sx={{ px: 4 }}
|
||||
<div
|
||||
className="absolute inset-0 bg-gradient-to-r from-red-600 to-pink-600 rounded-xl opacity-0 group-hover:opacity-100 transition-opacity duration-300"></div>
|
||||
<span className="relative flex items-center gap-2">
|
||||
Check
|
||||
</span>
|
||||
</a>
|
||||
<a
|
||||
href="/auth/logout"
|
||||
className="group relative px-6 py-3 bg-gradient-to-r from-red-500 to-pink-500 rounded-xl font-bold text-white shadow-2xl hover:shadow-red-500/25 transition-all duration-300 hover:scale-105 active:scale-95"
|
||||
>
|
||||
Load More Products
|
||||
</Button>
|
||||
</Box>
|
||||
)}
|
||||
</Container>
|
||||
|
||||
{/* Floating Action Button */}
|
||||
<Fab
|
||||
color="primary"
|
||||
sx={{
|
||||
position: 'fixed',
|
||||
bottom: 16,
|
||||
right: 16,
|
||||
background: 'linear-gradient(45deg, #D0BCFF 30%, #EADDFF 90%)',
|
||||
color: '#21005D'
|
||||
}}
|
||||
>
|
||||
<Badge badgeContent={cartCount} color="error">
|
||||
<ShoppingCart />
|
||||
</Badge>
|
||||
</Fab>
|
||||
</Box>
|
||||
</ThemeProvider>
|
||||
<div
|
||||
className="absolute inset-0 bg-gradient-to-r from-red-600 to-pink-600 rounded-xl opacity-0 group-hover:opacity-100 transition-opacity duration-300"></div>
|
||||
<span className="relative flex items-center gap-2">
|
||||
Sign Out
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div></div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ImprintLanding;
|
||||
}
|
||||
Reference in New Issue
Block a user