Compare commits
No commits in common. "ac39117cf4de5b82b2bb1e4c1c7829267c1a3d63" and "252adf0fc70ce6eb411c3fa3bbc8a6cdcdc340e6" have entirely different histories.
ac39117cf4
...
252adf0fc7
1
.gitignore
vendored
1
.gitignore
vendored
@ -406,4 +406,3 @@ FodyWeavers.xsd
|
|||||||
# Secrets
|
# Secrets
|
||||||
JOBot.TClient/appsettings.json
|
JOBot.TClient/appsettings.json
|
||||||
/.idea/.idea.JOBot/Docker/compose.generated.override.yml
|
/.idea/.idea.JOBot/Docker/compose.generated.override.yml
|
||||||
/.idea/.idea.JOBot/Docker/compose.dev.generated.override.yml
|
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
namespace JOBot.Backend.DAL.Context;
|
namespace JOBot.Backend.DAL.Context;
|
||||||
|
|
||||||
using Models;
|
using JOBot.Backend.DAL.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
|
public class AppDbContext : DbContext
|
||||||
{
|
{
|
||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
|
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity<User>()
|
modelBuilder.Entity<User>()
|
||||||
.HasAlternateKey(b => b.UserId);
|
.HasAlternateKey(b => b.TelegramId);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using JOBot.Proto;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace JOBot.Backend.DAL.Models;
|
namespace JOBot.Backend.DAL.Models;
|
||||||
@ -10,30 +9,10 @@ public class User
|
|||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
[Key]
|
[Key]
|
||||||
public required long UserId { get; set; }
|
public required long TelegramId { get; set; }
|
||||||
[MaxLength(255)]
|
[MaxLength(50)]
|
||||||
public string? Username { get; set; }
|
public string? Username { get; set; }
|
||||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
[MaxLength(255)] public string? AccessToken { get; set; } = null;
|
public string? HeadHunterResumeUrl { get; set; }
|
||||||
[MaxLength(255)] public string? RefreshToken { get; set; } = null;
|
|
||||||
|
|
||||||
public bool Eula { get; set; } = false;
|
|
||||||
[MaxLength(255)] public string? CvUrl { get; set; } = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Негоже это маппинги в DAL ложить
|
|
||||||
public static class UserMap
|
|
||||||
{
|
|
||||||
public static GetUserResponse MapToResponse(this User user)
|
|
||||||
{
|
|
||||||
return new GetUserResponse
|
|
||||||
{
|
|
||||||
UserId = user.UserId,
|
|
||||||
Username = user.Username,
|
|
||||||
Eula = user.Eula,
|
|
||||||
IsLogged = user.RefreshToken != null,
|
|
||||||
CVUrl = user.CvUrl
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace JOBot.Backend.Data.Migrations
|
namespace JOBot.Backend.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(AppDbContext))]
|
[DbContext(typeof(AppDbContext))]
|
||||||
[Migration("20250710203327_Initial")]
|
[Migration("20250710125338_Initial")]
|
||||||
partial class Initial
|
partial class Initial
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -31,34 +31,22 @@ namespace JOBot.Backend.Data.Migrations
|
|||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("uuid");
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
b.Property<string>("AccessToken")
|
|
||||||
.HasMaxLength(255)
|
|
||||||
.HasColumnType("character varying(255)");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAt")
|
b.Property<DateTime>("CreatedAt")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<string>("CvUrl")
|
b.Property<string>("HeadHunterResumeUrl")
|
||||||
.HasMaxLength(255)
|
.HasColumnType("text");
|
||||||
.HasColumnType("character varying(255)");
|
|
||||||
|
|
||||||
b.Property<bool>("Eula")
|
b.Property<long>("TelegramId")
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.Property<string>("RefreshToken")
|
|
||||||
.HasMaxLength(255)
|
|
||||||
.HasColumnType("character varying(255)");
|
|
||||||
|
|
||||||
b.Property<long>("UserId")
|
|
||||||
.HasColumnType("bigint");
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
b.Property<string>("Username")
|
b.Property<string>("Username")
|
||||||
.HasMaxLength(255)
|
.HasMaxLength(50)
|
||||||
.HasColumnType("character varying(255)");
|
.HasColumnType("character varying(50)");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasAlternateKey("UserId");
|
b.HasAlternateKey("TelegramId");
|
||||||
|
|
||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
@ -16,18 +16,15 @@ namespace JOBot.Backend.Data.Migrations
|
|||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
UserId = table.Column<long>(type: "bigint", nullable: false),
|
TelegramId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
Username = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
|
Username = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
||||||
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
AccessToken = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
|
HeadHunterResumeUrl = table.Column<string>(type: "text", nullable: true)
|
||||||
RefreshToken = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
|
|
||||||
Eula = table.Column<bool>(type: "boolean", nullable: false),
|
|
||||||
CvUrl = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true)
|
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_Users", x => x.Id);
|
table.PrimaryKey("PK_Users", x => x.Id);
|
||||||
table.UniqueConstraint("AK_Users_UserId", x => x.UserId);
|
table.UniqueConstraint("AK_Users_TelegramId", x => x.TelegramId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -28,34 +28,22 @@ namespace JOBot.Backend.Data.Migrations
|
|||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("uuid");
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
b.Property<string>("AccessToken")
|
|
||||||
.HasMaxLength(255)
|
|
||||||
.HasColumnType("character varying(255)");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAt")
|
b.Property<DateTime>("CreatedAt")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<string>("CvUrl")
|
b.Property<string>("HeadHunterResumeUrl")
|
||||||
.HasMaxLength(255)
|
.HasColumnType("text");
|
||||||
.HasColumnType("character varying(255)");
|
|
||||||
|
|
||||||
b.Property<bool>("Eula")
|
b.Property<long>("TelegramId")
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.Property<string>("RefreshToken")
|
|
||||||
.HasMaxLength(255)
|
|
||||||
.HasColumnType("character varying(255)");
|
|
||||||
|
|
||||||
b.Property<long>("UserId")
|
|
||||||
.HasColumnType("bigint");
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
b.Property<string>("Username")
|
b.Property<string>("Username")
|
||||||
.HasMaxLength(255)
|
.HasMaxLength(50)
|
||||||
.HasColumnType("character varying(255)");
|
.HasColumnType("character varying(50)");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasAlternateKey("UserId");
|
b.HasAlternateKey("TelegramId");
|
||||||
|
|
||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
@ -10,5 +10,4 @@ WORKDIR /app
|
|||||||
COPY --from=build /app .
|
COPY --from=build /app .
|
||||||
EXPOSE 5001
|
EXPOSE 5001
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
ENV ASPNETCORE_ENVIRONMENT Staging
|
|
||||||
ENTRYPOINT ["dotnet", "JOBot.Backend.dll"]
|
ENTRYPOINT ["dotnet", "JOBot.Backend.dll"]
|
@ -9,7 +9,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Google.Protobuf" Version="3.30.2" />
|
<PackageReference Include="Google.Protobuf" Version="3.30.2" />
|
||||||
<PackageReference Include="Grpc.AspNetCore" Version="2.71.0" />
|
<PackageReference Include="Grpc.AspNetCore" Version="2.71.0" />
|
||||||
<PackageReference Include="Grpc.AspNetCore.Server.Reflection" Version="2.71.0" />
|
|
||||||
<PackageReference Include="Grpc.Tools" Version="2.71.0">
|
<PackageReference Include="Grpc.Tools" Version="2.71.0">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
@ -25,8 +24,4 @@
|
|||||||
<Protobuf Include="..\Proto\*" GrpcServices="Server"></Protobuf>
|
<Protobuf Include="..\Proto\*" GrpcServices="Server"></Protobuf>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Data\Migrations\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -1,75 +1,43 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using JOBot.Backend.DAL.Context;
|
|
||||||
using JOBot.Backend.DAL.Models;
|
|
||||||
using JOBot.Proto;
|
using JOBot.Proto;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using JOBot.Backend.DAL.Context;
|
||||||
using User = JOBot.Backend.DAL.Models.User;
|
|
||||||
|
using Models = JOBot.Backend.DAL.Models;
|
||||||
|
|
||||||
namespace JOBot.Backend.Services.gRPC;
|
namespace JOBot.Backend.Services.gRPC;
|
||||||
|
public class UserService(AppDbContext dbContext) : User.UserBase
|
||||||
public class UserService(AppDbContext dbContext) : Proto.User.UserBase
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Create user
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="_"></param>
|
|
||||||
/// <returns>Status of operation (fail if user exists)</returns>
|
|
||||||
public override async Task<RegisterResponse> Register(RegisterRequest request, ServerCallContext _)
|
|
||||||
{
|
|
||||||
if (await dbContext.Users.AnyAsync(x => x.UserId == request.UserId))
|
|
||||||
return new RegisterResponse { Success = false };
|
|
||||||
|
|
||||||
dbContext.Users.Add(new User
|
public override Task<RegisterResponse> Register(
|
||||||
|
RegisterRequest request,
|
||||||
|
ServerCallContext context)
|
||||||
|
{
|
||||||
|
if(!dbContext.Users
|
||||||
|
.Any(x => x.TelegramId == request.UserId))
|
||||||
{
|
{
|
||||||
UserId = request.UserId,
|
dbContext.Users.Add(new Models.User
|
||||||
Username = !string.IsNullOrEmpty(request.Username) ? request.Username : null
|
{
|
||||||
|
TelegramId = request.UserId,
|
||||||
|
Username = !string.IsNullOrEmpty(request.Username) ? request.Username : null
|
||||||
|
});
|
||||||
|
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
return Task.FromResult(new RegisterResponse
|
||||||
|
{
|
||||||
|
Success = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult(new RegisterResponse
|
||||||
|
{
|
||||||
|
Success = false
|
||||||
});
|
});
|
||||||
await dbContext.SaveChangesAsync();
|
|
||||||
|
|
||||||
return new RegisterResponse { Success = true };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public override Task<GetUserResponse> GetUser(
|
||||||
/// Get user for client
|
GetUserRequest request,
|
||||||
/// </summary>
|
ServerCallContext context)
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="_"></param>
|
|
||||||
/// <returns>User, or throws RPC exception if not found</returns>
|
|
||||||
public override async Task<GetUserResponse> GetUser(GetUserRequest request, ServerCallContext _)
|
|
||||||
{
|
{
|
||||||
var user = await dbContext.Users.FirstOrDefaultAsync(x => x.UserId == request.UserId);
|
return null;
|
||||||
ThrowIfUserNotFound(user);
|
|
||||||
|
|
||||||
return user!.MapToResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Accept EULA for user
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="_"></param>
|
|
||||||
/// <returns>Status of operation</returns>
|
|
||||||
public override async Task<AcceptEulaResponse> AcceptEula(AcceptEulaRequest request, ServerCallContext _)
|
|
||||||
{
|
|
||||||
var user = await dbContext.Users.FirstOrDefaultAsync(x => x.UserId == request.UserId);
|
|
||||||
if (user == null)
|
|
||||||
return new AcceptEulaResponse { Success = false };
|
|
||||||
|
|
||||||
user.Eula = request.EulaAccepted;
|
|
||||||
await dbContext.SaveChangesAsync();
|
|
||||||
|
|
||||||
return new AcceptEulaResponse { Success = true };
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Throw RPCException if user not found
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user"></param>
|
|
||||||
/// <exception cref="RpcException"></exception>
|
|
||||||
private static void ThrowIfUserNotFound(User? user)
|
|
||||||
{
|
|
||||||
if (user == null)
|
|
||||||
throw new RpcException(new Status(StatusCode.NotFound, "User not found"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,16 +15,13 @@ public class Startup
|
|||||||
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddGrpc();
|
services.AddGrpc();
|
||||||
services.AddGrpcReflection();
|
|
||||||
|
|
||||||
services.AddDbContext<AppDbContext>(options =>
|
services.AddDbContext<AppDbContext>(options =>
|
||||||
options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL")));
|
options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(WebApplication app, IWebHostEnvironment env)
|
public void Configure(WebApplication app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
app.MapGrpcReflectionService().AllowAnonymous();
|
|
||||||
app.MapGrpcService<UserService>();
|
app.MapGrpcService<UserService>();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,8 +4,5 @@
|
|||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"ConnectionStrings": {
|
|
||||||
"PostgreSQL": "Host=localhost;Port=5432;Database=jobot;Username=postgres;Password=LocalDbPass"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"PostgreSQL": "Host=postgres;Port=5432;Database=jobot_test;Username=postgres;Password=LocalDbPass"
|
"PostgreSQL": "Host=localhost;Port=5432;Database=jobot_test;Username=postgres;Password=LocalDbPass"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,6 @@ option csharp_namespace = "JOBot.Proto";
|
|||||||
service User {
|
service User {
|
||||||
rpc Register (RegisterRequest) returns (RegisterResponse);
|
rpc Register (RegisterRequest) returns (RegisterResponse);
|
||||||
rpc GetUser (GetUserRequest) returns (GetUserResponse);
|
rpc GetUser (GetUserRequest) returns (GetUserResponse);
|
||||||
rpc AcceptEula (AcceptEulaRequest) returns (AcceptEulaResponse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
import "google/protobuf/wrappers.proto";
|
import "google/protobuf/wrappers.proto";
|
||||||
@ -23,18 +22,5 @@ message GetUserRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message GetUserResponse {
|
message GetUserResponse {
|
||||||
int64 user_id = 1;
|
bool logged_to_hh = 1;
|
||||||
google.protobuf.StringValue username = 2;
|
|
||||||
bool eula = 3;
|
|
||||||
bool is_logged = 4;
|
|
||||||
google.protobuf.StringValue CVUrl = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
message AcceptEulaRequest {
|
|
||||||
int64 user_id = 1;
|
|
||||||
bool eula_accepted = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message AcceptEulaResponse{
|
|
||||||
bool success = 1;
|
|
||||||
}
|
}
|
@ -1,37 +0,0 @@
|
|||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
|
||||||
postgres:
|
|
||||||
image: postgres:15
|
|
||||||
environment:
|
|
||||||
POSTGRES_PASSWORD: LocalDbPass
|
|
||||||
POSTGRES_DB: jobot
|
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
volumes:
|
|
||||||
- ./.docker/postgres_data:/var/lib/postgresql/data
|
|
||||||
networks:
|
|
||||||
- jobot
|
|
||||||
|
|
||||||
backend:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: JOBot.Backend/Dockerfile
|
|
||||||
depends_on:
|
|
||||||
- postgres
|
|
||||||
ports:
|
|
||||||
- "5001:5001"
|
|
||||||
networks:
|
|
||||||
- jobot
|
|
||||||
|
|
||||||
bot:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: JOBot.TClient/Dockerfile
|
|
||||||
depends_on:
|
|
||||||
- backend
|
|
||||||
networks:
|
|
||||||
- jobot
|
|
||||||
|
|
||||||
networks:
|
|
||||||
jobot:
|
|
@ -6,6 +6,8 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
POSTGRES_PASSWORD: LocalDbPass
|
POSTGRES_PASSWORD: LocalDbPass
|
||||||
POSTGRES_DB: jobot
|
POSTGRES_DB: jobot
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- ./.docker/postgres_data:/var/lib/postgresql/data
|
- ./.docker/postgres_data:/var/lib/postgresql/data
|
||||||
networks:
|
networks:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user