Compare commits

...

1 Commits

Author SHA1 Message Date
32a41fcd80 Добавить ChangeLog API и репозиторий 2024-11-15 11:50:49 +05:00
10 changed files with 204 additions and 5 deletions

View File

@ -0,0 +1,68 @@
using Microsoft.AspNetCore.Mvc;
using Persistence.Models;
using Persistence.Repositories;
namespace Persistence.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class ChangeLogController<TDto, TChangeLogDto> : ControllerBase, IChangeLogApi<TDto, TChangeLogDto>
where TDto : class, IChangeLogAbstract, new()
where TChangeLogDto : ChangeLogDto<TDto>
{
private IChangeLogRepository<TDto, TChangeLogDto> changeLogRepository;
public ChangeLogController(IChangeLogRepository<TDto, TChangeLogDto> changeLogRepository)
{
this.changeLogRepository = changeLogRepository;
}
[HttpGet]
public Task<ActionResult<IEnumerable<TDto>>> GetChangeLogCurrent(CancellationToken token)
{
throw new NotImplementedException();
}
[HttpGet("forDate")]
public Task<ActionResult<IEnumerable<TChangeLogDto>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token)
{
throw new NotImplementedException();
}
[HttpPost]
public Task<ActionResult<int>> AddAsync(TDto dto, CancellationToken token)
{
throw new NotImplementedException();
}
[HttpPost]
public Task<ActionResult<int>> AddRangeAsync(IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
[HttpPost]
public Task<ActionResult<int>> DeleteAsync(int id, CancellationToken token)
{
throw new NotImplementedException();
}
[HttpPost]
public Task<ActionResult<int>> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token)
{
throw new NotImplementedException();
}
[HttpPost("update")]
public Task<ActionResult<int>> UpdateAsync(TDto dto, CancellationToken token)
{
throw new NotImplementedException();
}
[HttpPost("update")]
public Task<ActionResult<int>> UpdateRangeAsync(IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace Persistence.Database.Model
{
public class ChangeLog : IChangeLogData
{
[Column("id")]
public int Id { get; set; }
[Column("idnext")]
public int? IdNext { get; set; }
[Column("idprevious")]
public int? IdPrevious { get; set; }
[Column("creation")]
public DateTimeOffset Creation { get; set; }
[Column("obsolete")]
public DateTimeOffset? Obsolete { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace Persistence.Database.Model
{
internal interface IChangeLogData
{
public int Id { get; set; }
public int? IdNext { get; set; }
public int? IdPrevious { get; set; }
public DateTimeOffset Creation { get; set; }
public DateTimeOffset? Obsolete { get; set; }
}
}

View File

@ -11,6 +11,7 @@ namespace Persistence.Database.Model;
public interface IPersistenceDbContext : IDisposable public interface IPersistenceDbContext : IDisposable
{ {
DbSet<DataSaub> DataSaub { get; } DbSet<DataSaub> DataSaub { get; }
DbSet<ChangeLog> ChangeLog { get; }
DatabaseFacade Database { get; } DatabaseFacade Database { get; }
Task<int> SaveChangesAsync(CancellationToken cancellationToken); Task<int> SaveChangesAsync(CancellationToken cancellationToken);
} }

View File

@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.Metrics; using System.Diagnostics.Metrics;
@ -11,6 +11,9 @@ namespace Persistence.Database.Model;
public partial class PersistenceDbContext : DbContext, IPersistenceDbContext public partial class PersistenceDbContext : DbContext, IPersistenceDbContext
{ {
public DbSet<DataSaub> DataSaub => Set<DataSaub>(); public DbSet<DataSaub> DataSaub => Set<DataSaub>();
public DbSet<ChangeLog> ChangeLog => Set<ChangeLog>();
public PersistenceDbContext() { } // Áåç ïóñòîãî êîíñòðóêòîðà ìèãðàöèÿ ïàäààåò
public PersistenceDbContext(DbContextOptions<PersistenceDbContext> options) public PersistenceDbContext(DbContextOptions<PersistenceDbContext> options)
{ {

View File

@ -0,0 +1,16 @@
using Persistence.Models;
namespace Persistence.Repository.Data
{
internal class LogDto : IChangeLogAbstract
{
public int Id { get; set; }
public int IdAuthor { get; set; }
public int? IdNext { get; set; }
public int? IdPrevious { get; set; }
public int? IdEditor { get; set; }
public int IdState { get; set; }
public DateTimeOffset Creation { get; set; }
public DateTimeOffset? Obsolete { get; set; }
}
}

View File

@ -5,6 +5,7 @@ using Persistence.Repositories;
using Persistence.Database.Model; using Persistence.Database.Model;
using Persistence.Repository.Data; using Persistence.Repository.Data;
using Persistence.Repository.Repositories; using Persistence.Repository.Repositories;
using Persistence.Models;
namespace Persistence.Repository; namespace Persistence.Repository;
public static class DependencyInjection public static class DependencyInjection
@ -24,6 +25,7 @@ public static class DependencyInjection
services.AddScoped<IPersistenceDbContext>(provider => provider.GetRequiredService<PersistenceDbContext>()); services.AddScoped<IPersistenceDbContext>(provider => provider.GetRequiredService<PersistenceDbContext>());
services.AddTransient<ITimeSeriesDataRepository<DataSaubDto>, TimeSeriesDataRepository<DataSaub, DataSaubDto>>(); services.AddTransient<ITimeSeriesDataRepository<DataSaubDto>, TimeSeriesDataRepository<DataSaub, DataSaubDto>>();
services.AddTransient<IChangeLogRepository<LogDto, ChangeLogDto<LogDto>>, ChangeLogRepository<ChangeLog, LogDto, ChangeLogDto<LogDto>>>();
return services; return services;
} }

View File

@ -0,0 +1,71 @@
using Microsoft.EntityFrameworkCore;
using Persistence.Models;
using Persistence.Repositories;
namespace Persistence.Repository.Repositories
{
public abstract class ChangeLogRepository<TEntity, TDto, TChangeLogDto> : IChangeLogRepository<TDto, TChangeLogDto>
where TEntity : class
where TDto : class, IChangeLogAbstract, new()
where TChangeLogDto : ChangeLogDto<TDto>
{
private DbContext db;
public ChangeLogRepository(DbContext db)
{
this.db = db;
}
protected virtual IQueryable<TEntity> GetQueryReadOnly() => db.Set<TEntity>();
public Task<int> Clear(int idUser, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<int> ClearAndInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<IEnumerable<TChangeLogDto>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<IEnumerable<TDto>> GetCurrent(DateTimeOffset moment, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<IEnumerable<DateOnly>> GetDatesChange(CancellationToken token)
{
throw new NotImplementedException();
}
public Task<IEnumerable<TDto>> GetGtDate(DateTimeOffset dateBegin, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<int> MarkAsDeleted(int idUser, IEnumerable<int> ids, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<int> UpdateOrInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<int> UpdateRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
}
}

View File

@ -59,4 +59,9 @@ public interface IChangeLogAbstract
/// Id заменяемой записи /// Id заменяемой записи
/// </summary> /// </summary>
public int? IdPrevious { get; set; } public int? IdPrevious { get; set; }
/// <summary>
/// Id последующей записи
/// </summary>
public int? IdNext { get; set; }
} }

View File

@ -7,7 +7,7 @@ namespace Persistence.Repositories;
/// </summary> /// </summary>
/// <typeparam name="TDto"></typeparam> /// <typeparam name="TDto"></typeparam>
public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDto> public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDto>
where TDto : class, ITimeSeriesAbstractDto, new() where TDto : class, IChangeLogAbstract, new()
where TChangeLogDto : ChangeLogDto<TDto> where TChangeLogDto : ChangeLogDto<TDto>
{ {
/// <summary> /// <summary>