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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ obj/
project.lock.json
project.fragment.lock.json
artifacts/
appsettings.Development.json
appsettings.Staging.json
appsettings.Production.json

# React Native
*.orig.*
Expand Down
42 changes: 42 additions & 0 deletions HelpingHand.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "apps", "apps", "{1787FE1D-075E-9E68-7218-25F1BD1BBEAB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "database", "database", "{F705D443-EAB5-B768-10AC-B11C88742C98}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelpingHand.Db", "apps\database\HelpingHand.Db.csproj", "{13FA3BE4-1E3F-A186-77A1-150ABC99B57E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "api", "api", "{BC2D172B-13BC-136C-CDB1-4B1A687208C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelpingHand.Api", "apps\api\HelpingHand.Api.csproj", "{5B4628A9-2C3B-2F4E-D005-D50856B5F42D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{13FA3BE4-1E3F-A186-77A1-150ABC99B57E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13FA3BE4-1E3F-A186-77A1-150ABC99B57E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13FA3BE4-1E3F-A186-77A1-150ABC99B57E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13FA3BE4-1E3F-A186-77A1-150ABC99B57E}.Release|Any CPU.Build.0 = Release|Any CPU
{5B4628A9-2C3B-2F4E-D005-D50856B5F42D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B4628A9-2C3B-2F4E-D005-D50856B5F42D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B4628A9-2C3B-2F4E-D005-D50856B5F42D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B4628A9-2C3B-2F4E-D005-D50856B5F42D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F705D443-EAB5-B768-10AC-B11C88742C98} = {1787FE1D-075E-9E68-7218-25F1BD1BBEAB}
{13FA3BE4-1E3F-A186-77A1-150ABC99B57E} = {F705D443-EAB5-B768-10AC-B11C88742C98}
{BC2D172B-13BC-136C-CDB1-4B1A687208C4} = {1787FE1D-075E-9E68-7218-25F1BD1BBEAB}
{5B4628A9-2C3B-2F4E-D005-D50856B5F42D} = {BC2D172B-13BC-136C-CDB1-4B1A687208C4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4292AA31-1262-48BE-B5DB-0A67419072F9}
EndGlobalSection
EndGlobal
19 changes: 0 additions & 19 deletions apps/api/Data/AppDbContext.cs

This file was deleted.

9 changes: 6 additions & 3 deletions apps/api/HelpingHand.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>HelpingHand.Api</RootNamespace>
<AssemblyName>HelpingHand.Api</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.2">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../database/HelpingHand.Db.csproj" />
</ItemGroup>

</Project>
6 changes: 4 additions & 2 deletions apps/api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
builder.Services.AddSwaggerGen();

// PostgreSQL (connection string from appsettings per environment)
builder.Services.AddDbContext<HelpingHand.Api.Data.AppDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddDbContext<HelpingHand.Db.AppDbContext>(options =>
options.UseNpgsql(
builder.Configuration.GetConnectionString("DefaultConnection"),
b => b.MigrationsAssembly("HelpingHand.Db")));

// CORS (origins from appsettings per environment)
var corsOrigins = builder.Configuration.GetSection("Api:CorsOrigins").Get<string[]>() ?? Array.Empty<string>();
Expand Down
15 changes: 15 additions & 0 deletions apps/api/appsettings.Development.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore": "Information"
}
},
"ConnectionStrings": {
"DefaultConnection": "Host=<host>;Port=5432;Database=<database>;Username=<username>;Password=<password>;Ssl Mode=Require;Trust Server Certificate=true;Include Error Detail=true"
},
"Api": {
"BaseUrl": "https://localhost:7001",
"CorsOrigins": [ "http://localhost:3000", "http://localhost:8081" ]
}
}
136 changes: 136 additions & 0 deletions apps/database/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using HelpingHand.Db.Entities;
using Microsoft.EntityFrameworkCore;

namespace HelpingHand.Db;

public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }

public DbSet<User> Users => Set<User>();
public DbSet<Role> Roles => Set<Role>();
public DbSet<UserRole> UserRoles => Set<UserRole>();
public DbSet<BorrowerProfile> BorrowerProfiles => Set<BorrowerProfile>();
public DbSet<Address> Addresses => Set<Address>();
public DbSet<ReferenceContact> ReferenceContacts => Set<ReferenceContact>();
public DbSet<Document> Documents => Set<Document>();
public DbSet<AdminProfile> AdminProfiles => Set<AdminProfile>();
public DbSet<AuditLog> AuditLogs => Set<AuditLog>();

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

modelBuilder.Entity<User>(e =>
{
e.HasKey(u => u.Id);
e.Property(u => u.Id).HasDefaultValueSql("gen_random_uuid()");
e.HasIndex(u => u.Email).IsUnique();
e.HasIndex(u => u.PhoneNumber).IsUnique();
e.Property(u => u.IsActive).HasDefaultValue(true);
e.Property(u => u.CreatedAt).HasDefaultValueSql("now()");
e.Property(u => u.UpdatedAt).HasDefaultValueSql("now()");
});

modelBuilder.Entity<Role>(e =>
{
e.HasKey(r => r.Id);
e.HasIndex(r => r.Name).IsUnique();
});

modelBuilder.Entity<UserRole>(e =>
{
e.HasKey(ur => new { ur.UserId, ur.RoleId });
e.Property(ur => ur.AssignedAt).HasDefaultValueSql("now()");
e.HasOne(ur => ur.User)
.WithMany(u => u.UserRoles)
.HasForeignKey(ur => ur.UserId)
.OnDelete(DeleteBehavior.Cascade);
e.HasOne(ur => ur.Role)
.WithMany(r => r.UserRoles)
.HasForeignKey(ur => ur.RoleId)
.OnDelete(DeleteBehavior.Cascade);
e.HasOne(ur => ur.AssignedByUser)
.WithMany()
.HasForeignKey(ur => ur.AssignedBy)
.OnDelete(DeleteBehavior.SetNull);
});

modelBuilder.Entity<BorrowerProfile>(e =>
{
e.HasKey(b => b.Id);
e.Property(b => b.Id).HasDefaultValueSql("gen_random_uuid()");
e.HasIndex(b => b.UserId).IsUnique();
e.Property(b => b.MonthlyIncome).HasPrecision(15, 2);
e.Property(b => b.CreatedAt).HasDefaultValueSql("now()");
e.Property(b => b.UpdatedAt).HasDefaultValueSql("now()");
e.HasOne(b => b.User)
.WithOne(u => u.BorrowerProfile)
.HasForeignKey<BorrowerProfile>(b => b.UserId)
.OnDelete(DeleteBehavior.Cascade);
});

modelBuilder.Entity<Address>(e =>
{
e.HasKey(a => a.Id);
e.Property(a => a.Id).HasDefaultValueSql("gen_random_uuid()");
e.Property(a => a.CreatedAt).HasDefaultValueSql("now()");
e.HasOne(a => a.User)
.WithMany(u => u.Addresses)
.HasForeignKey(a => a.UserId)
.OnDelete(DeleteBehavior.Cascade);
});

modelBuilder.Entity<ReferenceContact>(e =>
{
e.HasKey(r => r.Id);
e.Property(r => r.Id).HasDefaultValueSql("gen_random_uuid()");
e.Property(r => r.CreatedAt).HasDefaultValueSql("now()");
e.HasOne(r => r.BorrowerProfile)
.WithMany(b => b.ReferenceContacts)
.HasForeignKey(r => r.BorrowerProfileId)
.OnDelete(DeleteBehavior.Cascade);
});

modelBuilder.Entity<Document>(e =>
{
e.HasKey(d => d.Id);
e.Property(d => d.Id).HasDefaultValueSql("gen_random_uuid()");
e.Property(d => d.Status).HasDefaultValue("Pending");
e.Property(d => d.CreatedAt).HasDefaultValueSql("now()");
e.HasOne(d => d.User)
.WithMany(u => u.Documents)
.HasForeignKey(d => d.UserId)
.OnDelete(DeleteBehavior.Cascade);
e.HasOne(d => d.VerifiedByUser)
.WithMany()
.HasForeignKey(d => d.VerifiedBy)
.OnDelete(DeleteBehavior.SetNull);
});

modelBuilder.Entity<AdminProfile>(e =>
{
e.HasKey(a => a.Id);
e.Property(a => a.Id).HasDefaultValueSql("gen_random_uuid()");
e.HasIndex(a => a.UserId).IsUnique();
e.Property(a => a.CreatedAt).HasDefaultValueSql("now()");
e.HasOne(a => a.User)
.WithOne(u => u.AdminProfile)
.HasForeignKey<AdminProfile>(a => a.UserId)
.OnDelete(DeleteBehavior.Cascade);
});

modelBuilder.Entity<AuditLog>(e =>
{
e.HasKey(a => a.Id);
e.Property(a => a.Id).HasDefaultValueSql("gen_random_uuid()");
e.Property(a => a.CreatedAt).HasDefaultValueSql("now()");
e.Property(a => a.OldValues).HasColumnType("jsonb");
e.Property(a => a.NewValues).HasColumnType("jsonb");
e.HasOne(a => a.User)
.WithMany()
.HasForeignKey(a => a.UserId)
.OnDelete(DeleteBehavior.Restrict);
});
}
}
17 changes: 17 additions & 0 deletions apps/database/Entities/Address.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace HelpingHand.Db.Entities;

public class Address
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string Type { get; set; } = null!; // Home, Work, Permanent
public string Street { get; set; } = null!;
public string Barangay { get; set; } = null!;
public string City { get; set; } = null!;
public string Province { get; set; } = null!;
public string ZipCode { get; set; } = null!;
public bool IsPrimary { get; set; }
public DateTime CreatedAt { get; set; }

public User User { get; set; } = null!;
}
13 changes: 13 additions & 0 deletions apps/database/Entities/AdminProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace HelpingHand.Db.Entities;

public class AdminProfile
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string FirstName { get; set; } = null!;
public string LastName { get; set; } = null!;
public string? Department { get; set; }
public DateTime CreatedAt { get; set; }

public User User { get; set; } = null!;
}
16 changes: 16 additions & 0 deletions apps/database/Entities/AuditLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace HelpingHand.Db.Entities;

public class AuditLog
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string Action { get; set; } = null!;
public string EntityType { get; set; } = null!;
public Guid? EntityId { get; set; }
public string? OldValues { get; set; } // jsonb
public string? NewValues { get; set; } // jsonb
public string? IpAddress { get; set; }
public DateTime CreatedAt { get; set; }

public User User { get; set; } = null!;
}
25 changes: 25 additions & 0 deletions apps/database/Entities/BorrowerProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace HelpingHand.Db.Entities;

public class BorrowerProfile
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string FirstName { get; set; } = null!;
public string LastName { get; set; } = null!;
public string? MiddleName { get; set; }
public DateOnly DateOfBirth { get; set; }
public string Gender { get; set; } = null!;
public string CivilStatus { get; set; } = null!;
public string Nationality { get; set; } = null!;
public string NationalIdType { get; set; } = null!;
public string NationalIdNumber { get; set; } = null!;
public string EmploymentStatus { get; set; } = null!;
public string? EmployerName { get; set; }
public decimal MonthlyIncome { get; set; }
public string? ProfilePhotoUrl { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }

public User User { get; set; } = null!;
public ICollection<ReferenceContact> ReferenceContacts { get; set; } = [];
}
17 changes: 17 additions & 0 deletions apps/database/Entities/Document.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace HelpingHand.Db.Entities;

public class Document
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string Type { get; set; } = null!; // GovernmentId, ProofOfIncome, ProofOfBilling, Selfie
public string FileUrl { get; set; } = null!;
public string Status { get; set; } = "Pending"; // Pending, Verified, Rejected
public Guid? VerifiedBy { get; set; }
public DateTime? VerifiedAt { get; set; }
public string? RejectionReason { get; set; }
public DateTime CreatedAt { get; set; }

public User User { get; set; } = null!;
public User? VerifiedByUser { get; set; }
}
14 changes: 14 additions & 0 deletions apps/database/Entities/ReferenceContact.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace HelpingHand.Db.Entities;

public class ReferenceContact
{
public Guid Id { get; set; }
public Guid BorrowerProfileId { get; set; }
public string FullName { get; set; } = null!;
public string Relationship { get; set; } = null!;
public string PhoneNumber { get; set; } = null!;
public string? Email { get; set; }
public DateTime CreatedAt { get; set; }

public BorrowerProfile BorrowerProfile { get; set; } = null!;
}
10 changes: 10 additions & 0 deletions apps/database/Entities/Role.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace HelpingHand.Db.Entities;

public class Role
{
public short Id { get; set; }
public string Name { get; set; } = null!;
public string? Description { get; set; }

public ICollection<UserRole> UserRoles { get; set; } = [];
}
Loading