Initial commit
This commit is contained in:
59
DataApi/Controllers/DataPacketsController.cs
Normal file
59
DataApi/Controllers/DataPacketsController.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MoniteurBaie.DataApi.Interfaces.Repositories;
|
||||
using MoniteurBaie.DataModels;
|
||||
|
||||
namespace MoniteurBaie.DataApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("packets")]
|
||||
public class DataPacketsController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<DataPacketsController> _logger;
|
||||
private readonly IDataRepository _dataRepository;
|
||||
|
||||
public DataPacketsController(ILogger<DataPacketsController> logger, IDataRepository dataRepository)
|
||||
{
|
||||
_logger = logger;
|
||||
_dataRepository = dataRepository;
|
||||
}
|
||||
|
||||
[HttpGet("{id}", Name = "GetDataPacket")]
|
||||
public async Task<IActionResult> GetAsync(uint id)
|
||||
{
|
||||
var packet = await _dataRepository.GetAsync(id);
|
||||
return packet is null ? NotFound() : Ok(packet);
|
||||
}
|
||||
|
||||
[HttpPost(Name = "CreateDataPacket")]
|
||||
public async Task<IActionResult> CreateAsync(DataPacket packet)
|
||||
{
|
||||
var packetId = await _dataRepository.CreateAsync(packet);
|
||||
return CreatedAtRoute("GetDataPacket", new { id = packetId }, packet with { Id = packetId });
|
||||
}
|
||||
|
||||
[HttpDelete("{id}", Name = "DeleteDataPacket")]
|
||||
public async Task<IActionResult> DeleteAsync(uint id)
|
||||
{
|
||||
var success = await _dataRepository.DeleteAsync(id);
|
||||
return success ? NoContent() : NotFound();
|
||||
}
|
||||
|
||||
[HttpGet("last", Name = "GetLastDataPackets")]
|
||||
public IActionResult GetLastAsync(int count)
|
||||
{
|
||||
return Ok(_dataRepository.GetLastAsync(count));
|
||||
}
|
||||
|
||||
[HttpGet("range", Name = "GetRangeDataPackets")]
|
||||
public IActionResult GetRangeAsync(DateTime fromInstant, DateTime toInstant)
|
||||
{
|
||||
return Ok(_dataRepository.GetRangeAsync(fromInstant, toInstant));
|
||||
}
|
||||
|
||||
[HttpPost("bulk", Name = "BulkCreateDataPackets")]
|
||||
public async Task<IActionResult> BulkCreateAsync(IEnumerable<DataPacket> packets)
|
||||
{
|
||||
await _dataRepository.BulkCreateAsync(packets);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user