70 lines
1.9 KiB
C#
70 lines
1.9 KiB
C#
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
|
|
{
|
|
[Authorize(AuthenticationSchemes = AuthSchemes, Roles = "admin")]
|
|
[Route("/[controller]")]
|
|
[ApiController]
|
|
public class TurnController : ControllerBase
|
|
{
|
|
public const string AuthSchemes = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
private readonly ModelBaseContext _db;
|
|
|
|
public TurnController(ModelBaseContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Тестовый гет.
|
|
/// </summary>
|
|
[HttpGet("test/{param}")]
|
|
public ActionResult<string> Get(string param)
|
|
{
|
|
try
|
|
{
|
|
ChessGame game = new();
|
|
|
|
return Ok(param);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
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}");
|
|
}
|
|
}
|
|
}
|
|
}
|