62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using AutobusApi.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace AutobusApi.Infrastructure.Data.Configurations;
|
|
|
|
public class ReviewConfiguration : EntityBaseConfiguration<Review>
|
|
{
|
|
public override void Configure(EntityTypeBuilder<Review> builder)
|
|
{
|
|
base.Configure(builder);
|
|
|
|
builder
|
|
.ToTable("reviews")
|
|
.HasKey(e => e.Id);
|
|
|
|
builder
|
|
.Property(r => r.Rating)
|
|
.HasColumnName("rating")
|
|
.HasColumnType("numeric(1,0)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(r => r.Comment)
|
|
.HasColumnName("comment")
|
|
.HasColumnType("varchar(128)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(r => r.PostDateTimeUtc)
|
|
.HasColumnName("post_timestamp_utc")
|
|
.HasColumnType("timestamptz")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(r => r.UserId)
|
|
.HasColumnName("user_id")
|
|
.HasColumnType("int")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.HasOne(r => r.User)
|
|
.WithMany(u => u.Reviews)
|
|
.HasForeignKey(r => r.UserId)
|
|
.HasConstraintName("fk_reviews_users_userId")
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder
|
|
.Property(r => r.VehicleEnrollmentId)
|
|
.HasColumnName("vehicle_enrollment_id")
|
|
.HasColumnType("int")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.HasOne(r => r.VehicleEnrollment)
|
|
.WithMany(ve => ve.Reviews)
|
|
.HasForeignKey(r => r.VehicleEnrollmentId)
|
|
.HasConstraintName("fk_reviews_vehicleEnrollments_vehicleEnrollmentId")
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|