diff --git a/WatchIt.Database/WatchIt.Database.Model/Account/Account.cs b/WatchIt.Database/WatchIt.Database.Model/Account/Account.cs new file mode 100644 index 0000000..9bdbfee --- /dev/null +++ b/WatchIt.Database/WatchIt.Database.Model/Account/Account.cs @@ -0,0 +1,99 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WatchIt.Database.Model.Account +{ + public class Account : IEntity + { + #region PROPERTIES + + public long Id { get; set; } + public string Username { get; set; } + public string Email { get; set; } + public string Description { get; set; } + public Guid AccountProfilePictureId { get; set; } + + // BackgroundPicture key to MovieImages + // public Guid BackgroundPicture { get; set; } + + public byte[] Password { get; set; } + public string LeftSalt { get; set; } + public string RightSalt { get; set; } + public bool IsAdmin { get; set; } = false; + public DateTimeOffset CreationDate { get; set; } + public DateTimeOffset LastActive { get; set; } + + #endregion + + + + #region NAVIGATION + + public AccountProfilePicture AccountProfilePicture { get; set; } + + #endregion + + + + #region METHODS + + static void IEntity.Build(EntityTypeBuilder builder) + { + builder.HasKey(x => x.Id); + builder.HasIndex(x => x.Id) + .IsUnique(); + builder.Property(x => x.Id) + .IsRequired(); + + builder.Property(x => x.Username) + .HasMaxLength(50) + .IsRequired(); + + builder.Property(x => x.Email) + .HasMaxLength(320) + .IsRequired(); + + builder.Property(x => x.Description) + .HasMaxLength(1000); + + builder.HasOne(x => x.AccountProfilePicture) + .WithOne(x => x.Account) + .HasForeignKey(e => e.AccountProfilePictureId); + builder.Property(x => x.AccountProfilePictureId); + + builder.Property(x => x.Password) + .HasMaxLength(1000) + .IsRequired(); + + builder.Property(x => x.LeftSalt) + .HasMaxLength(20) + .IsRequired(); + + builder.Property(x => x.RightSalt) + .HasMaxLength(20) + .IsRequired(); + + builder.Property(x => x.IsAdmin) + .IsRequired(); + + builder.Property(x => x.CreationDate) + .IsRequired() + .HasDefaultValueSql("now()"); + + builder.Property(x => x.LastActive) + .IsRequired() + .HasDefaultValueSql("now()"); + } + + #endregion + } +} diff --git a/WatchIt.Database/WatchIt.Database.Model/Account/AccountProfilePicture.cs b/WatchIt.Database/WatchIt.Database.Model/Account/AccountProfilePicture.cs new file mode 100644 index 0000000..50cbe97 --- /dev/null +++ b/WatchIt.Database/WatchIt.Database.Model/Account/AccountProfilePicture.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WatchIt.Database.Model.Account +{ + public class AccountProfilePicture : IEntity + { + #region PROPERTIES + + public Guid Id { get; set; } + public byte[] Image { get; set; } + public string MimeType { get; set; } + public DateTimeOffset UploadDate { get; set; } + + #endregion + + + + #region NAVIGATION + + public Account Account { get; set; } + + #endregion + + + + #region PUBLIC METHODS + + static void IEntity.Build(EntityTypeBuilder builder) + { + builder.HasKey(x => x.Id); + builder.HasIndex(x => x.Id) + .IsUnique(); + builder.Property(x => x.Id) + .IsRequired(); + + builder.Property(x => x.Image) + .HasMaxLength(-1) + .IsRequired(); + + builder.Property(x => x.MimeType) + .HasMaxLength(50) + .IsRequired(); + + builder.Property(x => x.UploadDate) + .IsRequired() + .HasDefaultValueSql("now()"); + } + + #endregion + } +} diff --git a/WatchIt.Database/WatchIt.Database.Model/EntityBuilder.cs b/WatchIt.Database/WatchIt.Database.Model/EntityBuilder.cs new file mode 100644 index 0000000..5d58bd5 --- /dev/null +++ b/WatchIt.Database/WatchIt.Database.Model/EntityBuilder.cs @@ -0,0 +1,20 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WatchIt.Database.Model +{ + public static class EntityBuilder + { + #region PUBLIC METHODS + + public static void Build(ModelBuilder builder) where T : class, IEntity => Build(builder.Entity()); + public static void Build(EntityTypeBuilder builder) where T : class, IEntity => T.Build(builder); + + #endregion + } +} diff --git a/WatchIt.Database/WatchIt.Database.Model/IEntity.cs b/WatchIt.Database/WatchIt.Database.Model/IEntity.cs new file mode 100644 index 0000000..de27755 --- /dev/null +++ b/WatchIt.Database/WatchIt.Database.Model/IEntity.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WatchIt.Database.Model +{ + public interface IEntity where T : class + { + #region METHODS + + static abstract void Build(EntityTypeBuilder builder); + + #endregion + } +} diff --git a/WatchIt.Database/WatchIt.Database.Model/WatchIt.Database.Model.csproj b/WatchIt.Database/WatchIt.Database.Model/WatchIt.Database.Model.csproj new file mode 100644 index 0000000..e3240b1 --- /dev/null +++ b/WatchIt.Database/WatchIt.Database.Model/WatchIt.Database.Model.csproj @@ -0,0 +1,16 @@ + + + + net8.0 + enable + enable + + + + + + + + + + diff --git a/WatchIt.Database/WatchIt.Database/DatabaseContext.cs b/WatchIt.Database/WatchIt.Database/DatabaseContext.cs new file mode 100644 index 0000000..8634160 --- /dev/null +++ b/WatchIt.Database/WatchIt.Database/DatabaseContext.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Principal; +using System.Text; +using System.Threading.Tasks; +using WatchIt.Database.Model; +using WatchIt.Database.Model.Account; + +namespace WatchIt.Database +{ + public class DatabaseContext : DbContext + { + #region CONSTRUCTORS + + public DatabaseContext() { } + + public DatabaseContext(DbContextOptions options) : base(options) { } + + #endregion + + + + #region PROPERTIES + + // Account + public virtual DbSet Accounts { get; set; } + public virtual DbSet AccountProfilePictures { get; set; } + + #endregion + + + + #region METHODS + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseNpgsql("name=Default"); + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + // Account + EntityBuilder.Build(modelBuilder); + EntityBuilder.Build(modelBuilder); + } + + #endregion + } +} diff --git a/WatchIt.Database/WatchIt.Database/Migrations/20240317125055_Migration1.Designer.cs b/WatchIt.Database/WatchIt.Database/Migrations/20240317125055_Migration1.Designer.cs new file mode 100644 index 0000000..7745a9f --- /dev/null +++ b/WatchIt.Database/WatchIt.Database/Migrations/20240317125055_Migration1.Designer.cs @@ -0,0 +1,141 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using WatchIt.Database; + +#nullable disable + +namespace WatchIt.Database.Migrations +{ + [DbContext(typeof(DatabaseContext))] + [Migration("20240317125055_Migration1")] + partial class Migration1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AccountProfilePictureId") + .HasColumnType("uuid"); + + b.Property("CreationDate") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(320) + .HasColumnType("character varying(320)"); + + b.Property("IsAdmin") + .HasColumnType("boolean"); + + b.Property("LastActive") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("LeftSalt") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("bytea"); + + b.Property("RightSalt") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("AccountProfilePictureId") + .IsUnique(); + + b.HasIndex("Id") + .IsUnique(); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("WatchIt.Database.Model.Account.AccountProfilePicture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasMaxLength(-1) + .HasColumnType("bytea"); + + b.Property("MimeType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("UploadDate") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.HasKey("Id"); + + b.HasIndex("Id") + .IsUnique(); + + b.ToTable("AccountProfilePictures"); + }); + + modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b => + { + b.HasOne("WatchIt.Database.Model.Account.AccountProfilePicture", "AccountProfilePicture") + .WithOne("Account") + .HasForeignKey("WatchIt.Database.Model.Account.Account", "AccountProfilePictureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("AccountProfilePicture"); + }); + + modelBuilder.Entity("WatchIt.Database.Model.Account.AccountProfilePicture", b => + { + b.Navigation("Account") + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WatchIt.Database/WatchIt.Database/Migrations/20240317125055_Migration1.cs b/WatchIt.Database/WatchIt.Database/Migrations/20240317125055_Migration1.cs new file mode 100644 index 0000000..e68d4a5 --- /dev/null +++ b/WatchIt.Database/WatchIt.Database/Migrations/20240317125055_Migration1.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace WatchIt.Database.Migrations +{ + /// + public partial class Migration1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AccountProfilePictures", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Image = table.Column(type: "bytea", maxLength: -1, nullable: false), + MimeType = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + UploadDate = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()") + }, + constraints: table => + { + table.PrimaryKey("PK_AccountProfilePictures", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Accounts", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Username = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "character varying(320)", maxLength: 320, nullable: false), + Description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: false), + AccountProfilePictureId = table.Column(type: "uuid", nullable: false), + Password = table.Column(type: "bytea", maxLength: 1000, nullable: false), + LeftSalt = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + RightSalt = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + IsAdmin = table.Column(type: "boolean", nullable: false), + CreationDate = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), + LastActive = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()") + }, + constraints: table => + { + table.PrimaryKey("PK_Accounts", x => x.Id); + table.ForeignKey( + name: "FK_Accounts_AccountProfilePictures_AccountProfilePictureId", + column: x => x.AccountProfilePictureId, + principalTable: "AccountProfilePictures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AccountProfilePictures_Id", + table: "AccountProfilePictures", + column: "Id", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Accounts_AccountProfilePictureId", + table: "Accounts", + column: "AccountProfilePictureId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Accounts_Id", + table: "Accounts", + column: "Id", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Accounts"); + + migrationBuilder.DropTable( + name: "AccountProfilePictures"); + } + } +} diff --git a/WatchIt.Database/WatchIt.Database/Migrations/DatabaseContextModelSnapshot.cs b/WatchIt.Database/WatchIt.Database/Migrations/DatabaseContextModelSnapshot.cs new file mode 100644 index 0000000..5dbbac4 --- /dev/null +++ b/WatchIt.Database/WatchIt.Database/Migrations/DatabaseContextModelSnapshot.cs @@ -0,0 +1,138 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using WatchIt.Database; + +#nullable disable + +namespace WatchIt.Database.Migrations +{ + [DbContext(typeof(DatabaseContext))] + partial class DatabaseContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AccountProfilePictureId") + .HasColumnType("uuid"); + + b.Property("CreationDate") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(320) + .HasColumnType("character varying(320)"); + + b.Property("IsAdmin") + .HasColumnType("boolean"); + + b.Property("LastActive") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("LeftSalt") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("bytea"); + + b.Property("RightSalt") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("AccountProfilePictureId") + .IsUnique(); + + b.HasIndex("Id") + .IsUnique(); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("WatchIt.Database.Model.Account.AccountProfilePicture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasMaxLength(-1) + .HasColumnType("bytea"); + + b.Property("MimeType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("UploadDate") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.HasKey("Id"); + + b.HasIndex("Id") + .IsUnique(); + + b.ToTable("AccountProfilePictures"); + }); + + modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b => + { + b.HasOne("WatchIt.Database.Model.Account.AccountProfilePicture", "AccountProfilePicture") + .WithOne("Account") + .HasForeignKey("WatchIt.Database.Model.Account.Account", "AccountProfilePictureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("AccountProfilePicture"); + }); + + modelBuilder.Entity("WatchIt.Database.Model.Account.AccountProfilePicture", b => + { + b.Navigation("Account") + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WatchIt.Database/WatchIt.Database/WatchIt.Database.csproj b/WatchIt.Database/WatchIt.Database/WatchIt.Database.csproj new file mode 100644 index 0000000..49b2ef1 --- /dev/null +++ b/WatchIt.Database/WatchIt.Database/WatchIt.Database.csproj @@ -0,0 +1,31 @@ + + + + net8.0 + enable + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + diff --git a/WatchIt.sln b/WatchIt.sln index 16c8536..66d758f 100644 --- a/WatchIt.sln +++ b/WatchIt.sln @@ -3,12 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34701.34 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt", "WatchIt\WatchIt.csproj", "{2F0CE680-4F0C-4369-966A-B1332CE97094}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WatchIt", "WatchIt\WatchIt.csproj", "{2F0CE680-4F0C-4369-966A-B1332CE97094}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WatchIt.Website", "WatchIt.Website", "{2BB2D2C3-6095-4714-8B69-4CF8C2CBD075}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WatchIt.WebAPI", "WatchIt.WebAPI", "{76B40EBF-8054-4A15-ABE8-141E1CCA6E4E}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WatchIt.Database", "WatchIt.Database", "{98C91E27-2C36-4C74-A80F-9ACD7F28BC54}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WatchIt.Database", "WatchIt.Database\WatchIt.Database\WatchIt.Database.csproj", "{8CDAA140-05FC-4EB7-A9F5-A85032C8FD2F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.Database.Model", "WatchIt.Database\WatchIt.Database.Model\WatchIt.Database.Model.csproj", "{46A294FF-F15F-4773-9E33-AFFC6DF2148C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -19,10 +25,22 @@ Global {2F0CE680-4F0C-4369-966A-B1332CE97094}.Debug|Any CPU.Build.0 = Debug|Any CPU {2F0CE680-4F0C-4369-966A-B1332CE97094}.Release|Any CPU.ActiveCfg = Release|Any CPU {2F0CE680-4F0C-4369-966A-B1332CE97094}.Release|Any CPU.Build.0 = Release|Any CPU + {8CDAA140-05FC-4EB7-A9F5-A85032C8FD2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CDAA140-05FC-4EB7-A9F5-A85032C8FD2F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CDAA140-05FC-4EB7-A9F5-A85032C8FD2F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CDAA140-05FC-4EB7-A9F5-A85032C8FD2F}.Release|Any CPU.Build.0 = Release|Any CPU + {46A294FF-F15F-4773-9E33-AFFC6DF2148C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46A294FF-F15F-4773-9E33-AFFC6DF2148C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46A294FF-F15F-4773-9E33-AFFC6DF2148C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46A294FF-F15F-4773-9E33-AFFC6DF2148C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {8CDAA140-05FC-4EB7-A9F5-A85032C8FD2F} = {98C91E27-2C36-4C74-A80F-9ACD7F28BC54} + {46A294FF-F15F-4773-9E33-AFFC6DF2148C} = {98C91E27-2C36-4C74-A80F-9ACD7F28BC54} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1D253492-C786-4DD9-80B5-7DE51D4D3304} EndGlobalSection diff --git a/WatchIt/Program.cs b/WatchIt/Program.cs index c739100..474574c 100644 --- a/WatchIt/Program.cs +++ b/WatchIt/Program.cs @@ -1,18 +1,37 @@ +using Microsoft.EntityFrameworkCore; +using WatchIt.Database; using WatchIt.Website; namespace WatchIt { public class Program { + #region FIELDS + + protected static WebApplicationBuilder _builder; + + #endregion + + + + #region PUBLIC METHODS + public static void Main(string[] args) { - var builder = WebApplication.CreateBuilder(args); + _builder = WebApplication.CreateBuilder(args); + + // Logging + _builder.Logging.ClearProviders(); + _builder.Logging.AddConsole(); + + // Database + _builder.Services.AddDbContext(x => x.UseNpgsql(_builder.Configuration.GetConnectionString("Default")), ServiceLifetime.Singleton); // Add services to the container. - builder.Services.AddRazorComponents() + _builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); - var app = builder.Build(); + var app = _builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) @@ -28,9 +47,11 @@ namespace WatchIt app.UseAntiforgery(); app.MapRazorComponents() - .AddInteractiveServerRenderMode(); + .AddInteractiveServerRenderMode(); app.Run(); } + + #endregion } } diff --git a/WatchIt/WatchIt.csproj b/WatchIt/WatchIt.csproj index fd6fa38..c41500f 100644 --- a/WatchIt/WatchIt.csproj +++ b/WatchIt/WatchIt.csproj @@ -10,4 +10,24 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + diff --git a/WatchIt/appsettings.json b/WatchIt/appsettings.json index 10f68b8..2c99ff3 100644 --- a/WatchIt/appsettings.json +++ b/WatchIt/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "Default": "Host=localhost;Database=watchit;Username=postgres;Password=95sYN7qwjLxsP9w" + } }