Compare commits
5 Commits
87d7262d0a
...
d7c416256c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7c416256c | ||
|
|
5d3ec27128 | ||
|
|
d5fc0c2e51 | ||
|
|
7272b26105 | ||
|
|
d8f3143c8a |
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
@@ -10,6 +10,8 @@
|
|||||||
<PackageReference Include="Asp.Versioning.Http" Version="8.1.1" />
|
<PackageReference Include="Asp.Versioning.Http" Version="8.1.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.28" />
|
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.28" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
|
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,72 @@
|
|||||||
|
using Serilog;
|
||||||
|
using DocumentOperator.Infrastructure.Configuration;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// ========================================
|
||||||
|
// 1. Serilog Configuration
|
||||||
|
// ========================================
|
||||||
|
Log.Logger = new LoggerConfiguration()
|
||||||
|
.ReadFrom.Configuration(builder.Configuration)
|
||||||
|
.Enrich.FromLogContext()
|
||||||
|
.Enrich.WithProperty("Application", "DocumentOperator")
|
||||||
|
.CreateLogger();
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Host.UseSerilog();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
|
||||||
builder.Services.AddSwaggerGen();
|
|
||||||
|
|
||||||
var app = builder.Build();
|
Log.Information("Starting DocumentOperator API...");
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
try
|
||||||
if (app.Environment.IsDevelopment())
|
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
// ========================================
|
||||||
app.UseSwaggerUI();
|
// 2. Options Pattern Configuration
|
||||||
|
// ========================================
|
||||||
|
builder.Services.Configure<DocumentOperatorSettings>(
|
||||||
|
builder.Configuration.GetSection(DocumentOperatorSettings.SectionName));
|
||||||
|
|
||||||
|
builder.Services.Configure<RedisSettings>(
|
||||||
|
builder.Configuration.GetSection(RedisSettings.SectionName));
|
||||||
|
|
||||||
|
builder.Services.Configure<ApiKeySettings>(
|
||||||
|
builder.Configuration.GetSection(ApiKeySettings.SectionName));
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
// 3. Services
|
||||||
|
// ========================================
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
// 4. Build App
|
||||||
|
// ========================================
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
// 5. Middleware Pipeline
|
||||||
|
// ========================================
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseSerilogRequestLogging(); // Log HTTP Requests
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
app.UseAuthorization();
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
Log.Information("DocumentOperator API started successfully");
|
||||||
|
|
||||||
|
app.Run();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
app.UseHttpsRedirection();
|
{
|
||||||
|
Log.Fatal(ex, "Application startup failed");
|
||||||
app.UseAuthorization();
|
throw;
|
||||||
|
}
|
||||||
app.MapControllers();
|
finally
|
||||||
|
{
|
||||||
app.Run();
|
Log.CloseAndFlush();
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Ardalis.Result" Version="10.1.0" />
|
|
||||||
<PackageReference Include="FluentValidation" Version="12.1.1" />
|
<PackageReference Include="FluentValidation" Version="12.1.1" />
|
||||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
|
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
|
||||||
<PackageReference Include="MediatR" Version="14.1.0" />
|
<PackageReference Include="MediatR" Version="14.1.0" />
|
||||||
|
|||||||
25
DocumentOperator.Domain/Common/Exceptions/DomainException.cs
Normal file
25
DocumentOperator.Domain/Common/Exceptions/DomainException.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
namespace DocumentOperator.Domain.Common.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base exception for all domain-related exceptions.
|
||||||
|
/// Caught by the Exception Handling Middleware in the API layer.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class DomainException : Exception
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Error code for categorization and logging.
|
||||||
|
/// </summary>
|
||||||
|
public string ErrorCode { get; }
|
||||||
|
|
||||||
|
protected DomainException(string message, string errorCode)
|
||||||
|
: base(message)
|
||||||
|
{
|
||||||
|
ErrorCode = errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DomainException(string message, string errorCode, Exception innerException)
|
||||||
|
: base(message, innerException)
|
||||||
|
{
|
||||||
|
ErrorCode = errorCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
namespace DocumentOperator.Domain.Common.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Exception thrown when domain validation fails (e.g., invalid Value Objects).
|
||||||
|
/// Maps to HTTP 400 Bad Request in the API layer.
|
||||||
|
/// </summary>
|
||||||
|
public class DomainValidationException : DomainException
|
||||||
|
{
|
||||||
|
public string PropertyName { get; }
|
||||||
|
|
||||||
|
public DomainValidationException(string message)
|
||||||
|
: base(message, "DOMAIN_VALIDATION_ERROR")
|
||||||
|
{
|
||||||
|
PropertyName = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DomainValidationException(string propertyName, string message)
|
||||||
|
: base(message, "DOMAIN_VALIDATION_ERROR")
|
||||||
|
{
|
||||||
|
PropertyName = propertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DomainValidationException(string message, Exception innerException)
|
||||||
|
: base(message, "DOMAIN_VALIDATION_ERROR", innerException)
|
||||||
|
{
|
||||||
|
PropertyName = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
namespace DocumentOperator.Domain.Common.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Exception thrown when a requested resource is not found.
|
||||||
|
/// Maps to HTTP 404 Not Found in the API layer.
|
||||||
|
/// </summary>
|
||||||
|
public class NotFoundException : DomainException
|
||||||
|
{
|
||||||
|
public string ResourceType { get; }
|
||||||
|
public object ResourceId { get; }
|
||||||
|
|
||||||
|
public NotFoundException(string resourceType, object resourceId)
|
||||||
|
: base($"{resourceType} with ID '{resourceId}' was not found.", "RESOURCE_NOT_FOUND")
|
||||||
|
{
|
||||||
|
ResourceType = resourceType;
|
||||||
|
ResourceId = resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotFoundException(string resourceType, object resourceId, string customMessage)
|
||||||
|
: base(customMessage, "RESOURCE_NOT_FOUND")
|
||||||
|
{
|
||||||
|
ResourceType = resourceType;
|
||||||
|
ResourceId = resourceId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
namespace DocumentOperator.Domain.Common.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Exception thrown when PDF processing operations fail.
|
||||||
|
/// Maps to HTTP 500 Internal Server Error or 422 Unprocessable Entity in the API layer.
|
||||||
|
/// </summary>
|
||||||
|
public class PdfProcessingException : DomainException
|
||||||
|
{
|
||||||
|
public string Operation { get; }
|
||||||
|
|
||||||
|
public PdfProcessingException(string operation, string message)
|
||||||
|
: base($"PDF processing failed during '{operation}': {message}", "PDF_PROCESSING_ERROR")
|
||||||
|
{
|
||||||
|
Operation = operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PdfProcessingException(string operation, string message, Exception innerException)
|
||||||
|
: base($"PDF processing failed during '{operation}': {message}", "PDF_PROCESSING_ERROR", innerException)
|
||||||
|
{
|
||||||
|
Operation = operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PdfProcessingException(string message)
|
||||||
|
: base(message, "PDF_PROCESSING_ERROR")
|
||||||
|
{
|
||||||
|
Operation = "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
public PdfProcessingException(string message, Exception innerException)
|
||||||
|
: base(message, "PDF_PROCESSING_ERROR", innerException)
|
||||||
|
{
|
||||||
|
Operation = "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Common\Exceptions\" />
|
|
||||||
<Folder Include="Common\Results\" />
|
<Folder Include="Common\Results\" />
|
||||||
<Folder Include="Constants\" />
|
<Folder Include="Constants\" />
|
||||||
<Folder Include="Models\Enums\" />
|
<Folder Include="Models\Enums\" />
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace DocumentOperator.Infrastructure.Configuration;
|
||||||
|
|
||||||
|
public class ApiKeySettings
|
||||||
|
{
|
||||||
|
public const string SectionName = "ApiKeySettings";
|
||||||
|
|
||||||
|
public bool EnableValidation { get; set; } = true;
|
||||||
|
public Dictionary<string, TenantInfo> Keys { get; set; } = new();
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace DocumentOperator.Infrastructure.Configuration;
|
||||||
|
|
||||||
|
public class DocumentOperatorSettings
|
||||||
|
{
|
||||||
|
public const string SectionName = "DocumentOperatorSettings";
|
||||||
|
|
||||||
|
public string TempFolderPath { get; set; } = string.Empty;
|
||||||
|
public int TempFileRetentionHours { get; set; }
|
||||||
|
public int MaxPdfSizeMB { get; set; }
|
||||||
|
public bool EnableDetailedLogging { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace DocumentOperator.Infrastructure.Configuration;
|
||||||
|
|
||||||
|
public class RedisSettings
|
||||||
|
{
|
||||||
|
public const string SectionName = "RedisSettings";
|
||||||
|
|
||||||
|
public string ConnectionString { get; set; } = "localhost:6379";
|
||||||
|
public string InstanceName { get; set; } = "DocumentOperator:";
|
||||||
|
public int CacheExpirationMinutes { get; set; } = 60;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace DocumentOperator.Infrastructure.Configuration;
|
||||||
|
|
||||||
|
public class TenantInfo
|
||||||
|
{
|
||||||
|
public string TenantId { get; set; } = string.Empty;
|
||||||
|
public string TenantName { get; set; } = string.Empty;
|
||||||
|
public bool IsActive { get; set; } = true;
|
||||||
|
}
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Configuration\" />
|
|
||||||
<Folder Include="DependencyInjection\" />
|
<Folder Include="DependencyInjection\" />
|
||||||
<Folder Include="Services\FileStorage\" />
|
<Folder Include="Services\FileStorage\" />
|
||||||
<Folder Include="Services\DocumentValidation\" />
|
<Folder Include="Services\DocumentValidation\" />
|
||||||
|
|||||||
1640
ROADMAP.md
Normal file
1640
ROADMAP.md
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user