From 881ae85ef7bfb9c1d8d14e576660e59e0b76aa77 Mon Sep 17 00:00:00 2001 From: Lisoveliy <1986developer@gmail.com> Date: Thu, 1 May 2025 00:33:12 +0300 Subject: [PATCH] feat: added DAL --- JOBot.Backend/DAL/Context/AppDbContext.cs | 11 +++++++++++ JOBot.Backend/DAL/Models/User.cs | 9 +++++++++ JOBot.Backend/JOBot.Backend.csproj | 4 ++-- JOBot.Backend/Program.cs | 7 +++++++ JOBot.Backend/Services/gRPC/UserService.cs | 3 +++ JOBot.Backend/appsettings.json | 7 +++++-- JOBot.sln | 3 +++ {Contracts/Proto => Proto}/user.proto | 0 compose.yml | 12 ++++++++++++ sad.proto | 0 10 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 JOBot.Backend/DAL/Context/AppDbContext.cs create mode 100644 JOBot.Backend/DAL/Models/User.cs rename {Contracts/Proto => Proto}/user.proto (100%) create mode 100644 compose.yml create mode 100644 sad.proto diff --git a/JOBot.Backend/DAL/Context/AppDbContext.cs b/JOBot.Backend/DAL/Context/AppDbContext.cs new file mode 100644 index 0000000..a60473f --- /dev/null +++ b/JOBot.Backend/DAL/Context/AppDbContext.cs @@ -0,0 +1,11 @@ +namespace JOBot.Backend.DAL.Context; + +using JOBot.Backend.DAL.Models; +using Microsoft.EntityFrameworkCore; + +class AppDbContext : DbContext +{ + public DbSet Users { get; set; } + + public AppDbContext(DbContextOptions options) : base(options) { } +} \ No newline at end of file diff --git a/JOBot.Backend/DAL/Models/User.cs b/JOBot.Backend/DAL/Models/User.cs new file mode 100644 index 0000000..5ce5d36 --- /dev/null +++ b/JOBot.Backend/DAL/Models/User.cs @@ -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; +} \ No newline at end of file diff --git a/JOBot.Backend/JOBot.Backend.csproj b/JOBot.Backend/JOBot.Backend.csproj index 0d0f710..5850b0b 100644 --- a/JOBot.Backend/JOBot.Backend.csproj +++ b/JOBot.Backend/JOBot.Backend.csproj @@ -21,7 +21,7 @@ - + - + \ No newline at end of file diff --git a/JOBot.Backend/Program.cs b/JOBot.Backend/Program.cs index b50f840..35e3e07 100644 --- a/JOBot.Backend/Program.cs +++ b/JOBot.Backend/Program.cs @@ -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(options => + options.UseNpgsql(builder.Configuration.GetConnectionString("PostgreSQL"))); + var app = builder.Build(); diff --git a/JOBot.Backend/Services/gRPC/UserService.cs b/JOBot.Backend/Services/gRPC/UserService.cs index 719d3be..3743a03 100644 --- a/JOBot.Backend/Services/gRPC/UserService.cs +++ b/JOBot.Backend/Services/gRPC/UserService.cs @@ -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 diff --git a/JOBot.Backend/appsettings.json b/JOBot.Backend/appsettings.json index 10f68b8..12d83db 100644 --- a/JOBot.Backend/appsettings.json +++ b/JOBot.Backend/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" -} + "AllowedHosts": "*", + "ConnectionStrings": { + "PostgreSQL": "Host=localhost;Port=5432;Database=jobot;Username=postgres;Password=LocalDbPass" + } +} \ No newline at end of file diff --git a/JOBot.sln b/JOBot.sln index 40d69d0..e1513fe 100644 --- a/JOBot.sln +++ b/JOBot.sln @@ -45,4 +45,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2E6F4A6D-013E-457A-893F-964E6F350AE7} + EndGlobalSection EndGlobal diff --git a/Contracts/Proto/user.proto b/Proto/user.proto similarity index 100% rename from Contracts/Proto/user.proto rename to Proto/user.proto diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..567e105 --- /dev/null +++ b/compose.yml @@ -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 \ No newline at end of file diff --git a/sad.proto b/sad.proto new file mode 100644 index 0000000..e69de29