Notes
This commit is contained in:
parent
4c2b5cca93
commit
43b4d50e43
28 changed files with 674 additions and 249 deletions
3
shared/InkForge.Data/Blob.cs
Normal file
3
shared/InkForge.Data/Blob.cs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
namespace InkForge.Data;
|
||||
|
||||
public class Blob : Entity<byte[], string>;
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
using InkForge.Data.Infrastructure;
|
||||
|
||||
namespace InkForge.Data.Domain;
|
||||
|
||||
public class Note
|
||||
{
|
||||
public DateTimeOffset Created { get; set; }
|
||||
|
||||
public NoteEntity? Parent { get; set; }
|
||||
|
||||
public string Name { get; set; } = default!;
|
||||
|
||||
public DateTimeOffset Updated { get; set; }
|
||||
|
||||
public DateTimeOffset? Deleted { get; set; }
|
||||
|
||||
public Blob Content { get; set; } = default!;
|
||||
}
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
using System.Numerics;
|
||||
|
||||
namespace InkForge.Data
|
||||
{
|
||||
public abstract class ValueEntity<TEntity>
|
||||
|
|
@ -10,14 +8,13 @@ namespace InkForge.Data
|
|||
public abstract class Entity<TEntity, TKey>
|
||||
: ValueEntity<TEntity>
|
||||
{
|
||||
public TKey? Id { get; set; }
|
||||
public TKey Id { get; set; } = default!;
|
||||
}
|
||||
|
||||
public abstract class VersionedEntity<TEntity, TKey>
|
||||
: ValueEntity<TEntity>
|
||||
public abstract class Entity<TSelf, TEntity, TKey>
|
||||
: Entity<TEntity, TKey>
|
||||
where TSelf : Entity<TSelf, TEntity, TKey>
|
||||
{
|
||||
public TKey Id { get; set; }
|
||||
|
||||
public int? Version { get; set; }
|
||||
public TSelf? Parent { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
namespace InkForge.Data;
|
||||
|
||||
public class Blob
|
||||
{
|
||||
public string Id { get; set; } = default!;
|
||||
|
||||
public byte[] Content { get; set; } = default!;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
namespace InkForge.Data.Infrastructure;
|
||||
|
||||
public class MetadataEntity : Entity<string, string>;
|
||||
|
||||
public class MetadataVersionEntity : VersionedEntity<string, string>;
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
using InkForge.Data.Domain;
|
||||
|
||||
namespace InkForge.Data.Infrastructure
|
||||
{
|
||||
public class NoteEntity : Entity<Note, int>;
|
||||
|
||||
public class NoteVersionEntity : VersionedEntity<Note, int>;
|
||||
}
|
||||
3
shared/InkForge.Data/Metadata.cs
Normal file
3
shared/InkForge.Data/Metadata.cs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
namespace InkForge.Data;
|
||||
|
||||
public class MetadataEntity : Entity<string, string>;
|
||||
|
|
@ -1,22 +1,19 @@
|
|||
using InkForge.Data.Infrastructure;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace InkForge.Data;
|
||||
|
||||
public class NoteDbContext(
|
||||
DbContextOptions<NoteDbContext> options
|
||||
DbContextOptions options
|
||||
) : DbContext(options)
|
||||
{
|
||||
public DbSet<Blob> Blobs { get; set; } = default!;
|
||||
|
||||
public DbSet<MetadataEntity> Metadata { get; set; } = default!;
|
||||
|
||||
public DbSet<MetadataVersionEntity> MetadataHistory { get; set; } = default!;
|
||||
|
||||
public DbSet<NoteEntity> Notes { get; set; } = default!;
|
||||
|
||||
public DbSet<NoteVersionEntity> NoteVersions { get; set; } = default!;
|
||||
public NoteDbContext(DbContextOptions<NoteDbContext> options) : this((DbContextOptions)options)
|
||||
{ }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
|
@ -25,26 +22,13 @@ public class NoteDbContext(
|
|||
options.HasKey(m => m.Id);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<MetadataVersionEntity>(options =>
|
||||
{
|
||||
options.Property(m => m.Id).IsRequired();
|
||||
options.HasKey(m => m.Version);
|
||||
options.HasIndex(nameof(MetadataVersionEntity.Id), nameof(MetadataVersionEntity.Version)).IsUnique();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<NoteEntity>(options =>
|
||||
{
|
||||
options.OwnsOne(m => m.Value);
|
||||
|
||||
options.HasKey(m => m.Id);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<NoteVersionEntity>(options =>
|
||||
{
|
||||
options.OwnsOne(m => m.Value);
|
||||
options.Property(m => m.Id).IsRequired();
|
||||
options.HasKey(m => m.Version);
|
||||
options.HasIndex(nameof(NoteVersionEntity.Id), nameof(NoteVersionEntity.Version)).IsUnique();
|
||||
|
||||
options.HasOne(m => m.Parent);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
17
shared/InkForge.Data/Notes.cs
Normal file
17
shared/InkForge.Data/Notes.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
namespace InkForge.Data
|
||||
{
|
||||
public class Note
|
||||
{
|
||||
public DateTimeOffset Created { get; set; }
|
||||
|
||||
public string Name { get; set; } = default!;
|
||||
|
||||
public DateTimeOffset Updated { get; set; }
|
||||
|
||||
public DateTimeOffset? Deleted { get; set; }
|
||||
|
||||
public Blob Content { get; set; } = default!;
|
||||
}
|
||||
|
||||
public class NoteEntity : Entity<NoteEntity, Note, int>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue