| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 3 | | using MechanicsSoftware.Domain.Entities; |
| | | 4 | | using MechanicsSoftware.Domain.ValueObjects; |
| | | 5 | | using MechanicsSoftware.Domain.Enums; |
| | | 6 | | using MechanicsSoftware.Domain.Exceptions; |
| | | 7 | | |
| | | 8 | | namespace MechanicsSoftware.Infrastructure.Persistence.Configurations; |
| | | 9 | | |
| | | 10 | | public sealed class ServiceConfiguration : IEntityTypeConfiguration<Service> |
| | 1 | 11 | | { |
| | 1 | 12 | | public void Configure(EntityTypeBuilder<Service> builder) |
| | 2 | 13 | | { |
| | 3 | 14 | | builder.ToTable("services"); |
| | 1 | 15 | | |
| | 2 | 16 | | builder.HasKey(s => s.Id); |
| | 3 | 17 | | builder.Property(s => s.Id).HasColumnName("id"); |
| | 1 | 18 | | |
| | 3 | 19 | | builder.Property(s => s.Name) |
| | 3 | 20 | | .HasColumnName("name") |
| | 2 | 21 | | .HasMaxLength(100) |
| | 3 | 22 | | .IsRequired(); |
| | 1 | 23 | | |
| | 3 | 24 | | builder.Property(s => s.Description) |
| | 2 | 25 | | .HasColumnName("description") |
| | 3 | 26 | | .HasMaxLength(500); |
| | 1 | 27 | | |
| | 3 | 28 | | builder.Property(s => s.BasePrice) |
| | 3 | 29 | | .HasConversion( |
| | 3 | 30 | | m => m.Cents, |
| | 3 | 31 | | m => new Money(m)) |
| | 2 | 32 | | .HasColumnName("base_price") |
| | 3 | 33 | | .IsRequired(); |
| | 1 | 34 | | |
| | 3 | 35 | | builder.Property(s => s.EstimatedMinutes) |
| | 2 | 36 | | .HasColumnName("estimated_minutes") |
| | 3 | 37 | | .IsRequired(); |
| | 1 | 38 | | |
| | 3 | 39 | | builder.HasIndex(s => s.Name) |
| | 3 | 40 | | .IsUnique() |
| | 2 | 41 | | .HasDatabaseName("ix_services_name"); |
| | 2 | 42 | | } |
| | | 43 | | } |