78 lines
1.3 KiB
C#
78 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Http.HttpResults;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SampleApplication.Entities;
|
|
|
|
namespace SampleApplication.Controllers
|
|
{
|
|
[Route("api/shapes")]
|
|
public class ShapesController : ControllerBase
|
|
{
|
|
|
|
private readonly SampleDbContext _db;
|
|
|
|
private readonly ShapeProcessor _calculator;
|
|
|
|
public ShapesController(
|
|
|
|
SampleDbContext db,
|
|
|
|
ShapeProcessor calculator)
|
|
|
|
{
|
|
|
|
_db = db;
|
|
|
|
_calculator = calculator;
|
|
|
|
}
|
|
|
|
[HttpPost]
|
|
|
|
public IActionResult AddShapes(List<ShapeInput> shapes)
|
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
// - Validate
|
|
|
|
// - Ignore duplicate IDs
|
|
|
|
// - Save via EF Core
|
|
|
|
this._calculator.AddShapes(shapes);
|
|
|
|
this._db.Shapes.AddRange(shapes);
|
|
|
|
return Ok(shapes);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
public async Task<IActionResult> Get(int id)
|
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
var shape = await this._db.Shapes.Where(s => s.Id == id).FirstOrDefaultAsync();
|
|
|
|
return Ok(shape);
|
|
}
|
|
|
|
[HttpGet("stats")]
|
|
|
|
public IActionResult Stats()
|
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
}
|