diff --git a/SurveyBackend/SurveyBackend.API/Controllers/TestController.cs b/SurveyBackend/SurveyBackend.API/Controllers/TestController.cs index f962090..0056728 100644 --- a/SurveyBackend/SurveyBackend.API/Controllers/TestController.cs +++ b/SurveyBackend/SurveyBackend.API/Controllers/TestController.cs @@ -1,6 +1,23 @@ +using Microsoft.AspNetCore.Mvc; +using SurveyLib.Core.Services; + namespace SurveyBackend.Controllers; -public class TestController +[ApiController] +[Route("test")] +public class TestController : ControllerBase { - + private readonly ISurveyService _surveyService; + + public TestController(ISurveyService surveyService) + { + _surveyService = surveyService; + } + + [HttpGet] + public async Task Get() + { + var result = await _surveyService.GetSurveysAsync(); + return Ok(result); + } } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/Program.cs b/SurveyBackend/SurveyBackend.API/Program.cs index 23fd2d7..2aa90b2 100644 --- a/SurveyBackend/SurveyBackend.API/Program.cs +++ b/SurveyBackend/SurveyBackend.API/Program.cs @@ -4,6 +4,11 @@ using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using SurveyBackend.Infrastructure; using SurveyBackend.Infrastructure.Data; +using SurveyLib.Core.Repositories; +using SurveyLib.Core.Services; +using SurveyLib.Infrastructure.EFCore.Data; +using SurveyLib.Infrastructure.EFCore.Repositories; +using SurveyLib.Infrastructure.EFCore.Services; namespace SurveyBackend; @@ -18,9 +23,13 @@ public class Program builder.Services.AddAuthorization(); builder.Services.AddDbContext(options => - { - options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")); - }); + options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"))); + + builder.Services.AddScoped(provider => provider.GetRequiredService()); + + builder.Services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => diff --git a/SurveyBackend/SurveyBackend.Infrastructure/Data/ApplicationDbContext.cs b/SurveyBackend/SurveyBackend.Infrastructure/Data/ApplicationDbContext.cs index fb500db..66a0468 100644 --- a/SurveyBackend/SurveyBackend.Infrastructure/Data/ApplicationDbContext.cs +++ b/SurveyBackend/SurveyBackend.Infrastructure/Data/ApplicationDbContext.cs @@ -1,16 +1,42 @@ -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using SurveyBackend.Core.Models; +using SurveyLib.Core.Models; +using SurveyLib.Infrastructure.EFCore.Data; namespace SurveyBackend.Infrastructure.Data; -public class ApplicationDbContext : DbContext +public class ApplicationDbContext : SurveyDbContext { public DbSet Users { get; set; } public DbSet Groups { get; set; } - public ApplicationDbContext(DbContextOptions options) : base(options) + public ApplicationDbContext(DbContextOptions options) + : base(options) { + + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + // Вызов конфигурации базового контекста для моделей библиотеки + base.OnModelCreating(modelBuilder); + + // Здесь можно описывать конфигурацию дополнительных сущностей и связи между моделями библиотеки и моделями приложения. + // Например, если Survey должен иметь связь с User (скажем, владелец опроса): + + // Допустим, Survey не имеет в исходной модели свойства UserId. + // Можно использовать теневой ключ, или если ты готов расширить модель Survey в бэкенде. + // Пример с теневым ключом: + // modelBuilder.Entity() + // .HasOne() // тип связи: один пользователь + // .WithMany() // например, пользователь может владеть несколькими опросами + // .HasForeignKey("OwnerId"); // теневой ключ, который не прописан в модели Survey + + // Или, если расширить Survey: + // public int? OwnerId { get; set; } + // modelBuilder.Entity() + // .HasOne() + // .WithMany(u => u.Surveys) + // .HasForeignKey(s => s.OwnerId); } } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj b/SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj index ce7dbfc..8d6e23a 100644 --- a/SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj +++ b/SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj @@ -12,6 +12,7 @@ + diff --git a/SurveyBackend/SurveyBackend.sln b/SurveyBackend/SurveyBackend.sln index c79d7d1..bbfd9ab 100644 --- a/SurveyBackend/SurveyBackend.sln +++ b/SurveyBackend/SurveyBackend.sln @@ -6,6 +6,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyBackend.Core", "Surve EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyBackend.Infrastructure", "SurveyBackend.Infrastructure\SurveyBackend.Infrastructure.csproj", "{4006471D-9F65-4AD6-852B-88A1211B49F4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyLib.Infrastructure.EFCore", "..\SurveyLib\SurveyLib.Infrastructure.EFCore\SurveyLib.Infrastructure.EFCore.csproj", "{CD9FE310-CDD1-4661-AB41-E606D35E1694}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyLib.Core", "..\SurveyLib\SurveyLib.Core\SurveyLib.Core.csproj", "{C17C405B-37CF-48E6-AA44-44B878F4DE56}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,5 +28,13 @@ Global {4006471D-9F65-4AD6-852B-88A1211B49F4}.Debug|Any CPU.Build.0 = Debug|Any CPU {4006471D-9F65-4AD6-852B-88A1211B49F4}.Release|Any CPU.ActiveCfg = Release|Any CPU {4006471D-9F65-4AD6-852B-88A1211B49F4}.Release|Any CPU.Build.0 = Release|Any CPU + {CD9FE310-CDD1-4661-AB41-E606D35E1694}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD9FE310-CDD1-4661-AB41-E606D35E1694}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD9FE310-CDD1-4661-AB41-E606D35E1694}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD9FE310-CDD1-4661-AB41-E606D35E1694}.Release|Any CPU.Build.0 = Release|Any CPU + {C17C405B-37CF-48E6-AA44-44B878F4DE56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C17C405B-37CF-48E6-AA44-44B878F4DE56}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C17C405B-37CF-48E6-AA44-44B878F4DE56}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C17C405B-37CF-48E6-AA44-44B878F4DE56}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal