Skip to content
Merged
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
9 changes: 9 additions & 0 deletions FinTrack/Core/NewUserInformationManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace FinTrack.Core
{
public static class NewUserInformationManager
{
public static string? FullName { get; set; }
public static string? Email { get; set; }
public static string? Password { get; set; }
}
}
19 changes: 19 additions & 0 deletions FinTrack/Core/SessionManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace FinTrack.Core
{
public static class SessionManager
{
public static string CurrentToken { get; private set; }

Check warning on line 5 in FinTrack/Core/SessionManager.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Non-nullable property 'CurrentToken' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public static void SetToken(string token)
{
CurrentToken = token;
}

public static void ClearToken()
{
CurrentToken = null;

Check warning on line 14 in FinTrack/Core/SessionManager.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot convert null literal to non-nullable reference type.
}

public static bool IsLoggedIn => !string.IsNullOrEmpty(CurrentToken);
}
}
155 changes: 155 additions & 0 deletions FinTrack/Data/AppDatabaseContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using FinTrack.Models;
using Microsoft.EntityFrameworkCore;
using System.IO;

namespace FinTrack.Data
{
public class AppDatabaseContext : DbContext
{
public AppDatabaseContext() { }

public DbSet<UserModel> Users { get; set; }
public DbSet<UserSettingsModel> UserSettings { get; set; }
public DbSet<AccountModel> Accounts { get; set; }
public DbSet<TransactionModel> Transactions { get; set; }
public DbSet<CategoryModel> Categories { get; set; }
public DbSet<BudgetModel> Budgets { get; set; }
public DbSet<BudgetCategoryModel> BudgetCategories { get; set; }
public DbSet<NotificationModel> Notifications { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
var userProfileFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var dbPath = Path.Combine(userProfileFolder, "FinTrackWindows.db");

optionsBuilder.UseSqlite($"Data Source={dbPath}");
}
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<UserModel>(entity =>
{
entity.ToTable("Users");

entity.HasOne(u => u.UserSettings)
.WithOne(s => s.User)
.HasForeignKey<UserSettingsModel>(s => s.UserId)
.OnDelete(DeleteBehavior.Cascade);

entity.HasMany(u => u.Accounts)
.WithOne(a => a.User)
.HasForeignKey(a => a.UserId)
.OnDelete(DeleteBehavior.Cascade);

entity.HasMany(u => u.Categories)
.WithOne(c => c.User)
.HasForeignKey(c => c.UserId)
.OnDelete(DeleteBehavior.Cascade);

entity.HasMany(u => u.Transactions)
.WithOne(t => t.User)
.HasForeignKey(t => t.UserId)
.OnDelete(DeleteBehavior.Cascade);

entity.HasMany(u => u.Budgets)
.WithOne(b => b.User)
.HasForeignKey(b => b.UserId)
.OnDelete(DeleteBehavior.Cascade);

entity.HasMany(u => u.Notifications)
.WithOne(n => n.User)
.HasForeignKey(n => n.UserId)
.OnDelete(DeleteBehavior.Cascade);
});

modelBuilder.Entity<UserSettingsModel>(entity =>
{
entity.ToTable("UserSettings");
entity.HasKey(s => s.Id);
entity.Property(s => s.Id).ValueGeneratedOnAdd();
entity.HasIndex(s => s.UserId).IsUnique();
});

modelBuilder.Entity<AccountModel>(entity =>
{
entity.ToTable("Accounts");
entity.HasKey(a => a.Id);
entity.Property(a => a.Id).ValueGeneratedOnAdd();
entity.Property(a => a.Balance).HasColumnType("decimal(18, 2)").IsRequired();
entity.Property(a => a.Name).IsRequired();
entity.HasIndex(a => new { a.UserId, a.Name }).IsUnique();
});

modelBuilder.Entity<TransactionModel>(entity =>
{
entity.ToTable("Transactions");
entity.HasKey(t => t.Id);
entity.Property(t => t.Id).ValueGeneratedOnAdd();
entity.Property(t => t.Amount).HasColumnType("decimal(18, 2)").IsRequired();
entity.HasIndex(t => t.UserId);
entity.HasIndex(t => t.CategoryId);
entity.HasIndex(t => t.TransactionDateUtc);
entity.HasIndex(t => t.AccountId);
});

modelBuilder.Entity<CategoryModel>(entity =>
{
entity.ToTable("Categories");
entity.HasKey(c => c.Id);
entity.Property(c => c.Id).ValueGeneratedOnAdd();
entity.Property(c => c.Name).HasColumnName("CategoryName").IsRequired();
entity.Property(c => c.Type).HasColumnName("CategoryType").HasConversion<string>().IsRequired();
entity.HasIndex(c => new { c.UserId, c.Name, c.Type, }).IsUnique();

entity
.HasMany(c => c.BudgetAllocations)
.WithOne(bc => bc.Category)
.HasForeignKey(bc => bc.CategoryId)
.OnDelete(DeleteBehavior.Restrict);

entity
.HasMany(c => c.Transactions)
.WithOne(t => t.Category)
.HasForeignKey(t => t.CategoryId)
.OnDelete(DeleteBehavior.Restrict);
});

modelBuilder.Entity<BudgetModel>(entity =>
{
entity.ToTable("Budgets");
entity.HasKey(b => b.Id);
entity.Property(b => b.Id).ValueGeneratedOnAdd();
entity.Property(b => b.Name).HasColumnName("BudgetName").IsRequired();
entity.Property(b => b.Description).IsRequired(false);

entity.HasMany(b => b.BudgetCategories).WithOne(bc => bc.Budget).HasForeignKey(bc => bc.BudgetId).OnDelete(DeleteBehavior.Cascade);
});

modelBuilder.Entity<BudgetCategoryModel>(entity =>
{
entity.ToTable("BudgetCategories");
entity.HasKey(bc => bc.Id);
entity.Property(bc => bc.Id).ValueGeneratedOnAdd();
entity.Property(bc => bc.AllocatedAmount).HasColumnType("decimal(18, 2)").IsRequired();
entity.HasIndex(bc => new { bc.BudgetId, bc.CategoryId }).IsUnique();
});

modelBuilder.Entity<NotificationModel>(entity =>
{
entity.ToTable("Notifications");
entity.HasKey(n => n.NotificationId);
entity.Property(n => n.NotificationId).ValueGeneratedOnAdd();
entity.Property(n => n.MessageHead).IsRequired().HasMaxLength(200);
entity.Property(n => n.MessageBody).IsRequired().HasMaxLength(1000);
entity.Property(n => n.CreatedAtUtc).IsRequired().HasDefaultValueSql("CURRENT_TIMESTAMP");
entity.Property(n => n.IsRead).IsRequired().HasDefaultValue(false);
entity.HasIndex(n => n.UserId);
});
}
}
}
21 changes: 21 additions & 0 deletions FinTrack/Dtos/LoginRequestDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace FinTrack.Dtos
{
public class LoginRequestDto
{
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}

public class LoginResponseDto
{
public string Id { get; set; } = string.Empty;
public int UserId { get; set; }
public string UserName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string ProfilePicture { get; set; } = string.Empty;
public string AccessToken { get; set; } = string.Empty;
public string RefreshToken { get; set; } = string.Empty;
public string RolesId { get; set; } = string.Empty;
public string RolesValues { get; set; } = string.Empty;
}
}
16 changes: 16 additions & 0 deletions FinTrack/Dtos/RegisterRequestDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace FinTrack.Dtos
{
public class RegisterRequestDto
{
public string? UserName { get; set; }
public string Email { get; set; } = null!;
public string Password { get; set; } = null!;
public string? ProfilePicture { get; set; }
}

public class OtpVerifyCodeRequestDto
{
public string Email { get; set; } = null!;
public string Code { get; set; } = null!;
}
}
6 changes: 5 additions & 1 deletion FinTrack/FinTrack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="CSharper" Version="0.1.7" />
<PackageReference Include="LiveChartsCore.SkiaSharpView.WPF" Version="2.0.0-rc5.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.3" />
Expand Down
Loading
Loading