Hold on Subscriptions
This commit is contained in:
@@ -8,6 +8,10 @@ public class ContentDbContext(
|
|||||||
{
|
{
|
||||||
public const string SchemaName = "Content";
|
public const string SchemaName = "Content";
|
||||||
|
|
||||||
|
public DbSet<Content> Contents => Set<Content>();
|
||||||
|
public DbSet<Creator> Creators => Set<Creator>();
|
||||||
|
public DbSet<Subscription> Subscriptions => Set<Subscription>();
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.HasDefaultSchema("Content");
|
modelBuilder.HasDefaultSchema("Content");
|
||||||
@@ -24,21 +28,20 @@ public class ContentDbContext(
|
|||||||
|
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.Entity<Creator>()
|
.Entity<Creator>()
|
||||||
.OwnsOne<SocialNetworks>(x => x.SocialNetworks);
|
.OwnsOne<SocialNetworks>(x => x.SocialNetworks)
|
||||||
|
.ToTable(nameof(SocialNetworks));
|
||||||
|
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.Entity<Creator>()
|
.Entity<Creator>()
|
||||||
.OwnsOne<ProfileColors>(x => x.ProfileColors);
|
.OwnsOne<ProfileColors>(x => x.ProfileColors)
|
||||||
|
.ToTable(nameof(ProfileColors));
|
||||||
|
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.Entity<Creator>()
|
.Entity<Creator>()
|
||||||
.OwnsOne<StoredDataUrls>(x => x.StoredDataUrls);
|
.OwnsOne<StoredDataUrls>(x => x.StoredDataUrls)
|
||||||
|
.ToTable(nameof(StoredDataUrls));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DbSet<Content> Contents { get; init; } = null!;
|
|
||||||
public DbSet<Creator> Creators { get; init; } = null!;
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<Creator?> FindByCreatorAliasAsync(
|
public async Task<Creator?> FindByCreatorAliasAsync(
|
||||||
string creatorAlias,
|
string creatorAlias,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
|
|||||||
9
src/Web/Features/Contents/Data/Subscription.cs
Normal file
9
src/Web/Features/Contents/Data/Subscription.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Hutopy.Web.Features.Contents.Data;
|
||||||
|
|
||||||
|
public class Subscription
|
||||||
|
{
|
||||||
|
public Guid Id { get; init; }
|
||||||
|
public Guid CreatorId { get; init; }
|
||||||
|
public Guid CreatedBy { get; init; }
|
||||||
|
public DateTimeOffset CreatedAt { get; init; }
|
||||||
|
}
|
||||||
@@ -28,7 +28,7 @@ public class GetCreatorByAliasHandler(
|
|||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/creators/@{Name}");
|
Get("/api/creators/@{Name}");
|
||||||
Options((o => o.WithTags("Creators")));
|
Options((o => o.WithTags("Contents")));
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class GetCreatorByIdHandler(
|
|||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/creators/{CreatorId}");
|
Get("/api/creators/{CreatorId}");
|
||||||
Options((o => o.WithTags("Creators")));
|
Options((o => o.WithTags("Contents")));
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
src/Web/Features/Contents/Handlers/GetSubscriptions.cs
Normal file
31
src/Web/Features/Contents/Handlers/GetSubscriptions.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Hutopy.Web.Common;
|
||||||
|
using Hutopy.Web.Features.Contents.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||||
|
|
||||||
|
public class GetSubscriptionsHandler(
|
||||||
|
ContentDbContext context)
|
||||||
|
: EndpointWithoutRequest
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/api/subscriptions");
|
||||||
|
Options((o => o.WithTags("Creators")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(
|
||||||
|
CancellationToken ct)
|
||||||
|
{
|
||||||
|
var userId = HttpContext.User.GetUserId();
|
||||||
|
|
||||||
|
await context
|
||||||
|
.Subscriptions
|
||||||
|
.Where(s => s.CreatedBy == userId)
|
||||||
|
.Include(s => s.Creator)
|
||||||
|
.ToListAsync(cancellationToken: ct);
|
||||||
|
|
||||||
|
await SendOkAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/Web/Features/Contents/Handlers/SubscripbeFromCreator.cs
Normal file
21
src/Web/Features/Contents/Handlers/SubscripbeFromCreator.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||||
|
|
||||||
|
public record UnsubscribeFromCreatorRequest(
|
||||||
|
Guid CreatorId);
|
||||||
|
|
||||||
|
public class UnsubscribeFromCreatorHandler
|
||||||
|
: Endpoint<UnsubscribeFromCreatorRequest>
|
||||||
|
{ public override void Configure()
|
||||||
|
{
|
||||||
|
Post("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(
|
||||||
|
UnsubscribeFromCreatorRequest req,
|
||||||
|
CancellationToken ct)
|
||||||
|
{
|
||||||
|
return base.HandleAsync(req, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/Web/Features/Contents/Handlers/SubscripbeToCreator.cs
Normal file
30
src/Web/Features/Contents/Handlers/SubscripbeToCreator.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Hutopy.Web.Common;
|
||||||
|
using Hutopy.Web.Features.Contents.Data;
|
||||||
|
|
||||||
|
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||||
|
|
||||||
|
public record SubscribeToCreatorRequest(
|
||||||
|
Guid CreatorId);
|
||||||
|
|
||||||
|
public sealed class SubscribeToCreatorHandler(
|
||||||
|
ContentDbContext context)
|
||||||
|
: Endpoint<UnsubscribeFromCreatorRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/api/creators/{CreatorId}/subscribe");
|
||||||
|
Options((o => o.WithTags("Creators")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(
|
||||||
|
UnsubscribeFromCreatorRequest req,
|
||||||
|
CancellationToken ct)
|
||||||
|
{
|
||||||
|
await context.Subscriptions.AddAsync(
|
||||||
|
new() { CreatedBy = HttpContext.User.GetUserId(), CreatorId = req.CreatorId },
|
||||||
|
ct);
|
||||||
|
|
||||||
|
await SendOkAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user