initial commit

This commit is contained in:
cubecraft-agents[bot]
2026-04-25 18:51:05 +00:00
commit 230c3b295d
78 changed files with 8093 additions and 0 deletions

View File

@@ -0,0 +1,100 @@
using Extrudex.API.DTOs.Materials;
using FluentValidation;
namespace Extrudex.API.Validators;
/// <summary>
/// Validation rules for creating a MaterialBase.
/// </summary>
public class CreateMaterialBaseRequestValidator : AbstractValidator<CreateMaterialBaseRequest>
{
public CreateMaterialBaseRequestValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Material name is required.")
.MaximumLength(50).WithMessage("Material name must not exceed 50 characters.");
RuleFor(x => x.DensityGperCm3)
.GreaterThan(0).WithMessage("Density must be greater than zero.");
}
}
/// <summary>
/// Validation rules for updating a MaterialBase.
/// </summary>
public class UpdateMaterialBaseRequestValidator : AbstractValidator<UpdateMaterialBaseRequest>
{
public UpdateMaterialBaseRequestValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Material name is required.")
.MaximumLength(50).WithMessage("Material name must not exceed 50 characters.");
RuleFor(x => x.DensityGperCm3)
.GreaterThan(0).WithMessage("Density must be greater than zero.");
}
}
/// <summary>
/// Validation rules for creating a MaterialFinish.
/// </summary>
public class CreateMaterialFinishRequestValidator : AbstractValidator<CreateMaterialFinishRequest>
{
public CreateMaterialFinishRequestValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Finish name is required.")
.MaximumLength(50).WithMessage("Finish name must not exceed 50 characters.");
RuleFor(x => x.MaterialBaseId)
.NotEmpty().WithMessage("MaterialBaseId is required.");
}
}
/// <summary>
/// Validation rules for updating a MaterialFinish.
/// </summary>
public class UpdateMaterialFinishRequestValidator : AbstractValidator<UpdateMaterialFinishRequest>
{
public UpdateMaterialFinishRequestValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Finish name is required.")
.MaximumLength(50).WithMessage("Finish name must not exceed 50 characters.");
RuleFor(x => x.MaterialBaseId)
.NotEmpty().WithMessage("MaterialBaseId is required.");
}
}
/// <summary>
/// Validation rules for creating a MaterialModifier.
/// </summary>
public class CreateMaterialModifierRequestValidator : AbstractValidator<CreateMaterialModifierRequest>
{
public CreateMaterialModifierRequestValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Modifier name is required.")
.MaximumLength(50).WithMessage("Modifier name must not exceed 50 characters.");
RuleFor(x => x.MaterialBaseId)
.NotEmpty().WithMessage("MaterialBaseId is required.");
}
}
/// <summary>
/// Validation rules for updating a MaterialModifier.
/// </summary>
public class UpdateMaterialModifierRequestValidator : AbstractValidator<UpdateMaterialModifierRequest>
{
public UpdateMaterialModifierRequestValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Modifier name is required.")
.MaximumLength(50).WithMessage("Modifier name must not exceed 50 characters.");
RuleFor(x => x.MaterialBaseId)
.NotEmpty().WithMessage("MaterialBaseId is required.");
}
}

View File

@@ -0,0 +1,106 @@
using Extrudex.API.DTOs.PrintJobs;
using FluentValidation;
namespace Extrudex.API.Validators;
/// <summary>
/// Validation rules for creating a PrintJob.
/// </summary>
public class CreatePrintJobRequestValidator : AbstractValidator<CreatePrintJobRequest>
{
private static readonly string[] ValidDataSources = { "Mqtt", "Moonraker", "Manual" };
public CreatePrintJobRequestValidator()
{
RuleFor(x => x.PrinterId)
.NotEmpty().WithMessage("PrinterId is required.");
RuleFor(x => x.SpoolId)
.NotEmpty().WithMessage("SpoolId is required.");
RuleFor(x => x.PrintName)
.NotEmpty().WithMessage("PrintName is required.")
.MaximumLength(200).WithMessage("PrintName must not exceed 200 characters.");
RuleFor(x => x.MmExtruded)
.GreaterThanOrEqualTo(0).WithMessage("MmExtruded must be non-negative.");
RuleFor(x => x.GramsDerived)
.GreaterThanOrEqualTo(0).WithMessage("GramsDerived must be non-negative.");
RuleFor(x => x.DataSource)
.Must(x => ValidDataSources.Contains(x, StringComparer.OrdinalIgnoreCase))
.WithMessage("DataSource must be 'Mqtt', 'Moonraker', or 'Manual'.");
RuleFor(x => x.FilamentDiameterAtPrintMm)
.GreaterThan(0).WithMessage("Filament diameter must be greater than zero.");
RuleFor(x => x.MaterialDensityAtPrint)
.GreaterThan(0).WithMessage("Material density must be greater than zero.");
When(x => x.GcodeFilePath != null, () =>
{
RuleFor(x => x.GcodeFilePath!)
.MaximumLength(500).WithMessage("G-code file path must not exceed 500 characters.");
});
When(x => x.Notes != null, () =>
{
RuleFor(x => x.Notes!)
.MaximumLength(2000).WithMessage("Notes must not exceed 2000 characters.");
});
}
}
/// <summary>
/// Validation rules for updating a PrintJob.
/// </summary>
public class UpdatePrintJobRequestValidator : AbstractValidator<UpdatePrintJobRequest>
{
public UpdatePrintJobRequestValidator()
{
RuleFor(x => x.PrinterId)
.NotEmpty().WithMessage("PrinterId is required.");
RuleFor(x => x.SpoolId)
.NotEmpty().WithMessage("SpoolId is required.");
RuleFor(x => x.PrintName)
.NotEmpty().WithMessage("PrintName is required.")
.MaximumLength(200).WithMessage("PrintName must not exceed 200 characters.");
RuleFor(x => x.MmExtruded)
.GreaterThanOrEqualTo(0).WithMessage("MmExtruded must be non-negative.");
RuleFor(x => x.GramsDerived)
.GreaterThanOrEqualTo(0).WithMessage("GramsDerived must be non-negative.");
When(x => x.GcodeFilePath != null, () =>
{
RuleFor(x => x.GcodeFilePath!)
.MaximumLength(500).WithMessage("G-code file path must not exceed 500 characters.");
});
When(x => x.Notes != null, () =>
{
RuleFor(x => x.Notes!)
.MaximumLength(2000).WithMessage("Notes must not exceed 2000 characters.");
});
}
}
/// <summary>
/// Validation rules for updating a PrintJob status.
/// </summary>
public class UpdatePrintJobStatusRequestValidator : AbstractValidator<UpdatePrintJobStatusRequest>
{
private static readonly string[] ValidStatuses = { "Queued", "Printing", "Completed", "Cancelled", "Failed" };
public UpdatePrintJobStatusRequestValidator()
{
RuleFor(x => x.Status)
.NotEmpty().WithMessage("Status is required.")
.Must(x => ValidStatuses.Contains(x, StringComparer.OrdinalIgnoreCase))
.WithMessage("Status must be one of: Queued, Printing, Completed, Cancelled, Failed.");
}
}

View File

@@ -0,0 +1,82 @@
using Extrudex.API.DTOs.Printers;
using FluentValidation;
namespace Extrudex.API.Validators;
/// <summary>
/// Validation rules for creating a Printer.
/// </summary>
public class CreatePrinterRequestValidator : AbstractValidator<CreatePrinterRequest>
{
private static readonly string[] ValidPrinterTypes = { "Fdm", "Resin" };
private static readonly string[] ValidConnectionTypes = { "Mqtt", "Moonraker" };
public CreatePrinterRequestValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Printer name is required.")
.MaximumLength(100).WithMessage("Printer name must not exceed 100 characters.");
RuleFor(x => x.Manufacturer)
.NotEmpty().WithMessage("Manufacturer is required.")
.MaximumLength(100).WithMessage("Manufacturer must not exceed 100 characters.");
RuleFor(x => x.Model)
.NotEmpty().WithMessage("Model is required.")
.MaximumLength(100).WithMessage("Model must not exceed 100 characters.");
RuleFor(x => x.PrinterType)
.Must(x => ValidPrinterTypes.Contains(x, StringComparer.OrdinalIgnoreCase))
.WithMessage("PrinterType must be 'Fdm' or 'Resin'.");
RuleFor(x => x.ConnectionType)
.Must(x => ValidConnectionTypes.Contains(x, StringComparer.OrdinalIgnoreCase))
.WithMessage("ConnectionType must be 'Mqtt' or 'Moonraker'.");
RuleFor(x => x.HostnameOrIp)
.NotEmpty().WithMessage("HostnameOrIp is required.")
.MaximumLength(255).WithMessage("HostnameOrIp must not exceed 255 characters.");
RuleFor(x => x.Port)
.InclusiveBetween(1, 65535).WithMessage("Port must be between 1 and 65535.");
}
}
/// <summary>
/// Validation rules for updating a Printer.
/// </summary>
public class UpdatePrinterRequestValidator : AbstractValidator<UpdatePrinterRequest>
{
private static readonly string[] ValidPrinterTypes = { "Fdm", "Resin" };
private static readonly string[] ValidConnectionTypes = { "Mqtt", "Moonraker" };
public UpdatePrinterRequestValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Printer name is required.")
.MaximumLength(100).WithMessage("Printer name must not exceed 100 characters.");
RuleFor(x => x.Manufacturer)
.NotEmpty().WithMessage("Manufacturer is required.")
.MaximumLength(100).WithMessage("Manufacturer must not exceed 100 characters.");
RuleFor(x => x.Model)
.NotEmpty().WithMessage("Model is required.")
.MaximumLength(100).WithMessage("Model must not exceed 100 characters.");
RuleFor(x => x.PrinterType)
.Must(x => ValidPrinterTypes.Contains(x, StringComparer.OrdinalIgnoreCase))
.WithMessage("PrinterType must be 'Fdm' or 'Resin'.");
RuleFor(x => x.ConnectionType)
.Must(x => ValidConnectionTypes.Contains(x, StringComparer.OrdinalIgnoreCase))
.WithMessage("ConnectionType must be 'Mqtt' or 'Moonraker'.");
RuleFor(x => x.HostnameOrIp)
.NotEmpty().WithMessage("HostnameOrIp is required.")
.MaximumLength(255).WithMessage("HostnameOrIp must not exceed 255 characters.");
RuleFor(x => x.Port)
.InclusiveBetween(1, 65535).WithMessage("Port must be between 1 and 65535.");
}
}

View File

@@ -0,0 +1,96 @@
using Extrudex.API.DTOs.Spools;
using FluentValidation;
namespace Extrudex.API.Validators;
/// <summary>
/// Validation rules for creating a Spool.
/// </summary>
public class CreateSpoolRequestValidator : AbstractValidator<CreateSpoolRequest>
{
public CreateSpoolRequestValidator()
{
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(100).WithMessage("Brand must not exceed 100 characters.");
RuleFor(x => x.ColorName)
.NotEmpty().WithMessage("ColorName is required.")
.MaximumLength(100).WithMessage("ColorName must not exceed 100 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.FilamentDiameterMm)
.GreaterThan(0).WithMessage("Filament diameter must be greater than zero.");
RuleFor(x => x.SpoolSerial)
.NotEmpty().WithMessage("SpoolSerial is required.")
.MaximumLength(100).WithMessage("SpoolSerial must not exceed 100 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 Spool.
/// </summary>
public class UpdateSpoolRequestValidator : AbstractValidator<UpdateSpoolRequest>
{
public UpdateSpoolRequestValidator()
{
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(100).WithMessage("Brand must not exceed 100 characters.");
RuleFor(x => x.ColorName)
.NotEmpty().WithMessage("ColorName is required.")
.MaximumLength(100).WithMessage("ColorName must not exceed 100 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.FilamentDiameterMm)
.GreaterThan(0).WithMessage("Filament diameter must be greater than zero.");
RuleFor(x => x.SpoolSerial)
.NotEmpty().WithMessage("SpoolSerial is required.")
.MaximumLength(100).WithMessage("SpoolSerial must not exceed 100 characters.");
When(x => x.PurchasePrice.HasValue, () =>
{
RuleFor(x => x.PurchasePrice!.Value)
.GreaterThanOrEqualTo(0).WithMessage("Purchase price must be non-negative.");
});
}
}