using Asp.Versioning; using MediatR; using Microsoft.AspNetCore.Mvc; using Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallDetails; using Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList; using Mirea.Api.Dto.Responses; using Mirea.Api.Endpoint.Common.Attributes; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Mirea.Api.Endpoint.Controllers.V1; [ApiVersion("1.0")] [CacheMaxAge(true)] public class LectureHallController(IMediator mediator) : BaseController { /// /// Retrieves a list of all lecture halls. /// /// A list of lecture halls. [HttpGet] public async Task>> Get() { var result = await mediator.Send(new GetLectureHallListQuery()); return Ok(result.LectureHalls .Select(l => new LectureHallResponse() { Id = l.Id, Name = l.Name, CampusId = l.CampusId }) ); } /// /// Retrieves details of a specific lecture hall by its ID. /// /// The ID of the lecture hall to retrieve. /// The details of the specified lecture hall. [HttpGet("{id:int}")] [BadRequestResponse] [NotFoundResponse] public async Task> GetDetails(int id) { var result = await mediator.Send(new GetLectureHallInfoQuery() { Id = id }); return Ok(new LectureHallDetailsResponse() { Id = result.Id, Name = result.Name, CampusId = result.CampusId, CampusCode = result.CampusCode, CampusName = result.CampusName }); } /// /// Retrieves a list of lecture halls by campus ID. /// /// The ID of the campus. /// A list of lecture halls in the specified campus. [HttpGet("GetByCampus/{id:int}")] [BadRequestResponse] [NotFoundResponse] public async Task>> GetByCampus(int id) { var result = await mediator.Send(new GetLectureHallListQuery()); return Ok(result.LectureHalls.Where(l => l.CampusId == id) .Select(l => new LectureHallResponse() { Id = l.Id, Name = l.Name, CampusId = l.CampusId })); } }