Ченджлог (наработки)

This commit is contained in:
Olga Nemt 2024-11-26 10:32:44 +05:00
parent d7b5b7e3ab
commit 24046d8505
6 changed files with 42 additions and 17 deletions

View File

@ -9,52 +9,63 @@ namespace Persistence.API.Controllers;
[ApiController]
[Authorize]
[Route("api/[controller]")]
public class ChangeLogRotorController : ControllerBase, IChangeLogApi<ProcessMapRotorDto, ChangeLogDto<ProcessMapRotorDto>>
public class ChangeLogController<TDto> : ControllerBase, IChangeLogApi<TDto, ChangeLogDto<TDto>>
where TDto : class, IChangeLogDto, new()
{
private IChangeLogRepository<ProcessMapRotorDto, ChangeLogDto<ProcessMapRotorDto>> repository;
private IChangeLogRepository<TDto, ChangeLogDto<TDto>> repository;
public ChangeLogRotorController(IChangeLogRepository<ProcessMapRotorDto, ChangeLogDto<ProcessMapRotorDto>> repository)
public ChangeLogController(IChangeLogRepository<TDto, ChangeLogDto<TDto>> repository)
{
this.repository = repository;
}
public async Task<ActionResult<int>> Add(ProcessMapRotorDto dto, CancellationToken token)
{
await repository.InsertRange(0, [dto], token);
return null;
[HttpPost]
public async Task<ActionResult<int>> Add(TDto dto, CancellationToken token)
{
var userId = User.GetUserId<Guid>();
var result = await repository.InsertRange(userId, [dto], token);
return Ok(result);
}
public Task<ActionResult<int>> AddRange(IEnumerable<ProcessMapRotorDto> dtos, CancellationToken token)
[HttpPost("range")]
public Task<ActionResult<int>> AddRange(IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
[HttpDelete]
public Task<ActionResult<int>> Delete(int id, CancellationToken token)
{
throw new NotImplementedException();
}
[HttpDelete("range")]
public Task<ActionResult<int>> DeleteRange(IEnumerable<int> ids, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<ActionResult<IEnumerable<ProcessMapRotorDto>>> GetChangeLogCurrent(CancellationToken token)
[HttpGet]
public Task<ActionResult<IEnumerable<TDto>>> GetChangeLogCurrent(CancellationToken token)
{
throw new NotImplementedException();
}
public Task<ActionResult<IEnumerable<ChangeLogDto<ProcessMapRotorDto>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token)
[HttpGet("history")]
public Task<ActionResult<IEnumerable<ChangeLogDto<TDto>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<ActionResult<int>> Update(ProcessMapRotorDto dto, CancellationToken token)
[HttpPut]
public Task<ActionResult<int>> Update(TDto dto, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<ActionResult<int>> UpdateRange(IEnumerable<ProcessMapRotorDto> dtos, CancellationToken token)
[HttpPut("range")]
public Task<ActionResult<int>> UpdateRange(IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}

View File

@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Persistence.Database.Model;
using Persistence.Models;
using Persistence.Repositories;
using Persistence.Repository.Data;
using Persistence.Repository.Repositories;
@ -16,6 +17,7 @@ public static class DependencyInjection
MapsterSetup();
services.AddTransient<ITimeSeriesDataRepository<DataSaubDto>, TimeSeriesDataCachedRepository<DataSaub, DataSaubDto>>();
services.AddTransient(typeof(IChangeLogRepository<,>), typeof(ChangeLogRepository<,>));
return services;
}

View File

@ -46,9 +46,21 @@ public class ChangeLogRepository<TDto, TChangeLogDto> : IChangeLogRepository<TDt
throw new NotImplementedException();
}
public Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
public Task<int> InsertRange(Guid idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
var entity = new ChangeLog() {
Value = dtos,
Creation = DateTimeOffset.UtcNow,
Id = idUser,
IdAuthor = idUser,
IdDiscriminator = new Guid(),
IdEditor = idUser
};
entity.Id = idUser;
db.Set<ChangeLog>().Add(entity);
var result = db.SaveChangesAsync(token);
return result;
}
public Task<int> MarkAsDeleted(int idUser, IEnumerable<int> ids, CancellationToken token)

View File

@ -7,7 +7,7 @@ namespace Persistence.API;
/// Интерфейс для работы с API журнала изменений
/// </summary>
public interface IChangeLogApi<TDto, TChangeLogDto>
where TDto : class, new()
where TDto : class, IChangeLogDto, new()
where TChangeLogDto : ChangeLogDto<TDto>
{
/// <summary>

View File

@ -5,7 +5,7 @@ namespace Persistence.Models;
/// Часть записи описывающая изменение
/// </summary>
public class ChangeLogDto<T> : IChangeLogDto
where T: class
where T: class, IChangeLogDto, new()
{
/// <summary>
/// Запись

View File

@ -17,7 +17,7 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token);
Task<int> InsertRange(Guid idUser, IEnumerable<TDto> dtos, CancellationToken token);
/// <summary>
/// Редактирование записей