| | | 1 | | using ArturRios.Heimdall.Domain.Entities; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Heimdall.Data.EntityMaps; |
| | | 6 | | |
| | | 7 | | internal static class ApplicationCredentialDbMap |
| | | 8 | | { |
| | | 9 | | public static void Configure(this EntityTypeBuilder<ApplicationCredential> credential) |
| | | 10 | | { |
| | 3 | 11 | | credential.ToTable("application_credential"); |
| | | 12 | | |
| | 3 | 13 | | credential.HasKey(x => x.Id); |
| | | 14 | | |
| | 3 | 15 | | credential.Property(x => x.PublicId).IsRequired(); |
| | 3 | 16 | | credential.HasIndex(x => x.PublicId).IsUnique(); |
| | | 17 | | |
| | | 18 | | // UC-56 looks a credential up by the hash of the presented secret, so the hash is indexed; |
| | | 19 | | // unique because two credentials sharing one would make that lookup ambiguous. |
| | 3 | 20 | | credential.Property(x => x.SecretHash).IsRequired(); |
| | 3 | 21 | | credential.HasIndex(x => x.SecretHash).IsUnique(); |
| | | 22 | | |
| | 3 | 23 | | credential.Property(x => x.CreatedAt).IsRequired(); |
| | | 24 | | |
| | | 25 | | // Credentials go with their application when it is hard-deleted (UC-20); a logical delete |
| | | 26 | | // leaves them, and UC-56/UC-57 refuse them through the application's flag. |
| | 3 | 27 | | credential.HasOne(x => x.Application) |
| | 3 | 28 | | .WithMany(a => a.Credentials) |
| | 3 | 29 | | .HasForeignKey(x => x.ApplicationId) |
| | 3 | 30 | | .IsRequired() |
| | 3 | 31 | | .OnDelete(DeleteBehavior.Cascade); |
| | 3 | 32 | | } |
| | | 33 | | } |