24 lines
774 B
C#
24 lines
774 B
C#
namespace Application.Subjects.Queries;
|
|
|
|
using Application.Subjects.DTOs;
|
|
using Domain.Ports.Repositories;
|
|
using MediatR;
|
|
|
|
public record GetSubjectsQuery : IRequest<IReadOnlyList<SubjectDto>>;
|
|
|
|
public class GetSubjectsHandler(ISubjectRepository subjectRepository)
|
|
: IRequestHandler<GetSubjectsQuery, IReadOnlyList<SubjectDto>>
|
|
{
|
|
public async Task<IReadOnlyList<SubjectDto>> Handle(GetSubjectsQuery request, CancellationToken ct)
|
|
{
|
|
// Direct projection - only SELECT needed columns
|
|
return await subjectRepository.GetAllProjectedAsync(
|
|
s => new SubjectDto(
|
|
s.Id,
|
|
s.Name,
|
|
s.Credits,
|
|
s.ProfessorId,
|
|
s.Professor != null ? s.Professor.Name : ""), ct);
|
|
}
|
|
}
|