Add queries #8
@ -0,0 +1,22 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents basic information about a campus.
|
||||
/// </summary>
|
||||
public class CampusBasicInfoDto
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the campus.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The code name associated with the campus.
|
||||
/// </summary>
|
||||
public required string CodeName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The full name of the campus.
|
||||
/// </summary>
|
||||
public string? FullName { get; set; }
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model containing basic information about multiple campuses.
|
||||
/// </summary>
|
||||
public class CampusBasicInfoVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of campus basic information.
|
||||
/// </summary>
|
||||
public IList<CampusBasicInfoDto> Campuses { get; set; } = new List<CampusBasicInfoDto>();
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
||||
|
||||
public class GetCampusBasicInfoListQuery : IRequest<CampusBasicInfoVm>;
|
@ -0,0 +1,26 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
||||
|
||||
public class GetCampusBasicInfoListQueryHandler(ICampusDbContext dbContext) : IRequestHandler<GetCampusBasicInfoListQuery, CampusBasicInfoVm>
|
||||
{
|
||||
public async Task<CampusBasicInfoVm> Handle(GetCampusBasicInfoListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var dtos = await dbContext.Campuses.Select(c => new CampusBasicInfoDto()
|
||||
{
|
||||
Id = c.Id,
|
||||
CodeName = c.CodeName,
|
||||
FullName = c.FullName
|
||||
}).ToListAsync(cancellationToken);
|
||||
|
||||
return new CampusBasicInfoVm
|
||||
{
|
||||
Campuses = dtos
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model containing detailed information about a campus.
|
||||
/// </summary>
|
||||
public class CampusDetailsVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the campus.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The code name associated with the campus.
|
||||
/// </summary>
|
||||
public required string CodeName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The full name of the campus.
|
||||
/// </summary>
|
||||
public string? FullName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The address of the campus.
|
||||
/// </summary>
|
||||
public string? Address { get; set; }
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
|
||||
|
||||
public class GetCampusDetailsQuery : IRequest<CampusDetailsVm>
|
||||
{
|
||||
public required int Id { get; set; }
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using MediatR;
|
||||
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
||||
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Mirea.Api.DataAccess.Application.Common.Exceptions;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
|
||||
|
||||
public class GetCampusDetailsQueryHandler(ICampusDbContext dbContext) : IRequestHandler<GetCampusDetailsQuery, CampusDetailsVm>
|
||||
{
|
||||
public async Task<CampusDetailsVm> Handle(GetCampusDetailsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var campus = await dbContext.Campuses.FirstOrDefaultAsync(c => c.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Campus), request.Id);
|
||||
|
||||
return new CampusDetailsVm()
|
||||
{
|
||||
Id = campus.Id,
|
||||
CodeName = campus.CodeName,
|
||||
FullName = campus.FullName,
|
||||
Address = campus.Address
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user