using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Persistence.Models; using Persistence.Repositories; using Persistence.Repository.Repositories; using System.Net; namespace Persistence.API.Controllers; [ApiController] [Authorize] [Route("api/[controller]/{idDiscriminator}")] public class TimestampedSetController : ControllerBase { private readonly ITimestampedSetRepository repository; public TimestampedSetController(ITimestampedSetRepository repository) { this.repository = repository; } [HttpPost] [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)] public async Task InsertRange([FromRoute]Guid idDiscriminator, [FromBody]IEnumerable sets, CancellationToken token) { var result = await repository.InsertRange(idDiscriminator, sets, token); return Ok(result); } [HttpGet] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] public async Task Get(Guid idDiscriminator, DateTimeOffset? geTimestamp, [FromQuery]IEnumerable? props, int skip, int take, CancellationToken token) { var result = await repository.Get(idDiscriminator, geTimestamp, props, skip, take, token); return Ok(result); } [HttpGet("last")] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] public async Task GetLast(Guid idDiscriminator, [FromQuery]IEnumerable? props, int take, CancellationToken token) { var result = await repository.GetLast(idDiscriminator, props, take, token); return Ok(result); } [HttpGet("datesRange")] [ProducesResponseType(typeof(DatesRangeDto), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] public async Task GetDatesRange(Guid idDiscriminator, CancellationToken token) { var result = await repository.GetDatesRange(idDiscriminator, token); return Ok(result); } [HttpGet("count")] [ProducesResponseType(typeof(DatesRangeDto), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] public async Task Count(Guid idDiscriminator, CancellationToken token) { var result = await repository.Count(idDiscriminator, token); return Ok(result); } }