| | | 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("works")] |
| | | 16 | | public class Work : 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 | | |
| | | 25 | | [MapperIgnore] |
| | | 26 | | public Guid OwnerId { get; set; } |
| | | 27 | | |
| | | 28 | | public required string Title { get; set; } |
| | | 29 | | |
| | | 30 | | public string? Description { get; set; } |
| | | 31 | | |
| | | 32 | | public NodaTime.ZonedDateTime? WorkPublishedAt { get; set; } |
| | | 33 | | public NodaTime.ZonedDateTime? WorkUpdatedAt { get; set; } |
| | | 34 | | public List<WorkIdentifier> WorkIdentifiers { get; set; } = []; |
| | | 35 | | |
| | | 36 | | // Navigation Properties |
| | | 37 | | public List<WorkTag> WorkTags { get; set; } = []; |
| | | 38 | | public List<Author> Authors { get; set; } = []; |
| | | 39 | | |
| | | 40 | | [MapperIgnore] |
| | | 41 | | public List<WorkTag_Work> WorkTag_Works { get; set; } = []; |
| | | 42 | | [MapperIgnore] |
| | | 43 | | public List<Work_Author> Work_Authors { get; set; } = []; |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | public record WorkIdentifier( |
| | | 47 | | string WorkIdentifierType, |
| | | 48 | | string WorkIdentifierValue); |
| | | 49 | | |
| | | 50 | | public class WorkTypeConfiguration : IEntityTypeConfiguration<Work> |
| | | 51 | | { |
| | | 52 | | public void Configure(EntityTypeBuilder<Work> builder) |
| | 1 | 53 | | { |
| | 1 | 54 | | builder |
| | 1 | 55 | | .ComplexCollection(w => w.WorkIdentifiers, wid => wid.ToJson()) |
| | 1 | 56 | | .HasIndex(w => w.WorkIdentifiers.Select(wid => wid)); |
| | 1 | 57 | | } |
| | | 58 | | } |