142 lines
4.2 KiB
C#
142 lines
4.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Persistence.Models;
|
|
using Persistence.Models.Requests;
|
|
using Persistence.Repositories;
|
|
|
|
namespace Persistence.API.Controllers;
|
|
|
|
[ApiController]
|
|
[Authorize]
|
|
[Route("api/[controller]")]
|
|
public class ChangeLogController : ControllerBase, IChangeLogApi
|
|
{
|
|
private IChangeLogRepository repository;
|
|
|
|
public ChangeLogController(IChangeLogRepository repository)
|
|
{
|
|
this.repository = repository;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<ActionResult<int>> Add(
|
|
Guid idDiscriminator,
|
|
[FromBody] DataWithWellDepthAndSectionDto dto,
|
|
CancellationToken token)
|
|
{
|
|
var userId = User.GetUserId<Guid>();
|
|
var result = await repository.InsertRange(userId, idDiscriminator, [dto], token);
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpPost("range")]
|
|
public async Task<ActionResult<int>> AddRange(
|
|
Guid idDiscriminator,
|
|
[FromBody] IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token)
|
|
{
|
|
var userId = User.GetUserId<Guid>();
|
|
var result = await repository.InsertRange(userId, idDiscriminator, dtos, token);
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpDelete]
|
|
public async Task<ActionResult<int>> Delete(Guid id, CancellationToken token)
|
|
{
|
|
var userId = User.GetUserId<Guid>();
|
|
var result = await repository.MarkAsDeleted(userId, [id], token);
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpDelete("range")]
|
|
public async Task<ActionResult<int>> DeleteRange(IEnumerable<Guid> ids, CancellationToken token)
|
|
{
|
|
var userId = User.GetUserId<Guid>();
|
|
var result = await repository.MarkAsDeleted(userId, ids, token);
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpPost("replace")]
|
|
public async Task<IActionResult> ClearAndInsertRange(
|
|
Guid idDiscriminator,
|
|
IEnumerable<DataWithWellDepthAndSectionDto> dtos,
|
|
CancellationToken token)
|
|
{
|
|
var userId = User.GetUserId<Guid>();
|
|
var result = await repository.ClearAndInsertRange(userId, idDiscriminator, dtos, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpPut]
|
|
public async Task<ActionResult<int>> Update(
|
|
Guid idDiscriminator,
|
|
DataWithWellDepthAndSectionDto dto,
|
|
CancellationToken token)
|
|
{
|
|
var userId = User.GetUserId<Guid>();
|
|
var result = await repository.UpdateRange(userId, idDiscriminator, [dto], token);
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpPut("range")]
|
|
public async Task<ActionResult<int>> UpdateRange(
|
|
Guid idDiscriminator,
|
|
IEnumerable<DataWithWellDepthAndSectionDto> dtos,
|
|
CancellationToken token)
|
|
{
|
|
var userId = User.GetUserId<Guid>();
|
|
var result = await repository.UpdateRange(userId, idDiscriminator, dtos, token);
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult<PaginationContainer<DataWithWellDepthAndSectionDto>>> GetCurrent(
|
|
Guid idDiscriminator,
|
|
[FromQuery]SectionPartRequest request,
|
|
CancellationToken token)
|
|
{
|
|
var moment = new DateTimeOffset(3000, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
|
var result = await repository.GetByDate(idDiscriminator, moment, request, token);
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("moment")]
|
|
public async Task<ActionResult<PaginationContainer<DataWithWellDepthAndSectionDto>>> GetByDate(
|
|
Guid idDiscriminator,
|
|
DateTimeOffset moment,
|
|
SectionPartRequest request,
|
|
CancellationToken token)
|
|
{
|
|
var result = await repository.GetByDate(idDiscriminator, moment, request, token);
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("history")]
|
|
public async Task<ActionResult<IEnumerable<ChangeLogDto>>> GetChangeLogForDate(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
|
|
{
|
|
var result = await repository.GetChangeLogForDate(idDiscriminator, dateBegin, dateEnd, token);
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("datesChange")]
|
|
public async Task<ActionResult<IEnumerable<DateOnly>>> GetDatesChange(Guid idDiscriminator, CancellationToken token)
|
|
{
|
|
var result = await repository.GetDatesChange(idDiscriminator, token);
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|