Added shared projects

This commit is contained in:
Khwezi Mngoma
2026-05-03 16:10:27 +02:00
parent 66c08dc54b
commit 1b997013bb
81 changed files with 4507 additions and 1 deletions
@@ -0,0 +1,94 @@
using LiteCharms.Models;
namespace LiteCharms.Extensions;
public static class EntityModeMappers
{
public static Customer ToModel(this Entities.Customer entity) =>
new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
Active = entity.Active,
Address = entity.Address,
City = entity.City,
Company = entity.Company,
Country = entity.Country,
Discord = entity.Discord,
Email = entity.Email,
LastName = entity.LastName,
LinkedIn = entity.LinkedIn,
Name = entity.Name,
Phone = entity.Phone,
PostalCode = entity.PostalCode,
Region = entity.Region,
Slack = entity.Slack,
Tax = entity.Tax,
Website = entity.Website,
Whatsapp = entity.Whatsapp
};
public static Lead ToModel(this Entities.Lead entity) =>
new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
AdGroupId = entity.AdGroupId,
AdName = entity.AdName,
AppClickId = entity.AppClickId,
AttributionHash = entity.AttributionHash,
CampaignId = entity.CampaignId,
ClickLocation = entity.ClickLocation,
CustomerId = entity.CustomerId,
FeedItemId = entity.FeedItemId,
GoogleClickId = entity.GoogleClickId,
TargetId = entity.TargetId,
WebClickId = entity.WebClickId,
Status = entity.Status
};
public static Order ToModel(this Entities.Order entity) =>
new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
CustomerId = entity.CustomerId,
ProductPriceId = entity.ProductPriceId,
Notes = entity.Notes,
RefundId = entity.RefundId
};
public static OrderRefund ToModel(this Entities.OrderRefund entity) =>
new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
OrderId = entity.OrderId,
Reason = entity.Reason,
Amount = entity.Amount
};
public static Product ToModel(this Entities.Product entity) =>
new()
{
Id = entity.Id,
Name = entity.Name,
Description = entity.Description,
Active = entity.Active
};
public static ProductPrice ToModel(this Entities.ProductPrice entity) =>
new()
{
Id = entity.Id,
ProductId = entity.ProductId,
Price = entity.Price,
Active = entity.Active,
CreatedAt = entity.CreatedAt,
Discount = entity.Discount,
UpdatedAt = entity.UpdatedAt
};
}
@@ -0,0 +1,95 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\LiteCharms.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<!-- Nuget Package Details -->
<PropertyGroup>
<PackageId>LiteCharms.Extensions</PackageId>
<Version>1.0.1</Version>
<Authors>Khwezi Mngoma</Authors>
<Company>Lite Charms (PTY) Ltd</Company>
<Description>Extension components for Lite Charms applications.</Description>
<PackageProjectUrl>https://gitea.khongisa.co.za/litecharms/leadgenerator</PackageProjectUrl>
<RepositoryUrl>https://gitea.khongisa.co.za/litecharms/leadgenerator.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageTags>utility;dotnet</PackageTags>
<PackageIcon>icon.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
<None Include="..\LICENSE" Pack="true" PackagePath="\"/>
<None Include="..\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>
<!-- Shared Usings -->
<ItemGroup>
<Using Include="Microsoft.AspNetCore.Builder" />
<Using Include="Microsoft.Extensions.Configuration" />
<Using Include="Microsoft.Extensions.DependencyInjection" />
<Using Include="Microsoft.Extensions.Logging" />
</ItemGroup>
<!-- Health Checks -->
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI" Version="9.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Core" Version="9.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Data" Version="9.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.SQLite.Storage" Version="9.0.0" />
<!-- Global Usings -->
<Using Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<Using Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
</ItemGroup>
<!-- Open Telemetry -->
<ItemGroup>
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.3" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.15.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.2" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.15.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.15.1" />
<!-- Global Usings -->
<Using Include="OpenTelemetry.Resources" />
<Using Include="OpenTelemetry.Exporter" />
<Using Include="OpenTelemetry.Logs" />
<Using Include="OpenTelemetry.Metrics" />
<Using Include="OpenTelemetry.Trace" />
</ItemGroup>
<!-- Database -->
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.1" />
<!-- Global Usings -->
<Using Include="Npgsql" />
<Using Include="Microsoft.EntityFrameworkCore" />
<Using Include="Microsoft.EntityFrameworkCore.Design" />
<Using Include="Microsoft.EntityFrameworkCore.Metadata.Builders" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LiteCharms.Entities\LiteCharms.Entities.csproj" />
<ProjectReference Include="..\LiteCharms.Infrastructure\LiteCharms.Infrastructure.csproj" />
<ProjectReference Include="..\LiteCharms.Models\LiteCharms.Models.csproj" />
</ItemGroup>
</Project>
+78
View File
@@ -0,0 +1,78 @@
using LiteCharms.Infrastructure.Database;
using LiteCharms.Infrastructure.HealthChecks;
namespace LiteCharms.Extensions;
public static class Services
{
public static IServiceCollection AddHealthChecksSupport(this IServiceCollection services, IConfiguration configuration)
{
services.AddHealthChecks()
.AddCheck("Self", () => HealthCheckResult.Healthy())
.AddCheck<PostgresHealthCheck>("PostgreSQL");
//services.AddHealthChecksUI(setup =>
//{
// setup.AddHealthCheckEndpoint("Lead Generator", $"{configuration["ASPNETCORE_URLS"]}/healthui");
// setup.SetEvaluationTimeInSeconds(15);
//}).AddSqliteStorage($"Data Source=health_history.db");
return services;
}
public static IServiceCollection AddLeadGeneratorDatabase(this IServiceCollection services, IConfiguration configuration)
{
services.AddPooledDbContextFactory<LeadGeneratorDbContext>(options =>
options.UseNpgsql(configuration.GetConnectionString("PostgresLeadGenerator")));
return services;
}
public static WebApplicationBuilder AddMonitoring(this WebApplicationBuilder builder)
{
var serviceName = builder.Configuration.GetValue<string>("Monitoring:ServiceName") ?? "LiteCharms.Capture";
var endpoint = builder.Configuration.GetValue<string>("Monitoring:Address")!;
var apiKey = builder.Configuration.GetValue<string>("Monitoring:ApiKey");
var resourceBuilder = ResourceBuilder.CreateDefault()
.AddService(serviceName);
var otlpHeaders = !string.IsNullOrEmpty(apiKey) ? $"x-otlp-api-key={apiKey}" : null;
builder.Logging.AddOpenTelemetry(logging =>
{
logging.SetResourceBuilder(resourceBuilder);
logging.AddOtlpExporter(opt =>
{
opt.Endpoint = new Uri(endpoint);
opt.Protocol = OtlpExportProtocol.Grpc;
opt.Headers = otlpHeaders;
});
});
builder.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing
.SetResourceBuilder(resourceBuilder)
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddOtlpExporter(opt =>
{
opt.Endpoint = new Uri(endpoint);
opt.Protocol = OtlpExportProtocol.Grpc;
opt.Headers = otlpHeaders;
}))
.WithMetrics(metrics => metrics
.SetResourceBuilder(resourceBuilder)
.AddMeter(serviceName)
.AddAspNetCoreInstrumentation()
.AddRuntimeInstrumentation()
.AddOtlpExporter(opt =>
{
opt.Endpoint = new Uri(endpoint);
opt.Protocol = OtlpExportProtocol.Grpc;
opt.Headers = otlpHeaders;
}));
return builder;
}
}