28 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using MediatR;
 | 
						|
using Microsoft.EntityFrameworkCore;
 | 
						|
using Mirea.Api.DataAccess.Application.Common.Exceptions;
 | 
						|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
 | 
						|
using System.Threading;
 | 
						|
using System.Threading.Tasks;
 | 
						|
 | 
						|
namespace Mirea.Api.DataAccess.Application.Cqrs.Group
 | 
						|
    .Queries.GetGroupDetails;
 | 
						|
 | 
						|
public class GetGroupInfoQueryHandler(IGroupDbContext dbContext) : IRequestHandler<GetGroupInfoQuery, GroupInfoVm>
 | 
						|
{
 | 
						|
    public async Task<GroupInfoVm> Handle(GetGroupInfoQuery request, CancellationToken cancellationToken)
 | 
						|
    {
 | 
						|
        var discipline = await dbContext.Groups
 | 
						|
            .Include(g => g.Faculty)
 | 
						|
            .FirstOrDefaultAsync(g => g.Id == request.Id, cancellationToken)
 | 
						|
                         ?? throw new NotFoundException(typeof(Domain.Schedule.Group), request.Id);
 | 
						|
 | 
						|
        return new GroupInfoVm()
 | 
						|
        {
 | 
						|
            Id = discipline.Id,
 | 
						|
            Name = discipline.Name,
 | 
						|
            Faculty = discipline.Faculty?.Name,
 | 
						|
            FacultyId = discipline.FacultyId
 | 
						|
        };
 | 
						|
    }
 | 
						|
} |