Web Api layout
This commit is contained in:
parent
5619093f41
commit
da6d5576bf
32 changed files with 515 additions and 29 deletions
18
shared/InkForge.Data/Domain/Note.cs
Normal file
18
shared/InkForge.Data/Domain/Note.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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!;
|
||||
}
|
||||
8
shared/InkForge.Data/Infrastructure/Blob.cs
Normal file
8
shared/InkForge.Data/Infrastructure/Blob.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
namespace InkForge.Data;
|
||||
|
||||
public class Blob
|
||||
{
|
||||
public string Id { get; set; } = default!;
|
||||
|
||||
public byte[] Content { get; set; } = default!;
|
||||
}
|
||||
25
shared/InkForge.Data/Infrastructure/Entities.cs
Normal file
25
shared/InkForge.Data/Infrastructure/Entities.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System.Numerics;
|
||||
|
||||
namespace InkForge.Data
|
||||
{
|
||||
public abstract class ValueEntity<TEntity>
|
||||
{
|
||||
public TEntity Value { get; set; } = default!;
|
||||
}
|
||||
|
||||
public abstract class Entity<TEntity, TKey>
|
||||
: ValueEntity<TEntity>
|
||||
where TKey : struct, INumber<TKey>
|
||||
{
|
||||
public TKey? Id { get; set; }
|
||||
}
|
||||
|
||||
public abstract class VersionedEntity<TEntity, TKey>
|
||||
: ValueEntity<TEntity>
|
||||
where TKey : struct, INumber<TKey>
|
||||
{
|
||||
public TKey Id { get; set; }
|
||||
|
||||
public int? Version { get; set; }
|
||||
}
|
||||
}
|
||||
8
shared/InkForge.Data/Infrastructure/NoteEntities.cs
Normal file
8
shared/InkForge.Data/Infrastructure/NoteEntities.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using InkForge.Data.Domain;
|
||||
|
||||
namespace InkForge.Data.Infrastructure
|
||||
{
|
||||
public class NoteEntity : Entity<Note, int>;
|
||||
|
||||
public class NoteVersionEntity : VersionedEntity<Note, int>;
|
||||
}
|
||||
|
|
@ -7,4 +7,8 @@
|
|||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
34
shared/InkForge.Data/NoteDbContext.cs
Normal file
34
shared/InkForge.Data/NoteDbContext.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using InkForge.Data.Infrastructure;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace InkForge.Data;
|
||||
|
||||
public class NoteDbContext(
|
||||
DbContextOptions<NoteDbContext> options
|
||||
) : DbContext(options)
|
||||
{
|
||||
public DbSet<Blob> Blobs { get; set; } = default!;
|
||||
|
||||
public DbSet<NoteEntity> Notes { get; set; } = default!;
|
||||
|
||||
public DbSet<NoteVersionEntity> NoteVersions { get; set; } = default!;
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue