db + migrations
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Тестовый гет.
|
||||
/// </summary>
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать игру.
|
||||
/// </summary>
|
||||
[HttpGet("startgame/{blackUser}/{whiteUser}")]
|
||||
public ActionResult<string> 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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user