feat: foo
This commit is contained in:
1 parent
9d741b8516
commit
3413c4f94a
5 files changed
+81
-87
No files matched your search
@@ -1,8 +1,15 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Phenix.Models;
|
||||
using Phenix.Services;
|
||||
|
||||
namespace Phenix.Controllers;
|
||||
|
||||
public record CreateGameRequest(
|
||||
string Date, string Time, string Home, string Away,
|
||||
int? HomeScore = null, int? AwayScore = null,
|
||||
bool Practice = false, bool Rain = false
|
||||
);
|
||||
|
||||
[Route("/api")]
|
||||
public class ApiController : Controller
|
||||
{
|
||||
@@ -42,4 +49,26 @@ public class ApiController : Controller
|
||||
var years = games.Select(g => g.Year).Distinct().OrderByDescending(y => y);
|
||||
return Json(years);
|
||||
}
|
||||
|
||||
[HttpPost("games")]
|
||||
public async Task<IActionResult> CreateGame([FromBody] CreateGameRequest req)
|
||||
{
|
||||
var (game, error) = await _games.CreateNewGame(req.Date, req.Time, req.Home, req.Away);
|
||||
if (game is null)
|
||||
return error switch
|
||||
{
|
||||
"game already exists at this date/time" => Conflict(new { error }),
|
||||
_ => BadRequest(new { error }),
|
||||
};
|
||||
|
||||
await _games.UpdateGame(game.Id, req.HomeScore, req.AwayScore, req.Rain, req.Practice);
|
||||
return Created($"/api/games/{game.Id}", game);
|
||||
}
|
||||
|
||||
[HttpDelete("games")]
|
||||
public async Task<IActionResult> ClearGames()
|
||||
{
|
||||
await _games.ClearAllGames();
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user