Seeding, cleanup, fix nginx proxying
This commit is contained in:
@@ -23,7 +23,6 @@ public class RoleConfiguration : IEntityTypeConfiguration<Role>
|
||||
.HasDatabaseName("IX_Role_RoleName");
|
||||
|
||||
builder.HasData(
|
||||
new Role { Id = Guid.Parse("11111111-1111-1111-1111-111111111111"), RoleName = "User" },
|
||||
new Role { Id = Guid.Parse("22222222-2222-2222-2222-222222222222"), RoleName = "Merchant" },
|
||||
new Role { Id = Guid.Parse("33333333-3333-3333-3333-333333333333"), RoleName = "Admin" }
|
||||
);
|
||||
|
||||
@@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace Imprink.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20250608204903_InitialSetup")]
|
||||
[Migration("20250609202250_InitialSetup")]
|
||||
partial class InitialSetup
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -8,35 +8,9 @@ namespace Imprink.Infrastructure.Repositories;
|
||||
|
||||
public class ProductRepository(ApplicationDbContext context) : IProductRepository
|
||||
{
|
||||
public async Task<Product?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await context.Products
|
||||
.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<Product?> GetByIdWithVariantsAsync(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await context.Products
|
||||
.Include(p => p.ProductVariants.Where(pv => pv.IsActive))
|
||||
.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<Product?> GetByIdWithCategoryAsync(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await context.Products
|
||||
.Include(p => p.Category)
|
||||
.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<Product?> GetByIdFullAsync(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await context.Products
|
||||
.Include(p => p.Category)
|
||||
.Include(p => p.ProductVariants.Where(pv => pv.IsActive))
|
||||
.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<Product>> GetPagedAsync(ProductFilterParameters filterParameters, CancellationToken cancellationToken = default)
|
||||
public async Task<PagedResult<Product>> GetPagedAsync(
|
||||
ProductFilterParameters filterParameters,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = context.Products
|
||||
.Include(p => p.Category)
|
||||
@@ -49,8 +23,9 @@ public class ProductRepository(ApplicationDbContext context) : IProductRepositor
|
||||
|
||||
if (!string.IsNullOrEmpty(filterParameters.SearchTerm))
|
||||
{
|
||||
query = query.Where(p => p.Name.Contains(filterParameters.SearchTerm) ||
|
||||
(p.Description != null && p.Description.Contains(filterParameters.SearchTerm)));
|
||||
query = query.Where(
|
||||
p => p.Name.Contains(filterParameters.SearchTerm)
|
||||
|| (p.Description != null && p.Description.Contains(filterParameters.SearchTerm)));
|
||||
}
|
||||
|
||||
if (filterParameters.CategoryId.HasValue)
|
||||
@@ -101,6 +76,34 @@ public class ProductRepository(ApplicationDbContext context) : IProductRepositor
|
||||
PageSize = filterParameters.PageSize
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<Product?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await context.Products
|
||||
.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<Product?> GetByIdWithVariantsAsync(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await context.Products
|
||||
.Include(p => p.ProductVariants.Where(pv => pv.IsActive))
|
||||
.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<Product?> GetByIdWithCategoryAsync(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await context.Products
|
||||
.Include(p => p.Category)
|
||||
.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<Product?> GetByIdFullAsync(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await context.Products
|
||||
.Include(p => p.Category)
|
||||
.Include(p => p.ProductVariants.Where(pv => pv.IsActive))
|
||||
.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Product>> GetByCategoryAsync(Guid categoryId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -68,62 +68,12 @@ public class UserRepository(ApplicationDbContext context) : IUserRepository
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<User> CreateUserAsync(User user, CancellationToken cancellationToken = default)
|
||||
{
|
||||
context.Users.Add(user);
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
return user;
|
||||
}
|
||||
|
||||
public async Task<User> UpdateUserAsync(User user, CancellationToken cancellationToken = default)
|
||||
{
|
||||
context.Users.Update(user);
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
return user;
|
||||
}
|
||||
|
||||
public async Task DeleteUserAsync(string userId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var user = await context.Users.FindAsync(new object[] { userId }, cancellationToken);
|
||||
if (user != null)
|
||||
{
|
||||
context.Users.Remove(user);
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UserExistsAsync(string userId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await context.Users
|
||||
.AnyAsync(u => u.Id == userId, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<bool> EmailExistsAsync(string email, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await context.Users
|
||||
.AnyAsync(u => u.Email == email, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<bool> ActivateUserAsync(string userId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var user = await context.Users.FindAsync(new object[] { userId }, cancellationToken);
|
||||
if (user == null) return false;
|
||||
|
||||
user.IsActive = true;
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> DeactivateUserAsync(string userId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var user = await context.Users.FindAsync(new object[] { userId }, cancellationToken);
|
||||
if (user == null) return false;
|
||||
|
||||
user.IsActive = false;
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<User>> GetUsersByRoleAsync(Guid roleId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await context.Users
|
||||
Reference in New Issue
Block a user