feat: added DAL

This commit is contained in:
Lisoveliy
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"
}
}