MireaBackend/Endpoint/Controllers/V1/LectureHallController.cs

82 lines
2.5 KiB
C#
Raw Permalink Normal View History

2024-09-18 06:00:07 +03:00
using Asp.Versioning;
using MediatR;
2024-02-17 14:22:29 +03:00
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;
2024-05-28 07:09:40 +03:00
namespace Mirea.Api.Endpoint.Controllers.V1;
[ApiVersion("1.0")]
2024-08-24 02:27:05 +03:00
[CacheMaxAge(true)]
2024-05-28 07:09:40 +03:00
public class LectureHallController(IMediator mediator) : BaseController
2024-02-17 14:22:29 +03:00
{
2024-05-28 07:09:40 +03:00
/// <summary>
/// Retrieves a list of all lecture halls.
/// </summary>
/// <returns>A list of lecture halls.</returns>
[HttpGet]
public async Task<ActionResult<List<LectureHallResponse>>> Get()
2024-02-17 14:22:29 +03:00
{
2024-05-28 07:09:40 +03:00
var result = await mediator.Send(new GetLectureHallListQuery());
2024-02-17 14:22:29 +03:00
2024-05-28 07:09:40 +03:00
return Ok(result.LectureHalls
.Select(l => new LectureHallResponse()
2024-02-17 14:22:29 +03:00
{
2024-05-28 07:09:40 +03:00
Id = l.Id,
Name = l.Name,
CampusId = l.CampusId
})
);
}
2024-02-17 14:22:29 +03:00
2024-05-28 07:09:40 +03:00
/// <summary>
/// Retrieves details of a specific lecture hall by its ID.
/// </summary>
/// <param name="id">The ID of the lecture hall to retrieve.</param>
/// <returns>The details of the specified lecture hall.</returns>
[HttpGet("{id:int}")]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<LectureHallDetailsResponse>> GetDetails(int id)
{
var result = await mediator.Send(new GetLectureHallInfoQuery()
{
Id = id
});
2024-02-19 12:03:10 +03:00
2024-05-28 07:09:40 +03:00
return Ok(new LectureHallDetailsResponse()
2024-02-19 12:03:10 +03:00
{
2024-05-28 07:09:40 +03:00
Id = result.Id,
Name = result.Name,
CampusId = result.CampusId,
CampusCode = result.CampusCode,
CampusName = result.CampusName
});
}
2024-02-19 12:03:10 +03:00
2024-05-28 07:09:40 +03:00
/// <summary>
/// Retrieves a list of lecture halls by campus ID.
/// </summary>
/// <param name="id">The ID of the campus.</param>
/// <returns>A list of lecture halls in the specified campus.</returns>
[HttpGet("GetByCampus/{id:int}")]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<List<LectureHallResponse>>> 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
}));
2024-02-17 14:22:29 +03:00
}
2024-05-28 07:09:40 +03:00
}