ref: project structure
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using mws.backend.dotnet.application.Common;
|
||||
using mws.backend.dotnet.application.Common.Repositories;
|
||||
using mws.backend.dotnet.domain.Tasks;
|
||||
using TaskPriority = mws.backend.dotnet.domain.Tasks.TaskPriority;
|
||||
using TaskStatus = mws.backend.dotnet.domain.Tasks.TaskStatus;
|
||||
|
||||
namespace mws.backend.dotnet.infrastructure.Persistence.Repositories;
|
||||
|
||||
public class TaskRepository(AppDbContext db) : RepositoryBase<TaskItem>(db), ITaskRepository
|
||||
{
|
||||
public Task<TaskItem?> GetByIdAsync(Guid id, CancellationToken ct = default) =>
|
||||
Set.FirstOrDefaultAsync(t => t.Id == id, ct);
|
||||
|
||||
public Task<TaskItem?> GetWithAssigneeAsync(Guid id, CancellationToken ct = default) =>
|
||||
Set.Include(t => t.Assignee).FirstOrDefaultAsync(t => t.Id == id, ct);
|
||||
|
||||
public Task<PagedResult<TaskItem>> GetForProjectAsync(
|
||||
Guid projectId, TaskStatus? status, TaskPriority? priority, Guid? assigneeId, int page, int pageSize, CancellationToken ct = default)
|
||||
{
|
||||
var query = Set.Where(t => t.ProjectId == projectId);
|
||||
|
||||
if (status.HasValue)
|
||||
{
|
||||
query = query.Where(t => t.Status == status);
|
||||
}
|
||||
if (priority.HasValue)
|
||||
{
|
||||
query = query.Where(t => t.Priority == priority);
|
||||
}
|
||||
if (assigneeId.HasValue)
|
||||
{
|
||||
query = query.Where(t => t.AssigneeId == assigneeId);
|
||||
}
|
||||
|
||||
return query.Include(t => t.Assignee).OrderByDescending(t => t.UpdatedAt).ToPagedResultAsync(page, pageSize, ct);
|
||||
}
|
||||
|
||||
public Task<List<TaskItem>> SearchWithAssigneeAsync(List<Guid> projectIds, string? term, int take, CancellationToken ct = default)
|
||||
{
|
||||
var query = Set.Where(t => projectIds.Contains(t.ProjectId));
|
||||
if (!string.IsNullOrWhiteSpace(term))
|
||||
{
|
||||
var lower = term.Trim().ToLower();
|
||||
query = query.Where(t => t.Title.ToLower().Contains(lower));
|
||||
}
|
||||
|
||||
return query.Include(t => t.Assignee).OrderByDescending(t => t.UpdatedAt).Take(take).ToListAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<TaskStatus, int>> CountByStatusForProjectAsync(Guid projectId, CancellationToken ct = default)
|
||||
{
|
||||
return await Set.Where(t => t.ProjectId == projectId)
|
||||
.GroupBy(t => t.Status)
|
||||
.Select(g => new { Status = g.Key, Count = g.Count() })
|
||||
.ToDictionaryAsync(a => a.Status, a => a.Count, ct);
|
||||
}
|
||||
|
||||
public Task<List<TaskItem>> GetRecentForProjectAsync(Guid projectId, int take, CancellationToken ct = default) =>
|
||||
Set.Where(t => t.ProjectId == projectId).OrderByDescending(t => t.UpdatedAt).Take(take).ToListAsync(ct);
|
||||
}
|
||||
Reference in New Issue
Block a user