Compare commits
3 Commits
agent/dex/
...
0cd8bb1939
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cd8bb1939 | |||
| 7d0369b8e9 | |||
|
|
9cd27e213b |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -2,4 +2,9 @@ bin/
|
|||||||
obj/
|
obj/
|
||||||
*.user
|
*.user
|
||||||
*.suo
|
*.suo
|
||||||
.vs/
|
.vs/
|
||||||
|
|
||||||
|
# Frontend build artifacts
|
||||||
|
frontend/dist/
|
||||||
|
frontend/node_modules/
|
||||||
|
frontend/.angular/
|
||||||
69
backend/API/Filters/FluentValidationFilter.cs
Normal file
69
backend/API/Filters/FluentValidationFilter.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
|
||||||
|
namespace Extrudex.API.Filters;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Action filter that automatically validates request DTOs using FluentValidation
|
||||||
|
/// validators registered in DI. Runs before the controller action executes.
|
||||||
|
/// Returns 400 Bad Request with validation errors if validation fails.
|
||||||
|
/// </summary>
|
||||||
|
public class FluentValidationFilter : IAsyncActionFilter
|
||||||
|
{
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
private readonly ILogger<FluentValidationFilter> _logger;
|
||||||
|
|
||||||
|
public FluentValidationFilter(IServiceProvider serviceProvider, ILogger<FluentValidationFilter> logger)
|
||||||
|
{
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||||
|
{
|
||||||
|
foreach (var argument in context.ActionArguments.Values)
|
||||||
|
{
|
||||||
|
if (argument is null) continue;
|
||||||
|
|
||||||
|
var argumentType = argument.GetType();
|
||||||
|
var validatorType = typeof(IValidator<>).MakeGenericType(argumentType);
|
||||||
|
|
||||||
|
// Try to resolve a validator for this argument type
|
||||||
|
var validator = _serviceProvider.GetService(validatorType) as IValidator;
|
||||||
|
if (validator is null) continue;
|
||||||
|
|
||||||
|
_logger.LogDebug("Validating {Type} with {Validator}", argumentType.Name, validator.GetType().Name);
|
||||||
|
|
||||||
|
var validationResult = await validator.ValidateAsync(
|
||||||
|
new ValidationContext<object>(argument), context.HttpContext.RequestAborted);
|
||||||
|
|
||||||
|
if (!validationResult.IsValid)
|
||||||
|
{
|
||||||
|
foreach (var error in validationResult.Errors)
|
||||||
|
{
|
||||||
|
context.ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var errors = context.ModelState
|
||||||
|
.Where(kvp => kvp.Value?.Errors.Count > 0)
|
||||||
|
.ToDictionary(
|
||||||
|
kvp => kvp.Key,
|
||||||
|
kvp => kvp.Value!.Errors.Select(e => e.ErrorMessage).ToArray());
|
||||||
|
|
||||||
|
context.Result = new BadRequestObjectResult(new
|
||||||
|
{
|
||||||
|
title = "Validation failed",
|
||||||
|
status = 400,
|
||||||
|
errors
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await next();
|
||||||
|
}
|
||||||
|
}
|
||||||
108
backend/API/Validators/FilamentValidators.cs
Normal file
108
backend/API/Validators/FilamentValidators.cs
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
using Extrudex.API.DTOs.Filaments;
|
||||||
|
using FluentValidation;
|
||||||
|
|
||||||
|
namespace Extrudex.API.Validators;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rules for creating a Filament (Spool) via the /filaments route.
|
||||||
|
/// Mirrors the domain rules enforced in the controller and ensures consistent
|
||||||
|
/// validation regardless of the request pipeline entry point.
|
||||||
|
/// </summary>
|
||||||
|
public class CreateFilamentRequestValidator : AbstractValidator<CreateFilamentRequest>
|
||||||
|
{
|
||||||
|
public CreateFilamentRequestValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.MaterialBaseId)
|
||||||
|
.NotEmpty().WithMessage("MaterialBaseId is required.");
|
||||||
|
|
||||||
|
RuleFor(x => x.MaterialFinishId)
|
||||||
|
.NotEmpty().WithMessage("MaterialFinishId is required.");
|
||||||
|
|
||||||
|
RuleFor(x => x.Brand)
|
||||||
|
.NotEmpty().WithMessage("Brand is required.")
|
||||||
|
.MaximumLength(200).WithMessage("Brand must not exceed 200 characters.");
|
||||||
|
|
||||||
|
RuleFor(x => x.ColorName)
|
||||||
|
.NotEmpty().WithMessage("ColorName is required.")
|
||||||
|
.MaximumLength(200).WithMessage("ColorName must not exceed 200 characters.");
|
||||||
|
|
||||||
|
RuleFor(x => x.ColorHex)
|
||||||
|
.NotEmpty().WithMessage("ColorHex is required.")
|
||||||
|
.Matches(@"^#[0-9A-Fa-f]{6}$").WithMessage("ColorHex must be a valid hex color code (e.g., #FF0000).");
|
||||||
|
|
||||||
|
RuleFor(x => x.WeightTotalGrams)
|
||||||
|
.GreaterThan(0).WithMessage("Total weight must be greater than zero.");
|
||||||
|
|
||||||
|
RuleFor(x => x.WeightRemainingGrams)
|
||||||
|
.GreaterThanOrEqualTo(0).WithMessage("Remaining weight must be non-negative.");
|
||||||
|
|
||||||
|
RuleFor(x => x.WeightRemainingGrams)
|
||||||
|
.LessThanOrEqualTo(x => x.WeightTotalGrams)
|
||||||
|
.WithMessage("WeightRemainingGrams cannot exceed WeightTotalGrams.");
|
||||||
|
|
||||||
|
RuleFor(x => x.FilamentDiameterMm)
|
||||||
|
.GreaterThan(0).WithMessage("Filament diameter must be greater than zero.");
|
||||||
|
|
||||||
|
RuleFor(x => x.SpoolSerial)
|
||||||
|
.NotEmpty().WithMessage("SpoolSerial is required.")
|
||||||
|
.MaximumLength(200).WithMessage("SpoolSerial must not exceed 200 characters.");
|
||||||
|
|
||||||
|
When(x => x.PurchasePrice.HasValue, () =>
|
||||||
|
{
|
||||||
|
RuleFor(x => x.PurchasePrice!.Value)
|
||||||
|
.GreaterThanOrEqualTo(0).WithMessage("Purchase price must be non-negative.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rules for updating a Filament (Spool) via the /filaments route.
|
||||||
|
/// Enforces the same domain rules as creation, plus ensures the updated
|
||||||
|
/// WeightRemainingGrams does not exceed the updated WeightTotalGrams.
|
||||||
|
/// </summary>
|
||||||
|
public class UpdateFilamentRequestValidator : AbstractValidator<UpdateFilamentRequest>
|
||||||
|
{
|
||||||
|
public UpdateFilamentRequestValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.MaterialBaseId)
|
||||||
|
.NotEmpty().WithMessage("MaterialBaseId is required.");
|
||||||
|
|
||||||
|
RuleFor(x => x.MaterialFinishId)
|
||||||
|
.NotEmpty().WithMessage("MaterialFinishId is required.");
|
||||||
|
|
||||||
|
RuleFor(x => x.Brand)
|
||||||
|
.NotEmpty().WithMessage("Brand is required.")
|
||||||
|
.MaximumLength(200).WithMessage("Brand must not exceed 200 characters.");
|
||||||
|
|
||||||
|
RuleFor(x => x.ColorName)
|
||||||
|
.NotEmpty().WithMessage("ColorName is required.")
|
||||||
|
.MaximumLength(200).WithMessage("ColorName must not exceed 200 characters.");
|
||||||
|
|
||||||
|
RuleFor(x => x.ColorHex)
|
||||||
|
.NotEmpty().WithMessage("ColorHex is required.")
|
||||||
|
.Matches(@"^#[0-9A-Fa-f]{6}$").WithMessage("ColorHex must be a valid hex color code (e.g., #FF0000).");
|
||||||
|
|
||||||
|
RuleFor(x => x.WeightTotalGrams)
|
||||||
|
.GreaterThan(0).WithMessage("Total weight must be greater than zero.");
|
||||||
|
|
||||||
|
RuleFor(x => x.WeightRemainingGrams)
|
||||||
|
.GreaterThanOrEqualTo(0).WithMessage("Remaining weight must be non-negative.");
|
||||||
|
|
||||||
|
RuleFor(x => x.WeightRemainingGrams)
|
||||||
|
.LessThanOrEqualTo(x => x.WeightTotalGrams)
|
||||||
|
.WithMessage("WeightRemainingGrams cannot exceed WeightTotalGrams.");
|
||||||
|
|
||||||
|
RuleFor(x => x.FilamentDiameterMm)
|
||||||
|
.GreaterThan(0).WithMessage("Filament diameter must be greater than zero.");
|
||||||
|
|
||||||
|
RuleFor(x => x.SpoolSerial)
|
||||||
|
.NotEmpty().WithMessage("SpoolSerial is required.")
|
||||||
|
.MaximumLength(200).WithMessage("SpoolSerial must not exceed 200 characters.");
|
||||||
|
|
||||||
|
When(x => x.PurchasePrice.HasValue, () =>
|
||||||
|
{
|
||||||
|
RuleFor(x => x.PurchasePrice!.Value)
|
||||||
|
.GreaterThanOrEqualTo(0).WithMessage("Purchase price must be non-negative.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,4 +27,8 @@ COPY --from=build /app/publish .
|
|||||||
# ASP.NET Core listens on 8080 by default in .NET 8+
|
# ASP.NET Core listens on 8080 by default in .NET 8+
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# Health check against /health endpoint
|
||||||
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||||
|
CMD curl --fail http://localhost:8080/health || exit 1
|
||||||
|
|
||||||
ENTRYPOINT ["dotnet", "Extrudex.dll"]
|
ENTRYPOINT ["dotnet", "Extrudex.dll"]
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="9.0.0" />
|
||||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
|
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3" />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Extrudex.API.Filters;
|
||||||
using Extrudex.API.Hubs;
|
using Extrudex.API.Hubs;
|
||||||
using Extrudex.Domain.Interfaces;
|
using Extrudex.Domain.Interfaces;
|
||||||
using Extrudex.Infrastructure.Data;
|
using Extrudex.Infrastructure.Data;
|
||||||
@@ -23,7 +24,10 @@ builder.Services.AddDbContext<ExtrudexDbContext>(options =>
|
|||||||
options.UseNpgsql(connectionString));
|
options.UseNpgsql(connectionString));
|
||||||
|
|
||||||
// ── API Services ───────────────────────────────────────────
|
// ── API Services ───────────────────────────────────────────
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers(options =>
|
||||||
|
{
|
||||||
|
options.Filters.AddService<FluentValidationFilter>();
|
||||||
|
});
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
@@ -50,6 +54,10 @@ builder.Services.AddSingleton<IQrCodeService, QrCodeService>();
|
|||||||
// Registers all validators from the API assembly into DI.
|
// Registers all validators from the API assembly into DI.
|
||||||
builder.Services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
builder.Services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
||||||
|
|
||||||
|
// Register the FluentValidation action filter so validators run automatically
|
||||||
|
// on all API controller actions before the action executes.
|
||||||
|
builder.Services.AddScoped<FluentValidationFilter>();
|
||||||
|
|
||||||
// ── CORS (kiosk + remote browser) ─────────────────────────
|
// ── CORS (kiosk + remote browser) ─────────────────────────
|
||||||
// AllowAnyOrigin disallows credentials by spec; this is fine for
|
// AllowAnyOrigin disallows credentials by spec; this is fine for
|
||||||
// REST API calls. SignalR WebSockets negotiate without credentials
|
// REST API calls. SignalR WebSockets negotiate without credentials
|
||||||
@@ -69,6 +77,10 @@ builder.Services.AddCors(options =>
|
|||||||
// ── SignalR (real-time printer updates) ────────────────────
|
// ── SignalR (real-time printer updates) ────────────────────
|
||||||
builder.Services.AddSignalR();
|
builder.Services.AddSignalR();
|
||||||
|
|
||||||
|
// ── Health Checks ───────────────────────────────────────────
|
||||||
|
builder.Services.AddHealthChecks()
|
||||||
|
.AddNpgSql(connectionString);
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// ── Middleware ──────────────────────────────────────────────
|
// ── Middleware ──────────────────────────────────────────────
|
||||||
@@ -85,6 +97,9 @@ app.MapControllers();
|
|||||||
// ── Hub Endpoints ───────────────────────────────────────────
|
// ── Hub Endpoints ───────────────────────────────────────────
|
||||||
app.MapHub<PrinterHub>("/hubs/printer");
|
app.MapHub<PrinterHub>("/hubs/printer");
|
||||||
|
|
||||||
|
// ── Health Check Endpoint ──────────────────────────────────
|
||||||
|
app.MapHealthChecks("/health");
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
// Helper: builds a connection string from individual env vars.
|
// Helper: builds a connection string from individual env vars.
|
||||||
|
|||||||
33
deploy.sh
Executable file
33
deploy.sh
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🔧 Deploying Extrudex Docker runtime..."
|
||||||
|
|
||||||
|
# Check if Docker Compose is available
|
||||||
|
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
|
||||||
|
echo "❌ Docker Compose is not installed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
COMPOSE_CMD="docker compose"
|
||||||
|
if command -v docker-compose &> /dev/null; then
|
||||||
|
COMPOSE_CMD="docker-compose"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "📦 Building and starting services..."
|
||||||
|
$COMPOSE_CMD -f docker-compose.dev.yml up -d --build
|
||||||
|
|
||||||
|
echo "⏳ Waiting for services to become healthy..."
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
echo "✅ Deployment complete!"
|
||||||
|
echo ""
|
||||||
|
echo "Services running:"
|
||||||
|
echo " • Extrudex API: http://localhost:5080"
|
||||||
|
echo " • Control Center Web: http://localhost:5081"
|
||||||
|
echo ""
|
||||||
|
echo "To view logs:"
|
||||||
|
echo " $COMPOSE_CMD -f docker-compose.dev.yml logs -f"
|
||||||
|
echo ""
|
||||||
|
echo "To stop:"
|
||||||
|
echo " $COMPOSE_CMD -f docker-compose.dev.yml down"
|
||||||
40
docker-compose.dev.yml
Normal file
40
docker-compose.dev.yml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
extrudex-api:
|
||||||
|
build:
|
||||||
|
context: ./backend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: extrudex-api
|
||||||
|
ports:
|
||||||
|
- "5080:8080"
|
||||||
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
|
- ASPNETCORE_URLS=http://+:8080
|
||||||
|
restart: unless-stopped
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
|
networks:
|
||||||
|
- extrudex-network
|
||||||
|
|
||||||
|
control-center-web:
|
||||||
|
build:
|
||||||
|
context: ../Control-Center/frontend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: control-center-web
|
||||||
|
ports:
|
||||||
|
- "5081:80"
|
||||||
|
depends_on:
|
||||||
|
extrudex-api:
|
||||||
|
condition: service_healthy
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- extrudex-network
|
||||||
|
|
||||||
|
networks:
|
||||||
|
extrudex-network:
|
||||||
|
driver: bridge
|
||||||
Reference in New Issue
Block a user