guys probably we just created INTEGRATION with our library......

This commit is contained in:
Вячеслав 2025-04-16 21:01:10 +05:00
parent 8c0ba59ff7
commit 720f041abf
5 changed files with 74 additions and 9 deletions

View file

@ -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<IActionResult> Get()
{
var result = await _surveyService.GetSurveysAsync();
return Ok(result);
}
}

View file

@ -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<ApplicationDbContext>(options =>
{
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"));
});
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddScoped<SurveyDbContext>(provider => provider.GetRequiredService<ApplicationDbContext>());
builder.Services.AddScoped<ISurveyRepository, SurveyRepository>();
builder.Services.AddScoped<ISurveyService, SurveyService>();
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>

View file

@ -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<User> Users { get; set; }
public DbSet<Group> Groups { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Вызов конфигурации базового контекста для моделей библиотеки
base.OnModelCreating(modelBuilder);
// Здесь можно описывать конфигурацию дополнительных сущностей и связи между моделями библиотеки и моделями приложения.
// Например, если Survey должен иметь связь с User (скажем, владелец опроса):
// Допустим, Survey не имеет в исходной модели свойства UserId.
// Можно использовать теневой ключ, или если ты готов расширить модель Survey в бэкенде.
// Пример с теневым ключом:
// modelBuilder.Entity<Survey>()
// .HasOne<User>() // тип связи: один пользователь
// .WithMany() // например, пользователь может владеть несколькими опросами
// .HasForeignKey("OwnerId"); // теневой ключ, который не прописан в модели Survey
// Или, если расширить Survey:
// public int? OwnerId { get; set; }
// modelBuilder.Entity<Survey>()
// .HasOne<User>()
// .WithMany(u => u.Surveys)
// .HasForeignKey(s => s.OwnerId);
}
}

View file

@ -12,6 +12,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SurveyLib\SurveyLib.Infrastructure.EFCore\SurveyLib.Infrastructure.EFCore.csproj" />
<ProjectReference Include="..\SurveyBackend.Core\SurveyBackend.Core.csproj" />
</ItemGroup>

View file

@ -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