Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions NBA-Notifier/NBANotifer.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NBANotifier", "NBANotifier\NBANotifier.csproj", "{757A46B6-036C-4C7C-98F5-0073411D07E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{757A46B6-036C-4C7C-98F5-0073411D07E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{757A46B6-036C-4C7C-98F5-0073411D07E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{757A46B6-036C-4C7C-98F5-0073411D07E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{757A46B6-036C-4C7C-98F5-0073411D07E2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
39 changes: 39 additions & 0 deletions NBA-Notifier/NBANotifier/AppOrchestrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using NBANotifier.Interfaces;
using NBANotifier.Models;
using NBANotifier.Services;
using RazorLight;

namespace NBANotifier;

public class AppOrchestrator(
IScrapingService scrapingService,
IReportService reportService,
ISubscriberService subscriberService,
IEmailService emailService)
{
public async Task RunAsync()
{
var engine = new RazorLightEngineBuilder()
.UseFileSystemProject(Utils.GetTemplateDirectory())
.UseMemoryCachingProvider()
.Build();

var nbaData = scrapingService.GetNbaResults();
var wnbaData = scrapingService.GetWnbaResults();
var subscribers = await subscriberService.GetSubscribersAsync();

foreach (var subscriber in subscribers)
{
var model = new DailyReportModel
{
NbaResults = nbaData,
WnbaResults = wnbaData,
Subscriber = subscriber
};

var report = await reportService.BuildHtmlReportAsync(model);
var email = emailService.BuildEmail(report, subscriber);
await emailService.SendEmailAsync(email, subscriber);
}
}
}
18 changes: 18 additions & 0 deletions NBA-Notifier/NBANotifier/Configuration/appSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"SportsResultSiteUrls": {
"Nba": "https://www.basketball-reference.com/boxscores/",
"Wnba": "https://www.basketball-reference.com/wnba/boxscores/index.fcgi"
},
"ScrapingSettings": {
"UseSnapshot": true
},
"EmailSettings": {
"SenderName": "NBA Daily Report",
"SenderEmail": "test@test.com",
"SmtpUser": "",
"SmtpPassword": "",
"SmtpHost": "localhost",
"SmtpPort": 25,
"UseTls": false
}
}
21 changes: 21 additions & 0 deletions NBA-Notifier/NBANotifier/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using NBANotifier.Models;
using NBANotifier.Services;

namespace NBANotifier.Data;

public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
public DbSet<Subscriber> Subscribers { get; set; }
}

public class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
public AppDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
optionsBuilder.UseSqlite(Utils.GetDatabaseConnectionString());
return new AppDbContext(optionsBuilder.Options);
}
}
19 changes: 19 additions & 0 deletions NBA-Notifier/NBANotifier/Data/DbSeeder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using NBANotifier.Models;

namespace NBANotifier.Data;

public class DbSeeder
{
public static async Task SeedTestSubscribersAsync(AppDbContext db)
{
var subscribers = new List<Subscriber>
{
new() { Name = "John Doe", Email = "FakeEmail@gmail.com", SubscribeToWnbaReports = false },
new() { Name = "Jane Doe", Email = "TestEmail@hotmail.com", SubscribeToWnbaReports = true },
new() { Name = "Jackson Doe", Email = "DevelopmentEmail@outlook.com", SubscribeToWnbaReports = true }
};

await db.Subscribers.AddRangeAsync(subscribers);
await db.SaveChangesAsync();
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace NBANotifier.Data.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Subscribers",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Email = table.Column<string>(type: "TEXT", nullable: false),
SubscribeToWnbaReports = table.Column<bool>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Subscribers", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Subscribers");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NBANotifier.Data;

#nullable disable

namespace NBANotifier.Data.Migrations
{
[DbContext(typeof(AppDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.7");

modelBuilder.Entity("NBANotifier.Models.Subscriber", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");

b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");

b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");

b.Property<bool>("SubscribeToWnbaReports")
.HasColumnType("INTEGER");

b.HasKey("Id");

b.ToTable("Subscribers");
});
#pragma warning restore 612, 618
}
}
}
10 changes: 10 additions & 0 deletions NBA-Notifier/NBANotifier/Interfaces/IEmailService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using MimeKit;
using NBANotifier.Models;

namespace NBANotifier.Interfaces;

public interface IEmailService
{
public MimeMessage BuildEmail(string htmlBody, Subscriber subscriber);
public Task SendEmailAsync(MimeMessage message, Subscriber subscriber);
}
8 changes: 8 additions & 0 deletions NBA-Notifier/NBANotifier/Interfaces/IReportService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using NBANotifier.Models;

namespace NBANotifier.Interfaces;

public interface IReportService
{
public Task<string> BuildHtmlReportAsync(DailyReportModel model);
}
10 changes: 10 additions & 0 deletions NBA-Notifier/NBANotifier/Interfaces/IScrapingService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using NBANotifier.Models;

namespace NBANotifier.Interfaces;

public interface IScrapingService
{
public void UpdateSnapshots();
public NbaResults GetNbaResults();
public WnbaResults GetWnbaResults();
}
8 changes: 8 additions & 0 deletions NBA-Notifier/NBANotifier/Interfaces/ISubscriberRepo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using NBANotifier.Models;

namespace NBANotifier.Interfaces;

public interface ISubscriberRepo
{
public Task<List<Subscriber>> GetSubscribersAsync();
}
8 changes: 8 additions & 0 deletions NBA-Notifier/NBANotifier/Interfaces/ISubscriberService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using NBANotifier.Models;

namespace NBANotifier.Interfaces;

public interface ISubscriberService
{
public Task<List<Subscriber>> GetSubscribersAsync();
}
9 changes: 9 additions & 0 deletions NBA-Notifier/NBANotifier/Models/DailyReportModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NBANotifier.Models;

public class DailyReportModel
{
public string Date { get; set; } = DateTime.Today.ToString("yyyy-MM-dd");
public required NbaResults NbaResults { get; set; }
public required WnbaResults WnbaResults { get; set; }
public required Subscriber Subscriber { get; set; }
}
12 changes: 12 additions & 0 deletions NBA-Notifier/NBANotifier/Models/EmailSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace NBANotifier.Models;

public class EmailSettings
{
public required string SenderName { get; set; }
public required string SenderEmail { get; set; }
public required string SmtpUser { get; set; }
public required string SmtpPassword { get; set; }
public required string SmtpHost { get; set; }
public required int SmtpPort { get; set; }
public required bool UseTls { get; set; }
}
9 changes: 9 additions & 0 deletions NBA-Notifier/NBANotifier/Models/Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NBANotifier.Models;

public class Game
{
public required string HomeTeam { get; set; }
public required string AwayTeam { get; set; }
public required int HomeScore { get; set; }
public required int AwayScore { get; set; }
}
8 changes: 8 additions & 0 deletions NBA-Notifier/NBANotifier/Models/NbaResults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace NBANotifier.Models;

public class NbaResults
{
public List<Game> Games { get; set; }
public required List<Team> WesternConference { get; set; }
public required List<Team> EasternConference { get; set; }
}
9 changes: 9 additions & 0 deletions NBA-Notifier/NBANotifier/Models/Subscriber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NBANotifier.Models;

public class Subscriber
{
public int Id { get; set; }
public required string Name { get; set; }
public required string Email { get; set; }
public required bool SubscribeToWnbaReports { get; set; } = false;
}
12 changes: 12 additions & 0 deletions NBA-Notifier/NBANotifier/Models/Team.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace NBANotifier.Models;

public class Team
{
public required string Name { get; set; }
public required string Wins { get; set; }
public required string Losses { get; set; }
public required string WinLossPercentage { get; set; }
public required string GamesBack { get; set; }
public required string PointsPerGame { get; set; }
public required string PointsAllowedPerGame { get; set; }
}
6 changes: 6 additions & 0 deletions NBA-Notifier/NBANotifier/Models/WnbaResults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace NBANotifier.Models;

public class WnbaResults
{
public List<Game> Games { get; set; }
}
Loading