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..1fc7c9b 100644 --- a/TURN.Services.Chess/Controllers/TurnController.cs +++ b/TURN.Services.Chess/Controllers/TurnController.cs @@ -1,6 +1,8 @@ -using Microsoft.AspNetCore.Authentication.JwtBearer; +using ChessDotNet; +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using TURN.Services.Chess.DBModel; namespace TURN.Services.Chess.Controllers { @@ -11,6 +13,13 @@ namespace TURN.Services.Chess.Controllers { public const string AuthSchemes = JwtBearerDefaults.AuthenticationScheme; + private readonly ModelBaseContext _db; + + public TurnController(ModelBaseContext db) + { + _db = db; + } + /// /// Тестовый гет. /// @@ -19,6 +28,8 @@ namespace TURN.Services.Chess.Controllers { try { + ChessGame game = new(); + return Ok(param); } catch (Exception ex) @@ -26,5 +37,33 @@ namespace TURN.Services.Chess.Controllers 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 = DateTime.Now.ToString() + }; + + _ = _db.Add(obj); + _ = _db.SaveChanges(); + + return Ok($"Game {obj.GameId} started."); + } + catch (Exception 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..d78889a --- /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/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