Restructured query repositries to move ef logic from handlers
This commit is contained in:
@@ -6,8 +6,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Interfaces\" />
|
||||
<Folder Include="Handlers\QueryHandlers\" />
|
||||
<Folder Include="Queries\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using BrightGlimmer.Domain;
|
||||
using MediatR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Service.Commands
|
||||
{
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
using BrightGlimmer.Domain;
|
||||
using BrightGlimmer.Service.Commands;
|
||||
using MediatR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
using BrightGlimmer.Data.Interfaces;
|
||||
using BrightGlimmer.Domain;
|
||||
using BrightGlimmer.Services.Queries;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore; /* TODO */
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BrightGlimmer.Services.Handlers.QueryHandlers
|
||||
{
|
||||
public class GetAllStudentsQueryHandler : IRequestHandler<GetAllStudentsQuery, IEnumerable<Student>>
|
||||
{
|
||||
private readonly IQueryRepository<Student> repository;
|
||||
|
||||
public GetAllStudentsQueryHandler(IQueryRepository<Student> repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Student>> Handle(GetAllStudentsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await repository.Get()
|
||||
.Include(x => x.Phones)
|
||||
.Include(x => x.Address)
|
||||
.Include(x => x.AssignedCourses)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using BrightGlimmer.Data.Interfaces;
|
||||
using BrightGlimmer.Domain;
|
||||
using BrightGlimmer.Service.Queries;
|
||||
using MediatR;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BrightGlimmer.Service.Handlers.QueryHandlers
|
||||
{
|
||||
public class GetStudentQueryHandler : IRequestHandler<GetStudentQuery, Student>
|
||||
{
|
||||
private readonly IQueryRepository<Student> repository;
|
||||
|
||||
public GetStudentQueryHandler(IQueryRepository<Student> repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public async Task<Student> Handle(GetStudentQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await repository.GetAsync(request.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using BrightGlimmer.Data.Interfaces;
|
||||
using BrightGlimmer.Domain;
|
||||
using BrightGlimmer.Service.Queries;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BrightGlimmer.Service.Handlers.QueryHandlers
|
||||
{
|
||||
public class GetStudentsQueryHandler : IRequestHandler<GetStudentsQuery, IEnumerable<Student>>
|
||||
{
|
||||
private readonly IQueryRepository<Student> repository;
|
||||
|
||||
public GetStudentsQueryHandler(IQueryRepository<Student> repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Student>> Handle(GetStudentsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await repository.Get().ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using BrightGlimmer.Domain;
|
||||
using MediatR;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BrightGlimmer.Services.Queries
|
||||
{
|
||||
public class GetAllStudentsQuery : IRequest<IEnumerable<Student>>
|
||||
{
|
||||
}
|
||||
}
|
||||
16
BrightGlimmer.Service/Queries/GetStudentQuery.cs
Normal file
16
BrightGlimmer.Service/Queries/GetStudentQuery.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using BrightGlimmer.Domain;
|
||||
using MediatR;
|
||||
using System;
|
||||
|
||||
namespace BrightGlimmer.Service.Queries
|
||||
{
|
||||
public class GetStudentQuery : IRequest<Student>
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public GetStudentQuery(Guid id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
BrightGlimmer.Service/Queries/GetStudentsQuery.cs
Normal file
10
BrightGlimmer.Service/Queries/GetStudentsQuery.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using BrightGlimmer.Domain;
|
||||
using MediatR;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BrightGlimmer.Service.Queries
|
||||
{
|
||||
public class GetStudentsQuery : IRequest<IEnumerable<Student>>
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user