feat: added DAL

This commit is contained in:
Pavel-Savely Savianok 2025-05-01 00:33:12 +03:00
parent 5164448dd5
commit 881ae85ef7
10 changed files with 52 additions and 4 deletions

View File

@ -0,0 +1,11 @@
namespace JOBot.Backend.DAL.Context;
using JOBot.Backend.DAL.Models;
using Microsoft.EntityFrameworkCore;
class AppDbContext : DbContext
{
public DbSet<User> Users { get; set; }
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
}

View File

@ -0,0 +1,9 @@
namespace JOBot.Backend.DAL.Models;
public class User
{
public Guid Id { get; set; }
public long TelegramId { get; set; }
public string? Username { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.Now;
}

View File

@ -21,7 +21,7 @@
</ItemGroup>
<ItemGroup>
<Protobuf Include="..\Contracts\Proto\*" GrpcServices="Server"></Protobuf>
<Protobuf Include="..\Proto\*" GrpcServices="Server"></Protobuf>
</ItemGroup>
</Project>
</Project>

View File

@ -1,6 +1,13 @@
using JOBot.Backend.DAL.Context;
using JOBot.Backend.Services.gRPC;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGrpc();
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("PostgreSQL")));
var app = builder.Build();

View File

@ -1,3 +1,5 @@
namespace JOBot.Backend.Services.gRPC;
using Grpc.Core;
using JOBot.Proto;
@ -8,6 +10,7 @@ class UserService : User.UserBase
ServerCallContext context)
{
return Task.FromResult(new RegisterResponse
{
UserId = request.UserId

View File

@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
"AllowedHosts": "*",
"ConnectionStrings": {
"PostgreSQL": "Host=localhost;Port=5432;Database=jobot;Username=postgres;Password=LocalDbPass"
}
}

View File

@ -45,4 +45,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2E6F4A6D-013E-457A-893F-964E6F350AE7}
EndGlobalSection
EndGlobal

12
compose.yml Normal file
View File

@ -0,0 +1,12 @@
version: '3.8'
services:
postgres:
image: postgres:15
environment:
POSTGRES_PASSWORD: LocalDbPass
POSTGRES_DB: jobot
ports:
- "5432:5432"
volumes:
- ./postgres_data:/var/lib/postgresql/data

0
sad.proto Normal file
View File