Compare commits

...

22 Commits

Author SHA1 Message Date
khwezi 371f8e6eef Merge commit '26075cd9a7c04c294053afead63c46fff7b16cfc' 2026-05-10 15:33:23 +00:00
Khwezi Mngoma 26075cd9a7 Updated job scheduler
continuous-integration/drone/pr Build is passing
2026-05-10 17:32:09 +02:00
khwezi 4deb732804 Merge pull request 'emailjobs' (#16) from emailjobs into master
Reviewed-on: #16
2026-05-10 16:51:24 +02:00
Khwezi Mngoma cecd9f90e9 Implemented service bus handling of emails and notification processing
continuous-integration/drone/pr Build is passing
2026-05-10 16:50:36 +02:00
Khwezi Mngoma 73ba41beaf Added outgoing email notification processing event 2026-05-10 16:07:53 +02:00
Khwezi Mngoma e8e9a85c57 Migrated database changes after refactoring the Notification model 2026-05-10 15:27:26 +02:00
Khwezi Mngoma 394429677e Added package management 2026-05-10 14:18:56 +02:00
khwezi 20d9387d0b Merge pull request 'Migrated database changes' (#15) from develop into master
Reviewed-on: #15
2026-05-10 11:17:54 +02:00
khwezi 9f6d0ccaa0 Merge pull request 'Populated README' (#14) from develop into master
Reviewed-on: #14
2026-05-10 09:48:35 +02:00
khwezi 1acbc4d213 Merge pull request 'fixed git repo naming' (#13) from develop into master
Reviewed-on: #13
2026-05-10 09:22:37 +02:00
khwezi 8c99668fac Merge pull request 'Added tag and release step after publish' (#12) from develop into master
Reviewed-on: #12
2026-05-10 09:19:33 +02:00
khwezi ad44f46204 Merge pull request 'Refactored Quartz instance id to AUTO, removed constant' (#11) from develop into master
Reviewed-on: #11
2026-05-10 08:21:08 +02:00
khwezi 49d999c1e3 Merge pull request 'Refactored postgres extension' (#10) from develop into master
Reviewed-on: #10
2026-05-09 17:45:00 +02:00
khwezi 9ed4777a18 Merge pull request 'Refactored database references' (#9) from develop into master
Reviewed-on: #9
2026-05-09 17:01:02 +02:00
khwezi 0cf44f68cc Merge pull request 'Added scheduler constants' (#8) from develop into master
Reviewed-on: #8
2026-05-09 15:27:50 +02:00
khwezi 41ed5a4288 Merge pull request 'Fixed quartz host config table prefix' (#7) from develop into master
Reviewed-on: #7
2026-05-09 13:30:33 +02:00
khwezi bbcba5e06c Merge pull request 'Fixed quartz table name prefix' (#6) from develop into master
Reviewed-on: #6
2026-05-09 13:28:29 +02:00
khwezi 502cc326dd Merge pull request 'Updated pipeline to use major version with minor always 0' (#5) from develop into master
Reviewed-on: #5
2026-05-09 12:02:19 +02:00
khwezi 4675d4c5fc Merge pull request 'Updated pipeline to use major versions only' (#4) from develop into master
continuous-integration/drone/push Build was killed
continuous-integration/drone Build is failing
Reviewed-on: #4
2026-05-09 11:56:20 +02:00
khwezi f80bb2fff9 Merge pull request 'Changed target branch from nain to master' (#3) from dronepipeline into master
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
Reviewed-on: #3
2026-05-09 11:37:39 +02:00
khwezi 6767906b0d Merge pull request 'Added pipeline separator' (#2) from dronepipeline into master
Reviewed-on: #2
2026-05-09 11:25:34 +02:00
khwezi a344af4498 Merge pull request 'Added .drone.yml pipeline' (#1) from dronepipeline into master
Reviewed-on: #1
2026-05-09 11:12:38 +02:00
58 changed files with 1192 additions and 819 deletions
+2
View File
@@ -5,6 +5,8 @@ public static class Constants
public const int QueueBounds = 100000;
public const string ShopSchedulerName = "shop";
public const string ShopEmailFromName = "Khongisa Shop";
public const string ShopEmailFromAddress = "shop@litecharms.co.za";
public const string EmailServiceBus = nameof(EmailServiceBus);
public const string GeneralServiceBus = nameof(GeneralServiceBus);
+12
View File
@@ -0,0 +1,12 @@
using static LiteCharms.Abstractions.Timezones;
namespace LiteCharms.Abstractions;
public abstract class EventBase
{
public Guid Id { get; set; } = Guid.CreateVersion7();
public DateTimeOffset EnqueueAt { get; set; } = SouthAfricanTimeZone.UtcNow();
public string CorrelationId { get; set; } = Guid.CreateVersion7().ToString();
}
@@ -1,4 +1,6 @@
namespace LiteCharms.Entities.Configuration;
using LiteCharms.Models;
namespace LiteCharms.Entities.Configuration;
public class NotificationConfiguration : IEntityTypeConfiguration<Notification>
{
@@ -9,18 +11,20 @@ public class NotificationConfiguration : IEntityTypeConfiguration<Notification>
builder.HasKey(f => f.Id);
builder.Property(f => f.CreatedAt).IsRequired().ValueGeneratedOnAdd();
builder.Property(f => f.UpdatedAt).IsRequired(false).ValueGeneratedOnUpdate();
builder.Property(f => f.Direction).IsRequired();
builder.Property(f => f.Platform).IsRequired();
builder.Property(f => f.Priority).IsRequired();
builder.Property(f => f.Direction).IsRequired().HasConversion<int>();
builder.Property(f => f.Platform).IsRequired().HasConversion<int>();
builder.Property(f => f.Priority).IsRequired().HasConversion<int>();
builder.Property(f => f.CorrelationIdType).IsRequired().HasConversion<int>();
builder.Property(f => f.Sender).IsRequired();
builder.Property(f => f.Subject).IsRequired();
builder.Property(f => f.Message).IsRequired();
builder.Property(f => f.Recipient).IsRequired();
builder.Property(f => f.RecipientAddress).IsRequired();
builder.Property(f => f.CorrelationId).IsRequired();
builder.Property(f => f.CorrelationIdType).IsRequired();
builder.Property(f => f.IsHtml).HasDefaultValue(false);
builder.Property(f => f.IsInternal).HasDefaultValue(true);
builder.Property(f => f.Processed).HasDefaultValue(false);
builder.Property(f => f.HasError).HasDefaultValue(false);
builder.Property(f => f.Errors).HasColumnType("jsonb").IsRequired(false);
}
}
@@ -11,7 +11,7 @@ public class QuoteConfiguration : IEntityTypeConfiguration<Quote>
builder.Property(f => f.UpdatedAt).IsRequired(false).ValueGeneratedOnUpdate();
builder.Property(f => f.ExpiredAt).IsRequired(false);
builder.Property(f => f.CustomerId).IsRequired();
builder.Property(f => f.Status).IsRequired();
builder.Property(f => f.Status).IsRequired().HasConversion<int>();
builder.Property(f => f.ShoppingCartId).IsRequired();
builder.Property(f => f.Reason).IsRequired(false);
+2
View File
@@ -12,4 +12,6 @@ public class ShoppingCart : Models.ShoppingCart
public virtual Quote? Quote { get; set; }
public virtual ICollection<ShoppingCartItem>? ShoppingCartItems { get; set; }
public virtual ICollection<Package>? Packages { get; set; }
}
+44 -4
View File
@@ -4,6 +4,36 @@ namespace LiteCharms.Extensions;
public static class EntityModeMappers
{
public static ShoppingCartPackage ToModel(this Entities.ShoppingCartPackage entity) =>
new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
PackageId = entity.PackageId,
ShoppingCartId = entity.ShoppingCartId
};
public static PackageItem ToModel(this Entities.PackageItem entity) =>
new()
{
Id = entity.Id,
Active = entity.Active,
CreatedAt = entity.CreatedAt,
PackageId = entity.PackageId,
ProductPriceId = entity.ProductPriceId
};
public static Package ToModel(this Entities.Package entity) =>
new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
Active = entity.Active,
Description = entity.Description,
Name = entity.Name,
UpdatedAt = entity.UpdatedAt
};
public static ShoppingCartItem ToModel(this Entities.ShoppingCartItem entity) =>
new()
{
@@ -36,7 +66,7 @@ public static class EntityModeMappers
ExpiredAt = entity.ExpiredAt,
Reason = entity.Reason,
ShoppingCartId = entity.ShoppingCartId,
Status = entity.Status
Status = entity.Status
};
public static Notification ToModel(this Entities.Notification entity) =>
@@ -53,7 +83,14 @@ public static class EntityModeMappers
Platform = entity.Platform,
Recipient = entity.Recipient,
Subject = entity.Subject,
Processed = entity.Processed
Processed = entity.Processed,
SenderName = entity.SenderName,
RecipientAddress = entity.RecipientAddress,
Priority = entity.Priority,
UpdatedAt = entity?.UpdatedAt,
IsHtml = entity!.IsHtml,
HasError = entity.HasError,
Errors = entity.Errors
};
public static Customer ToModel(this Entities.Customer entity) =>
@@ -78,7 +115,7 @@ public static class EntityModeMappers
Slack = entity.Slack,
Tax = entity.Tax,
Website = entity.Website,
Whatsapp = entity.Whatsapp
Whatsapp = entity.Whatsapp
};
public static Lead ToModel(this Entities.Lead entity) =>
@@ -113,7 +150,10 @@ public static class EntityModeMappers
RefundId = entity.RefundId,
QuoteId = entity.QuoteId,
Status = entity.Status,
ShoppingCartId = entity.ShoppingCartId
ShoppingCartId = entity.ShoppingCartId,
DepositRequired = entity.DepositRequired,
Requirements = entity.Requirements,
Terms = entity.Terms
};
public static OrderRefund ToModel(this Entities.OrderRefund entity) =>
@@ -0,0 +1,25 @@
namespace LiteCharms.Features.CartPackages.Commands;
public class AddPackageItemCommand : IRequest<Result<Guid>>
{
public Guid PackageId { get; set; }
public Guid ProductPriceId { get; set; }
private AddPackageItemCommand(Guid packageId, Guid productPriceId)
{
PackageId = packageId;
ProductPriceId = productPriceId;
}
public static AddPackageItemCommand Create(Guid packageId, Guid productPriceId)
{
if (packageId == Guid.Empty)
throw new ArgumentException("Package id is required", nameof(packageId));
if (productPriceId == Guid.Empty)
throw new ArgumentException("Product price id is required", nameof(productPriceId));
return new(packageId, productPriceId);
}
}
@@ -0,0 +1,23 @@
namespace LiteCharms.Features.CartPackages.Commands;
public class CreatePackageCommand : IRequest<Result<Guid>>
{
public string? Name { get; set; }
public string? Description { get; set; }
private CreatePackageCommand(string? name, string? description)
{
Name = name;
Description = description;
}
public static CreatePackageCommand Create(string? name, string? description)
{
ArgumentException.ThrowIfNullOrWhiteSpace(name, nameof(name));
ArgumentException.ThrowIfNullOrWhiteSpace(description, nameof(description));
return new(name, description);
}
}
@@ -0,0 +1,25 @@
namespace LiteCharms.Features.CartPackages.Commands;
public class DeletePackageItemCommand : IRequest<Result>
{
public Guid PackageId { get; set; }
public Guid PackageItemId { get; set; }
private DeletePackageItemCommand(Guid packageId, Guid packageItemId)
{
PackageId = packageId;
PackageItemId = packageItemId;
}
public static DeletePackageItemCommand Create(Guid packageId, Guid packageItemId)
{
if (packageId == Guid.Empty)
throw new ArgumentException("Package id is required", nameof(packageId));
if (packageItemId == Guid.Empty)
throw new ArgumentException("Product price id is required", nameof(packageItemId));
return new(packageId, packageItemId);
}
}
@@ -0,0 +1,16 @@
namespace LiteCharms.Features.CartPackages.Commands;
public class DeletePackageItemsCommand : IRequest<Result>
{
public Guid PackageId { get; set; }
private DeletePackageItemsCommand(Guid packageId) => PackageId = packageId;
public static DeletePackageItemsCommand Create(Guid packageId)
{
if (packageId == Guid.Empty)
throw new ArgumentException("Package ID is required", nameof(packageId));
return new(packageId);
}
}
@@ -0,0 +1,38 @@
using LiteCharms.Infrastructure.Database;
namespace LiteCharms.Features.CartPackages.Commands.Handlers;
public class AddPackageItemCommandHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<AddPackageItemCommand, Result<Guid>>
{
public async ValueTask<Result<Guid>> Handle(AddPackageItemCommand request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
if (!await context.Packages.AnyAsync(p => p.Id == request.PackageId, cancellationToken))
return Result.Fail($"Could not find package by ID {request.PackageId}");
if (!await context.ProductPrices.AnyAsync(p => p.Id == request.ProductPriceId && p.Active == true, cancellationToken))
return Result.Fail($"Could not find an active product price by ID {request.ProductPriceId}");
if (await context.PackageItems.AnyAsync(p => p.ProductPriceId == request.ProductPriceId && p.PackageId == request.PackageId, cancellationToken))
return Result.Fail<Guid>($"Product price {request.ProductPriceId} is already added to this package {request.PackageId}");
var newPackageItem = context.PackageItems.Add(new Entities.PackageItem
{
PackageId = request.PackageId,
ProductPriceId = request.ProductPriceId,
Active = true
});
return await context.SaveChangesAsync(cancellationToken) > 0
? Result.Ok(newPackageItem.Entity.Id)
: Result.Fail<Guid>($"Failed to add new package item by ID {request.ProductPriceId}");
}
catch (Exception ex)
{
return Result.Fail<Guid>(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -0,0 +1,32 @@
using LiteCharms.Infrastructure.Database;
namespace LiteCharms.Features.CartPackages.Commands.Handlers;
public class CreatePackageCommandHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<CreatePackageCommand, Result<Guid>>
{
public async ValueTask<Result<Guid>> Handle(CreatePackageCommand request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
if (await context.Packages.AnyAsync(p => p.Name == request.Name, cancellationToken))
return Result.Fail($"A package by the same name already exists: {request.Name}");
var newPackage = context.Packages.Add(new Entities.Package
{
Name = request.Name,
Description = request.Description,
Active = true
});
return await context.SaveChangesAsync(cancellationToken) > 0
? Result.Ok(newPackage.Entity.Id)
: Result.Fail($"Failed to create a new package by the name: {request.Name}");
}
catch (Exception ex)
{
return Result.Fail<Guid>(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -0,0 +1,32 @@
using LiteCharms.Infrastructure.Database;
namespace LiteCharms.Features.CartPackages.Commands.Handlers;
public class DeletePackageItemCommandHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<DeletePackageItemCommand, Result>
{
public async ValueTask<Result> Handle(DeletePackageItemCommand request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
if (!await context.Packages.AnyAsync(p => p.Id == request.PackageId, cancellationToken))
return Result.Fail($"Could not find package by ID {request.PackageId}");
var item = await context.PackageItems.FirstOrDefaultAsync(p => p.Id == request.PackageItemId && p.PackageId == request.PackageId, cancellationToken);
if(item is null)
return Result.Fail($"Product item {request.PackageItemId} is already added to this package {request.PackageId}");
context.PackageItems.Remove(item);
return await context.SaveChangesAsync(cancellationToken) > 0
? Result.Ok()
: Result.Fail($"Failed to delete package item by id {request.PackageItemId}");
}
catch (Exception ex)
{
return Result.Fail(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -0,0 +1,29 @@
using LiteCharms.Infrastructure.Database;
namespace LiteCharms.Features.CartPackages.Commands.Handlers;
public class DeletePackageItemsCommandHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<DeletePackageItemsCommand, Result>
{
public async ValueTask<Result> Handle(DeletePackageItemsCommand request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
if (!await context.Packages.AnyAsync(p => p.Id == request.PackageId, cancellationToken))
return Result.Fail($"Could not find package by ID {request.PackageId}");
var items = await context.PackageItems.Where(i => i.PackageId == request.PackageId).ToArrayAsync(cancellationToken);
context.PackageItems.RemoveRange(items);
return await context.SaveChangesAsync(cancellationToken) > 0
? Result.Ok()
: Result.Fail($"Failed to delete package {request.PackageId} items");
}
catch (Exception ex)
{
return Result.Fail(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -0,0 +1,33 @@
using LiteCharms.Infrastructure.Database;
namespace LiteCharms.Features.CartPackages.Commands.Handlers;
public class UpdatePackageCommandHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<UpdatePackageCommand, Result>
{
public async ValueTask<Result> Handle(UpdatePackageCommand request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
if (await context.Packages.AnyAsync(p => p.Name == request.Name, cancellationToken))
return Result.Fail($"A package by the same name already exists: {request.Name}");
var package = await context.Packages.FirstOrDefaultAsync(p => p.Id == request.PackageId, cancellationToken);
if (package is null)
return Result.Fail($"Could not find package by id {request.PackageId}");
package.Name = request.Name;
package.Description = request.Description;
return await context.SaveChangesAsync(cancellationToken) > 0
? Result.Ok()
: Result.Fail($"Failed to update package with id {request.PackageId}");
}
catch (Exception ex)
{
return Result.Fail(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -0,0 +1,29 @@
using LiteCharms.Infrastructure.Database;
namespace LiteCharms.Features.CartPackages.Commands.Handlers;
public class UpdatePackageStatusCommandHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<UpdatePackageStatusCommand, Result>
{
public async ValueTask<Result> Handle(UpdatePackageStatusCommand request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var package = await context.Packages.FirstOrDefaultAsync(p => p.Id == request.PackageId, cancellationToken);
if (package is null)
return Result.Fail($"Could not find package by id {request.PackageId}");
package.Active = request.Active;
return await context.SaveChangesAsync(cancellationToken) > 0
? Result.Ok()
: Result.Fail($"Failed to update package with id {request.PackageId}");
}
catch (Exception ex)
{
return Result.Fail(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -0,0 +1,28 @@
namespace LiteCharms.Features.CartPackages.Commands;
public class UpdatePackageCommand : IRequest<Result>
{
public Guid PackageId { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
private UpdatePackageCommand(Guid packageId, string? name, string? description)
{
PackageId = packageId;
Name = name;
Description = description;
}
public static UpdatePackageCommand Create(Guid packageId, string? name, string? description)
{
if (packageId == Guid.Empty)
throw new ArgumentException($"Package ID is required", nameof(packageId));
ArgumentNullException.ThrowIfNullOrWhiteSpace(name, nameof(name));
ArgumentNullException.ThrowIfNullOrWhiteSpace(description, nameof(description));
return new(packageId, name, description);
}
}
@@ -0,0 +1,22 @@
namespace LiteCharms.Features.CartPackages.Commands;
public class UpdatePackageStatusCommand : IRequest<Result>
{
public Guid PackageId { get; set; }
public bool Active { get; set; }
private UpdatePackageStatusCommand(Guid packageId, bool active)
{
PackageId = packageId;
Active = active;
}
public static UpdatePackageStatusCommand Create(Guid packageId, bool active)
{
if(packageId == Guid.Empty)
throw new ArgumentException($"Package id is required", nameof(packageId));
return new(packageId, active);
}
}
@@ -0,0 +1,18 @@
using LiteCharms.Models;
namespace LiteCharms.Features.CartPackages.Queries;
public class GetPackageItemsQuery : IRequest<Result<PackageItem[]>>
{
public Guid PackageId { get; set; }
private GetPackageItemsQuery(Guid packageId) => PackageId = packageId;
public static GetPackageItemsQuery Create(Guid packageId)
{
if (packageId == Guid.Empty)
throw new ArgumentException("Package ID is required", nameof(packageId));
return new(packageId);
}
}
@@ -0,0 +1,18 @@
using LiteCharms.Models;
namespace LiteCharms.Features.CartPackages.Queries;
public class GetPackageQuery : IRequest<Result<Package>>
{
public Guid PackageId { get; set; }
private GetPackageQuery(Guid packageId) => PackageId = packageId;
public static GetPackageQuery Create(Guid packageId)
{
if(packageId == Guid.Empty)
throw new ArgumentException("Package ID is required", nameof(packageId));
return new(packageId);
}
}
@@ -0,0 +1,33 @@
using LiteCharms.Models;
namespace LiteCharms.Features.CartPackages.Queries;
public class GetPackagesQuery : IRequest<Result<Package[]>>
{
public DateOnly From { get; set; }
public DateOnly To { get; set; }
public int MaxRecords { get; set; }
public bool Active { get; set; }
private GetPackagesQuery(DateOnly from, DateOnly to, int maxRecords = 1000, bool active = true)
{
From = from;
To = to;
MaxRecords = maxRecords;
Active = active;
}
public static GetPackagesQuery Create(DateOnly from, DateOnly to, int maxRecords = 1000, bool active = true)
{
if (from > to)
throw new ArgumentException("From date cannot be greater than To date.");
if (maxRecords <= 0)
throw new ArgumentException("MaxRecords must be a positive integer.");
return new(from, to, maxRecords, active);
}
}
@@ -0,0 +1,32 @@
using LiteCharms.Extensions;
using LiteCharms.Infrastructure.Database;
using LiteCharms.Models;
namespace LiteCharms.Features.CartPackages.Queries.Handlers;
public class GetPackageItemsQueryHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<GetPackageItemsQuery, Result<PackageItem[]>>
{
public async ValueTask<Result<PackageItem[]>> Handle(GetPackageItemsQuery request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
if (!await context.Packages.AnyAsync(p => p.Id == request.PackageId, cancellationToken))
return Result.Fail<PackageItem[]>($"Package could not be found with ID {request.PackageId}");
var items = await context.PackageItems.AsNoTracking()
.OrderByDescending(o => o.CreatedAt)
.Where(p => p.PackageId == request.PackageId)
.ToArrayAsync(cancellationToken);
return items?.Length > 0
? Result.Ok(items.Select(i => i.ToModel()).ToArray())
: Result.Fail<PackageItem[]>($"Could not find package items by package ID {request.PackageId}");
}
catch (Exception ex)
{
return Result.Fail<PackageItem[]>(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -0,0 +1,27 @@
using LiteCharms.Extensions;
using LiteCharms.Infrastructure.Database;
using LiteCharms.Models;
namespace LiteCharms.Features.CartPackages.Queries.Handlers;
public class GetPackageQueryHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<GetPackageQuery, Result<Package>>
{
public async ValueTask<Result<Package>> Handle(GetPackageQuery request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var package = await context.Packages.FirstOrDefaultAsync(p => p.Id == request.PackageId, cancellationToken);
return package is not null
? Result.Ok(package.ToModel())
: Result.Fail($"Failed to find package by ID {request.PackageId}");
}
catch (Exception ex)
{
return Result.Fail<Package>(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -0,0 +1,35 @@
using LiteCharms.Extensions;
using LiteCharms.Infrastructure.Database;
using LiteCharms.Models;
namespace LiteCharms.Features.CartPackages.Queries.Handlers;
public class GetPackagesQueryHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<GetPackagesQuery, Result<Package[]>>
{
public async ValueTask<Result<Package[]>> Handle(GetPackagesQuery request, CancellationToken cancellationToken)
{
try
{
var fromDate = request.From.ToDateTime(TimeOnly.MinValue);
var toDate = request.To.ToDateTime(TimeOnly.MaxValue);
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var packages = await context.Packages
.AsNoTracking()
.OrderByDescending(o => o.CreatedAt)
.Where(p => p.CreatedAt >= fromDate && p.CreatedAt <= toDate)
.Where(p => p.Active == request.Active)
.Take(request.MaxRecords)
.ToArrayAsync(cancellationToken);
return packages?.Length > 0
? Result.Ok(packages.Select(o => o.ToModel()).ToArray())
: Result.Fail<Package[]>(new Error($"No packages found for the specified date range {request.From} - {request.To}."));
}
catch (Exception ex)
{
return Result.Fail<Package[]>(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -1,6 +1,7 @@
using LiteCharms.Models.Configuraton.Email;
using LiteCharms.Features.Email.Commands;
using LiteCharms.Models.Configuraton.Email;
namespace LiteCharms.Features.Utilities.Commands.Handlers;
namespace LiteCharms.Features.Email.Commands.Handlers;
public class SendEmailCommandHandler(IOptions<SmtpSettings> smtpOptions) : IRequestHandler<SendEmailCommand, Result>
{
@@ -1,4 +1,4 @@
namespace LiteCharms.Features.Utilities.Commands;
namespace LiteCharms.Features.Email.Commands;
public class SendEmailCommand : IRequest<Result>
{
@@ -0,0 +1,18 @@
using LiteCharms.Features.Notifications.Commands;
using static LiteCharms.Abstractions.Constants;
namespace LiteCharms.Features.Email.Events.Handlers;
public class SendShopEmailEnquiryEventHandler(ISender mediator) :
INotificationHandler<SendShopEmailEnquiryEvent>
{
public async ValueTask Handle(SendShopEmailEnquiryEvent notification, CancellationToken cancellationToken)
{
var command = CreateNotificationCommand.Create(Models.NotificationDirection.Outgoing, notification.SenderName!,
notification.SenderAddress!, notification.Subject!, notification.Message!, Models.NotificationPlatforms.Email,
notification.Priority, ShopEmailFromName, ShopEmailFromAddress, Guid.CreateVersion7().ToString(),
Models.CorrelationIdTypes.None, isInternal: true, isHtml: false);
await mediator.Send(command, cancellationToken);
}
}
@@ -0,0 +1,40 @@
using LiteCharms.Abstractions;
using LiteCharms.Models;
namespace LiteCharms.Features.Email.Events;
public class SendShopEmailEnquiryEvent : EventBase, IEvent
{
public string Name { get; set; } = nameof(SendShopEmailEnquiryEvent);
public string? SenderName { get; set; }
public string? SenderAddress { get; set; }
public string? Subject { get; set; }
public string? Message { get; set; }
public Priorities Priority { get; set; }
public SendShopEmailEnquiryEvent() { }
private SendShopEmailEnquiryEvent(string senderName, string senderAddress, string subject, string message, Priorities priority = Priorities.Medium)
{
SenderName = senderName;
SenderAddress = senderAddress;
Subject = subject;
Message = message;
Priority = priority;
}
public static SendShopEmailEnquiryEvent Create(string senderName, string senderAddress, string subject, string message, Priorities priority = Priorities.Medium)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(senderName, nameof(senderName));
ArgumentNullException.ThrowIfNullOrWhiteSpace(senderAddress, nameof(senderAddress));
ArgumentNullException.ThrowIfNullOrWhiteSpace(subject, nameof(subject));
ArgumentNullException.ThrowIfNullOrWhiteSpace(message, nameof(message));
return new(senderName, senderAddress, subject, message, priority);
}
}
@@ -1,4 +1,4 @@
using LiteCharms.Features.Utilities.Commands;
using LiteCharms.Features.Utilities.Hash.Commands;
using LiteCharms.Infrastructure.Database;
namespace LiteCharms.Features.Leads.Commands.Handlers;
@@ -54,6 +54,7 @@
<Using Include="System.Security.Cryptography" />
<Using Include="Microsoft.EntityFrameworkCore" />
<Using Include="Microsoft.Extensions.Options" />
<Using Include="Microsoft.Extensions.Logging" />
</ItemGroup>
<ItemGroup>
@@ -6,55 +6,67 @@ public class CreateNotificationCommand : IRequest<Result<Guid>>
{
public NotificationDirection Direction { get; set; }
public string? Author { get; set; }
public string? Sender { get; set; }
public string? Title { get; set; }
public string? SenderAddress { get; set; }
public string? Description { get; set; }
public string? Subject { get; set; }
public string? Message { get; set; }
public NotificationPlatforms Platform { get; set; }
public string? PlatformAddress { get; set; }
public Priorities Priority { get; set; }
public string? Recipient { get; set; }
public string? RecipientAddress { get; set; }
public string? CorrelationId { get; set; }
public string? CorrelationIdType { get; set; }
public CorrelationIdTypes CorrelationIdType { get; set; }
public bool IsInternal { get; set; }
private CreateNotificationCommand(NotificationDirection direction, string author, string title, string description, NotificationPlatforms platform, string platformAddress, string correlationId, string correlationIdType, bool isInternal)
public bool IsHtml { get; set; }
private CreateNotificationCommand(NotificationDirection direction, string sender, string senderAddress, string subject, string message, NotificationPlatforms platform, Priorities priority, string recipient, string recipientAddress, string correlationId, CorrelationIdTypes correlationIdType, bool isInternal, bool isHtml = false)
{
Direction = direction;
Author = author;
Title = title;
Description = description;
Sender = sender;
SenderAddress = senderAddress;
Subject = subject;
Message = message;
Platform = platform;
PlatformAddress = platformAddress;
Priority = priority;
Recipient = recipient;
RecipientAddress = recipientAddress;
CorrelationId = correlationId;
CorrelationIdType = correlationIdType;
IsInternal = isInternal;
IsHtml = isHtml;
}
public static CreateNotificationCommand Create(NotificationDirection direction, string author, string title, string description, NotificationPlatforms platform, string platformAddress, string correlationId, string correlationIdType, bool isInternal)
public static CreateNotificationCommand Create(NotificationDirection direction, string sender, string senderAddress, string subject, string message, NotificationPlatforms platform, Priorities priority, string recipient, string recipientAddress, string correlationId, CorrelationIdTypes correlationIdType, bool isInternal, bool isHtml = false)
{
if (string.IsNullOrWhiteSpace(author))
throw new ArgumentException("Author cannot be null or whitespace.", nameof(author));
if (string.IsNullOrWhiteSpace(sender))
throw new ArgumentException("Sender name is required.", nameof(sender));
if (string.IsNullOrWhiteSpace(title))
throw new ArgumentException("Title cannot be null or whitespace.", nameof(title));
if (string.IsNullOrWhiteSpace(subject))
throw new ArgumentException("Subject is required.", nameof(subject));
if (string.IsNullOrWhiteSpace(description))
throw new ArgumentException("Description cannot be null or whitespace.", nameof(description));
if (string.IsNullOrWhiteSpace(message))
throw new ArgumentException("Message is required.", nameof(message));
if (string.IsNullOrWhiteSpace(platformAddress))
throw new ArgumentException("PlatformAddress cannot be null or whitespace.", nameof(platformAddress));
if (string.IsNullOrWhiteSpace(recipient))
throw new ArgumentException("Recipient name is required.", nameof(recipient));
if (string.IsNullOrWhiteSpace(recipientAddress))
throw new ArgumentException("Recipient address is required.", nameof(recipientAddress));
if (string.IsNullOrWhiteSpace(correlationId))
throw new ArgumentException("CorrelationId cannot be null or whitespace.", nameof(correlationId));
throw new ArgumentException("CorrelationId is required.", nameof(correlationId));
if (string.IsNullOrWhiteSpace(correlationIdType))
throw new ArgumentException("CorrelationIdType cannot be null or whitespace.", nameof(correlationIdType));
return new(direction, author, title, description, platform, platformAddress, correlationId, correlationIdType, isInternal);
return new(direction, sender, senderAddress, subject, message, platform, priority, recipient, recipientAddress, correlationId, correlationIdType, isInternal, isHtml);
}
}
@@ -6,29 +6,34 @@ public class CreateNotificationCommandHandler(IDbContextFactory<ShopDbContext> c
{
public async ValueTask<Result<Guid>> Handle(CreateNotificationCommand request, CancellationToken cancellationToken)
{
try
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var newNotification = context.Notifications.Add(new Entities.Notification
{
Direction = request.Direction,
Sender = request.Author,
Subject = request.Title,
Message = request.Description,
SenderName = request.Sender,
Sender = request.SenderAddress,
Recipient = request.Recipient,
RecipientAddress = request.RecipientAddress,
Subject = request.Subject,
Message = request.Message,
Platform = request.Platform,
Recipient = request.PlatformAddress,
Priority = request.Priority,
CorrelationId = request.CorrelationId,
CorrelationIdType = request.CorrelationIdType,
IsInternal = request.IsInternal,
IsHtml = request.IsHtml,
Processed = false
});
return newNotification is not null
? Result.Ok(newNotification.Entity.Id)
return newNotification is not null
? Result.Ok(newNotification.Entity.Id)
: Result.Fail(new Error("Failed to create notification"));
}
catch (Exception ex)
{
catch (Exception ex)
{
return Result.Fail(new Error(ex.Message).CausedBy(ex));
}
}
@@ -17,6 +17,12 @@ public class UpdateNotificationCommandHandler(IDbContextFactory<ShopDbContext> c
notification.Processed = request.Processed;
if (request.HasError)
{
notification.HasError = request.HasError;
notification.Errors = request.Errors;
}
return await context.SaveChangesAsync(cancellationToken) > 0
? Result.Ok()
: Result.Fail(new Error($"Failed to update notification with id {request.NotificationId}."));
@@ -6,13 +6,19 @@ public class UpdateNotificationCommand : IRequest<Result>
public bool Processed { get; set; }
private UpdateNotificationCommand(Guid notificationId, bool processed)
public bool HasError { get; set; }
public string[]? Errors { get; set; }
private UpdateNotificationCommand(Guid notificationId, bool processed, bool hasError = false, string[]? errors = null)
{
NotificationId = notificationId;
Processed = processed;
HasError = hasError;
Errors = errors;
}
public static UpdateNotificationCommand Create(Guid notificationId, bool processed)
public static UpdateNotificationCommand Create(Guid notificationId, bool processed, bool hasError = false, string[]? errors = null)
{
if(notificationId == Guid.Empty)
throw new ArgumentException("Notification ID cannot be empty.", nameof(notificationId));
@@ -0,0 +1,70 @@
using LiteCharms.Features.Email.Commands;
using LiteCharms.Infrastructure.Database;
using static LiteCharms.Abstractions.Constants;
namespace LiteCharms.Features.Notifications.Events.Handlers;
public class ProcessEmailNotificationsEventHandler(IDbContextFactory<ShopDbContext> contextFactory, ILogger<ProcessEmailNotificationsEvent> logger, ISender mediator) :
INotificationHandler<ProcessEmailNotificationsEvent>
{
public async ValueTask Handle(ProcessEmailNotificationsEvent message, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var notifications = await context.Notifications
.OrderByDescending(o => o.Priority)
.ThenBy(o => o.CreatedAt)
.Where(n => n.CorrelationIdType == Models.CorrelationIdTypes.Email)
.Where(n => n.Direction == Models.NotificationDirection.Outgoing)
.Take(message.MaxRecords)
.ToListAsync(cancellationToken);
foreach (var notification in notifications)
{
var sendResult = await SendEmailAsync(notification, cancellationToken);
if(sendResult.IsFailed)
{
var errors = new List<string>(1000);
errors.AddRange(sendResult.Errors.Select(e => e.Message));
if (sendResult.Reasons?.Count > 0)
errors.AddRange(sendResult.Reasons.Select(e => e.Message));
notification.HasError = true;
notification.Errors = [.. errors];
}
notification.Processed = true;
}
await context.SaveChangesAsync(cancellationToken);
}
catch (Exception ex)
{
logger.LogError(ex, ex.Message);
}
}
private async Task<Result> SendEmailAsync(Entities.Notification notification, CancellationToken cancellationToken = default)
{
try
{
var request = SendEmailCommand.Create(notification.Sender!, notification.SenderName!, ShopEmailFromAddress,
ShopEmailFromName, notification.Subject!, notification.Message!);
var result = await mediator.Send(request, cancellationToken);
return result.IsFailed
? Result.Fail(result.Errors)
: Result.Ok();
}
catch (Exception ex)
{
return Result.Fail(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -0,0 +1,14 @@
using LiteCharms.Abstractions;
namespace LiteCharms.Features.Notifications.Events;
public class ProcessEmailNotificationsEvent : EventBase, IEvent
{
public string Name { get; set; } = nameof(ProcessEmailNotificationsEvent);
public int MaxRecords { get; set; }
private ProcessEmailNotificationsEvent(int maxRecords = 1000) => MaxRecords = maxRecords;
public static ProcessEmailNotificationsEvent Create(int maxRecords = 1000) => new(maxRecords);
}
@@ -12,7 +12,7 @@ public class GetNotificationQueryHandler(IDbContextFactory<ShopDbContext> contex
{
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var notification = await context.Notifications.FindAsync(new object[] { request.NotificationId }, cancellationToken);
var notification = await context.Notifications.FirstOrDefaultAsync(n => n.Id == request.NotificationId, cancellationToken);
return notification is not null
? Result.Ok(notification.ToModel())
@@ -8,14 +8,26 @@ public class CreateOrderCommand : IRequest<Result<Guid>>
public Guid? QuoteId { get; set; }
private CreateOrderCommand(Guid customerId, Guid shoppingCartId, Guid? quoteId = null)
public string[]? Requirements { get; set; }
public string[]? Notes { get; set; }
public string[]? Terms { get; set; }
public bool DepositRequired { get; set; }
private CreateOrderCommand(Guid customerId, Guid shoppingCartId, bool depositRequired, Guid? quoteId = null, string[]? requirements = null, string[]? notes = null, string[]? terms = null)
{
CustomerId = customerId;
ShoppingCartId = shoppingCartId;
DepositRequired = depositRequired;
QuoteId = quoteId;
Requirements = requirements;
Notes = notes;
Terms = terms;
}
public static CreateOrderCommand Create(Guid customerId, Guid shoppingCartId, Guid? quoteId = null)
public static CreateOrderCommand Create(Guid customerId, Guid shoppingCartId, bool depositRequired, Guid? quoteId = null, string[]? requirements = null, string[]? notes = null, string[]? terms = null)
{
if (customerId == Guid.Empty)
throw new ArgumentException("CustomerId is required.", nameof(customerId));
@@ -23,6 +35,6 @@ public class CreateOrderCommand : IRequest<Result<Guid>>
if (shoppingCartId == Guid.Empty)
throw new ArgumentException("ShoppingCartId is required.", nameof(shoppingCartId));
return new(customerId, shoppingCartId, quoteId);
return new(customerId, shoppingCartId, depositRequired, quoteId, requirements, notes, terms);
}
}
@@ -1,4 +1,5 @@
using LiteCharms.Infrastructure.Database;
using LiteCharms.Models;
namespace LiteCharms.Features.Orders.Commands.Handlers;
@@ -21,10 +22,15 @@ public class CreateOrderCommandHandler(IDbContextFactory<ShopDbContext> contextF
var newOrder = context.Orders.Add(new Entities.Order
{
CreatedAt = DateTime.UtcNow,
Status = OrderStatus.Pending,
CustomerId = request.CustomerId,
ShoppingCartId = request.ShoppingCartId,
QuoteId = request.QuoteId,
CreatedAt = DateTime.UtcNow
ShoppingCartId = request.ShoppingCartId,
DepositRequired = request.DepositRequired,
Requirements = request.Requirements,
Notes = request.Notes,
Terms = request.Terms
});
return await context.SaveChangesAsync(cancellationToken) > 0
@@ -16,6 +16,7 @@ public class GetOrdersQueryHandler(IDbContextFactory<ShopDbContext> contextFacto
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var orders = await context.Orders
.AsNoTracking()
.OrderByDescending(o => o.CreatedAt)
.Where(o => o.CreatedAt >= fromDate && o.CreatedAt <= toDate)
.Take(request.MaxRecords)
@@ -0,0 +1,25 @@
namespace LiteCharms.Features.ShoppingCarts.Commands;
public class AddPackageToShoppingCartCommand : IRequest<Result>
{
public Guid ShoppingCartId { get; set; }
public Guid PackageId { get; set; }
private AddPackageToShoppingCartCommand(Guid shoppingCartId, Guid packageId)
{
ShoppingCartId = shoppingCartId;
PackageId = packageId;
}
public static AddPackageToShoppingCartCommand Create(Guid shoppingCartId, Guid packageId)
{
if (shoppingCartId == Guid.Empty)
throw new ArgumentException($"Shopping cart ID is required", nameof(shoppingCartId));
if (packageId == Guid.Empty)
throw new ArgumentException($"Package ID is required", nameof(packageId));
return new(shoppingCartId, packageId);
}
}
@@ -0,0 +1,39 @@
using LiteCharms.Infrastructure.Database;
namespace LiteCharms.Features.ShoppingCarts.Commands.Handlers;
public class AddPackageToShoppingCartCommandHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<AddPackageToShoppingCartCommand, Result>
{
public async ValueTask<Result> Handle(AddPackageToShoppingCartCommand request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
if (!await context.Packages.AnyAsync(p => p.Id == request.PackageId, cancellationToken))
return Result.Fail($"Package cold not be found by ID {request.PackageId}");
var shoppingCart = await context.ShoppingCarts.FirstOrDefaultAsync(c => c.Id == request.ShoppingCartId, cancellationToken);
if (shoppingCart is null)
return Result.Fail($"Shopping cart could not be found by ID {request.ShoppingCartId}");
if (!await context.ShoppingCartPackages.AnyAsync(cp => cp.ShoppingCartId == request.ShoppingCartId, cancellationToken))
return Result.Fail($"Package {request.PackageId} is already in the cart");
var newShoppingCartPackage = context.ShoppingCartPackages.Add(new Entities.ShoppingCartPackage
{
ShoppingCartId = request.ShoppingCartId,
PackageId = request.PackageId
});
return await context.SaveChangesAsync(cancellationToken) > 0
? Result.Ok()
: Result.Fail($"Could not add package of id {request.PackageId} to shopping cart {request.ShoppingCartId}");
}
catch (Exception ex)
{
return Result.Fail(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -0,0 +1,35 @@
using LiteCharms.Infrastructure.Database;
namespace LiteCharms.Features.ShoppingCarts.Commands.Handlers;
public class RemovePackageFromShoppingCartCommandHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<RemovePackageFromShoppingCartCommand, Result>
{
public async ValueTask<Result> Handle(RemovePackageFromShoppingCartCommand request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
if (!await context.ShoppingCarts.AnyAsync(c => c.Id == request.ShoppingCartId, cancellationToken))
return Result.Fail($"Shopping cart could not be found by ID {request.ShoppingCartId}");
if (!await context.ShoppingCartPackages.AnyAsync(p => p.Id == request.ShoppingCartPackageId, cancellationToken))
return Result.Fail($"Shopping cart package {request.ShoppingCartPackageId} is not in the shopping cart {request.ShoppingCartId}");
var shoppingCartPackage = await context.ShoppingCartPackages.FirstOrDefaultAsync(cp => cp.Id == request.ShoppingCartPackageId, cancellationToken);
if (shoppingCartPackage is null)
return Result.Ok();
context.ShoppingCartPackages.Remove(shoppingCartPackage!);
return await context.SaveChangesAsync(cancellationToken) > 0
? Result.Ok()
: Result.Fail($"Could remove package of id {request.ShoppingCartPackageId} from shopping cart {request.ShoppingCartId}");
}
catch (Exception ex)
{
return Result.Fail(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -0,0 +1,25 @@
namespace LiteCharms.Features.ShoppingCarts.Commands;
public class RemovePackageFromShoppingCartCommand : IRequest<Result>
{
public Guid ShoppingCartId { get; set; }
public Guid ShoppingCartPackageId { get; set; }
private RemovePackageFromShoppingCartCommand(Guid shoppingCartId, Guid shoppingCartPackageId)
{
ShoppingCartId = shoppingCartId;
ShoppingCartPackageId = shoppingCartPackageId;
}
public static RemovePackageFromShoppingCartCommand Create(Guid shoppingCartId, Guid shoppingCartPackageId)
{
if (shoppingCartId == Guid.Empty)
throw new ArgumentException($"Shopping cart ID is required", nameof(shoppingCartId));
if (shoppingCartPackageId == Guid.Empty)
throw new ArgumentException($"Shopping cart Package ID is required", nameof(shoppingCartPackageId));
return new(shoppingCartId, shoppingCartPackageId);
}
}
@@ -0,0 +1,18 @@
using LiteCharms.Models;
namespace LiteCharms.Features.ShoppingCarts.Queries;
public class GetShoppingCartPackagesQuery : IRequest<Result<ShoppingCartPackage[]>>
{
public Guid ShoppingCartId { get; set; }
private GetShoppingCartPackagesQuery(Guid shoppingCartId) => ShoppingCartId = shoppingCartId;
public static GetShoppingCartPackagesQuery Create(Guid shoppingCartId)
{
if (shoppingCartId == Guid.Empty)
throw new ArgumentException("Shopping cart id is required", nameof(shoppingCartId));
return new(shoppingCartId);
}
}
@@ -0,0 +1,32 @@
using LiteCharms.Extensions;
using LiteCharms.Infrastructure.Database;
using LiteCharms.Models;
namespace LiteCharms.Features.ShoppingCarts.Queries.Handlers;
public class GetShoppingCartPackagesQueryHandler(IDbContextFactory<ShopDbContext> contextFactory) : IRequestHandler<GetShoppingCartPackagesQuery, Result<ShoppingCartPackage[]>>
{
public async ValueTask<Result<ShoppingCartPackage[]>> Handle(GetShoppingCartPackagesQuery request, CancellationToken cancellationToken)
{
try
{
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
if (!await context.ShoppingCarts.AnyAsync(c => c.Id == request.ShoppingCartId, cancellationToken))
return Result.Fail($"Shopping cart could not be found by ID {request.ShoppingCartId}");
var packages = await context.ShoppingCartPackages.AsNoTracking()
.OrderByDescending(o => o.CreatedAt)
.Where(cp => cp.ShoppingCartId == request.ShoppingCartId)
.ToArrayAsync(cancellationToken);
return packages?.Length > 0
? Result.Ok(packages.Select(p => p.ToModel()).ToArray())
: Result.Fail($"Could not find packaged in shopping cart by ID {request.ShoppingCartId}");
}
catch (Exception ex)
{
return Result.Fail<ShoppingCartPackage[]>(new Error(ex.Message).CausedBy(ex));
}
}
}
@@ -1,4 +1,4 @@
namespace LiteCharms.Features.Utilities.Commands;
namespace LiteCharms.Features.Utilities.Hash.Commands;
public class ComputeHashCommand : IRequest<Result<string>>
{
@@ -1,4 +1,6 @@
namespace LiteCharms.Features.Utilities.Commands.Handlers;
using LiteCharms.Features.Utilities.Hash.Commands;
namespace LiteCharms.Features.Utilities.Hash.Commands.Handlers;
public class ComputeHashCommandHandler : IRequestHandler<ComputeHashCommand, Result<string>>
{
@@ -1,631 +0,0 @@
// <auto-generated />
using System;
using LiteCharms.Infrastructure.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace LiteCharms.Infrastructure.Database.Migrations
{
[DbContext(typeof(ShopDbContext))]
[Migration("20260510090446_Init")]
partial class Init
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("LiteCharms.Entities.Customer", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("Active")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(true);
b.Property<string>("Address")
.HasColumnType("text");
b.Property<string>("City")
.HasColumnType("text");
b.Property<string>("Company")
.HasColumnType("text");
b.Property<string>("Country")
.HasColumnType("text");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone");
b.Property<string>("Discord")
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("LinkedIn")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Phone")
.HasColumnType("text");
b.Property<string>("PostalCode")
.HasColumnType("text");
b.Property<string>("Region")
.HasColumnType("text");
b.Property<string>("Slack")
.HasColumnType("text");
b.Property<string>("Tax")
.HasColumnType("text");
b.Property<DateTimeOffset?>("UpdatedAt")
.ValueGeneratedOnUpdate()
.HasColumnType("timestamp with time zone");
b.Property<string>("Website")
.HasColumnType("text");
b.Property<string>("Whatsapp")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Customer", (string)null);
});
modelBuilder.Entity("LiteCharms.Entities.Lead", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<long?>("AdGroupId")
.HasColumnType("bigint");
b.Property<long?>("AdName")
.HasColumnType("bigint");
b.Property<string>("AppClickId")
.HasColumnType("text");
b.Property<string>("AttributionHash")
.IsRequired()
.HasColumnType("text");
b.Property<long?>("CampaignId")
.HasColumnType("bigint");
b.Property<string>("ClickId")
.HasColumnType("text");
b.Property<string>("ClickLocation")
.HasColumnType("text");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("CustomerId")
.HasColumnType("uuid");
b.Property<long?>("FeedItemId")
.HasColumnType("bigint");
b.Property<string>("Source")
.HasColumnType("text");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<long?>("TargetId")
.HasColumnType("bigint");
b.Property<DateTimeOffset?>("UpdatedAt")
.ValueGeneratedOnUpdate()
.HasColumnType("timestamp with time zone");
b.Property<string>("WebClickId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.ToTable("Lead", (string)null);
});
modelBuilder.Entity("LiteCharms.Entities.Notification", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("CorrelationId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("CorrelationIdType")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone");
b.Property<int>("Direction")
.HasColumnType("integer");
b.Property<bool>("IsHtml")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false);
b.Property<bool>("IsInternal")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(true);
b.Property<string>("Message")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Platform")
.HasColumnType("integer");
b.Property<int>("Priority")
.HasColumnType("integer");
b.Property<bool>("Processed")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false);
b.Property<string>("Recipient")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecipientAddress")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Sender")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SenderName")
.HasColumnType("text");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset?>("UpdatedAt")
.ValueGeneratedOnUpdate()
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Notification", (string)null);
});
modelBuilder.Entity("LiteCharms.Entities.Order", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone");
b.Property<Guid>("CustomerId")
.HasColumnType("uuid");
b.Property<bool>("DepositRequired")
.HasColumnType("boolean");
b.PrimitiveCollection<string>("Notes")
.HasColumnType("jsonb");
b.Property<Guid?>("QuoteId")
.HasColumnType("uuid");
b.Property<Guid?>("RefundId")
.HasColumnType("uuid");
b.PrimitiveCollection<string>("Requirements")
.HasColumnType("jsonb");
b.Property<Guid>("ShoppingCartId")
.HasColumnType("uuid");
b.Property<int>("Status")
.HasColumnType("integer");
b.PrimitiveCollection<string>("Terms")
.HasColumnType("jsonb");
b.Property<DateTimeOffset?>("UpdatedAt")
.ValueGeneratedOnUpdate()
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("QuoteId")
.IsUnique();
b.HasIndex("ShoppingCartId")
.IsUnique();
b.ToTable("Order", (string)null);
});
modelBuilder.Entity("LiteCharms.Entities.OrderRefund", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<decimal>("Amount")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone");
b.Property<Guid>("OrderId")
.HasColumnType("uuid");
b.Property<string>("Reason")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("OrderId")
.IsUnique();
b.ToTable("OrderRefund", (string)null);
});
modelBuilder.Entity("LiteCharms.Entities.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("Active")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(true);
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Product", (string)null);
});
modelBuilder.Entity("LiteCharms.Entities.ProductPrice", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("Active")
.HasColumnType("boolean");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone");
b.Property<decimal>("Discount")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)");
b.Property<decimal>("Price")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("UpdatedAt")
.ValueGeneratedOnUpdate()
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("ProductPrice", (string)null);
});
modelBuilder.Entity("LiteCharms.Entities.Quote", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone");
b.Property<Guid>("CustomerId")
.HasColumnType("uuid");
b.Property<Guid?>("CustomerId1")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("ExpiredAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Reason")
.HasColumnType("text");
b.Property<Guid>("ShoppingCartId")
.HasColumnType("uuid");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<DateTimeOffset?>("UpdatedAt")
.ValueGeneratedOnUpdate()
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("CustomerId1");
b.HasIndex("ShoppingCartId")
.IsUnique();
b.ToTable("Quote", (string)null);
});
modelBuilder.Entity("LiteCharms.Entities.ShoppingCart", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("CustomerId")
.HasColumnType("uuid");
b.Property<Guid?>("OrderId")
.HasColumnType("uuid");
b.Property<Guid?>("QuoteId")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("UpdatedAt")
.ValueGeneratedOnUpdate()
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.ToTable("ShoppingCart", (string)null);
});
modelBuilder.Entity("LiteCharms.Entities.ShoppingCartItem", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("ProductPriceId")
.HasColumnType("uuid");
b.Property<int>("Quantity")
.HasColumnType("integer");
b.Property<Guid>("ShoppingCartId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("ProductPriceId");
b.HasIndex("ShoppingCartId");
b.ToTable("ShoppingCartItems");
});
modelBuilder.Entity("LiteCharms.Entities.Lead", b =>
{
b.HasOne("LiteCharms.Entities.Customer", "Customer")
.WithMany("Leads")
.HasForeignKey("CustomerId")
.OnDelete(DeleteBehavior.NoAction);
b.Navigation("Customer");
});
modelBuilder.Entity("LiteCharms.Entities.Order", b =>
{
b.HasOne("LiteCharms.Entities.Customer", "Customer")
.WithMany("Orders")
.HasForeignKey("CustomerId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("LiteCharms.Entities.Quote", "Quote")
.WithOne("Order")
.HasForeignKey("LiteCharms.Entities.Order", "QuoteId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("LiteCharms.Entities.ShoppingCart", "ShoppingCart")
.WithOne("Order")
.HasForeignKey("LiteCharms.Entities.Order", "ShoppingCartId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Customer");
b.Navigation("Quote");
b.Navigation("ShoppingCart");
});
modelBuilder.Entity("LiteCharms.Entities.OrderRefund", b =>
{
b.HasOne("LiteCharms.Entities.Order", "Order")
.WithOne("Refund")
.HasForeignKey("LiteCharms.Entities.OrderRefund", "OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
});
modelBuilder.Entity("LiteCharms.Entities.ProductPrice", b =>
{
b.HasOne("LiteCharms.Entities.Product", "Product")
.WithMany("ProductPrices")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Product");
});
modelBuilder.Entity("LiteCharms.Entities.Quote", b =>
{
b.HasOne("LiteCharms.Entities.Customer", "Customer")
.WithMany()
.HasForeignKey("CustomerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LiteCharms.Entities.Customer", null)
.WithMany("Quotes")
.HasForeignKey("CustomerId1");
b.HasOne("LiteCharms.Entities.ShoppingCart", "ShoppingCart")
.WithOne("Quote")
.HasForeignKey("LiteCharms.Entities.Quote", "ShoppingCartId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Customer");
b.Navigation("ShoppingCart");
});
modelBuilder.Entity("LiteCharms.Entities.ShoppingCart", b =>
{
b.HasOne("LiteCharms.Entities.Customer", "Customer")
.WithMany("ShoppingCarts")
.HasForeignKey("CustomerId")
.OnDelete(DeleteBehavior.NoAction);
b.Navigation("Customer");
});
modelBuilder.Entity("LiteCharms.Entities.ShoppingCartItem", b =>
{
b.HasOne("LiteCharms.Entities.ProductPrice", "ProductPrice")
.WithMany()
.HasForeignKey("ProductPriceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LiteCharms.Entities.ShoppingCart", "ShoppingCart")
.WithMany("ShoppingCartItems")
.HasForeignKey("ShoppingCartId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("ProductPrice");
b.Navigation("ShoppingCart");
});
modelBuilder.Entity("LiteCharms.Entities.Customer", b =>
{
b.Navigation("Leads");
b.Navigation("Orders");
b.Navigation("Quotes");
b.Navigation("ShoppingCarts");
});
modelBuilder.Entity("LiteCharms.Entities.Order", b =>
{
b.Navigation("Refund");
});
modelBuilder.Entity("LiteCharms.Entities.Product", b =>
{
b.Navigation("ProductPrices");
});
modelBuilder.Entity("LiteCharms.Entities.Quote", b =>
{
b.Navigation("Order");
});
modelBuilder.Entity("LiteCharms.Entities.ShoppingCart", b =>
{
b.Navigation("Order");
b.Navigation("Quote");
b.Navigation("ShoppingCartItems");
});
#pragma warning restore 612, 618
}
}
}
@@ -1,114 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LiteCharms.Infrastructure.Database.Migrations
{
/// <inheritdoc />
public partial class AddedPackages : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Package",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
Name = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: false),
Active = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Package", x => x.Id);
});
migrationBuilder.CreateTable(
name: "PackageItem",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
PackageId1 = table.Column<Guid>(type: "uuid", nullable: true),
PackageId = table.Column<Guid>(type: "uuid", nullable: false),
ProductPriceId = table.Column<Guid>(type: "uuid", nullable: false),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Active = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PackageItem", x => x.Id);
table.ForeignKey(
name: "FK_PackageItem_Package_PackageId",
column: x => x.PackageId,
principalTable: "Package",
principalColumn: "Id");
table.ForeignKey(
name: "FK_PackageItem_Package_PackageId1",
column: x => x.PackageId1,
principalTable: "Package",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "ShoppingCartPackage",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
ShoppingCartId = table.Column<Guid>(type: "uuid", nullable: false),
PackageId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ShoppingCartPackage", x => x.Id);
table.ForeignKey(
name: "FK_ShoppingCartPackage_Package_PackageId",
column: x => x.PackageId,
principalTable: "Package",
principalColumn: "Id");
table.ForeignKey(
name: "FK_ShoppingCartPackage_ShoppingCart_ShoppingCartId",
column: x => x.ShoppingCartId,
principalTable: "ShoppingCart",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_PackageItem_PackageId",
table: "PackageItem",
column: "PackageId");
migrationBuilder.CreateIndex(
name: "IX_PackageItem_PackageId1",
table: "PackageItem",
column: "PackageId1");
migrationBuilder.CreateIndex(
name: "IX_ShoppingCartPackage_PackageId",
table: "ShoppingCartPackage",
column: "PackageId");
migrationBuilder.CreateIndex(
name: "IX_ShoppingCartPackage_ShoppingCartId",
table: "ShoppingCartPackage",
column: "ShoppingCartId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PackageItem");
migrationBuilder.DropTable(
name: "ShoppingCartPackage");
migrationBuilder.DropTable(
name: "Package");
}
}
}
@@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace LiteCharms.Infrastructure.Database.Migrations
{
[DbContext(typeof(ShopDbContext))]
[Migration("20260510091540_AddedPackages")]
partial class AddedPackages
[Migration("20260510132008_Init")]
partial class Init
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -171,9 +171,8 @@ namespace LiteCharms.Infrastructure.Database.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<string>("CorrelationIdType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("CorrelationIdType")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
@@ -182,6 +181,14 @@ namespace LiteCharms.Infrastructure.Database.Migrations
b.Property<int>("Direction")
.HasColumnType("integer");
b.PrimitiveCollection<string>("Errors")
.HasColumnType("jsonb");
b.Property<bool>("HasError")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false);
b.Property<bool>("IsHtml")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
@@ -339,12 +346,17 @@ namespace LiteCharms.Infrastructure.Database.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("ShoppingCartId")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("UpdatedAt")
.ValueGeneratedOnUpdate()
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("ShoppingCartId");
b.ToTable("Package", (string)null);
});
@@ -614,6 +626,13 @@ namespace LiteCharms.Infrastructure.Database.Migrations
b.Navigation("Order");
});
modelBuilder.Entity("LiteCharms.Entities.Package", b =>
{
b.HasOne("LiteCharms.Entities.ShoppingCart", null)
.WithMany("Packages")
.HasForeignKey("ShoppingCartId");
});
modelBuilder.Entity("LiteCharms.Entities.PackageItem", b =>
{
b.HasOne("LiteCharms.Entities.Package", "Package")
@@ -746,6 +765,8 @@ namespace LiteCharms.Infrastructure.Database.Migrations
{
b.Navigation("Order");
b.Navigation("Packages");
b.Navigation("Quote");
b.Navigation("ShoppingCartItems");
@@ -51,6 +51,7 @@ namespace LiteCharms.Infrastructure.Database.Migrations
Direction = table.Column<int>(type: "integer", nullable: false),
Platform = table.Column<int>(type: "integer", nullable: false),
Priority = table.Column<int>(type: "integer", nullable: false),
CorrelationIdType = table.Column<int>(type: "integer", nullable: false),
Sender = table.Column<string>(type: "text", nullable: false),
SenderName = table.Column<string>(type: "text", nullable: true),
Subject = table.Column<string>(type: "text", nullable: false),
@@ -58,10 +59,11 @@ namespace LiteCharms.Infrastructure.Database.Migrations
Recipient = table.Column<string>(type: "text", nullable: false),
RecipientAddress = table.Column<string>(type: "text", nullable: false),
CorrelationId = table.Column<string>(type: "text", nullable: false),
CorrelationIdType = table.Column<string>(type: "text", nullable: false),
IsHtml = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
IsInternal = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
Processed = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false)
Processed = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
HasError = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
Errors = table.Column<string>(type: "jsonb", nullable: true)
},
constraints: table =>
{
@@ -157,6 +159,28 @@ namespace LiteCharms.Infrastructure.Database.Migrations
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Package",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
ShoppingCartId = table.Column<Guid>(type: "uuid", nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
Name = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: false),
Active = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Package", x => x.Id);
table.ForeignKey(
name: "FK_Package_ShoppingCart_ShoppingCartId",
column: x => x.ShoppingCartId,
principalTable: "ShoppingCart",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Quote",
columns: table => new
@@ -220,6 +244,56 @@ namespace LiteCharms.Infrastructure.Database.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PackageItem",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
PackageId1 = table.Column<Guid>(type: "uuid", nullable: true),
PackageId = table.Column<Guid>(type: "uuid", nullable: false),
ProductPriceId = table.Column<Guid>(type: "uuid", nullable: false),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Active = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PackageItem", x => x.Id);
table.ForeignKey(
name: "FK_PackageItem_Package_PackageId",
column: x => x.PackageId,
principalTable: "Package",
principalColumn: "Id");
table.ForeignKey(
name: "FK_PackageItem_Package_PackageId1",
column: x => x.PackageId1,
principalTable: "Package",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "ShoppingCartPackage",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
ShoppingCartId = table.Column<Guid>(type: "uuid", nullable: false),
PackageId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ShoppingCartPackage", x => x.Id);
table.ForeignKey(
name: "FK_ShoppingCartPackage_Package_PackageId",
column: x => x.PackageId,
principalTable: "Package",
principalColumn: "Id");
table.ForeignKey(
name: "FK_ShoppingCartPackage_ShoppingCart_ShoppingCartId",
column: x => x.ShoppingCartId,
principalTable: "ShoppingCart",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Order",
columns: table => new
@@ -308,6 +382,21 @@ namespace LiteCharms.Infrastructure.Database.Migrations
column: "OrderId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Package_ShoppingCartId",
table: "Package",
column: "ShoppingCartId");
migrationBuilder.CreateIndex(
name: "IX_PackageItem_PackageId",
table: "PackageItem",
column: "PackageId");
migrationBuilder.CreateIndex(
name: "IX_PackageItem_PackageId1",
table: "PackageItem",
column: "PackageId1");
migrationBuilder.CreateIndex(
name: "IX_ProductPrice_ProductId",
table: "ProductPrice",
@@ -343,6 +432,16 @@ namespace LiteCharms.Infrastructure.Database.Migrations
name: "IX_ShoppingCartItems_ShoppingCartId",
table: "ShoppingCartItems",
column: "ShoppingCartId");
migrationBuilder.CreateIndex(
name: "IX_ShoppingCartPackage_PackageId",
table: "ShoppingCartPackage",
column: "PackageId");
migrationBuilder.CreateIndex(
name: "IX_ShoppingCartPackage_ShoppingCartId",
table: "ShoppingCartPackage",
column: "ShoppingCartId");
}
/// <inheritdoc />
@@ -357,15 +456,24 @@ namespace LiteCharms.Infrastructure.Database.Migrations
migrationBuilder.DropTable(
name: "OrderRefund");
migrationBuilder.DropTable(
name: "PackageItem");
migrationBuilder.DropTable(
name: "ShoppingCartItems");
migrationBuilder.DropTable(
name: "ShoppingCartPackage");
migrationBuilder.DropTable(
name: "Order");
migrationBuilder.DropTable(
name: "ProductPrice");
migrationBuilder.DropTable(
name: "Package");
migrationBuilder.DropTable(
name: "Quote");
@@ -168,9 +168,8 @@ namespace LiteCharms.Infrastructure.Database.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<string>("CorrelationIdType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("CorrelationIdType")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
@@ -179,6 +178,14 @@ namespace LiteCharms.Infrastructure.Database.Migrations
b.Property<int>("Direction")
.HasColumnType("integer");
b.PrimitiveCollection<string>("Errors")
.HasColumnType("jsonb");
b.Property<bool>("HasError")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false);
b.Property<bool>("IsHtml")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
@@ -336,12 +343,17 @@ namespace LiteCharms.Infrastructure.Database.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("ShoppingCartId")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("UpdatedAt")
.ValueGeneratedOnUpdate()
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("ShoppingCartId");
b.ToTable("Package", (string)null);
});
@@ -611,6 +623,13 @@ namespace LiteCharms.Infrastructure.Database.Migrations
b.Navigation("Order");
});
modelBuilder.Entity("LiteCharms.Entities.Package", b =>
{
b.HasOne("LiteCharms.Entities.ShoppingCart", null)
.WithMany("Packages")
.HasForeignKey("ShoppingCartId");
});
modelBuilder.Entity("LiteCharms.Entities.PackageItem", b =>
{
b.HasOne("LiteCharms.Entities.Package", "Package")
@@ -743,6 +762,8 @@ namespace LiteCharms.Infrastructure.Database.Migrations
{
b.Navigation("Order");
b.Navigation("Packages");
b.Navigation("Quote");
b.Navigation("ShoppingCartItems");
@@ -89,10 +89,11 @@
<ProjectReference Include="..\LiteCharms.Models\LiteCharms.Models.csproj" />
</ItemGroup>
<!-- Global Usings -->
<!-- Global Shared Usings -->
<ItemGroup>
<Using Include="System.Text.Json" />
<Using Include="Microsoft.Extensions.Hosting" />
<Using Include="Microsoft.Extensions.Logging" />
</ItemGroup>
<ItemGroup>
@@ -35,7 +35,7 @@ public class JobOrchestrator(ISchedulerFactory schedulerFactory) : IJobOrchestra
var chainedJobGroup = "scheduled-jobs";
var scheduler = await schedulerFactory.GetScheduler(cancellationToken);
var jobKey = new JobKey($"{notification.Name.ToLower()}-{notification.CorrelationId.ToLower()}", chainedJobGroup);
var jobKey = new JobKey($"{notification.Name.ToLower()}", chainedJobGroup);
var triggerKey = new TriggerKey($"{jobKey.Name}-trigger", chainedJobGroup);
var job = JobBuilder.Create<MediatorJob<TNotification>>()
@@ -2,11 +2,36 @@
namespace LiteCharms.Infrastructure.ServiceBus.Exchanges;
public class EmailExchange(EmailQueue messages) : BackgroundService
public class EmailExchange(EmailQueue messages, ILogger<EmailExchange> logger, IPublisher mediator) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
if(messages.Incoming.CanCount)
while (!stoppingToken.IsCancellationRequested)
{
while (messages.Incoming.TryRead(out var message))
{
try
{
switch (message.Name)
{
case "SendShopEmailEnquiryEvent":
await mediator.Publish(message, stoppingToken);
break;
case "ProcessEmailNotificationsEvent":
await mediator.Publish(message, stoppingToken);
break;
default:
logger.LogWarning("Unsupported email event {Event}", message.Name);
break;
}
}
catch (Exception ex)
{
logger.LogError(ex, ex.Message);
}
}
await Task.Delay(1000, stoppingToken);
}
}
}
+15
View File
@@ -1,5 +1,20 @@
namespace LiteCharms.Models;
public enum CorrelationIdTypes : int
{
None = 0,
Email = 1,
Discord = 2,
Slack = 3,
Whatsapp = 4,
Customer = 5,
Order = 6,
Refund = 7,
Lead = 8,
Quote = 9,
LinkedIn = 10
}
public enum Priorities : int
{
Low = 0,
+6 -2
View File
@@ -14,6 +14,8 @@ public class Notification
public Priorities Priority { get; set; }
public CorrelationIdTypes CorrelationIdType { get; set; }
public string? Sender { get; set; }
public string? SenderName { get; set; }
@@ -28,11 +30,13 @@ public class Notification
public string? CorrelationId { get; set; }
public string? CorrelationIdType { get; set; }
public bool IsHtml { get; set; }
public bool IsInternal { get; set; }
public bool Processed { get; set; }
public bool HasError { get; set; }
public string[]? Errors { get; set; }
}