Удалён лишний файл
This commit is contained in:
@@ -7,15 +7,6 @@ namespace LiquidCode.Domain.Interfaces.Repositories;
|
||||
/// </summary>
|
||||
public interface IMissionRepository : IRepository<DbMission>
|
||||
{
|
||||
/// <summary>
|
||||
/// Получает миссии с пагинацией
|
||||
/// </summary>
|
||||
/// <param name="pageSize">Количество элементов на странице</param>
|
||||
/// <param name="pageNumber">Номер страницы (начиная с нуля)</param>
|
||||
/// <param name="cancellationToken">Токен отмены</param>
|
||||
/// <returns>Кортеж (миссии, естьСледующаяСтраница)</returns>
|
||||
Task<(IEnumerable<DbMission> Missions, bool HasNextPage)> GetMissionsPageAsync(
|
||||
int pageSize, int pageNumber, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Получает миссии по автору
|
||||
|
||||
@@ -23,12 +23,12 @@ public interface ISubmitRepository : IRepository<DbUserSubmit>
|
||||
Task<DbUserSubmit?> GetSubmissionWithDetailsAsync(int submissionId, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Получает решение для отправки
|
||||
/// Получает решение
|
||||
/// </summary>
|
||||
Task<DbSolution?> GetSolutionAsync(int submissionId, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Добавляет решение для отправки
|
||||
/// Добавляет решение
|
||||
/// </summary>
|
||||
Task AddSolutionAsync(DbSolution solution, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public class MissionService : IMissionService
|
||||
return null;
|
||||
}
|
||||
|
||||
var (missions, hasNextPage) = await _missionRepository.GetMissionsPageAsync(pageSize, pageNumber, cancellationToken);
|
||||
var (missions, hasNextPage) = await _missionRepository.GetPageAsync(pageSize, pageNumber, cancellationToken);
|
||||
var apiList = missions.Select(MissionResponse.FromEntity);
|
||||
|
||||
return new MissionsPageResponse(hasNextPage, apiList);
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
using LiquidCode.Domain.Interfaces.Repositories;
|
||||
using LiquidCode.Infrastructure.Database;
|
||||
using LiquidCode.Infrastructure.Database.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LiquidCode.Infrastructure.Database.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Базовая реализация репозитория, предоставляющая общие операции CRUD
|
||||
/// </summary>
|
||||
public class DbCrud<TEntity> : IRepository<TEntity> where TEntity : class, ISoftDeletable
|
||||
{
|
||||
private readonly LiquidDbContext _dbContext;
|
||||
public readonly DbSet<TEntity> DbSet;
|
||||
|
||||
public DbCrud(LiquidDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
DbSet = dbContext.Set<TEntity>();
|
||||
}
|
||||
|
||||
public virtual async Task<TEntity?> FindByIdAsync(int id, CancellationToken cancellationToken = default) =>
|
||||
await DbSet.FindAsync(new object?[] { id }, cancellationToken);
|
||||
|
||||
public virtual async Task<(IEnumerable<TEntity> Items, bool HasNextPage)> GetPageAsync(
|
||||
int pageSize, int pageNumber, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (pageSize <= 0 || pageNumber < 0)
|
||||
throw new ArgumentException("Page size must be positive, page number must be non-negative");
|
||||
|
||||
var totalCount = await DbSet.CountAsync(cancellationToken);
|
||||
var hasNextPage = totalCount > pageSize * (pageNumber + 1);
|
||||
|
||||
var items = await DbSet
|
||||
.OrderBy(x => EF.Property<int>(x, "Id"))
|
||||
.Skip(pageSize * pageNumber)
|
||||
.Take(pageSize)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return (items, hasNextPage);
|
||||
}
|
||||
|
||||
public virtual async Task CreateAsync(TEntity entity, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await DbSet.AddAsync(entity, cancellationToken);
|
||||
await SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default)
|
||||
{
|
||||
DbSet.Update(entity);
|
||||
await SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default)
|
||||
{
|
||||
DbSet.Remove(entity);
|
||||
await SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task SoftDeleteAsync(TEntity entity, CancellationToken cancellationToken = default)
|
||||
{
|
||||
entity.IsDeleted = true;
|
||||
DbSet.Update(entity);
|
||||
await SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task SaveChangesAsync(CancellationToken cancellationToken = default) =>
|
||||
await _dbContext.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
Reference in New Issue
Block a user