🐛 Bug fixes
This commit is contained in:
parent
5990b17b4c
commit
c5ef9b065b
@ -10,7 +10,7 @@ public record class SubscriptionTypeData(
|
|||||||
decimal BasePrice
|
decimal BasePrice
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
public static Dictionary<string, SubscriptionTypeData> SubscriptionDict =
|
public static readonly Dictionary<string, SubscriptionTypeData> SubscriptionDict =
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
[SubscriptionType.Twinkle] = new SubscriptionTypeData(SubscriptionType.Twinkle, 0),
|
[SubscriptionType.Twinkle] = new SubscriptionTypeData(SubscriptionType.Twinkle, 0),
|
||||||
@ -145,8 +145,7 @@ public class Subscription : ModelBase
|
|||||||
return new SubscriptionReferenceObject
|
return new SubscriptionReferenceObject
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
BegunAt = BegunAt,
|
Status = Status,
|
||||||
EndedAt = EndedAt,
|
|
||||||
Identifier = Identifier,
|
Identifier = Identifier,
|
||||||
IsActive = IsActive,
|
IsActive = IsActive,
|
||||||
AccountId = AccountId,
|
AccountId = AccountId,
|
||||||
@ -166,9 +165,8 @@ public class PaymentDetails
|
|||||||
public class SubscriptionReferenceObject : ModelBase
|
public class SubscriptionReferenceObject : ModelBase
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
public Instant BegunAt { get; set; }
|
public SubscriptionStatus Status { get; set; }
|
||||||
public Instant? EndedAt { get; set; }
|
public string Identifier { get; set; } = null!;
|
||||||
[MaxLength(4096)] public string Identifier { get; set; } = null!;
|
|
||||||
public bool IsActive { get; set; } = true;
|
public bool IsActive { get; set; } = true;
|
||||||
public Guid AccountId { get; set; }
|
public Guid AccountId { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,24 @@ public class SubscriptionController(SubscriptionService subscriptions, AppDataba
|
|||||||
return subscriptionsList;
|
return subscriptionsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("fuzzy/{prefix}")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult<Subscription>> GetSubscriptionFuzzy(string prefix)
|
||||||
|
{
|
||||||
|
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
|
||||||
|
|
||||||
|
var subs = await db.WalletSubscriptions
|
||||||
|
.Where(s => s.AccountId == currentUser.Id && s.IsActive)
|
||||||
|
.Where(s => EF.Functions.ILike(s.Identifier, prefix + "%"))
|
||||||
|
.OrderByDescending(s => s.BegunAt)
|
||||||
|
.ToListAsync();
|
||||||
|
if (subs.Count == 0) return NotFound();
|
||||||
|
var subscription = subs.FirstOrDefault(s => s.IsAvailable);
|
||||||
|
if (subscription is null) return NotFound();
|
||||||
|
|
||||||
|
return Ok(subscription);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("{identifier}")]
|
[HttpGet("{identifier}")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<ActionResult<Subscription>> GetSubscription(string identifier)
|
public async Task<ActionResult<Subscription>> GetSubscription(string identifier)
|
||||||
@ -70,9 +88,7 @@ public class SubscriptionController(SubscriptionService subscriptions, AppDataba
|
|||||||
|
|
||||||
Duration? cycleDuration = null;
|
Duration? cycleDuration = null;
|
||||||
if (request.CycleDurationDays.HasValue)
|
if (request.CycleDurationDays.HasValue)
|
||||||
{
|
|
||||||
cycleDuration = Duration.FromDays(request.CycleDurationDays.Value);
|
cycleDuration = Duration.FromDays(request.CycleDurationDays.Value);
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -155,15 +155,19 @@ public class SubscriptionService(AppDatabase db, PaymentService payment, ICacheS
|
|||||||
if (subscription is null)
|
if (subscription is null)
|
||||||
throw new InvalidOperationException("Invalid order.");
|
throw new InvalidOperationException("Invalid order.");
|
||||||
|
|
||||||
|
if (subscription.Status == SubscriptionStatus.Expired)
|
||||||
|
{
|
||||||
var now = SystemClock.Instance.GetCurrentInstant();
|
var now = SystemClock.Instance.GetCurrentInstant();
|
||||||
var cycle = subscription.BegunAt.Minus(subscription.RenewalAt ?? now);
|
var cycle = subscription.BegunAt.Minus(subscription.RenewalAt ?? subscription.EndedAt ?? now);
|
||||||
|
|
||||||
var nextRenewalAt = subscription.RenewalAt?.Plus(cycle);
|
var nextRenewalAt = subscription.RenewalAt?.Plus(cycle);
|
||||||
var nextEndedAt = subscription.RenewalAt?.Plus(cycle);
|
var nextEndedAt = subscription.EndedAt?.Plus(cycle);
|
||||||
|
|
||||||
subscription.Status = SubscriptionStatus.Paid;
|
|
||||||
subscription.RenewalAt = nextRenewalAt;
|
subscription.RenewalAt = nextRenewalAt;
|
||||||
subscription.EndedAt = nextEndedAt;
|
subscription.EndedAt = nextEndedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
subscription.Status = SubscriptionStatus.Paid;
|
||||||
|
|
||||||
db.Update(subscription);
|
db.Update(subscription);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user