diff --git a/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoDto.cs b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoDto.cs new file mode 100644 index 0000000..e0c9918 --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoDto.cs @@ -0,0 +1,22 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList; + +/// +/// Represents basic information about a campus. +/// +public class CampusBasicInfoDto +{ + /// + /// The unique identifier for the campus. + /// + public int Id { get; set; } + + /// + /// The code name associated with the campus. + /// + public required string CodeName { get; set; } + + /// + /// The full name of the campus. + /// + public string? FullName { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoVm.cs b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoVm.cs new file mode 100644 index 0000000..a3a5f2d --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoVm.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList; + +/// +/// Represents a view model containing basic information about multiple campuses. +/// +public class CampusBasicInfoVm +{ + /// + /// The list of campus basic information. + /// + public IList Campuses { get; set; } = new List(); +} \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQuery.cs b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQuery.cs new file mode 100644 index 0000000..2059735 --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQuery.cs @@ -0,0 +1,5 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList; + +public class GetCampusBasicInfoListQuery : IRequest; \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQueryHandler.cs b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQueryHandler.cs new file mode 100644 index 0000000..3cd6259 --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQueryHandler.cs @@ -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 +{ + public async Task 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 + }; + } +} \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusDetails/CampusDetailsVm.cs b/Application/Cqrs/Campus/Queries/GetCampusDetails/CampusDetailsVm.cs new file mode 100644 index 0000000..35246c1 --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusDetails/CampusDetailsVm.cs @@ -0,0 +1,27 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails; + +/// +/// Represents a view model containing detailed information about a campus. +/// +public class CampusDetailsVm +{ + /// + /// The unique identifier for the campus. + /// + public int Id { get; set; } + + /// + /// The code name associated with the campus. + /// + public required string CodeName { get; set; } + + /// + /// The full name of the campus. + /// + public string? FullName { get; set; } + + /// + /// The address of the campus. + /// + public string? Address { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQuery.cs b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQuery.cs new file mode 100644 index 0000000..f64bf8b --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQuery.cs @@ -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 +{ + public required int Id { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQueryHandler.cs b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQueryHandler.cs new file mode 100644 index 0000000..2cb791c --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQueryHandler.cs @@ -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 +{ + public async Task 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 + }; + } +} \ No newline at end of file