Compare commits
3
Commits
751982beff
...
25e6c093bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25e6c093bc | ||
|
|
855641a272 | ||
|
|
34acef713d |
@@ -2,6 +2,7 @@
|
|||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using NLog;
|
||||||
using TURN.Services.Chess.DBModel;
|
using TURN.Services.Chess.DBModel;
|
||||||
|
|
||||||
namespace TURN.Services.Chess.Controllers
|
namespace TURN.Services.Chess.Controllers
|
||||||
@@ -14,10 +15,12 @@ namespace TURN.Services.Chess.Controllers
|
|||||||
public const string AuthSchemes = JwtBearerDefaults.AuthenticationScheme;
|
public const string AuthSchemes = JwtBearerDefaults.AuthenticationScheme;
|
||||||
|
|
||||||
private readonly ModelBaseContext _db;
|
private readonly ModelBaseContext _db;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public TurnController(ModelBaseContext db)
|
public TurnController(ModelBaseContext db, Logger logger)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -34,6 +37,7 @@ namespace TURN.Services.Chess.Controllers
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
_logger.Error(ex);
|
||||||
return StatusCode(500, $"Internal server error: {ex.Message}");
|
return StatusCode(500, $"Internal server error: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +56,7 @@ namespace TURN.Services.Chess.Controllers
|
|||||||
{
|
{
|
||||||
BlackUserName = blackUser,
|
BlackUserName = blackUser,
|
||||||
WhiteUserName = whiteUser,
|
WhiteUserName = whiteUser,
|
||||||
StartDate = DateTime.Now.ToString()
|
StartDate = DateTimeOffset.Now.ToUnixTimeSeconds().ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
_ = _db.Add(obj);
|
_ = _db.Add(obj);
|
||||||
@@ -62,6 +66,7 @@ namespace TURN.Services.Chess.Controllers
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
_logger.Error(ex);
|
||||||
return StatusCode(500, $"Internal server error: {ex.Message}");
|
return StatusCode(500, $"Internal server error: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
namespace TURN.Services.Chess.DBModel
|
||||||
|
|
||||||
namespace TURN.Services.Chess.DBModel
|
|
||||||
{
|
{
|
||||||
public partial class ModelBaseContext : DbContext
|
public partial class ModelBaseContext : DbContext
|
||||||
{
|
{
|
||||||
@@ -15,10 +13,10 @@ namespace TURN.Services.Chess.DBModel
|
|||||||
|
|
||||||
public virtual DbSet<Game> Games { get; set; }
|
public virtual DbSet<Game> Games { get; set; }
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
//protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
//{
|
||||||
_ = optionsBuilder.UseNpgsql("Server=localhost;Port=5432;Database=TURNChess;UserId=postgres;Password=example;");
|
// _ = optionsBuilder.UseNpgsql("Server=localhost;Port=5432;Database=TURNChess;UserId=postgres;Password=example;");
|
||||||
}
|
//}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
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<long?>("GameId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint")
|
||||||
|
.HasColumnName("GameId");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long?>("GameId"));
|
||||||
|
|
||||||
|
b.Property<string>("BlackUserName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("StartDate")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("WhiteUserName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("GameId");
|
||||||
|
|
||||||
|
b.ToTable("Games");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace TURN.Services.Chess.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Init : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Games",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
GameId = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
BlackUserName = table.Column<string>(type: "varchar", nullable: true),
|
||||||
|
WhiteUserName = table.Column<string>(type: "varchar", nullable: true),
|
||||||
|
StartDate = table.Column<string>(type: "varchar", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Games", x => x.GameId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Games");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
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<long?>("GameId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint")
|
||||||
|
.HasColumnName("GameId");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long?>("GameId"));
|
||||||
|
|
||||||
|
b.Property<string>("BlackUserName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("StartDate")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("WhiteUserName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("GameId");
|
||||||
|
|
||||||
|
b.ToTable("Games");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user