Add challenge APIs.

This commit is contained in:
Anduin Xue
2024-01-02 05:48:45 +00:00
parent a3dd418997
commit 91b01b6341
2 changed files with 67 additions and 0 deletions
@@ -0,0 +1,41 @@
using Microsoft.AspNetCore.Mvc;
namespace Aiursoft.ChessServer.Controllers;
[Route("challenges")]
public class ChallengeController : ControllerBase
{
[HttpPost]
[Route("create")]
public IActionResult Create(Guid userId)
{
// Create a new challenge. Add to database.
return Ok();
}
[HttpGet]
[Route("list")]
public IActionResult List()
{
// Show all public challenges.
return Ok();
}
[HttpPost]
[Route("accept/{id:int}")]
public IActionResult Accept(int id, Guid userId)
{
// Accept a challenge. Remove the challenge from database.
// Create a new game. Redirect both players to the game.
return Ok();
}
[HttpPost]
[Route("reject/{id:int}")]
public IActionResult Edit(int id, Guid userId)
{
// If challenge owner is the same as user id,
// Edit a challenge in database.
return Ok();
}
}
+26
View File
@@ -10,4 +10,30 @@ public class Game
public AsyncObservable<string> FenChangedChannel { get; } = new();
public object MovePieceLock { get; } = new();
}
public enum RoleRule
{
CreatorWhite,
AccepterWhite,
Random
}
public enum ChallengePermission
{
Public,
Unlisted,
}
public class Challenge
{
public Guid CreatorId { get; set; }
public Guid? AccepterId { get; set; } = null;
public RoleRule RoleRule { get; set; } = RoleRule.Random;
public TimeSpan TimeLimit { get; set; } = TimeSpan.FromMinutes(10);
public ChallengePermission Permission { get; set; } = ChallengePermission.Public;
}