Skip to content

Commit

Permalink
Subscription notifications (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisK00 authored May 10, 2024
1 parent 73e3121 commit 28c6009
Show file tree
Hide file tree
Showing 16 changed files with 429 additions and 32 deletions.
1 change: 1 addition & 0 deletions subtrack.DAL/Entities/DateTimeSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class DateTimeSetting : SettingsBase
{
public const string LastAutoPaymentTimeStampKey = "LastAutoPaymentTimeStamp";
public const string LastSubscriptionExportTimeStampKey = "LastSubscriptionExportTimeStamp";
public const string LastSubscriptionReminderTimeStampKey = "LastSubscriptionReminderTimeStampKey";
public DateTime? Value { get; set; }
}
}
7 changes: 5 additions & 2 deletions subtrack.DAL/Entities/Subscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public class Subscription : ICloneable
public int Id { get; set; }

[Required]
[StringLength(50,ErrorMessage = "Service name should be less than 50 characters.")]
[StringLength(50, ErrorMessage = "Service name should be less than 50 characters.")]
public string Name { get; set; } = null!;
public string? Description { get; set; }
public bool IsAutoPaid { get; set; }

public decimal Cost { get; set; }

[Required]
public int FirstPaymentDay { get; set; }
public int FirstPaymentDay { get; set; }
[Required]
public DateTime LastPayment { get; set; }

Expand All @@ -32,6 +32,9 @@ public class Subscription : ICloneable

public string SecondaryColor { get; set; }

[Range(0, 31, ErrorMessage = "Notification can be set up to 31 days before due date")]
public int? NotificationDays { get; set; }

public object Clone()
{
return (Subscription)MemberwiseClone();
Expand Down
118 changes: 118 additions & 0 deletions subtrack.DAL/Migrations/20240509182319_NotificationDays.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions subtrack.DAL/Migrations/20240509182319_NotificationDays.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace subtrack.DAL.Migrations
{
/// <inheritdoc />
public partial class NotificationDays : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "NotificationDays",
table: "Subscriptions",
type: "INTEGER",
nullable: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "NotificationDays",
table: "Subscriptions");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions subtrack.DAL/Migrations/20240510155420_LastReminderTimestamp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace subtrack.DAL.Migrations
{
/// <inheritdoc />
public partial class LastReminderTimestamp : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "Settings",
columns: new[] { "Id", "Value", "settings_type" },
values: new object[] { "LastSubscriptionReminderTimeStampKey", null, "DateTimeSetting" });
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "Settings",
keyColumn: "Id",
keyValue: "LastSubscriptionReminderTimeStampKey");
}
}
}
7 changes: 7 additions & 0 deletions subtrack.DAL/Migrations/SubtrackDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasMaxLength(50)
.HasColumnType("TEXT");

b.Property<int?>("NotificationDays")
.HasColumnType("INTEGER");

b.Property<string>("PrimaryColor")
.IsRequired()
.HasColumnType("TEXT")
Expand Down Expand Up @@ -104,6 +107,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
new
{
Id = "LastSubscriptionExportTimeStamp"
},
new
{
Id = "LastSubscriptionReminderTimeStampKey"
});
});
#pragma warning restore 612, 618
Expand Down
1 change: 1 addition & 0 deletions subtrack.DAL/SubtrackDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<DateTimeSetting>().HasData(new DateTimeSetting { Id = DateTimeSetting.LastAutoPaymentTimeStampKey, Value = null });
modelBuilder.Entity<DateTimeSetting>().HasData(new DateTimeSetting { Id = DateTimeSetting.LastSubscriptionExportTimeStampKey, Value = null });
modelBuilder.Entity<DateTimeSetting>().HasData(new DateTimeSetting { Id = DateTimeSetting.LastSubscriptionReminderTimeStampKey, Value = null });

modelBuilder.Entity<Subscription>(entity =>
{
Expand Down
6 changes: 3 additions & 3 deletions subtrack.MAUI/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ private static void SeedDb(SubtrackDbContext dbContext)
var todayLastMonth = DateTime.Now.AddMonths(-1);
var availableBackgroundColors = CssUtil.AvailableBackgroundColors;
dbContext.Subscriptions.AddRange(
new DAL.Entities.Subscription() { Name = "paramount", LastPayment = todayLastMonth.AddDays(-1), FirstPaymentDay = todayLastMonth.AddDays(-1).Day, Cost = 3m, BillingOccurrence = DAL.Entities.BillingOccurrence.Week, BillingInterval = 2, PrimaryColor = availableBackgroundColors.First(), SecondaryColor = "#2a9fd6", Icon = "fa fa-tv" },
new DAL.Entities.Subscription() { Name = "Disney+", LastPayment = todayLastMonth, FirstPaymentDay = todayLastMonth.Day, Cost = 3m, BillingOccurrence = DAL.Entities.BillingOccurrence.Month, BillingInterval = 1, PrimaryColor = availableBackgroundColors.First(), SecondaryColor = "#2a9fd6", Icon = "fa fa-circle-play" },
new DAL.Entities.Subscription() { Name = "Netflix Premium Plan", LastPayment = DateTime.Now.AddDays(-1), FirstPaymentDay = DateTime.Now.AddDays(-1).Day, IsAutoPaid = true, Description = "family plan", Cost = 1000, BillingOccurrence = DAL.Entities.BillingOccurrence.Month, BillingInterval = 1, PrimaryColor = availableBackgroundColors.First(), SecondaryColor = "#2a9fd6" },
new DAL.Entities.Subscription() { Name = "paramount", LastPayment = todayLastMonth.AddDays(-1), FirstPaymentDay = todayLastMonth.AddDays(-1).Day, Cost = 3m, BillingOccurrence = DAL.Entities.BillingOccurrence.Week, BillingInterval = 2, PrimaryColor = availableBackgroundColors.First(), SecondaryColor = "#2a9fd6", Icon = "fa fa-tv", NotificationDays = 0 },
new DAL.Entities.Subscription() { Name = "Disney+", LastPayment = todayLastMonth, FirstPaymentDay = todayLastMonth.Day, Cost = 3m, BillingOccurrence = DAL.Entities.BillingOccurrence.Month, BillingInterval = 1, PrimaryColor = availableBackgroundColors.First(), SecondaryColor = "#2a9fd6", Icon = "fa fa-circle-play", NotificationDays = 0 },
new DAL.Entities.Subscription() { Name = "Netflix Premium Plan", LastPayment = DateTime.Now.AddDays(-1), FirstPaymentDay = DateTime.Now.AddDays(-1).Day, IsAutoPaid = true, Description = "family plan", Cost = 1000, BillingOccurrence = DAL.Entities.BillingOccurrence.Month, BillingInterval = 1, PrimaryColor = availableBackgroundColors.First(), SecondaryColor = "#2a9fd6", NotificationDays = 1 },
new DAL.Entities.Subscription() { Name = "Something Family Plan", LastPayment = DateTime.Now.AddDays(-150), FirstPaymentDay = DateTime.Now.AddDays(-150).Day, IsAutoPaid = false, Description = "family plan", Cost = 1000, BillingOccurrence = DAL.Entities.BillingOccurrence.Week, BillingInterval = 2, PrimaryColor = availableBackgroundColors.First(), SecondaryColor = "#2a9fd6", Icon = "fa fa-shield" },
new DAL.Entities.Subscription() { Name = "hbo", LastPayment = DateTime.Now, FirstPaymentDay = DateTime.Now.Day, Cost = 1.5m, BillingOccurrence = DAL.Entities.BillingOccurrence.Year, BillingInterval = 1, PrimaryColor = availableBackgroundColors.First(), SecondaryColor = "#2a9fd6" },
new DAL.Entities.Subscription() { Name = "hulu Standard plan", LastPayment = DateTime.Now.AddMonths(-2), FirstPaymentDay = 1, Cost = 1.5m, IsAutoPaid = true, BillingOccurrence = DAL.Entities.BillingOccurrence.Month, BillingInterval = 3, PrimaryColor = availableBackgroundColors.First(), SecondaryColor = "#2a9fd6", Icon = "fa fa-circle-play" }
Expand Down
Loading

0 comments on commit 28c6009

Please sign in to comment.