From 738c055bf7650a9f2d962f51acfba0deefb10b64 Mon Sep 17 00:00:00 2001 From: Aaron Po Date: Tue, 28 Oct 2025 18:28:30 -0400 Subject: [PATCH] begin scaffolding data access layer --- .gitignore | 428 ++++++++++++++++++ .../DataAccessLayer-Tests.csproj | 23 + DataAccessLayer/BeerPost.cs | 35 ++ DataAccessLayer/BeerPostPhoto.cs | 19 + DataAccessLayer/BeerStyle.cs | 15 + DataAccessLayer/BiergartenContext.cs | 300 ++++++++++++ DataAccessLayer/BreweryPost.cs | 23 + DataAccessLayer/BreweryPostPhoto.cs | 19 + DataAccessLayer/Comment.cs | 15 + DataAccessLayer/DataAccessLayer.csproj | 18 + DataAccessLayer/Photo.cs | 23 + DataAccessLayer/UserAccount.cs | 41 ++ DataAccessLayer/UserAvatar.cs | 17 + DataAccessLayer/UserCredential.cs | 19 + DataAccessLayer/UserFollow.cs | 19 + DataAccessLayer/UserVerification.cs | 15 + biergarten.sln | 31 ++ biergarten.sql => schema.sql | 14 +- 18 files changed, 1071 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 DataAccessLayer-Tests/DataAccessLayer-Tests.csproj create mode 100644 DataAccessLayer/BeerPost.cs create mode 100644 DataAccessLayer/BeerPostPhoto.cs create mode 100644 DataAccessLayer/BeerStyle.cs create mode 100644 DataAccessLayer/BiergartenContext.cs create mode 100644 DataAccessLayer/BreweryPost.cs create mode 100644 DataAccessLayer/BreweryPostPhoto.cs create mode 100644 DataAccessLayer/Comment.cs create mode 100644 DataAccessLayer/DataAccessLayer.csproj create mode 100644 DataAccessLayer/Photo.cs create mode 100644 DataAccessLayer/UserAccount.cs create mode 100644 DataAccessLayer/UserAvatar.cs create mode 100644 DataAccessLayer/UserCredential.cs create mode 100644 DataAccessLayer/UserFollow.cs create mode 100644 DataAccessLayer/UserVerification.cs create mode 100644 biergarten.sln rename biergarten.sql => schema.sql (96%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..47a94ef --- /dev/null +++ b/.gitignore @@ -0,0 +1,428 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates +*.env + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ + +[Dd]ebug/x64/ +[Dd]ebugPublic/x64/ +[Rr]elease/x64/ +[Rr]eleases/x64/ +bin/x64/ +obj/x64/ + +[Dd]ebug/x86/ +[Dd]ebugPublic/x86/ +[Rr]elease/x86/ +[Rr]eleases/x86/ +bin/x86/ +obj/x86/ + +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +[Aa][Rr][Mm]64[Ee][Cc]/ +bld/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Build results on 'Bin' directories +**/[Bb]in/* +# Uncomment if you have tasks that rely on *.refresh files to move binaries +# (https://github.com/github/gitignore/pull/3736) +#!**/[Bb]in/*.refresh + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* +*.trx + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Approval Tests result files +*.received.* + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.idb +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +# but not Directory.Build.rsp, as it configures directory-level build defaults +!Directory.Build.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +**/.paket/paket.exe +paket-files/ + +# FAKE - F# Make +**/.fake/ + +# CodeRush personal settings +**/.cr/personal + +# Python Tools for Visual Studio (PTVS) +**/__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +#tools/** +#!tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog +MSBuild_Logs/ + +# AWS SAM Build and Temporary Artifacts folder +.aws-sam + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +**/.mfractor/ + +# Local History for Visual Studio +**/.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +**/.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp diff --git a/DataAccessLayer-Tests/DataAccessLayer-Tests.csproj b/DataAccessLayer-Tests/DataAccessLayer-Tests.csproj new file mode 100644 index 0000000..9c5b30a --- /dev/null +++ b/DataAccessLayer-Tests/DataAccessLayer-Tests.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + diff --git a/DataAccessLayer/BeerPost.cs b/DataAccessLayer/BeerPost.cs new file mode 100644 index 0000000..3242b91 --- /dev/null +++ b/DataAccessLayer/BeerPost.cs @@ -0,0 +1,35 @@ +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 BeerPostPhotos { get; set; } = new List(); + + public virtual BeerStyle BeerStyle { get; set; } = null!; + + public virtual BreweryPost BrewedBy { get; set; } = null!; + + public virtual UserAccount PostedBy { get; set; } = null!; +} diff --git a/DataAccessLayer/BeerPostPhoto.cs b/DataAccessLayer/BeerPostPhoto.cs new file mode 100644 index 0000000..cdb8963 --- /dev/null +++ b/DataAccessLayer/BeerPostPhoto.cs @@ -0,0 +1,19 @@ +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!; +} diff --git a/DataAccessLayer/BeerStyle.cs b/DataAccessLayer/BeerStyle.cs new file mode 100644 index 0000000..4af1a81 --- /dev/null +++ b/DataAccessLayer/BeerStyle.cs @@ -0,0 +1,15 @@ +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 BeerPosts { get; set; } = new List(); +} diff --git a/DataAccessLayer/BiergartenContext.cs b/DataAccessLayer/BiergartenContext.cs new file mode 100644 index 0000000..883a87d --- /dev/null +++ b/DataAccessLayer/BiergartenContext.cs @@ -0,0 +1,300 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; + +namespace DataAccessLayer; + +public partial class BiergartenContext : DbContext +{ + public BiergartenContext() + { + } + + public BiergartenContext(DbContextOptions options) + : base(options) + { + } + + public virtual DbSet BeerPosts { get; set; } + + public virtual DbSet BeerPostPhotos { get; set; } + + public virtual DbSet BeerStyles { get; set; } + + public virtual DbSet BreweryPosts { get; set; } + + public virtual DbSet BreweryPostPhotos { get; set; } + + public virtual DbSet Comments { get; set; } + + public virtual DbSet Photos { get; set; } + + public virtual DbSet UserAccounts { get; set; } + + public virtual DbSet UserAvatars { get; set; } + + public virtual DbSet UserCredentials { get; set; } + + public virtual DbSet UserFollows { get; set; } + + public virtual DbSet 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(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(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(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(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(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(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(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(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(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(d => d.UserAccountID) + .HasConstraintName("FK_UserAvatar_UserAccount"); + }); + + modelBuilder.Entity(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(d => d.UserAccountID) + .HasConstraintName("FK_UserCredential_UserAccount"); + }); + + modelBuilder.Entity(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(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(d => d.UserAccountID) + .HasConstraintName("FK_UserVerification_UserAccount"); + }); + + OnModelCreatingPartial(modelBuilder); + } + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); +} diff --git a/DataAccessLayer/BreweryPost.cs b/DataAccessLayer/BreweryPost.cs new file mode 100644 index 0000000..c706b98 --- /dev/null +++ b/DataAccessLayer/BreweryPost.cs @@ -0,0 +1,23 @@ +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 BeerPosts { get; set; } = new List(); + + public virtual ICollection BreweryPostPhotos { get; set; } = new List(); + + public virtual UserAccount PostedBy { get; set; } = null!; +} diff --git a/DataAccessLayer/BreweryPostPhoto.cs b/DataAccessLayer/BreweryPostPhoto.cs new file mode 100644 index 0000000..1191ae6 --- /dev/null +++ b/DataAccessLayer/BreweryPostPhoto.cs @@ -0,0 +1,19 @@ +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!; +} diff --git a/DataAccessLayer/Comment.cs b/DataAccessLayer/Comment.cs new file mode 100644 index 0000000..4eb0a84 --- /dev/null +++ b/DataAccessLayer/Comment.cs @@ -0,0 +1,15 @@ +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!; +} diff --git a/DataAccessLayer/DataAccessLayer.csproj b/DataAccessLayer/DataAccessLayer.csproj new file mode 100644 index 0000000..bb3f681 --- /dev/null +++ b/DataAccessLayer/DataAccessLayer.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + DataAccessLayer + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/DataAccessLayer/Photo.cs b/DataAccessLayer/Photo.cs new file mode 100644 index 0000000..ba2b881 --- /dev/null +++ b/DataAccessLayer/Photo.cs @@ -0,0 +1,23 @@ +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 BeerPostPhotos { get; set; } = new List(); + + public virtual ICollection BreweryPostPhotos { get; set; } = new List(); + + public virtual UserAccount UploadedBy { get; set; } = null!; + + public virtual ICollection UserAvatars { get; set; } = new List(); +} diff --git a/DataAccessLayer/UserAccount.cs b/DataAccessLayer/UserAccount.cs new file mode 100644 index 0000000..a09ed2c --- /dev/null +++ b/DataAccessLayer/UserAccount.cs @@ -0,0 +1,41 @@ +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 BeerPosts { get; set; } = new List(); + + public virtual ICollection BreweryPosts { get; set; } = new List(); + + public virtual ICollection Comments { get; set; } = new List(); + + public virtual ICollection Photos { get; set; } = new List(); + + public virtual UserAvatar? UserAvatar { get; set; } + + public virtual UserCredential? UserCredential { get; set; } + + public virtual ICollection UserFollowFollowings { get; set; } = new List(); + + public virtual ICollection UserFollowUserAccounts { get; set; } = new List(); + + public virtual UserVerification? UserVerification { get; set; } +} diff --git a/DataAccessLayer/UserAvatar.cs b/DataAccessLayer/UserAvatar.cs new file mode 100644 index 0000000..d9b9aba --- /dev/null +++ b/DataAccessLayer/UserAvatar.cs @@ -0,0 +1,17 @@ +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!; +} diff --git a/DataAccessLayer/UserCredential.cs b/DataAccessLayer/UserCredential.cs new file mode 100644 index 0000000..039861c --- /dev/null +++ b/DataAccessLayer/UserCredential.cs @@ -0,0 +1,19 @@ +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!; +} diff --git a/DataAccessLayer/UserFollow.cs b/DataAccessLayer/UserFollow.cs new file mode 100644 index 0000000..975672f --- /dev/null +++ b/DataAccessLayer/UserFollow.cs @@ -0,0 +1,19 @@ +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!; +} diff --git a/DataAccessLayer/UserVerification.cs b/DataAccessLayer/UserVerification.cs new file mode 100644 index 0000000..c4d7105 --- /dev/null +++ b/DataAccessLayer/UserVerification.cs @@ -0,0 +1,15 @@ +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!; +} diff --git a/biergarten.sln b/biergarten.sln new file mode 100644 index 0000000..869e9ba --- /dev/null +++ b/biergarten.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36603.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccessLayer", "DataAccessLayer\DataAccessLayer.csproj", "{A9FCCEB3-DD88-F8C0-89A3-FD31A7C54F23}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccessLayer-Tests", "DataAccessLayer-Tests\DataAccessLayer-Tests.csproj", "{3638DC4E-D4C8-4DBE-CF3B-EF2C805509CE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A9FCCEB3-DD88-F8C0-89A3-FD31A7C54F23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9FCCEB3-DD88-F8C0-89A3-FD31A7C54F23}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9FCCEB3-DD88-F8C0-89A3-FD31A7C54F23}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9FCCEB3-DD88-F8C0-89A3-FD31A7C54F23}.Release|Any CPU.Build.0 = Release|Any CPU + {3638DC4E-D4C8-4DBE-CF3B-EF2C805509CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3638DC4E-D4C8-4DBE-CF3B-EF2C805509CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3638DC4E-D4C8-4DBE-CF3B-EF2C805509CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3638DC4E-D4C8-4DBE-CF3B-EF2C805509CE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9AF13035-54A8-46EA-8BED-866F683D9AED} + EndGlobalSection +EndGlobal diff --git a/biergarten.sql b/schema.sql similarity index 96% rename from biergarten.sql rename to schema.sql index 1297b47..eab8f62 100644 --- a/biergarten.sql +++ b/schema.sql @@ -321,12 +321,12 @@ CREATE TABLE BeerPost Name NVARCHAR(100) NOT NULL, - Description NVARCHAR(MAX), + Description NVARCHAR(MAX) NOT NULL, - ABV DECIMAL(4,2), + ABV DECIMAL(4,2) NOT NULL, -- Alcohol By Volume (typically 0-67%) - IBU INT, + IBU INT NOT NULL, -- International Bitterness Units (typically 0-100) PostedByID UNIQUEIDENTIFIER NOT NULL, @@ -408,3 +408,11 @@ ON BeerPostPhoto(BeerPostID, PhotoID); ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- + +/* + +Install-Package Microsoft.EntityFrameworkCore.SqlServer +Install-Package Microsoft.EntityFrameworkCore.Tools + +Scaffold-DbContext "Server=(localdb)\ProjectModels;Database=Biergarten;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -Context BiergartenContext -UseDatabaseNames -Force +*/