Refactor schema and test data; remove DAL code

Removed all DataAccessLayer C# code and related test project files. Updated schema.sql to add Country, StateProvince, and City tables, refactored brewery and beer post tables to include location and concurrency columns, and replaced the old comment/rating system with BeerPostComment. Updated test-data.sql to seed new location tables and refactored brewery data to use city and coordinates.
This commit is contained in:
Aaron Po
2025-11-11 03:45:01 -05:00
parent 8975044034
commit 33db1368ec
19 changed files with 246 additions and 828 deletions

View File

@@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class BeerPost
{
public Guid BeerPostID { get; set; }
public string Name { get; set; } = null!;
public string Description { get; set; } = null!;
public decimal ABV { get; set; }
public int IBU { get; set; }
public Guid PostedByID { get; set; }
public Guid BeerStyleID { get; set; }
public Guid BrewedByID { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
public virtual ICollection<BeerPostPhoto> BeerPostPhotos { get; set; } = new List<BeerPostPhoto>();
public virtual BeerStyle BeerStyle { get; set; } = null!;
public virtual BreweryPost BrewedBy { get; set; } = null!;
public virtual UserAccount PostedBy { get; set; } = null!;
}

View File

@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class BeerPostPhoto
{
public Guid BeerPostPhotoID { get; set; }
public Guid BeerPostID { get; set; }
public Guid PhotoID { get; set; }
public DateTime LinkedAt { get; set; }
public virtual BeerPost BeerPost { get; set; } = null!;
public virtual Photo Photo { get; set; } = null!;
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class BeerStyle
{
public Guid BeerStyleID { get; set; }
public string StyleName { get; set; } = null!;
public string? Description { get; set; }
public virtual ICollection<BeerPost> BeerPosts { get; set; } = new List<BeerPost>();
}

View File

@@ -1,300 +0,0 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
namespace DataAccessLayer;
public partial class BiergartenContext : DbContext
{
public BiergartenContext()
{
}
public BiergartenContext(DbContextOptions<BiergartenContext> options)
: base(options)
{
}
public virtual DbSet<BeerPost> BeerPosts { get; set; }
public virtual DbSet<BeerPostPhoto> BeerPostPhotos { get; set; }
public virtual DbSet<BeerStyle> BeerStyles { get; set; }
public virtual DbSet<BreweryPost> BreweryPosts { get; set; }
public virtual DbSet<BreweryPostPhoto> BreweryPostPhotos { get; set; }
public virtual DbSet<Comment> Comments { get; set; }
public virtual DbSet<Photo> Photos { get; set; }
public virtual DbSet<UserAccount> UserAccounts { get; set; }
public virtual DbSet<UserAvatar> UserAvatars { get; set; }
public virtual DbSet<UserCredential> UserCredentials { get; set; }
public virtual DbSet<UserFollow> UserFollows { get; set; }
public virtual DbSet<UserVerification> UserVerifications { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
=> optionsBuilder.UseSqlServer("Server=(localdb)\\ProjectModels;Database=Biergarten;Trusted_Connection=True;");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<BeerPost>(entity =>
{
entity.ToTable("BeerPost");
entity.HasIndex(e => e.BeerStyleID, "IX_BeerPost_BeerStyle");
entity.HasIndex(e => e.BrewedByID, "IX_BeerPost_BrewedBy");
entity.HasIndex(e => e.PostedByID, "IX_BeerPost_PostedBy");
entity.Property(e => e.BeerPostID).HasDefaultValueSql("(newid())");
entity.Property(e => e.ABV).HasColumnType("decimal(4, 2)");
entity.Property(e => e.CreatedAt)
.HasDefaultValueSql("(getdate())")
.HasColumnType("datetime");
entity.Property(e => e.Name).HasMaxLength(100);
entity.Property(e => e.UpdatedAt).HasColumnType("datetime");
entity.HasOne(d => d.BeerStyle).WithMany(p => p.BeerPosts)
.HasForeignKey(d => d.BeerStyleID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_BeerPost_BeerStyle");
entity.HasOne(d => d.BrewedBy).WithMany(p => p.BeerPosts)
.HasForeignKey(d => d.BrewedByID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_BeerPost_Brewery");
entity.HasOne(d => d.PostedBy).WithMany(p => p.BeerPosts)
.HasForeignKey(d => d.PostedByID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_BeerPost_PostedBy");
});
modelBuilder.Entity<BeerPostPhoto>(entity =>
{
entity.ToTable("BeerPostPhoto");
entity.HasIndex(e => new { e.BeerPostID, e.PhotoID }, "IX_BeerPostPhoto_BeerPost_Photo");
entity.HasIndex(e => new { e.PhotoID, e.BeerPostID }, "IX_BeerPostPhoto_Photo_BeerPost");
entity.Property(e => e.BeerPostPhotoID).HasDefaultValueSql("(newid())");
entity.Property(e => e.LinkedAt)
.HasDefaultValueSql("(getdate())")
.HasColumnType("datetime");
entity.HasOne(d => d.BeerPost).WithMany(p => p.BeerPostPhotos)
.HasForeignKey(d => d.BeerPostID)
.HasConstraintName("FK_BeerPostPhoto_BeerPost");
entity.HasOne(d => d.Photo).WithMany(p => p.BeerPostPhotos)
.HasForeignKey(d => d.PhotoID)
.HasConstraintName("FK_BeerPostPhoto_Photo");
});
modelBuilder.Entity<BeerStyle>(entity =>
{
entity.ToTable("BeerStyle");
entity.HasIndex(e => e.StyleName, "AK_BeerStyle_StyleName").IsUnique();
entity.Property(e => e.BeerStyleID).HasDefaultValueSql("(newid())");
entity.Property(e => e.StyleName).HasMaxLength(100);
});
modelBuilder.Entity<BreweryPost>(entity =>
{
entity.ToTable("BreweryPost");
entity.HasIndex(e => e.PostedByID, "IX_BreweryPost_PostedByID");
entity.Property(e => e.BreweryPostID).HasDefaultValueSql("(newid())");
entity.Property(e => e.CreatedAt)
.HasDefaultValueSql("(getdate())")
.HasColumnType("datetime");
entity.Property(e => e.Description).HasMaxLength(512);
entity.Property(e => e.UpdatedAt).HasColumnType("datetime");
entity.HasOne(d => d.PostedBy).WithMany(p => p.BreweryPosts)
.HasForeignKey(d => d.PostedByID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_BreweryPost_UserAccount");
});
modelBuilder.Entity<BreweryPostPhoto>(entity =>
{
entity.ToTable("BreweryPostPhoto");
entity.HasIndex(e => new { e.BreweryPostID, e.PhotoID }, "IX_BreweryPostPhoto_BreweryPost_Photo");
entity.HasIndex(e => new { e.PhotoID, e.BreweryPostID }, "IX_BreweryPostPhoto_Photo_BreweryPost");
entity.Property(e => e.BreweryPostPhotoID).HasDefaultValueSql("(newid())");
entity.Property(e => e.LinkedAt)
.HasDefaultValueSql("(getdate())")
.HasColumnType("datetime");
entity.HasOne(d => d.BreweryPost).WithMany(p => p.BreweryPostPhotos)
.HasForeignKey(d => d.BreweryPostID)
.HasConstraintName("FK_BreweryPostPhoto_BreweryPost");
entity.HasOne(d => d.Photo).WithMany(p => p.BreweryPostPhotos)
.HasForeignKey(d => d.PhotoID)
.HasConstraintName("FK_BreweryPostPhoto_Photo");
});
modelBuilder.Entity<Comment>(entity =>
{
entity.HasKey(e => e.CommentID).HasName("PK_CommentID");
entity.ToTable("Comment");
entity.HasIndex(e => e.PostedByID, "IX_Comment_PostedByID");
entity.Property(e => e.CommentID).HasDefaultValueSql("(newid())");
entity.Property(e => e.CommentText).HasMaxLength(512);
entity.HasOne(d => d.PostedBy).WithMany(p => p.Comments)
.HasForeignKey(d => d.PostedByID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_PostedByID");
});
modelBuilder.Entity<Photo>(entity =>
{
entity.ToTable("Photo");
entity.HasIndex(e => e.UploadedByID, "IX_Photo_UploadedByID");
entity.Property(e => e.PhotoID).HasDefaultValueSql("(newid())");
entity.Property(e => e.Hyperlink).HasMaxLength(256);
entity.Property(e => e.UploadedAt)
.HasDefaultValueSql("(getdate())")
.HasColumnType("datetime");
entity.HasOne(d => d.UploadedBy).WithMany(p => p.Photos)
.HasForeignKey(d => d.UploadedByID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Photo_UploadedBy");
});
modelBuilder.Entity<UserAccount>(entity =>
{
entity.ToTable("UserAccount");
entity.HasIndex(e => e.Email, "AK_Email").IsUnique();
entity.HasIndex(e => e.Username, "AK_Username").IsUnique();
entity.Property(e => e.UserAccountID).HasDefaultValueSql("(newid())");
entity.Property(e => e.CreatedAt).HasColumnType("datetime");
entity.Property(e => e.DateOfBirth).HasColumnType("datetime");
entity.Property(e => e.Email)
.HasMaxLength(128)
.IsUnicode(false);
entity.Property(e => e.FirstName).HasMaxLength(128);
entity.Property(e => e.LastName).HasMaxLength(128);
entity.Property(e => e.UpdatedAt).HasColumnType("datetime");
entity.Property(e => e.Username)
.HasMaxLength(64)
.IsUnicode(false);
});
modelBuilder.Entity<UserAvatar>(entity =>
{
entity.ToTable("UserAvatar");
entity.HasIndex(e => e.UserAccountID, "AK_UserAvatar_UserAccountID").IsUnique();
entity.HasIndex(e => e.UserAccountID, "IX_UserAvatar_UserAccount");
entity.Property(e => e.UserAvatarID).HasDefaultValueSql("(newid())");
entity.HasOne(d => d.Photo).WithMany(p => p.UserAvatars)
.HasForeignKey(d => d.PhotoID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_UserAvatar_PhotoID");
entity.HasOne(d => d.UserAccount).WithOne(p => p.UserAvatar)
.HasForeignKey<UserAvatar>(d => d.UserAccountID)
.HasConstraintName("FK_UserAvatar_UserAccount");
});
modelBuilder.Entity<UserCredential>(entity =>
{
entity.ToTable("UserCredential");
entity.HasIndex(e => e.UserAccountID, "AK_UserCredential_UserAccountID").IsUnique();
entity.HasIndex(e => e.UserAccountID, "IX_UserCredential_UserAccount");
entity.Property(e => e.UserCredentialID).HasDefaultValueSql("(newid())");
entity.Property(e => e.CreatedAt)
.HasDefaultValueSql("(getdate())")
.HasColumnType("datetime");
entity.Property(e => e.Expiry)
.HasDefaultValueSql("(dateadd(day,(90),getdate()))")
.HasColumnType("datetime");
entity.Property(e => e.Hash).HasMaxLength(100);
entity.HasOne(d => d.UserAccount).WithOne(p => p.UserCredential)
.HasForeignKey<UserCredential>(d => d.UserAccountID)
.HasConstraintName("FK_UserCredential_UserAccount");
});
modelBuilder.Entity<UserFollow>(entity =>
{
entity.ToTable("UserFollow");
entity.HasIndex(e => new { e.FollowingID, e.UserAccountID }, "IX_UserFollow_FollowingID_UserAccount");
entity.HasIndex(e => new { e.UserAccountID, e.FollowingID }, "IX_UserFollow_UserAccount_FollowingID");
entity.Property(e => e.UserFollowID).HasDefaultValueSql("(newid())");
entity.Property(e => e.CreatedAt)
.HasDefaultValueSql("(getdate())")
.HasColumnType("datetime");
entity.HasOne(d => d.Following).WithMany(p => p.UserFollowFollowings)
.HasForeignKey(d => d.FollowingID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_UserFollow_UserAccountFollowing");
entity.HasOne(d => d.UserAccount).WithMany(p => p.UserFollowUserAccounts)
.HasForeignKey(d => d.UserAccountID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_UserFollow_UserAccount");
});
modelBuilder.Entity<UserVerification>(entity =>
{
entity.ToTable("UserVerification");
entity.HasIndex(e => e.UserAccountID, "AK_UserVerification_UserAccountID").IsUnique();
entity.HasIndex(e => e.UserAccountID, "IX_UserVerification_UserAccount");
entity.Property(e => e.UserVerificationID).HasDefaultValueSql("(newid())");
entity.Property(e => e.VerificationDateTime)
.HasDefaultValueSql("(getdate())")
.HasColumnType("datetime");
entity.HasOne(d => d.UserAccount).WithOne(p => p.UserVerification)
.HasForeignKey<UserVerification>(d => d.UserAccountID)
.HasConstraintName("FK_UserVerification_UserAccount");
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}

View File

@@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class BreweryPost
{
public Guid BreweryPostID { get; set; }
public Guid PostedByID { get; set; }
public string Description { get; set; } = null!;
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
public virtual ICollection<BeerPost> BeerPosts { get; set; } = new List<BeerPost>();
public virtual ICollection<BreweryPostPhoto> BreweryPostPhotos { get; set; } = new List<BreweryPostPhoto>();
public virtual UserAccount PostedBy { get; set; } = null!;
}

View File

@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class BreweryPostPhoto
{
public Guid BreweryPostPhotoID { get; set; }
public Guid BreweryPostID { get; set; }
public Guid PhotoID { get; set; }
public DateTime LinkedAt { get; set; }
public virtual BreweryPost BreweryPost { get; set; } = null!;
public virtual Photo Photo { get; set; } = null!;
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class Comment
{
public Guid CommentID { get; set; }
public string? CommentText { get; set; }
public Guid PostedByID { get; set; }
public virtual UserAccount PostedBy { get; set; } = null!;
}

View File

@@ -1,18 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>DataAccessLayer</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class Photo
{
public Guid PhotoID { get; set; }
public string? Hyperlink { get; set; }
public Guid UploadedByID { get; set; }
public DateTime UploadedAt { get; set; }
public virtual ICollection<BeerPostPhoto> BeerPostPhotos { get; set; } = new List<BeerPostPhoto>();
public virtual ICollection<BreweryPostPhoto> BreweryPostPhotos { get; set; } = new List<BreweryPostPhoto>();
public virtual UserAccount UploadedBy { get; set; } = null!;
public virtual ICollection<UserAvatar> UserAvatars { get; set; } = new List<UserAvatar>();
}

View File

@@ -1,41 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class UserAccount
{
public Guid UserAccountID { get; set; }
public string Username { get; set; } = null!;
public string FirstName { get; set; } = null!;
public string LastName { get; set; } = null!;
public string Email { get; set; } = null!;
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
public DateTime DateOfBirth { get; set; }
public virtual ICollection<BeerPost> BeerPosts { get; set; } = new List<BeerPost>();
public virtual ICollection<BreweryPost> BreweryPosts { get; set; } = new List<BreweryPost>();
public virtual ICollection<Comment> Comments { get; set; } = new List<Comment>();
public virtual ICollection<Photo> Photos { get; set; } = new List<Photo>();
public virtual UserAvatar? UserAvatar { get; set; }
public virtual UserCredential? UserCredential { get; set; }
public virtual ICollection<UserFollow> UserFollowFollowings { get; set; } = new List<UserFollow>();
public virtual ICollection<UserFollow> UserFollowUserAccounts { get; set; } = new List<UserFollow>();
public virtual UserVerification? UserVerification { get; set; }
}

View File

@@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class UserAvatar
{
public Guid UserAvatarID { get; set; }
public Guid UserAccountID { get; set; }
public Guid PhotoID { get; set; }
public virtual Photo Photo { get; set; } = null!;
public virtual UserAccount UserAccount { get; set; } = null!;
}

View File

@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class UserCredential
{
public Guid UserCredentialID { get; set; }
public Guid UserAccountID { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime Expiry { get; set; }
public string Hash { get; set; } = null!;
public virtual UserAccount UserAccount { get; set; } = null!;
}

View File

@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class UserFollow
{
public Guid UserFollowID { get; set; }
public Guid UserAccountID { get; set; }
public Guid FollowingID { get; set; }
public DateTime CreatedAt { get; set; }
public virtual UserAccount Following { get; set; } = null!;
public virtual UserAccount UserAccount { get; set; } = null!;
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
namespace DataAccessLayer;
public partial class UserVerification
{
public Guid UserVerificationID { get; set; }
public Guid UserAccountID { get; set; }
public DateTime VerificationDateTime { get; set; }
public virtual UserAccount UserAccount { get; set; } = null!;
}