2024-11-25 18:11:46 +05:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Persistence.Models;
|
2024-11-28 16:29:00 +05:00
|
|
|
using Persistence.Models.Requests;
|
2024-11-25 18:11:46 +05:00
|
|
|
using Persistence.Repositories;
|
2024-11-29 10:03:52 +05:00
|
|
|
using System.Net;
|
2024-11-25 18:11:46 +05:00
|
|
|
|
|
|
|
namespace Persistence.API.Controllers;
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
[Authorize]
|
|
|
|
[Route("api/[controller]")]
|
2024-11-26 11:47:42 +05:00
|
|
|
public class ChangeLogController : ControllerBase, IChangeLogApi
|
2024-11-25 18:11:46 +05:00
|
|
|
{
|
2024-11-26 11:47:42 +05:00
|
|
|
private IChangeLogRepository repository;
|
2024-11-25 18:11:46 +05:00
|
|
|
|
2024-11-26 11:47:42 +05:00
|
|
|
public ChangeLogController(IChangeLogRepository repository)
|
2024-11-25 18:11:46 +05:00
|
|
|
{
|
|
|
|
this.repository = repository;
|
|
|
|
}
|
2024-11-26 10:32:44 +05:00
|
|
|
|
|
|
|
[HttpPost]
|
2024-11-29 10:03:52 +05:00
|
|
|
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> Add(
|
2024-11-27 17:59:37 +05:00
|
|
|
Guid idDiscriminator,
|
|
|
|
[FromBody] DataWithWellDepthAndSectionDto dto,
|
2024-11-26 11:47:42 +05:00
|
|
|
CancellationToken token)
|
2024-11-25 18:11:46 +05:00
|
|
|
{
|
2024-11-26 10:32:44 +05:00
|
|
|
var userId = User.GetUserId<Guid>();
|
2024-11-26 14:19:16 +05:00
|
|
|
var result = await repository.InsertRange(userId, idDiscriminator, [dto], token);
|
2024-11-25 18:11:46 +05:00
|
|
|
|
2024-11-26 10:32:44 +05:00
|
|
|
return Ok(result);
|
2024-11-25 18:11:46 +05:00
|
|
|
}
|
|
|
|
|
2024-11-26 10:32:44 +05:00
|
|
|
[HttpPost("range")]
|
2024-11-29 10:03:52 +05:00
|
|
|
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> AddRange(
|
2024-11-27 17:59:37 +05:00
|
|
|
Guid idDiscriminator,
|
|
|
|
[FromBody] IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token)
|
2024-11-25 18:11:46 +05:00
|
|
|
{
|
2024-11-27 17:59:37 +05:00
|
|
|
var userId = User.GetUserId<Guid>();
|
|
|
|
var result = await repository.InsertRange(userId, idDiscriminator, dtos, token);
|
|
|
|
|
|
|
|
return Ok(result);
|
2024-11-25 18:11:46 +05:00
|
|
|
}
|
|
|
|
|
2024-11-26 10:32:44 +05:00
|
|
|
[HttpDelete]
|
2024-11-29 10:03:52 +05:00
|
|
|
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> Delete(Guid id, CancellationToken token)
|
2024-11-25 18:11:46 +05:00
|
|
|
{
|
2024-11-27 17:59:37 +05:00
|
|
|
var userId = User.GetUserId<Guid>();
|
|
|
|
var result = await repository.MarkAsDeleted(userId, [id], token);
|
|
|
|
|
|
|
|
return Ok(result);
|
2024-11-25 18:11:46 +05:00
|
|
|
}
|
|
|
|
|
2024-11-26 10:32:44 +05:00
|
|
|
[HttpDelete("range")]
|
2024-11-29 10:03:52 +05:00
|
|
|
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> DeleteRange(IEnumerable<Guid> ids, CancellationToken token)
|
2024-11-25 18:11:46 +05:00
|
|
|
{
|
2024-11-27 17:59:37 +05:00
|
|
|
var userId = User.GetUserId<Guid>();
|
|
|
|
var result = await repository.MarkAsDeleted(userId, ids, token);
|
|
|
|
|
|
|
|
return Ok(result);
|
2024-11-25 18:11:46 +05:00
|
|
|
}
|
|
|
|
|
2024-11-28 16:29:00 +05:00
|
|
|
[HttpPost("replace")]
|
2024-11-29 10:03:52 +05:00
|
|
|
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
|
2024-11-28 16:29:00 +05:00
|
|
|
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]
|
2024-11-29 10:03:52 +05:00
|
|
|
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> Update(
|
2024-11-28 16:29:00 +05:00
|
|
|
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")]
|
2024-11-29 10:03:52 +05:00
|
|
|
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> UpdateRange(
|
2024-11-28 16:29:00 +05:00
|
|
|
Guid idDiscriminator,
|
|
|
|
IEnumerable<DataWithWellDepthAndSectionDto> dtos,
|
|
|
|
CancellationToken token)
|
|
|
|
{
|
|
|
|
var userId = User.GetUserId<Guid>();
|
|
|
|
var result = await repository.UpdateRange(userId, idDiscriminator, dtos, token);
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
}
|
|
|
|
|
2024-11-26 10:32:44 +05:00
|
|
|
[HttpGet]
|
2024-11-29 10:03:52 +05:00
|
|
|
[ProducesResponseType(typeof(PaginationContainer<DataWithWellDepthAndSectionDto>), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> GetCurrent(
|
2024-11-27 17:59:37 +05:00
|
|
|
Guid idDiscriminator,
|
2024-11-28 16:29:00 +05:00
|
|
|
[FromQuery]SectionPartRequest request,
|
2024-11-27 17:59:37 +05:00
|
|
|
CancellationToken token)
|
|
|
|
{
|
2024-11-28 16:29:00 +05:00
|
|
|
var moment = new DateTimeOffset(3000, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
|
var result = await repository.GetByDate(idDiscriminator, moment, request, token);
|
2024-11-27 17:59:37 +05:00
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("moment")]
|
2024-11-29 10:03:52 +05:00
|
|
|
[ProducesResponseType(typeof(PaginationContainer<DataWithWellDepthAndSectionDto>), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> GetByDate(
|
2024-11-27 17:59:37 +05:00
|
|
|
Guid idDiscriminator,
|
|
|
|
DateTimeOffset moment,
|
2024-11-28 16:29:00 +05:00
|
|
|
SectionPartRequest request,
|
2024-11-27 17:59:37 +05:00
|
|
|
CancellationToken token)
|
2024-11-25 18:11:46 +05:00
|
|
|
{
|
2024-11-28 16:29:00 +05:00
|
|
|
var result = await repository.GetByDate(idDiscriminator, moment, request, token);
|
2024-11-27 17:59:37 +05:00
|
|
|
|
|
|
|
return Ok(result);
|
2024-11-25 18:11:46 +05:00
|
|
|
}
|
|
|
|
|
2024-11-26 14:19:16 +05:00
|
|
|
[HttpGet("history")]
|
2024-11-29 10:03:52 +05:00
|
|
|
[ProducesResponseType(typeof(IEnumerable<ChangeLogDto>), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> GetChangeLogForDate(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
|
2024-11-25 18:11:46 +05:00
|
|
|
{
|
2024-11-27 17:59:37 +05:00
|
|
|
var result = await repository.GetChangeLogForDate(idDiscriminator, dateBegin, dateEnd, token);
|
|
|
|
|
|
|
|
return Ok(result);
|
2024-11-25 18:11:46 +05:00
|
|
|
}
|
|
|
|
|
2024-11-28 16:29:00 +05:00
|
|
|
[HttpGet("datesChange")]
|
2024-11-29 10:03:52 +05:00
|
|
|
[ProducesResponseType(typeof(IEnumerable<DateOnly>), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> GetDatesChange(Guid idDiscriminator, CancellationToken token)
|
2024-11-25 18:11:46 +05:00
|
|
|
{
|
2024-11-28 16:29:00 +05:00
|
|
|
var result = await repository.GetDatesChange(idDiscriminator, token);
|
2024-11-27 17:59:37 +05:00
|
|
|
|
|
|
|
return Ok(result);
|
2024-11-25 18:11:46 +05:00
|
|
|
}
|
|
|
|
|
2024-11-29 11:52:47 +05:00
|
|
|
[HttpGet("part")]
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DataWithWellDepthAndSectionDto>), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> GetPart(Guid idDiscriminator, DateTimeOffset dateBegin, int take = 86400, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var result = await repository.GetGtDate(idDiscriminator, dateBegin, token);
|
2024-11-27 17:59:37 +05:00
|
|
|
|
2024-11-29 11:52:47 +05:00
|
|
|
return Ok(result);
|
|
|
|
}
|
2024-11-28 16:29:00 +05:00
|
|
|
|
2024-11-29 11:52:47 +05:00
|
|
|
[HttpGet("datesRange")]
|
|
|
|
[ProducesResponseType(typeof(DatesRangeDto), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> GetDatesRangeAsync(Guid idDiscriminator, CancellationToken token)
|
|
|
|
{
|
|
|
|
var result = await repository.GetDatesRange(idDiscriminator, token);
|
2024-11-27 17:59:37 +05:00
|
|
|
|
2024-11-29 11:52:47 +05:00
|
|
|
return Ok(result);
|
|
|
|
}
|
2024-11-25 18:11:46 +05:00
|
|
|
}
|