The ASP.NET Core solution (mws.api/mws.application/mws.domain/ mws.infrastructure) existed only as untracked working files. Adding it to version control, plus a .gitignore for build output and local tooling directories, so the CQRS/mediator refactor plan has a real git history to branch and diff against.
42 lines
2.0 KiB
C#
42 lines
2.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Mws.Application.Common.Repositories;
|
|
using Mws.Domain.Documents;
|
|
|
|
namespace Mws.Infrastructure.Persistence.Repositories;
|
|
|
|
public class DocumentRepository(AppDbContext db) : RepositoryBase<Document>(db), IDocumentRepository
|
|
{
|
|
public Task<Document?> GetByIdAsync(Guid id, CancellationToken ct = default) =>
|
|
Set.FirstOrDefaultAsync(d => d.Id == id, ct);
|
|
|
|
public Task<List<Document>> GetTreeForProjectAsync(Guid projectId, CancellationToken ct = default) =>
|
|
Set.Where(d => d.ProjectId == projectId).OrderBy(d => d.Title).ToListAsync(ct);
|
|
|
|
public Task<Document?> GetInProjectAsync(Guid parentId, Guid projectId, CancellationToken ct = default) =>
|
|
Set.FirstOrDefaultAsync(d => d.Id == parentId && d.ProjectId == projectId, ct);
|
|
|
|
public Task<Guid?> GetParentIdAsync(Guid documentId, CancellationToken ct = default) =>
|
|
Set.Where(d => d.Id == documentId).Select(d => d.ParentId).SingleAsync(ct);
|
|
|
|
public Task<List<Document>> GetChildrenAsync(Guid parentId, CancellationToken ct = default) =>
|
|
Set.Where(d => d.ParentId == parentId).ToListAsync(ct);
|
|
|
|
public Task<List<Document>> SearchAsync(List<Guid> projectIds, string? term, int take, CancellationToken ct = default)
|
|
{
|
|
var query = Set.Where(d => projectIds.Contains(d.ProjectId));
|
|
if (!string.IsNullOrWhiteSpace(term))
|
|
{
|
|
var lower = term.Trim().ToLower();
|
|
query = query.Where(d => d.Title.ToLower().Contains(lower));
|
|
}
|
|
|
|
return query.OrderByDescending(d => d.UpdatedAt).Take(take).ToListAsync(ct);
|
|
}
|
|
|
|
public Task<int> CountByTypeForProjectAsync(Guid projectId, DocumentType type, CancellationToken ct = default) =>
|
|
Set.CountAsync(d => d.ProjectId == projectId && d.Type == type, ct);
|
|
|
|
public Task<List<Document>> GetRecentForProjectAsync(Guid projectId, DocumentType type, int take, CancellationToken ct = default) =>
|
|
Set.Where(d => d.ProjectId == projectId && d.Type == type).OrderByDescending(d => d.UpdatedAt).Take(take).ToListAsync(ct);
|
|
}
|