From 35331a87f172f786d08b504da8de9e8773ec352e Mon Sep 17 00:00:00 2001 From: shept Date: Tue, 25 Mar 2025 22:56:35 +0500 Subject: [PATCH] i'm not sure what i'm doing --- SurveyBackend/SurveyBackend.API/Program.cs | 20 ++++++++++++++++--- .../SurveyBackend.API.csproj | 6 ++++++ .../appsettings.Development.json | 3 +++ .../SurveyBackend.API/appsettings.json | 5 ++++- .../SurveyBackend.Core/Models/User.cs | 10 +++------- .../SurveyBackend.Core.csproj | 5 +++++ .../Data/DataContext.cs | 5 +++-- 7 files changed, 41 insertions(+), 13 deletions(-) diff --git a/SurveyBackend/SurveyBackend.API/Program.cs b/SurveyBackend/SurveyBackend.API/Program.cs index e7d098c..8aa2aca 100644 --- a/SurveyBackend/SurveyBackend.API/Program.cs +++ b/SurveyBackend/SurveyBackend.API/Program.cs @@ -1,3 +1,8 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using SurveyBackend.Core.Models; +using SurveyBackend.Infrastructure.Data; + namespace SurveyBackend; public class Program @@ -8,7 +13,16 @@ public class Program // Add services to the container. builder.Services.AddAuthorization(); - + + builder.Services.AddDbContext(options => + { + options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")); + }); + + builder.Services.AddIdentity>(options => { }) + .AddEntityFrameworkStores() + .AddDefaultTokenProviders(); + builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle @@ -25,9 +39,9 @@ public class Program } app.UseAuthorization(); - + app.MapControllers(); - + app.Run(); } } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj b/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj index 41529c3..e11596b 100644 --- a/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj +++ b/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj @@ -9,7 +9,13 @@ + + + + + + diff --git a/SurveyBackend/SurveyBackend.API/appsettings.Development.json b/SurveyBackend/SurveyBackend.API/appsettings.Development.json index 0c208ae..c14bf00 100644 --- a/SurveyBackend/SurveyBackend.API/appsettings.Development.json +++ b/SurveyBackend/SurveyBackend.API/appsettings.Development.json @@ -4,5 +4,8 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } + }, + "ConnectionStrings": { + "DefaultConnection": "Data Source=Application.db" } } diff --git a/SurveyBackend/SurveyBackend.API/appsettings.json b/SurveyBackend/SurveyBackend.API/appsettings.json index 10f68b8..19a74e6 100644 --- a/SurveyBackend/SurveyBackend.API/appsettings.json +++ b/SurveyBackend/SurveyBackend.API/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "DefaultConnection": "Data Source=Application.db" + } } diff --git a/SurveyBackend/SurveyBackend.Core/Models/User.cs b/SurveyBackend/SurveyBackend.Core/Models/User.cs index 0f57f37..ab4dcbe 100644 --- a/SurveyBackend/SurveyBackend.Core/Models/User.cs +++ b/SurveyBackend/SurveyBackend.Core/Models/User.cs @@ -1,15 +1,11 @@ +using Microsoft.AspNetCore.Identity; + namespace SurveyBackend.Core.Models; -public class User +public class User : IdentityUser { - public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } - public string Username { get; set; } - public string Email { get; set; } - - public byte[] PasswordSalt { get; set; } - public byte[] PasswordHash { get; set; } public ICollection Groups { get; set; } } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj b/SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj index 3a63532..7bc422a 100644 --- a/SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj +++ b/SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs b/SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs index 26cabc9..a44573f 100644 --- a/SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs +++ b/SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs @@ -1,11 +1,12 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using SurveyBackend.Core.Models; namespace SurveyBackend.Infrastructure.Data; -public class DataContext : DbContext +public class DataContext : IdentityDbContext, int> { - public DbSet Users { get; set; } public DbSet Groups { get; set; } public DataContext(DbContextOptions options) : base(options)