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