Compare commits
2 Commits
432ce39e62
...
agent/rex/
| Author | SHA1 | Date | |
|---|---|---|---|
| cfd4a81b5f | |||
| f5ca20307e |
@@ -1,117 +0,0 @@
|
|||||||
using Extrudex.API.DTOs.UsageLogs;
|
|
||||||
using Extrudex.Domain.Enums;
|
|
||||||
using Extrudex.Domain.Interfaces;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace Extrudex.API.Controllers;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// API controller for recording and querying filament usage logs.
|
|
||||||
/// Usage logs provide a fine-grained audit trail of filament consumption
|
|
||||||
/// from printer integrations or manual input.
|
|
||||||
/// </summary>
|
|
||||||
[ApiController]
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
[Produces("application/json")]
|
|
||||||
public class UsageLogsController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly IUsageLogService _usageLogService;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="UsageLogsController"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="usageLogService">The usage log service for recording and querying usage.</param>
|
|
||||||
public UsageLogsController(IUsageLogService usageLogService)
|
|
||||||
{
|
|
||||||
_usageLogService = usageLogService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Records a new filament usage entry.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The usage entry details.</param>
|
|
||||||
/// <returns>The created usage log entry.</returns>
|
|
||||||
[HttpPost]
|
|
||||||
[ProducesResponseType(typeof(UsageLogResponse), StatusCodes.Status201Created)]
|
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
||||||
public async Task<ActionResult<UsageLogResponse>> Create([FromBody] CreateUsageLogRequest request)
|
|
||||||
{
|
|
||||||
if (!Enum.TryParse<DataSource>(request.DataSource, ignoreCase: true, out var dataSource))
|
|
||||||
{
|
|
||||||
return BadRequest($"Invalid data source: '{request.DataSource}'. Valid values: Mqtt, Moonraker, Manual.");
|
|
||||||
}
|
|
||||||
|
|
||||||
var entry = await _usageLogService.RecordUsageAsync(
|
|
||||||
spoolId: request.SpoolId,
|
|
||||||
gramsUsed: request.GramsUsed,
|
|
||||||
dataSource: dataSource,
|
|
||||||
printerId: request.PrinterId,
|
|
||||||
printJobId: request.PrintJobId,
|
|
||||||
mmExtruded: request.MmExtruded,
|
|
||||||
usageTimestamp: request.UsageTimestamp,
|
|
||||||
notes: request.Notes
|
|
||||||
);
|
|
||||||
|
|
||||||
return CreatedAtAction(
|
|
||||||
nameof(GetBySpool),
|
|
||||||
new { spoolId = entry.SpoolId },
|
|
||||||
MapToResponse(entry));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets usage logs for a specific spool, ordered by most recent first.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="spoolId">The spool ID to filter by.</param>
|
|
||||||
/// <returns>A collection of usage log entries for the spool.</returns>
|
|
||||||
[HttpGet("spool/{spoolId:guid}")]
|
|
||||||
[ProducesResponseType(typeof(IEnumerable<UsageLogResponse>), StatusCodes.Status200OK)]
|
|
||||||
public async Task<ActionResult<IEnumerable<UsageLogResponse>>> GetBySpool(Guid spoolId)
|
|
||||||
{
|
|
||||||
var logs = await _usageLogService.GetBySpoolAsync(spoolId);
|
|
||||||
return Ok(logs.Select(MapToResponse));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets usage logs for a specific printer, ordered by most recent first.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="printerId">The printer ID to filter by.</param>
|
|
||||||
/// <returns>A collection of usage log entries for the printer.</returns>
|
|
||||||
[HttpGet("printer/{printerId:guid}")]
|
|
||||||
[ProducesResponseType(typeof(IEnumerable<UsageLogResponse>), StatusCodes.Status200OK)]
|
|
||||||
public async Task<ActionResult<IEnumerable<UsageLogResponse>>> GetByPrinter(Guid printerId)
|
|
||||||
{
|
|
||||||
var logs = await _usageLogService.GetByPrinterAsync(printerId);
|
|
||||||
return Ok(logs.Select(MapToResponse));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets usage logs for a specific print job, ordered by most recent first.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="printJobId">The print job ID to filter by.</param>
|
|
||||||
/// <returns>A collection of usage log entries for the print job.</returns>
|
|
||||||
[HttpGet("print-job/{printJobId:guid}")]
|
|
||||||
[ProducesResponseType(typeof(IEnumerable<UsageLogResponse>), StatusCodes.Status200OK)]
|
|
||||||
public async Task<ActionResult<IEnumerable<UsageLogResponse>>> GetByPrintJob(Guid printJobId)
|
|
||||||
{
|
|
||||||
var logs = await _usageLogService.GetByPrintJobAsync(printJobId);
|
|
||||||
return Ok(logs.Select(MapToResponse));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Maps a UsageLog domain entity to a UsageLogResponse DTO.
|
|
||||||
/// </summary>
|
|
||||||
private static UsageLogResponse MapToResponse(Domain.Entities.UsageLog log) => new()
|
|
||||||
{
|
|
||||||
Id = log.Id,
|
|
||||||
SpoolId = log.SpoolId,
|
|
||||||
PrinterId = log.PrinterId,
|
|
||||||
PrintJobId = log.PrintJobId,
|
|
||||||
GramsUsed = log.GramsUsed,
|
|
||||||
MmExtruded = log.MmExtruded,
|
|
||||||
UsageTimestamp = log.UsageTimestamp,
|
|
||||||
DataSource = log.DataSource.ToString(),
|
|
||||||
Notes = log.Notes,
|
|
||||||
CreatedAt = log.CreatedAt,
|
|
||||||
UpdatedAt = log.UpdatedAt
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace Extrudex.API.DTOs.UsageLogs;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Request DTO for recording a filament usage entry.
|
|
||||||
/// </summary>
|
|
||||||
public class CreateUsageLogRequest
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The ID of the spool that provided the filament.
|
|
||||||
/// </summary>
|
|
||||||
[Required]
|
|
||||||
public Guid SpoolId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The number of grams of filament consumed.
|
|
||||||
/// </summary>
|
|
||||||
[Required]
|
|
||||||
[Range(0.01, double.MaxValue, ErrorMessage = "GramsUsed must be a positive value.")]
|
|
||||||
public decimal GramsUsed { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The source of the usage data (Mqtt, Moonraker, Manual).
|
|
||||||
/// </summary>
|
|
||||||
[Required]
|
|
||||||
public string DataSource { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The ID of the printer that consumed the filament. Optional.
|
|
||||||
/// </summary>
|
|
||||||
public Guid? PrinterId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The ID of the print job associated with this usage. Optional.
|
|
||||||
/// </summary>
|
|
||||||
public Guid? PrintJobId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The number of millimeters of filament extruded. Optional.
|
|
||||||
/// </summary>
|
|
||||||
public decimal? MmExtruded { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// When the usage occurred (UTC). Defaults to now if not specified.
|
|
||||||
/// </summary>
|
|
||||||
public DateTime? UsageTimestamp { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Optional notes about this usage entry.
|
|
||||||
/// </summary>
|
|
||||||
[MaxLength(2000)]
|
|
||||||
public string? Notes { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Response DTO for a usage log entry.
|
|
||||||
/// </summary>
|
|
||||||
public class UsageLogResponse
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Unique identifier for the usage log entry.
|
|
||||||
/// </summary>
|
|
||||||
public Guid Id { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The spool that provided the filament.
|
|
||||||
/// </summary>
|
|
||||||
public Guid SpoolId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The printer that consumed the filament, if applicable.
|
|
||||||
/// </summary>
|
|
||||||
public Guid? PrinterId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The print job associated with this usage, if applicable.
|
|
||||||
/// </summary>
|
|
||||||
public Guid? PrintJobId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Grams of filament consumed.
|
|
||||||
/// </summary>
|
|
||||||
public decimal GramsUsed { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Millimeters of filament extruded, if available.
|
|
||||||
/// </summary>
|
|
||||||
public decimal? MmExtruded { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// When the usage occurred (UTC).
|
|
||||||
/// </summary>
|
|
||||||
public DateTime UsageTimestamp { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Source of the usage data (Mqtt, Moonraker, Manual).
|
|
||||||
/// </summary>
|
|
||||||
public string DataSource { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Optional notes about this usage entry.
|
|
||||||
/// </summary>
|
|
||||||
public string? Notes { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// When the record was created (UTC).
|
|
||||||
/// </summary>
|
|
||||||
public DateTime CreatedAt { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// When the record was last updated (UTC).
|
|
||||||
/// </summary>
|
|
||||||
public DateTime UpdatedAt { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
using Extrudex.Domain.Base;
|
|
||||||
using Extrudex.Domain.Enums;
|
|
||||||
|
|
||||||
namespace Extrudex.Domain.Entities;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a single filament usage log entry. Records how much filament
|
|
||||||
/// was consumed, by which printer, at what time, and optionally linked to
|
|
||||||
/// a print job. This provides a fine-grained audit trail of filament consumption
|
|
||||||
/// independent of print job lifecycle.
|
|
||||||
/// </summary>
|
|
||||||
public class UsageLog : AuditableEntity
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Foreign key to the spool that provided the filament.
|
|
||||||
/// </summary>
|
|
||||||
public Guid SpoolId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Navigation to the spool that provided the filament.
|
|
||||||
/// </summary>
|
|
||||||
public Spool Spool { get; set; } = null!;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Foreign key to the printer that consumed the filament.
|
|
||||||
/// Nullable to support manual entries without a specific printer.
|
|
||||||
/// </summary>
|
|
||||||
public Guid? PrinterId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Navigation to the printer that consumed the filament.
|
|
||||||
/// </summary>
|
|
||||||
public Printer? Printer { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Foreign key to the print job associated with this usage entry.
|
|
||||||
/// Nullable because usage can be logged before or without a print job.
|
|
||||||
/// </summary>
|
|
||||||
public Guid? PrintJobId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Navigation to the print job associated with this usage entry.
|
|
||||||
/// </summary>
|
|
||||||
public PrintJob? PrintJob { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The number of grams of filament consumed in this usage event.
|
|
||||||
/// </summary>
|
|
||||||
public decimal GramsUsed { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The number of millimeters of filament extruded in this usage event.
|
|
||||||
/// Optional — may not be available for all data sources.
|
|
||||||
/// </summary>
|
|
||||||
public decimal? MmExtruded { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Timestamp when the usage occurred (UTC). This is the actual time of
|
|
||||||
/// consumption, which may differ from CreatedAt if the entry was recorded later.
|
|
||||||
/// </summary>
|
|
||||||
public DateTime UsageTimestamp { get; set; } = DateTime.UtcNow;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The source of the usage data (which integration path provided it).
|
|
||||||
/// </summary>
|
|
||||||
public DataSource DataSource { get; set; } = DataSource.Manual;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Optional notes about this usage entry.
|
|
||||||
/// </summary>
|
|
||||||
public string? Notes { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
using Extrudex.Domain.Entities;
|
|
||||||
using Extrudex.Domain.Enums;
|
|
||||||
|
|
||||||
namespace Extrudex.Domain.Interfaces;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Service for recording filament usage entries. Writes to the usage_logs table
|
|
||||||
/// and provides query capabilities for usage history.
|
|
||||||
/// </summary>
|
|
||||||
public interface IUsageLogService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Records a filament usage entry.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="spoolId">The spool that provided the filament.</param>
|
|
||||||
/// <param name="gramsUsed">Grams of filament consumed.</param>
|
|
||||||
/// <param name="dataSource">Where the data came from.</param>
|
|
||||||
/// <param name="printerId">Optional printer ID.</param>
|
|
||||||
/// <param name="printJobId">Optional print job ID.</param>
|
|
||||||
/// <param name="mmExtruded">Optional mm extruded.</param>
|
|
||||||
/// <param name="usageTimestamp">When the usage occurred (defaults to UTC now).</param>
|
|
||||||
/// <param name="notes">Optional notes.</param>
|
|
||||||
/// <returns>The created UsageLog entity.</returns>
|
|
||||||
Task<UsageLog> RecordUsageAsync(
|
|
||||||
Guid spoolId,
|
|
||||||
decimal gramsUsed,
|
|
||||||
DataSource dataSource,
|
|
||||||
Guid? printerId = null,
|
|
||||||
Guid? printJobId = null,
|
|
||||||
decimal? mmExtruded = null,
|
|
||||||
DateTime? usageTimestamp = null,
|
|
||||||
string? notes = null);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves usage logs for a specific spool, ordered by usage timestamp descending.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="spoolId">The spool ID to filter by.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token.</param>
|
|
||||||
/// <returns>A collection of usage logs for the spool.</returns>
|
|
||||||
Task<IEnumerable<UsageLog>> GetBySpoolAsync(Guid spoolId, CancellationToken cancellationToken = default);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves usage logs for a specific printer, ordered by usage timestamp descending.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="printerId">The printer ID to filter by.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token.</param>
|
|
||||||
/// <returns>A collection of usage logs for the printer.</returns>
|
|
||||||
Task<IEnumerable<UsageLog>> GetByPrinterAsync(Guid printerId, CancellationToken cancellationToken = default);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves usage logs for a specific print job, ordered by usage timestamp descending.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="printJobId">The print job ID to filter by.</param>
|
|
||||||
/// <param name="cancellationToken">Cancellation token.</param>
|
|
||||||
/// <returns>A collection of usage logs for the print job.</returns>
|
|
||||||
Task<IEnumerable<UsageLog>> GetByPrintJobAsync(Guid printJobId, CancellationToken cancellationToken = default);
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
using Extrudex.Domain.Entities;
|
|
||||||
using Extrudex.Domain.Enums;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
||||||
|
|
||||||
namespace Extrudex.Infrastructure.Data.Configurations;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// EF Core configuration for the UsageLog entity.
|
|
||||||
/// Maps to the usage_logs table with snake_case columns and appropriate indexes.
|
|
||||||
/// </summary>
|
|
||||||
public class UsageLogConfiguration : BaseEntityConfiguration<UsageLog>
|
|
||||||
{
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public override void Configure(EntityTypeBuilder<UsageLog> builder)
|
|
||||||
{
|
|
||||||
base.Configure(builder);
|
|
||||||
|
|
||||||
builder.Property(e => e.SpoolId)
|
|
||||||
.HasColumnName("spool_id")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
builder.Property(e => e.PrinterId)
|
|
||||||
.HasColumnName("printer_id");
|
|
||||||
|
|
||||||
builder.Property(e => e.PrintJobId)
|
|
||||||
.HasColumnName("print_job_id");
|
|
||||||
|
|
||||||
builder.Property(e => e.GramsUsed)
|
|
||||||
.HasColumnName("grams_used")
|
|
||||||
.HasPrecision(10, 2)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
builder.Property(e => e.MmExtruded)
|
|
||||||
.HasColumnName("mm_extruded")
|
|
||||||
.HasPrecision(12, 2);
|
|
||||||
|
|
||||||
builder.Property(e => e.UsageTimestamp)
|
|
||||||
.HasColumnName("usage_timestamp")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
builder.Property(e => e.DataSource)
|
|
||||||
.HasColumnName("data_source")
|
|
||||||
.HasConversion<string>()
|
|
||||||
.HasMaxLength(50)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
builder.Property(e => e.Notes)
|
|
||||||
.HasColumnName("notes")
|
|
||||||
.HasMaxLength(2000);
|
|
||||||
|
|
||||||
// Index on spool_id for querying usage by spool
|
|
||||||
builder.HasIndex(e => e.SpoolId)
|
|
||||||
.HasDatabaseName("ix_usage_logs_spool_id");
|
|
||||||
|
|
||||||
// Index on printer_id for querying usage by printer
|
|
||||||
builder.HasIndex(e => e.PrinterId)
|
|
||||||
.HasDatabaseName("ix_usage_logs_printer_id");
|
|
||||||
|
|
||||||
// Index on print_job_id for querying usage by print job
|
|
||||||
builder.HasIndex(e => e.PrintJobId)
|
|
||||||
.HasDatabaseName("ix_usage_logs_print_job_id");
|
|
||||||
|
|
||||||
// Index on usage_timestamp for chronological queries
|
|
||||||
builder.HasIndex(e => e.UsageTimestamp)
|
|
||||||
.HasDatabaseName("ix_usage_logs_usage_timestamp");
|
|
||||||
|
|
||||||
// Index on data_source for filtering by integration path
|
|
||||||
builder.HasIndex(e => e.DataSource)
|
|
||||||
.HasDatabaseName("ix_usage_logs_data_source");
|
|
||||||
|
|
||||||
// Relationships
|
|
||||||
builder.HasOne(e => e.Spool)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey(e => e.SpoolId)
|
|
||||||
.HasConstraintName("fk_usage_logs_spool")
|
|
||||||
.OnDelete(DeleteBehavior.Restrict);
|
|
||||||
|
|
||||||
builder.HasOne(e => e.Printer)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey(e => e.PrinterId)
|
|
||||||
.HasConstraintName("fk_usage_logs_printer")
|
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
|
||||||
|
|
||||||
builder.HasOne(e => e.PrintJob)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey(e => e.PrintJobId)
|
|
||||||
.HasConstraintName("fk_usage_logs_print_job")
|
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +1,79 @@
|
|||||||
|
using Extrudex.Domain.Base;
|
||||||
|
using Extrudex.Domain.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Extrudex.Infrastructure.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Main EF Core database context for the Extrudex system.
|
||||||
|
/// Handles entity registration, snake_case naming, and automatic timestamp management.
|
||||||
|
/// </summary>
|
||||||
|
public class ExtrudexDbContext : DbContext
|
||||||
|
{
|
||||||
|
public ExtrudexDbContext(DbContextOptions<ExtrudexDbContext> options) : base(options) { }
|
||||||
|
|
||||||
|
// Lookup tables
|
||||||
|
public DbSet<MaterialBase> MaterialBases => Set<MaterialBase>();
|
||||||
|
public DbSet<MaterialFinish> MaterialFinishes => Set<MaterialFinish>();
|
||||||
|
public DbSet<MaterialModifier> MaterialModifiers => Set<MaterialModifier>();
|
||||||
|
|
||||||
|
// Core entities
|
||||||
|
public DbSet<Spool> Spools => Set<Spool>();
|
||||||
|
public DbSet<Printer> Printers => Set<Printer>();
|
||||||
|
public DbSet<AmsUnit> AmsUnits => Set<AmsUnit>();
|
||||||
|
public DbSet<AmsSlot> AmsSlots => Set<AmsSlot>();
|
||||||
|
public DbSet<PrintJob> PrintJobs => Set<PrintJob>();
|
||||||
|
public DbSet<FilamentUsage> FilamentUsages => Set<FilamentUsage>();
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
|
// Apply all entity type configurations from the assembly
|
||||||
|
modelBuilder.ApplyConfigurationsFromAssembly(typeof(ExtrudexDbContext).Assembly);
|
||||||
|
|
||||||
|
// Apply seed data
|
||||||
|
modelBuilder.Entity<MaterialBase>().HasData(SeedData.MaterialBases);
|
||||||
|
modelBuilder.Entity<MaterialFinish>().HasData(SeedData.MaterialFinishes);
|
||||||
|
modelBuilder.Entity<MaterialModifier>().HasData(SeedData.MaterialModifiers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Automatically set UpdatedAt on auditable entities during SaveChanges.
|
||||||
|
/// </summary>
|
||||||
|
public override int SaveChanges(bool acceptAllChangesOnSuccess)
|
||||||
|
{
|
||||||
|
SetAuditTimestamps();
|
||||||
|
return base.SaveChanges(acceptAllChangesOnSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<int> SaveChangesAsync(
|
||||||
|
bool acceptAllChangesOnSuccess,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
SetAuditTimestamps();
|
||||||
|
return await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets UpdatedAt on all auditable entities that have been modified.
|
||||||
|
/// Sets CreatedAt on all auditable entities that are being added.
|
||||||
|
/// </summary>
|
||||||
|
private void SetAuditTimestamps()
|
||||||
|
{
|
||||||
|
var entries = ChangeTracker.Entries<AuditableEntity>();
|
||||||
|
|
||||||
|
foreach (var entry in entries)
|
||||||
|
{
|
||||||
|
if (entry.State == EntityState.Added)
|
||||||
|
{
|
||||||
|
entry.Entity.CreatedAt = DateTime.UtcNow;
|
||||||
|
entry.Entity.UpdatedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
else if (entry.State == EntityState.Modified)
|
||||||
|
{
|
||||||
|
entry.Entity.UpdatedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,534 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace Extrudex.Infrastructure.Data.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class AddUsageLogTable : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "usage_logs",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
||||||
spool_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
||||||
printer_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
||||||
print_job_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
||||||
grams_used = table.Column<decimal>(type: "numeric(10,2)", precision: 10, scale: 2, nullable: false),
|
|
||||||
mm_extruded = table.Column<decimal>(type: "numeric(12,2)", precision: 12, scale: 2, nullable: true),
|
|
||||||
usage_timestamp = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
||||||
data_source = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
||||||
notes = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
|
|
||||||
created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
|
|
||||||
updated_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'")
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_usage_logs", x => x.id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "fk_usage_logs_print_job",
|
|
||||||
column: x => x.print_job_id,
|
|
||||||
principalTable: "print_jobs",
|
|
||||||
principalColumn: "id",
|
|
||||||
onDelete: ReferentialAction.SetNull);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "fk_usage_logs_printer",
|
|
||||||
column: x => x.printer_id,
|
|
||||||
principalTable: "printers",
|
|
||||||
principalColumn: "id",
|
|
||||||
onDelete: ReferentialAction.SetNull);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "fk_usage_logs_spool",
|
|
||||||
column: x => x.spool_id,
|
|
||||||
principalTable: "spools",
|
|
||||||
principalColumn: "id",
|
|
||||||
onDelete: ReferentialAction.Restrict);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000001"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(6535), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(6535) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000002"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7016), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7016) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000003"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7027), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7028) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000004"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7034), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7035) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000005"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7042), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7042) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000006"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7049), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7049) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000001"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7291), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7292) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000002"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7453), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7453) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000003"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7461), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7461) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000004"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7468), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7468) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000005"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7474), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7474) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000006"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7480), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7481) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000007"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7487), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7487) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000008"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7493), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7493) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000009"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7500), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7500) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000010"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7507), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7507) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000011"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7513), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7513) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000012"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7519), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7520) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000013"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7526), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7526) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000014"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7532), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7532) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000015"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7538), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7539) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000001"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7690), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7690) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000002"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7838), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7838) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000003"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7846), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7846) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000004"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7853), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7853) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000005"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7859), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7859) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000006"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7865), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7866) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000007"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7872), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7872) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000008"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7878), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7879) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000009"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7885), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7885) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000010"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7891), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7891) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000011"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7898), new DateTime(2026, 4, 26, 18, 43, 28, 895, DateTimeKind.Utc).AddTicks(7898) });
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "ix_usage_logs_data_source",
|
|
||||||
table: "usage_logs",
|
|
||||||
column: "data_source");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "ix_usage_logs_print_job_id",
|
|
||||||
table: "usage_logs",
|
|
||||||
column: "print_job_id");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "ix_usage_logs_printer_id",
|
|
||||||
table: "usage_logs",
|
|
||||||
column: "printer_id");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "ix_usage_logs_spool_id",
|
|
||||||
table: "usage_logs",
|
|
||||||
column: "spool_id");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "ix_usage_logs_usage_timestamp",
|
|
||||||
table: "usage_logs",
|
|
||||||
column: "usage_timestamp");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "usage_logs");
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000001"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1096), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1096) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000002"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1620), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1620) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000003"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1630), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1630) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000004"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1638), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1638) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000005"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1645), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1645) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_bases",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("10000000-0000-0000-0000-000000000006"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1651), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1652) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000001"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1850), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(1850) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000002"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2041), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2041) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000003"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2049), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2049) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000004"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2055), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2056) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000005"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2062), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2062) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000006"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2068), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2068) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000007"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2075), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2075) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000008"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2081), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2081) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000009"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2100), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2100) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000010"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2107), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2107) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000011"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2113), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2113) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000012"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2120), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2120) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000013"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2126), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2126) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000014"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2132), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2133) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_finishes",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("20000000-0000-0000-0000-000000000015"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2139), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2139) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000001"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2304), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2304) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000002"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2463), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2463) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000003"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2471), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2471) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000004"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2477), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2478) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000005"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2484), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2484) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000006"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2490), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2491) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000007"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2497), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2497) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000008"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2503), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2503) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000009"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2510), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2510) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000010"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2516), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2516) });
|
|
||||||
|
|
||||||
migrationBuilder.UpdateData(
|
|
||||||
table: "material_modifiers",
|
|
||||||
keyColumn: "id",
|
|
||||||
keyValue: new Guid("30000000-0000-0000-0000-000000000011"),
|
|
||||||
columns: new[] { "created_at", "updated_at" },
|
|
||||||
values: new object[] { new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2522), new DateTime(2026, 4, 26, 13, 14, 18, 745, DateTimeKind.Utc).AddTicks(2523) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
using Extrudex.Domain.Entities;
|
|
||||||
using Extrudex.Domain.Enums;
|
|
||||||
using Extrudex.Domain.Interfaces;
|
|
||||||
using Extrudex.Infrastructure.Data;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace Extrudex.Infrastructure.Services;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Implementation of <see cref="IUsageLogService"/> that persists usage entries
|
|
||||||
/// to the usage_logs table via EF Core.
|
|
||||||
/// </summary>
|
|
||||||
public class UsageLogService : IUsageLogService
|
|
||||||
{
|
|
||||||
private readonly ExtrudexDbContext _dbContext;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="UsageLogService"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dbContext">The EF Core database context for data persistence.</param>
|
|
||||||
public UsageLogService(ExtrudexDbContext dbContext)
|
|
||||||
{
|
|
||||||
_dbContext = dbContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public async Task<UsageLog> RecordUsageAsync(
|
|
||||||
Guid spoolId,
|
|
||||||
decimal gramsUsed,
|
|
||||||
DataSource dataSource,
|
|
||||||
Guid? printerId = null,
|
|
||||||
Guid? printJobId = null,
|
|
||||||
decimal? mmExtruded = null,
|
|
||||||
DateTime? usageTimestamp = null,
|
|
||||||
string? notes = null)
|
|
||||||
{
|
|
||||||
var entry = new UsageLog
|
|
||||||
{
|
|
||||||
SpoolId = spoolId,
|
|
||||||
GramsUsed = gramsUsed,
|
|
||||||
DataSource = dataSource,
|
|
||||||
PrinterId = printerId,
|
|
||||||
PrintJobId = printJobId,
|
|
||||||
MmExtruded = mmExtruded,
|
|
||||||
UsageTimestamp = usageTimestamp ?? DateTime.UtcNow,
|
|
||||||
Notes = notes
|
|
||||||
};
|
|
||||||
|
|
||||||
_dbContext.UsageLogs.Add(entry);
|
|
||||||
await _dbContext.SaveChangesAsync();
|
|
||||||
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public async Task<IEnumerable<UsageLog>> GetBySpoolAsync(Guid spoolId, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
return await _dbContext.UsageLogs
|
|
||||||
.Where(u => u.SpoolId == spoolId)
|
|
||||||
.OrderByDescending(u => u.UsageTimestamp)
|
|
||||||
.ToListAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public async Task<IEnumerable<UsageLog>> GetByPrinterAsync(Guid printerId, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
return await _dbContext.UsageLogs
|
|
||||||
.Where(u => u.PrinterId == printerId)
|
|
||||||
.OrderByDescending(u => u.UsageTimestamp)
|
|
||||||
.ToListAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public async Task<IEnumerable<UsageLog>> GetByPrintJobAsync(Guid printJobId, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
return await _dbContext.UsageLogs
|
|
||||||
.Where(u => u.PrintJobId == printJobId)
|
|
||||||
.OrderByDescending(u => u.UsageTimestamp)
|
|
||||||
.ToListAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -50,9 +50,6 @@ builder.Services.AddSwaggerGen(c =>
|
|||||||
// ── QR Code Generation ──────────────────────────────────────
|
// ── QR Code Generation ──────────────────────────────────────
|
||||||
builder.Services.AddSingleton<IQrCodeService, QrCodeService>();
|
builder.Services.AddSingleton<IQrCodeService, QrCodeService>();
|
||||||
|
|
||||||
// ── Usage Logging ───────────────────────────────────────────
|
|
||||||
builder.Services.AddScoped<IUsageLogService, UsageLogService>();
|
|
||||||
|
|
||||||
// ── FluentValidation ──────────────────────────────────────
|
// ── FluentValidation ──────────────────────────────────────
|
||||||
// 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());
|
||||||
|
|||||||
16
frontend/package-lock.json
generated
16
frontend/package-lock.json
generated
@@ -8,6 +8,7 @@
|
|||||||
"name": "frontend",
|
"name": "frontend",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@angular/animations": "^21.2.10",
|
||||||
"@angular/cdk": "^21.2.8",
|
"@angular/cdk": "^21.2.8",
|
||||||
"@angular/common": "^21.2.0",
|
"@angular/common": "^21.2.0",
|
||||||
"@angular/compiler": "^21.2.0",
|
"@angular/compiler": "^21.2.0",
|
||||||
@@ -326,6 +327,21 @@
|
|||||||
"yarn": ">= 1.13.0"
|
"yarn": ">= 1.13.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@angular/animations": {
|
||||||
|
"version": "21.2.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/@angular/animations/-/animations-21.2.10.tgz",
|
||||||
|
"integrity": "sha512-sIzAcxwtRCJ/fu0tK4mo1ooiEaDxJ+Nl6s9nK1D1NP1em12VX03Jx8CMixp/kVtgh4mZnm1x6psBB0FUz3U3Ug==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.3.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@angular/core": "21.2.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@angular/build": {
|
"node_modules/@angular/build": {
|
||||||
"version": "21.2.8",
|
"version": "21.2.8",
|
||||||
"resolved": "https://registry.npmjs.org/@angular/build/-/build-21.2.8.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/build/-/build-21.2.8.tgz",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"packageManager": "npm@11.11.0",
|
"packageManager": "npm@11.11.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@angular/animations": "^21.2.10",
|
||||||
"@angular/cdk": "^21.2.8",
|
"@angular/cdk": "^21.2.8",
|
||||||
"@angular/common": "^21.2.0",
|
"@angular/common": "^21.2.0",
|
||||||
"@angular/compiler": "^21.2.0",
|
"@angular/compiler": "^21.2.0",
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core';
|
import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core';
|
||||||
import { provideRouter } from '@angular/router';
|
import { provideRouter } from '@angular/router';
|
||||||
|
import { provideHttpClient, withFetch } from '@angular/common/http';
|
||||||
|
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
||||||
|
|
||||||
import { routes } from './app.routes';
|
import { routes } from './app.routes';
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [
|
providers: [
|
||||||
provideBrowserGlobalErrorListeners(),
|
provideBrowserGlobalErrorListeners(),
|
||||||
provideRouter(routes)
|
provideRouter(routes),
|
||||||
|
provideHttpClient(withFetch()),
|
||||||
|
provideAnimationsAsync(),
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<!-- Delete Filament Confirmation Dialog -->
|
||||||
|
<h2 mat-dialog-title>
|
||||||
|
<mat-icon aria-hidden="true">warning</mat-icon>
|
||||||
|
Delete Filament Spool?
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<mat-dialog-content>
|
||||||
|
<p class="dialog-description">
|
||||||
|
You are about to permanently remove this filament spool from inventory.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Spool details card -->
|
||||||
|
<div class="spool-details" role="list" aria-label="Spool details">
|
||||||
|
<div class="detail-row" role="listitem">
|
||||||
|
<span class="detail-label">Material</span>
|
||||||
|
<span class="detail-value">{{ filament.materialBaseName }}{{ filament.materialFinishName ? ' — ' + filament.materialFinishName : '' }}{{ filament.materialModifierName ? ' (' + filament.materialModifierName + ')' : '' }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="detail-row" role="listitem">
|
||||||
|
<span class="detail-label">Brand</span>
|
||||||
|
<span class="detail-value">{{ filament.brand }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="detail-row" role="listitem">
|
||||||
|
<span class="detail-label">Color</span>
|
||||||
|
<span class="detail-value color-value">
|
||||||
|
<span class="color-swatch-inline"
|
||||||
|
[style.background-color]="filament.colorHex"
|
||||||
|
[attr.aria-label]="filament.colorName">
|
||||||
|
</span>
|
||||||
|
{{ filament.colorName }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="detail-row" role="listitem">
|
||||||
|
<span class="detail-label">Serial</span>
|
||||||
|
<span class="detail-value serial-value">{{ filament.spoolSerial }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="detail-row" role="listitem">
|
||||||
|
<span class="detail-label">Remaining</span>
|
||||||
|
<span class="detail-value">{{ formatWeight(filament.weightRemainingGrams) }} / {{ formatWeight(filament.weightTotalGrams) }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="detail-row" role="listitem">
|
||||||
|
<span class="detail-label">Status</span>
|
||||||
|
<span class="detail-value">
|
||||||
|
<span class="status-badge"
|
||||||
|
[class.active]="filament.isActive"
|
||||||
|
[class.inactive]="!filament.isActive">
|
||||||
|
{{ filament.isActive ? 'Active' : 'Inactive' }}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="dialog-warning">
|
||||||
|
<mat-icon aria-hidden="true">info</mat-icon>
|
||||||
|
This action cannot be undone.
|
||||||
|
</p>
|
||||||
|
</mat-dialog-content>
|
||||||
|
|
||||||
|
<mat-dialog-actions align="end">
|
||||||
|
<button mat-button
|
||||||
|
type="button"
|
||||||
|
(click)="onCancel()"
|
||||||
|
class="cancel-button">
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button mat-flat-button
|
||||||
|
type="button"
|
||||||
|
color="warn"
|
||||||
|
(click)="onConfirm()"
|
||||||
|
class="confirm-button">
|
||||||
|
<mat-icon aria-hidden="true">delete</mat-icon>
|
||||||
|
Delete Spool
|
||||||
|
</button>
|
||||||
|
</mat-dialog-actions>
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
/**
|
||||||
|
* Delete Filament Dialog Styles
|
||||||
|
* Touch-optimized confirmation dialog for spool removal
|
||||||
|
*/
|
||||||
|
|
||||||
|
$spacing-unit: 8px;
|
||||||
|
$color-critical: #ef4444;
|
||||||
|
$color-inactive: #94a3b8;
|
||||||
|
$color-active: #22c55e;
|
||||||
|
|
||||||
|
// Dialog title
|
||||||
|
h2[mat-dialog-title] {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: $spacing-unit;
|
||||||
|
color: $color-critical;
|
||||||
|
|
||||||
|
mat-icon {
|
||||||
|
font-size: 24px !important;
|
||||||
|
width: 24px !important;
|
||||||
|
height: 24px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description text
|
||||||
|
.dialog-description {
|
||||||
|
margin: 0 0 $spacing-unit * 2;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: var(--mat-sys-on-surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spool details card
|
||||||
|
.spool-details {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: $spacing-unit;
|
||||||
|
padding: $spacing-unit * 1.5;
|
||||||
|
background-color: var(--mat-sys-surface-container);
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: $spacing-unit * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: $spacing-unit * 0.5 0;
|
||||||
|
font-size: 14px;
|
||||||
|
|
||||||
|
&:not(:last-child) {
|
||||||
|
border-bottom: 1px solid var(--mat-sys-outline-variant);
|
||||||
|
padding-bottom: $spacing-unit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-label {
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--mat-sys-on-surface-variant);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-value {
|
||||||
|
font-weight: 400;
|
||||||
|
color: var(--mat-sys-on-surface);
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Color swatch inline
|
||||||
|
.color-swatch-inline {
|
||||||
|
display: inline-block;
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 1.5px solid rgba(0, 0, 0, 0.12);
|
||||||
|
vertical-align: middle;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-value {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serial value — monospace
|
||||||
|
.serial-value {
|
||||||
|
font-family: 'JetBrains Mono', 'Roboto Mono', monospace;
|
||||||
|
font-size: 13px;
|
||||||
|
letter-spacing: 0.02em;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status badge — matches filament table styling
|
||||||
|
.status-badge {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 10px;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background-color: rgba($color-active, 0.12);
|
||||||
|
color: $color-active;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.inactive {
|
||||||
|
background-color: rgba($color-inactive, 0.12);
|
||||||
|
color: $color-inactive;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warning text
|
||||||
|
.dialog-warning {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: $spacing-unit;
|
||||||
|
margin: 0;
|
||||||
|
font-size: 13px;
|
||||||
|
color: $color-critical;
|
||||||
|
|
||||||
|
mat-icon {
|
||||||
|
font-size: 18px !important;
|
||||||
|
width: 18px !important;
|
||||||
|
height: 18px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dialog action buttons
|
||||||
|
mat-dialog-actions {
|
||||||
|
padding-top: $spacing-unit * 2;
|
||||||
|
|
||||||
|
.cancel-button {
|
||||||
|
min-width: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-button {
|
||||||
|
min-width: 120px;
|
||||||
|
|
||||||
|
mat-icon {
|
||||||
|
font-size: 18px !important;
|
||||||
|
width: 18px !important;
|
||||||
|
height: 18px !important;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import {
|
||||||
|
MAT_DIALOG_DATA,
|
||||||
|
MatDialogRef,
|
||||||
|
MatDialogModule,
|
||||||
|
} from '@angular/material/dialog';
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
|
import { MatChipsModule } from '@angular/material/chips';
|
||||||
|
|
||||||
|
import { Filament } from '../../models/filament.model';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data passed into the delete confirmation dialog.
|
||||||
|
*/
|
||||||
|
export interface DeleteFilamentDialogData {
|
||||||
|
filament: Filament;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete confirmation dialog for filament spool removal.
|
||||||
|
*
|
||||||
|
* Displays spool details (material, brand, color, serial, remaining weight)
|
||||||
|
* and requires the user to confirm before deletion proceeds.
|
||||||
|
* Cancel dismisses the dialog with no action.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'app-delete-filament-dialog',
|
||||||
|
standalone: true,
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
MatDialogModule,
|
||||||
|
MatButtonModule,
|
||||||
|
MatIconModule,
|
||||||
|
MatChipsModule,
|
||||||
|
],
|
||||||
|
templateUrl: './delete-filament-dialog.component.html',
|
||||||
|
styleUrl: './delete-filament-dialog.component.scss',
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
|
})
|
||||||
|
export class DeleteFilamentDialogComponent {
|
||||||
|
private readonly dialogRef = inject(
|
||||||
|
MatDialogRef<DeleteFilamentDialogComponent, boolean>
|
||||||
|
);
|
||||||
|
readonly data: DeleteFilamentDialogData = inject(MAT_DIALOG_DATA);
|
||||||
|
|
||||||
|
/** The filament spool being considered for deletion */
|
||||||
|
readonly filament = this.data.filament;
|
||||||
|
|
||||||
|
/** Format weight for display in dialog */
|
||||||
|
formatWeight(grams: number): string {
|
||||||
|
if (grams >= 1000) {
|
||||||
|
return `${(grams / 1000).toFixed(1)}kg`;
|
||||||
|
}
|
||||||
|
return `${Math.round(grams)}g`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Cancel — close dialog with false (no deletion) */
|
||||||
|
onCancel(): void {
|
||||||
|
this.dialogRef.close(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Confirm — close dialog with true (proceed with deletion) */
|
||||||
|
onConfirm(): void {
|
||||||
|
this.dialogRef.close(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- Filament Inventory Table — with low stock indicators -->
|
<!-- Filament Inventory Table — with low stock indicators and delete actions -->
|
||||||
<div class="filament-table-container" role="region" aria-label="Filament inventory">
|
<div class="filament-table-container" role="region" aria-label="Filament inventory">
|
||||||
|
|
||||||
<!-- Low Stock Alert Banner — shown when critical or low stock spools exist -->
|
<!-- Low Stock Alert Banner — shown when critical or low stock spools exist -->
|
||||||
@@ -106,10 +106,32 @@
|
|||||||
</td>
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
<!-- Actions Column — delete button -->
|
||||||
|
<ng-container matColumnDef="actions">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Actions</th>
|
||||||
|
<td mat-cell *matCellDef="let filament">
|
||||||
|
<button mat-icon-button
|
||||||
|
type="button"
|
||||||
|
color="warn"
|
||||||
|
[attr.aria-label]="'Delete ' + filament.materialBaseName + ' — ' + filament.colorName"
|
||||||
|
matTooltip="Delete spool"
|
||||||
|
matTooltipPosition="above"
|
||||||
|
[disabled]="deleting() === filament.id"
|
||||||
|
(click)="onDeleteClick(filament)">
|
||||||
|
@if (deleting() === filament.id) {
|
||||||
|
<mat-icon aria-hidden="true">hourglass_empty</mat-icon>
|
||||||
|
} @else {
|
||||||
|
<mat-icon aria-hidden="true">delete</mat-icon>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
<tr mat-header-row *matHeaderRowDef="columns()"></tr>
|
<tr mat-header-row *matHeaderRowDef="columns()"></tr>
|
||||||
<tr mat-row *matRowDef="let row; columns: columns();"
|
<tr mat-row *matRowDef="let row; columns: columns();"
|
||||||
[class.row-critical]="classifyStockLevel(row) === 'critical'"
|
[class.row-critical]="classifyStockLevel(row) === 'critical'"
|
||||||
[class.row-low]="classifyStockLevel(row) === 'low'">
|
[class.row-low]="classifyStockLevel(row) === 'low'"
|
||||||
|
[class.row-deleting]="deleting() === row.id">
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
@@ -235,6 +235,20 @@ mat-chip {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actions column
|
||||||
|
.actions-cell {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Row being deleted — subtle fade
|
||||||
|
:host ::ng-deep .row-deleting {
|
||||||
|
opacity: 0.5;
|
||||||
|
pointer-events: none;
|
||||||
|
transition: opacity 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
// Empty state
|
// Empty state
|
||||||
.empty-state {
|
.empty-state {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
Component,
|
Component,
|
||||||
Input,
|
Input,
|
||||||
computed,
|
computed,
|
||||||
|
inject,
|
||||||
signal,
|
signal,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
@@ -12,12 +13,21 @@ import { MatIconModule } from '@angular/material/icon';
|
|||||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||||
import { MatSortModule, Sort } from '@angular/material/sort';
|
import { MatSortModule, Sort } from '@angular/material/sort';
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||||
|
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Filament,
|
Filament,
|
||||||
StockLevel,
|
StockLevel,
|
||||||
getRemainingPercent,
|
getRemainingPercent,
|
||||||
classifyStockLevel,
|
classifyStockLevel,
|
||||||
} from '../../models/filament.model';
|
} from '../../models/filament.model';
|
||||||
|
import { FilamentService } from '../../services/filament.service';
|
||||||
|
import {
|
||||||
|
DeleteFilamentDialogComponent,
|
||||||
|
DeleteFilamentDialogData,
|
||||||
|
} from '../delete-filament-dialog/delete-filament-dialog.component';
|
||||||
|
|
||||||
/** Display column definitions for the filament table */
|
/** Display column definitions for the filament table */
|
||||||
export type FilamentColumn =
|
export type FilamentColumn =
|
||||||
@@ -27,7 +37,8 @@ export type FilamentColumn =
|
|||||||
| 'serial'
|
| 'serial'
|
||||||
| 'remaining'
|
| 'remaining'
|
||||||
| 'stockLevel'
|
| 'stockLevel'
|
||||||
| 'status';
|
| 'status'
|
||||||
|
| 'actions';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-filament-table',
|
selector: 'app-filament-table',
|
||||||
@@ -40,16 +51,26 @@ export type FilamentColumn =
|
|||||||
MatProgressBarModule,
|
MatProgressBarModule,
|
||||||
MatTooltipModule,
|
MatTooltipModule,
|
||||||
MatSortModule,
|
MatSortModule,
|
||||||
|
MatButtonModule,
|
||||||
|
MatDialogModule,
|
||||||
|
MatSnackBarModule,
|
||||||
],
|
],
|
||||||
templateUrl: './filament-table.component.html',
|
templateUrl: './filament-table.component.html',
|
||||||
styleUrl: './filament-table.component.scss',
|
styleUrl: './filament-table.component.scss',
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class FilamentTableComponent {
|
export class FilamentTableComponent {
|
||||||
|
private readonly dialog = inject(MatDialog);
|
||||||
|
private readonly snackBar = inject(MatSnackBar);
|
||||||
|
private readonly filamentService = inject(FilamentService);
|
||||||
|
|
||||||
/** Filament data input — reactive signal for live updates */
|
/** Filament data input — reactive signal for live updates */
|
||||||
readonly filaments = signal<Filament[]>([]);
|
readonly filaments = signal<Filament[]>([]);
|
||||||
|
|
||||||
/** Columns to display — defaults to all columns */
|
/** Whether a delete operation is in progress */
|
||||||
|
readonly deleting = signal<string | null>(null);
|
||||||
|
|
||||||
|
/** Columns to display — defaults to all columns including actions */
|
||||||
@Input()
|
@Input()
|
||||||
set displayedColumns(cols: FilamentColumn[]) {
|
set displayedColumns(cols: FilamentColumn[]) {
|
||||||
this._displayedColumns.set(cols);
|
this._displayedColumns.set(cols);
|
||||||
@@ -65,6 +86,7 @@ export class FilamentTableComponent {
|
|||||||
'remaining',
|
'remaining',
|
||||||
'stockLevel',
|
'stockLevel',
|
||||||
'status',
|
'status',
|
||||||
|
'actions',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/** Default columns for template binding */
|
/** Default columns for template binding */
|
||||||
@@ -252,6 +274,52 @@ export class FilamentTableComponent {
|
|||||||
this.sortedFilaments.set(sorted);
|
this.sortedFilaments.set(sorted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the delete confirmation dialog for a filament spool.
|
||||||
|
* On confirm: calls DELETE endpoint and removes the row on success.
|
||||||
|
* On cancel: dialog dismissed, no action taken.
|
||||||
|
*/
|
||||||
|
onDeleteClick(filament: Filament): void {
|
||||||
|
const dialogData: DeleteFilamentDialogData = { filament };
|
||||||
|
const dialogRef = this.dialog.open(DeleteFilamentDialogComponent, {
|
||||||
|
data: dialogData,
|
||||||
|
width: '480px',
|
||||||
|
disableClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
dialogRef.afterClosed().subscribe((confirmed: boolean | undefined) => {
|
||||||
|
if (!confirmed) {
|
||||||
|
return; // User cancelled — no action
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark as deleting for UI feedback
|
||||||
|
this.deleting.set(filament.id);
|
||||||
|
|
||||||
|
this.filamentService.deleteFilament(filament.id).subscribe({
|
||||||
|
next: () => {
|
||||||
|
// Remove the deleted filament from local data
|
||||||
|
const updated = this.filaments().filter((f) => f.id !== filament.id);
|
||||||
|
this.updateFilaments(updated);
|
||||||
|
this.deleting.set(null);
|
||||||
|
|
||||||
|
this.snackBar.open(
|
||||||
|
`Deleted ${filament.materialBaseName} — ${filament.colorName}`,
|
||||||
|
'Dismiss',
|
||||||
|
{ duration: 4000 }
|
||||||
|
);
|
||||||
|
},
|
||||||
|
error: () => {
|
||||||
|
this.deleting.set(null);
|
||||||
|
this.snackBar.open(
|
||||||
|
`Failed to delete ${filament.materialBaseName} — ${filament.colorName}. Please try again.`,
|
||||||
|
'Dismiss',
|
||||||
|
{ duration: 6000 }
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** Template helper: get remaining percent */
|
/** Template helper: get remaining percent */
|
||||||
getRemainingPercent = getRemainingPercent;
|
getRemainingPercent = getRemainingPercent;
|
||||||
|
|
||||||
|
|||||||
37
frontend/src/app/services/filament.service.ts
Normal file
37
frontend/src/app/services/filament.service.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { Injectable, inject } from '@angular/core';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
|
import { Filament } from '../models/filament.model';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API base URL — matches the Extrudex backend default.
|
||||||
|
* TODO: Move to environment config when multi-environment support is added.
|
||||||
|
*/
|
||||||
|
const API_BASE_URL = '/api';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service for CRUD operations on filament spools.
|
||||||
|
* Communicates with the Extrudex backend SpoolsController.
|
||||||
|
*/
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class FilamentService {
|
||||||
|
private readonly http = inject(HttpClient);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all filament spools from the backend.
|
||||||
|
* GET /api/spools
|
||||||
|
*/
|
||||||
|
getFilaments(): Observable<Filament[]> {
|
||||||
|
return this.http.get<Filament[]>(`${API_BASE_URL}/spools`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Soft-delete a filament spool by ID.
|
||||||
|
* DELETE /api/spools/{id}
|
||||||
|
* Returns 204 No Content on success.
|
||||||
|
*/
|
||||||
|
deleteFilament(id: string): Observable<void> {
|
||||||
|
return this.http.delete<void>(`${API_BASE_URL}/spools/${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user