Add MonitorPanel.DataAccess

This commit is contained in:
2026-07-08 03:13:21 +03:00
parent 7c4d557dc4
commit 08aa1bbf90
8 changed files with 106 additions and 0 deletions
@@ -8,11 +8,16 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.9" /> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.9">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.2.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="10.2.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\MonitorPanel.Core\MonitorPanel.Core.csproj" /> <ProjectReference Include="..\MonitorPanel.Core\MonitorPanel.Core.csproj" />
<ProjectReference Include="..\MonitorPanel.DataAccess\MonitorPanel.DataAccess.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -1,3 +1,8 @@
using Microsoft.EntityFrameworkCore;
using MonitorPanel.Core.Abstractions;
using MonitorPanel.DataAccess;
using MonitorPanel.DataAccess.Repositories;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
@@ -8,6 +13,11 @@ builder.Services.AddOpenApi();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<MonitorPanelDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddScoped<IServersRepository, ServersRepository>();
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
@@ -0,0 +1,11 @@
using MonitorPanel.Core.Models;
namespace MonitorPanel.Core.Abstractions;
public interface IServersRepository
{
Task<IEnumerable<Server>> GetAllServersAsync();
Task<Server?> GetServerByIdAsync(Guid id);
Task AddServerAsync(Server server);
Task UpdateServerAsync(Guid id, Server server);
Task DeleteServerAsync(Guid id);
}
@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
namespace MonitorPanel.DataAccess.Entities;
public class ServerEntity
{
public Guid Id { get; set; }
public string Name { get; set; } = null!;
public bool IsHttps { get; set; }
[Required]
public string Address { get; set; } = null!;
string? Path { get; set; }
[Required]
public int Port { get; set; }
}
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.9">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.9">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MonitorPanel.Core\MonitorPanel.Core.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,8 @@
using Microsoft.EntityFrameworkCore;
using MonitorPanel.DataAccess.Entities;
namespace MonitorPanel.DataAccess;
public class MonitorPanelDbContext(DbContextOptions<MonitorPanelDbContext> options) : DbContext(options)
{
public DbSet<ServerEntity> Servers => Set<ServerEntity>();
}
@@ -0,0 +1,31 @@
using MonitorPanel.Core.Abstractions;
using MonitorPanel.Core.Models;
namespace MonitorPanel.DataAccess.Repositories;
public class ServersRepository : IServersRepository
{
public Task AddServerAsync(Server server)
{
throw new NotImplementedException();
}
public Task DeleteServerAsync(Guid id)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Server>> GetAllServersAsync()
{
throw new NotImplementedException();
}
public Task<Server?> GetServerByIdAsync(Guid id)
{
throw new NotImplementedException();
}
public Task UpdateServerAsync(Guid id, Server server)
{
throw new NotImplementedException();
}
}
+1
View File
@@ -1,4 +1,5 @@
<Solution> <Solution>
<Project Path="MonitorPanel.API/MonitorPanel.API.csproj" /> <Project Path="MonitorPanel.API/MonitorPanel.API.csproj" />
<Project Path="MonitorPanel.Core/MonitorPanel.Core.csproj" /> <Project Path="MonitorPanel.Core/MonitorPanel.Core.csproj" />
<Project Path="MonitorPanel.DataAccess/MonitorPanel.DataAccess.csproj" />
</Solution> </Solution>