Add subscription tiers and responsive navigation
This commit is contained in:
1 parent
289f7eebbe
commit
de1d3d2d63
24 files changed
+1290
-602
No files matched your search
@@ -71,9 +71,10 @@ namespace OnlyPrompt.Backend.Controllers
|
||||
x.Saves.Any(s => s.UserId == userId),
|
||||
x.SubscriptionTier == null ? (int?)null : x.SubscriptionTier.Level,
|
||||
x.SubscriptionTier == null ? null : x.SubscriptionTier.Name,
|
||||
x.SubscriptionTier == null ? (decimal?)null : x.SubscriptionTier.MonthlyPrice,
|
||||
x.Reviews.Average(r => (double?)r.Rating),
|
||||
x.Reviews.Count,
|
||||
x.SubscriptionTier == null || x.Creator.Subscribers.Any(s => s.SubscriberId == userId && x.SubscriptionTier.Level < s.SubscriptionTier.Level)
|
||||
x.SubscriptionTier == null || x.Creator.Subscribers.Any(s => s.SubscriberId == userId && x.SubscriptionTier.Level <= s.SubscriptionTier.Level)
|
||||
)).ToArrayAsync();
|
||||
|
||||
return prompts;
|
||||
|
||||
@@ -81,9 +81,10 @@ namespace OnlyPrompt.Backend.Controllers
|
||||
x.Saves.Any(s => s.UserId == userId),
|
||||
x.SubscriptionTier == null ? (int?)null : x.SubscriptionTier.Level,
|
||||
x.SubscriptionTier == null ? null : x.SubscriptionTier.Name,
|
||||
x.SubscriptionTier == null ? (decimal?)null : x.SubscriptionTier.MonthlyPrice,
|
||||
x.Reviews.Average(r => (double?)r.Rating),
|
||||
x.Reviews.Count,
|
||||
x.CreatorId == userId || ((x.Price == null || x.Price <= 0) && (x.SubscriptionTier == null || x.Creator.Subscribers.Any(s => s.SubscriberId == userId && x.SubscriptionTier.Level < s.SubscriptionTier.Level)))
|
||||
x.CreatorId == userId || x.SubscriptionTier == null || x.Creator.Subscribers.Any(s => s.SubscriberId == userId && x.SubscriptionTier.Level <= s.SubscriptionTier.Level)
|
||||
)).ToArrayAsync();
|
||||
|
||||
return prompts;
|
||||
@@ -112,6 +113,7 @@ namespace OnlyPrompt.Backend.Controllers
|
||||
x.Saves.Any(s => s.UserId == userId),
|
||||
x.SubscriptionTier == null ? (int?)null : x.SubscriptionTier.Level,
|
||||
x.SubscriptionTier == null ? null : x.SubscriptionTier.Name,
|
||||
x.SubscriptionTier == null ? (decimal?)null : x.SubscriptionTier.MonthlyPrice,
|
||||
x.Reviews.Average(r => (double?)r.Rating),
|
||||
x.Reviews.Count,
|
||||
true
|
||||
@@ -132,9 +134,6 @@ namespace OnlyPrompt.Backend.Controllers
|
||||
if (prompt is null)
|
||||
return TypedResults.NotFound("Prompt not found");
|
||||
|
||||
if (prompt.CreatorId != userId && prompt.Price.HasValue && prompt.Price.Value > 0)
|
||||
return TypedResults.NotFound("Prompt not found or requires payment");
|
||||
|
||||
var canAccess = await GetAccessiblePrompts(userId.Value).AnyAsync(p => p.Id == prompt.Id);
|
||||
var apiPrompt = _mapper.Map<ApiPrompt>(prompt) with
|
||||
{
|
||||
@@ -169,7 +168,20 @@ namespace OnlyPrompt.Backend.Controllers
|
||||
prompt.Category = category;
|
||||
prompt.ExampleOutput = request.ExampleOutput;
|
||||
prompt.ExampleImageUrl = request.ExampleImageUrl;
|
||||
prompt.Price = request.Price;
|
||||
prompt.Price = null;
|
||||
prompt.SubscriptionTier = null;
|
||||
if (request.SubscriptionTier.HasValue)
|
||||
{
|
||||
var subscriptionTier = await _db.SubscriptionTiers.FirstOrDefaultAsync(
|
||||
t => t.Level == request.SubscriptionTier.Value
|
||||
&& t.UserId == userId
|
||||
);
|
||||
|
||||
if (subscriptionTier is null)
|
||||
return TypedResults.NotFound("Subscription tier not found");
|
||||
|
||||
prompt.SubscriptionTier = subscriptionTier;
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
var apiPrompt = _mapper.Map<ApiPrompt>(prompt) with { Content = prompt.Prompt, CanAccess = true };
|
||||
@@ -315,7 +327,7 @@ namespace OnlyPrompt.Backend.Controllers
|
||||
Prompt = request.Content,
|
||||
ExampleOutput = request.ExampleOutput,
|
||||
ExampleImageUrl = request.ExampleImageUrl,
|
||||
Price = request.Price,
|
||||
Price = null,
|
||||
CreatorId = userId.Value,
|
||||
SubscriptionTier = subscriptionTier,
|
||||
Category = category,
|
||||
|
||||
@@ -100,6 +100,35 @@ namespace OnlyPrompt.Backend.Controllers
|
||||
return subscription;
|
||||
}
|
||||
|
||||
[HttpGet("tiers")]
|
||||
public async Task<ApiSubscriptionTier[]> GetOwnSubscriptionTiersAsync()
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
return await _db.SubscriptionTiers
|
||||
.Where(t => t.UserId == userId)
|
||||
.OrderBy(t => t.Level)
|
||||
.ProjectTo<ApiSubscriptionTier>(_mapper.ConfigurationProvider)
|
||||
.ToArrayAsync();
|
||||
}
|
||||
|
||||
[HttpGet("tiers/{userId}")]
|
||||
public async Task<Results<Ok<ApiSubscriptionTier[]>, NotFound<string>>> GetCreatorSubscriptionTiersAsync([FromRoute(Name = "userId")] Identifier creatorId)
|
||||
{
|
||||
var creatorExists = await _db.Users.AnyAsync(
|
||||
user => creatorId.Id.HasValue ? user.Id == creatorId.Id.Value : user.Profile.Slug == creatorId.Slug
|
||||
);
|
||||
if (creatorExists == false)
|
||||
return TypedResults.NotFound($"No user found with identifier {creatorId}");
|
||||
|
||||
var tiers = await _db.SubscriptionTiers
|
||||
.Where(t => creatorId.Id.HasValue ? t.UserId == creatorId.Id.Value : t.User.Profile.Slug == creatorId.Slug)
|
||||
.OrderBy(t => t.Level)
|
||||
.ProjectTo<ApiSubscriptionTier>(_mapper.ConfigurationProvider)
|
||||
.ToArrayAsync();
|
||||
|
||||
return TypedResults.Ok(tiers);
|
||||
}
|
||||
|
||||
[HttpDelete("{userId}")]
|
||||
public async Task<Results<Ok, NotFound<string>>> UnsubscribeAsync([FromRoute(Name = "userId")] Identifier subscribeToId)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user