persistence/Persistence.API/Controllers/ChangeLogController.cs

118 lines
3.4 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Persistence.Models;
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;
}
2024-11-26 10:32:44 +05:00
[HttpPost]
public async Task<ActionResult<int>> Add(
2024-11-27 17:59:37 +05:00
Guid idDiscriminator,
[FromBody] DataWithWellDepthAndSectionDto dto,
CancellationToken token)
{
2024-11-26 10:32:44 +05:00
var userId = User.GetUserId<Guid>();
var result = await repository.InsertRange(userId, idDiscriminator, [dto], token);
2024-11-26 10:32:44 +05:00
return Ok(result);
}
2024-11-26 10:32:44 +05:00
[HttpPost("range")]
2024-11-27 17:59:37 +05:00
public async Task<ActionResult<int>> AddRange(
Guid idDiscriminator,
[FromBody] IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token)
{
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-26 10:32:44 +05:00
[HttpDelete]
2024-11-27 17:59:37 +05:00
public async Task<ActionResult<int>> Delete(Guid id, CancellationToken token)
{
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-26 10:32:44 +05:00
[HttpDelete("range")]
2024-11-27 17:59:37 +05:00
public async Task<ActionResult<int>> DeleteRange(IEnumerable<Guid> ids, CancellationToken token)
{
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-26 10:32:44 +05:00
[HttpGet]
2024-11-27 17:59:37 +05:00
public async Task<ActionResult<IEnumerable<DataWithWellDepthAndSectionDto>>> GetCurrent(
Guid idDiscriminator,
CancellationToken token)
{
var date = new DateTimeOffset(3000, 1, 1, 0, 0, 0, TimeSpan.Zero);
var result = await repository.GetByDate(idDiscriminator, date, token);
return Ok(result);
}
[HttpGet("moment")]
public async Task<ActionResult<IEnumerable<DataWithWellDepthAndSectionDto>>> GetByDate(
Guid idDiscriminator,
DateTimeOffset moment,
CancellationToken token)
{
2024-11-27 17:59:37 +05:00
var result = await repository.GetByDate(idDiscriminator, moment, token);
return Ok(result);
}
[HttpGet("history")]
2024-11-27 17:59:37 +05:00
public async Task<ActionResult<IEnumerable<ChangeLogDto>>> GetChangeLogForDate(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
{
2024-11-27 17:59:37 +05:00
var result = await repository.GetChangeLogForDate(idDiscriminator, dateBegin, dateEnd, token);
return Ok(result);
}
2024-11-26 10:32:44 +05:00
[HttpPut]
2024-11-27 17:59:37 +05:00
public async Task<ActionResult<int>> Update(
Guid idDiscriminator,
DataWithWellDepthAndSectionDto dto,
CancellationToken token)
{
2024-11-27 17:59:37 +05:00
var userId = User.GetUserId<Guid>();
var result = await repository.UpdateRange(userId, idDiscriminator, [dto], token);
return Ok(result);
}
2024-11-26 10:32:44 +05:00
[HttpPut("range")]
2024-11-27 17:59:37 +05:00
public async Task<ActionResult<int>> UpdateRange(
Guid idDiscriminator,
IEnumerable<DataWithWellDepthAndSectionDto> dtos,
CancellationToken token)
{
2024-11-27 17:59:37 +05:00
var userId = User.GetUserId<Guid>();
var result = await repository.UpdateRange(userId, idDiscriminator, dtos, token);
return Ok(result);
}
2024-11-27 17:59:37 +05:00
}