Add a Creator property on Content
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
namespace Hutopy.Web.Features.Contents.Data;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Data;
|
||||
|
||||
public class Content
|
||||
{
|
||||
public Guid Id { get; init; }
|
||||
public Guid CreatedBy { get; init; }
|
||||
public Creator? Creator { get; set; }
|
||||
public DateTimeOffset CreatedAt { get; init; }
|
||||
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
[MaxLength(128)] public required string Title { get; set; }
|
||||
[MaxLength(2048)] public required string Description { get; set; }
|
||||
public string[]? Urls { get; init; }
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@ public class ContentDbContext(
|
||||
.Property(c => c.CreatedAt)
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
|
||||
modelBuilder
|
||||
.Entity<Content>()
|
||||
.HasOne(c => c.Creator)
|
||||
.WithMany()
|
||||
.HasForeignKey(c => c.CreatedBy);
|
||||
|
||||
modelBuilder
|
||||
.Entity<Creator>()
|
||||
@@ -41,19 +47,4 @@ public class ContentDbContext(
|
||||
.OwnsOne<StoredDataUrls>(x => x.StoredDataUrls)
|
||||
.ToTable(nameof(StoredDataUrls));
|
||||
}
|
||||
|
||||
public async Task<Creator?> FindByCreatorAliasAsync(
|
||||
string creatorAlias,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrEmpty(creatorAlias);
|
||||
|
||||
var user = await Creators.SingleOrDefaultAsync(creator =>
|
||||
EF.Functions.Like(
|
||||
creatorAlias,
|
||||
creator.Name),
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user