| | | 1 | | // SPDX-FileCopyrightText: 2026 Alper Çelik <[email protected]> |
| | | 2 | | // |
| | | 3 | | // SPDX-License-Identifier: AGPL-3.0-or-later |
| | | 4 | | |
| | | 5 | | using System.ComponentModel.DataAnnotations; |
| | | 6 | | using System.ComponentModel.DataAnnotations.Schema; |
| | | 7 | | |
| | | 8 | | using Microsoft.EntityFrameworkCore; |
| | | 9 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 10 | | |
| | | 11 | | using Riok.Mapperly.Abstractions; |
| | | 12 | | |
| | | 13 | | namespace Api.Works.Models; |
| | | 14 | | |
| | | 15 | | [Table("authors")] |
| | | 16 | | public class Author : IEntityMetadata |
| | | 17 | | { |
| | | 18 | | [Key] |
| | | 19 | | public Guid Id { get; set; } |
| | | 20 | | public int RowVersion { get; set; } |
| | | 21 | | public NodaTime.Instant MetadataAddedAt { get; set; } |
| | | 22 | | public NodaTime.Instant MetadataUpdatedAt { get; set; } |
| | | 23 | | |
| | | 24 | | public string? FirstName { get; set; } |
| | | 25 | | |
| | | 26 | | public string? LastName { get; set; } |
| | | 27 | | |
| | | 28 | | public required string DisplayName { get; set; } |
| | | 29 | | |
| | | 30 | | public required List<string> PenNames { get; set; } |
| | | 31 | | |
| | | 32 | | // Navigation Properties |
| | | 33 | | [MapperIgnore] |
| | | 34 | | public List<Work> Works { get; set; } = []; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | [Table("work___author")] |
| | | 38 | | [PrimaryKey(nameof(WorkId), nameof(AuthorId))] |
| | | 39 | | public class Work_Author |
| | | 40 | | { |
| | | 41 | | public Guid WorkId { get; set; } |
| | | 42 | | public Guid AuthorId { get; set; } |
| | | 43 | | |
| | | 44 | | // Navigation Properties |
| | 0 | 45 | | public Work Work { get; set; } = null!; |
| | 0 | 46 | | public Author Author { get; set; } = null!; |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | public class AuthorTypeConfiguration : IEntityTypeConfiguration<Author> |
| | | 50 | | { |
| | | 51 | | public void Configure(EntityTypeBuilder<Author> builder) |
| | | 52 | | { |
| | | 53 | | builder |
| | | 54 | | .HasMany(a => a.Works) |
| | | 55 | | .WithMany(w => w.Authors) |
| | | 56 | | .UsingEntity(typeof(Work_Author)); |
| | | 57 | | } |
| | | 58 | | } |