diff --git a/TURN.Libraries.Core/LoggerFactory.cs b/TURN.Libraries.Core/LoggerFactory.cs
deleted file mode 100644
index c6c1042..0000000
--- a/TURN.Libraries.Core/LoggerFactory.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-using System;
-using System.Text;
-using NLog;
-using NLog.Targets;
-
-namespace TURN.Libraries.Core
-{
- public static class LoggerFactory
- {
- public static Logger GetLogger()
- {
- return LogManager.Setup().LoadConfiguration(c =>
- {
- ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget()
- {
- Layout = "${date}|${level:uppercase=true}|${message:withexception=true}"
- };
- FileTarget fileTarget = new FileTarget()
- {
- FileName = Environment.GetEnvironmentVariable("LOG_FILE_PATH"),
- Layout = "${date}|${level:uppercase=true}|${message:withexception=true}",
- Encoding = Encoding.UTF8,
- LineEnding = LineEndingMode.CRLF,
- KeepFileOpen = true,
- ConcurrentWrites = true,
- ArchiveAboveSize = long.Parse(Environment.GetEnvironmentVariable("LOG_FILE_SIZE")),
- MaxArchiveFiles = 10,
- MaxArchiveDays = 365
- };
-
- _ = c.ForLogger("consoleAndFile")
- .FilterMinLevel(LogLevel.Debug)
- .WriteTo(consoleTarget)
- .WriteTo(fileTarget);
- }).GetLogger("consoleAndFile");
- }
- }
-}
diff --git a/TURN.Libraries.Core/Properties/AssemblyInfo.cs b/TURN.Libraries.Core/Properties/AssemblyInfo.cs
deleted file mode 100644
index 740a6f9..0000000
--- a/TURN.Libraries.Core/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("TURN.Libraries.Core")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("*")]
-[assembly: AssemblyProduct("TURN.Libraries.Core")]
-[assembly: AssemblyCopyright("Copyright © * 2023")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("54acf6b1-2512-47c4-877a-5b78e9001b8c")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/TURN.Libraries.Core/TURN.Libraries.Core.csproj b/TURN.Libraries.Core/TURN.Libraries.Core.csproj
deleted file mode 100644
index 0d27a64..0000000
--- a/TURN.Libraries.Core/TURN.Libraries.Core.csproj
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {54ACF6B1-2512-47C4-877A-5B78E9001B8C}
- Library
- Properties
- TURN.Libraries.Core
- TURN.Libraries.Core
- v4.7.2
- 512
- true
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\packages\NLog.5.2.0\lib\net46\NLog.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/TURN.Libraries.Core/packages.config b/TURN.Libraries.Core/packages.config
deleted file mode 100644
index 367cb28..0000000
--- a/TURN.Libraries.Core/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/TURN.Services.Chess/Controllers/TurnController.cs b/TURN.Services.Chess/Controllers/TurnController.cs
index cabe301..d1cf0e1 100644
--- a/TURN.Services.Chess/Controllers/TurnController.cs
+++ b/TURN.Services.Chess/Controllers/TurnController.cs
@@ -1,6 +1,9 @@
-using Microsoft.AspNetCore.Authentication.JwtBearer;
+using ChessDotNet;
+using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
+using NLog;
+using TURN.Services.Chess.DBModel;
namespace TURN.Services.Chess.Controllers
{
@@ -11,6 +14,15 @@ namespace TURN.Services.Chess.Controllers
{
public const string AuthSchemes = JwtBearerDefaults.AuthenticationScheme;
+ private readonly ModelBaseContext _db;
+ private readonly Logger _logger;
+
+ public TurnController(ModelBaseContext db, Logger logger)
+ {
+ _db = db;
+ _logger = logger;
+ }
+
///
/// Тестовый гет.
///
@@ -19,10 +31,42 @@ namespace TURN.Services.Chess.Controllers
{
try
{
+ ChessGame game = new();
+
return Ok(param);
}
catch (Exception ex)
{
+ _logger.Error(ex);
+ return StatusCode(500, $"Internal server error: {ex.Message}");
+ }
+ }
+
+ ///
+ /// Создать игру.
+ ///
+ [HttpGet("startgame/{blackUser}/{whiteUser}")]
+ public ActionResult StartGame(string blackUser, string whiteUser)
+ {
+ try
+ {
+ ChessGame game = new();
+
+ Game obj = new()
+ {
+ BlackUserName = blackUser,
+ WhiteUserName = whiteUser,
+ StartDate = DateTimeOffset.Now.ToUnixTimeSeconds().ToString()
+ };
+
+ _ = _db.Add(obj);
+ _ = _db.SaveChanges();
+
+ return Ok($"Game {obj.GameId} started.");
+ }
+ catch (Exception ex)
+ {
+ _logger.Error(ex);
return StatusCode(500, $"Internal server error: {ex.Message}");
}
}
diff --git a/TURN.Services.Chess/DBModel/Game.cs b/TURN.Services.Chess/DBModel/Game.cs
new file mode 100644
index 0000000..03f4480
--- /dev/null
+++ b/TURN.Services.Chess/DBModel/Game.cs
@@ -0,0 +1,10 @@
+namespace TURN.Services.Chess.DBModel
+{
+ public partial class Game
+ {
+ public long? GameId { get; set; }
+ public string? BlackUserName { get; set; }
+ public string? WhiteUserName { get; set; }
+ public string? StartDate { get; set; }
+ }
+}
diff --git a/TURN.Services.Chess/DBModel/ModelBaseContext.cs b/TURN.Services.Chess/DBModel/ModelBaseContext.cs
new file mode 100644
index 0000000..ee89197
--- /dev/null
+++ b/TURN.Services.Chess/DBModel/ModelBaseContext.cs
@@ -0,0 +1,38 @@
+using Microsoft.EntityFrameworkCore;
+
+namespace TURN.Services.Chess.DBModel
+{
+ public partial class ModelBaseContext : DbContext
+ {
+ public ModelBaseContext()
+ {
+ }
+
+ public ModelBaseContext(DbContextOptions options)
+ : base(options)
+ {
+ }
+
+ public virtual DbSet Games { get; set; }
+
+ //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+ //{
+ // _ = optionsBuilder.UseNpgsql("Server=localhost;Port=5432;Database=TURNChess;UserId=postgres;Password=example;");
+ //}
+
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ _ = modelBuilder.Entity(entity =>
+ {
+ _ = entity.HasKey(e => e.GameId);
+ _ = entity.Property(e => e.GameId)
+ .ValueGeneratedOnAdd()
+ .HasColumnName("GameId");
+ });
+
+ OnModelCreatingPartial(modelBuilder);
+ }
+
+ partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
+ }
+}
diff --git a/TURN.Services.Chess/Migrations/20230625160918_Init.Designer.cs b/TURN.Services.Chess/Migrations/20230625160918_Init.Designer.cs
new file mode 100644
index 0000000..046b25d
--- /dev/null
+++ b/TURN.Services.Chess/Migrations/20230625160918_Init.Designer.cs
@@ -0,0 +1,53 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+using TURN.Services.Chess.DBModel;
+
+#nullable disable
+
+namespace TURN.Services.Chess.Migrations
+{
+ [DbContext(typeof(ModelBaseContext))]
+ [Migration("20230625160918_Init")]
+ partial class Init
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.8")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("TURN.Services.Chess.DBModel.Game", b =>
+ {
+ b.Property("GameId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("bigint")
+ .HasColumnName("GameId");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("GameId"));
+
+ b.Property("BlackUserName")
+ .HasColumnType("text");
+
+ b.Property("StartDate")
+ .HasColumnType("text");
+
+ b.Property("WhiteUserName")
+ .HasColumnType("text");
+
+ b.HasKey("GameId");
+
+ b.ToTable("Games");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/TURN.Services.Chess/Migrations/20230625160918_Init.cs b/TURN.Services.Chess/Migrations/20230625160918_Init.cs
new file mode 100644
index 0000000..bea4f6a
--- /dev/null
+++ b/TURN.Services.Chess/Migrations/20230625160918_Init.cs
@@ -0,0 +1,37 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace TURN.Services.Chess.Migrations
+{
+ ///
+ public partial class Init : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Games",
+ columns: table => new
+ {
+ GameId = table.Column(type: "bigint", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ BlackUserName = table.Column(type: "varchar", nullable: true),
+ WhiteUserName = table.Column(type: "varchar", nullable: true),
+ StartDate = table.Column(type: "varchar", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Games", x => x.GameId);
+ });
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Games");
+ }
+ }
+}
diff --git a/TURN.Services.Chess/Migrations/ModelBaseContextModelSnapshot.cs b/TURN.Services.Chess/Migrations/ModelBaseContextModelSnapshot.cs
new file mode 100644
index 0000000..d945f69
--- /dev/null
+++ b/TURN.Services.Chess/Migrations/ModelBaseContextModelSnapshot.cs
@@ -0,0 +1,50 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+using TURN.Services.Chess.DBModel;
+
+#nullable disable
+
+namespace TURN.Services.Chess.Migrations
+{
+ [DbContext(typeof(ModelBaseContext))]
+ partial class ModelBaseContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.8")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("TURN.Services.Chess.DBModel.Game", b =>
+ {
+ b.Property("GameId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("bigint")
+ .HasColumnName("GameId");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("GameId"));
+
+ b.Property("BlackUserName")
+ .HasColumnType("text");
+
+ b.Property("StartDate")
+ .HasColumnType("text");
+
+ b.Property("WhiteUserName")
+ .HasColumnType("text");
+
+ b.HasKey("GameId");
+
+ b.ToTable("Games");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/TURN.Services.Chess/Properties/launchSettings.json b/TURN.Services.Chess/Properties/launchSettings.json
deleted file mode 100644
index 322941c..0000000
--- a/TURN.Services.Chess/Properties/launchSettings.json
+++ /dev/null
@@ -1,32 +0,0 @@
-{
- "profiles": {
- "http": {
- "commandName": "Project",
- "launchBrowser": true,
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
- },
- "dotnetRunMessages": true,
- "applicationUrl": "http://localhost:5110"
- },
- "IIS Express": {
- "commandName": "IISExpress",
- "launchBrowser": true,
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
- }
- },
- "Docker": {
- "commandName": "Docker",
- "publishAllPorts": true
- }
- },
- "iisSettings": {
- "windowsAuthentication": false,
- "anonymousAuthentication": true,
- "iisExpress": {
- "applicationUrl": "http://localhost:12777",
- "sslPort": 0
- }
- }
-}
\ No newline at end of file
diff --git a/TURN.Services.Chess/Startup.cs b/TURN.Services.Chess/Startup.cs
index 2021ad9..3364c26 100644
--- a/TURN.Services.Chess/Startup.cs
+++ b/TURN.Services.Chess/Startup.cs
@@ -1,7 +1,9 @@
using System.Reflection;
+using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json.Converters;
+using TURN.Services.Chess.DBModel;
namespace TURN.Services.Chess
{
@@ -16,8 +18,8 @@ namespace TURN.Services.Chess
{
jsonOptions.SerializerSettings.Converters.Add(new StringEnumConverter());
});
- //_ = services.AddDbContext(
- // options => options.UseSqlServer(Environment.GetEnvironmentVariable("DB")));
+ _ = services.AddDbContext(
+ options => options.UseNpgsql(Environment.GetEnvironmentVariable("DB")));
}
public void Configure(IApplicationBuilder app)
diff --git a/TURN.Services.Chess/TURN.Services.Chess.csproj b/TURN.Services.Chess/TURN.Services.Chess.csproj
index 1e3faa2..0f3b555 100644
--- a/TURN.Services.Chess/TURN.Services.Chess.csproj
+++ b/TURN.Services.Chess/TURN.Services.Chess.csproj
@@ -11,12 +11,23 @@
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
@@ -24,4 +35,8 @@
+
+
+
+
diff --git a/docker-compose.yml b/docker-compose.yml
index a9977c7..ee2c036 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -9,6 +9,7 @@ services:
- LOG_FILE_PATH=/logs/log.log
- LOG_FILE_SIZE=50000000
- AUTH_API_KEY=asdasdasd
+ - DB=Server=postgresdb;Port=5432;Database=TURNChess;UserId=postgres;Password=example;
ports:
- 80:80
volumes:
@@ -22,11 +23,11 @@ services:
ports:
- 5432:5432
environment:
- - POSTGRES_DB=TURNChese
+ - POSTGRES_DB=TURNChess
- POSTGRES_PASSWORD=example
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- - /d/programming/ChessData/pgdata:/var/lib/postgresql/data
+ - /d/programming/ChessData/db:/var/lib/postgresql/data
networks:
- app-network