feat: add controller for lecture hall
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m34s
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m34s
This commit is contained in:
parent
59eccf8b93
commit
e3d74c373e
63
Endpoint/Controllers/V1/LectureHallController.cs
Normal file
63
Endpoint/Controllers/V1/LectureHallController.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
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.DataAccess.Persistence;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
public class LectureHallController(IMediator mediator, UberDbContext dbContext) : BaseControllerV1
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves a list of all lecture halls.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A list of lecture halls.</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public async Task<ActionResult<List<LectureHallResponse>>> 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
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[BadRequestResponse]
|
||||||
|
[NotFoundResponse]
|
||||||
|
public async Task<ActionResult<LectureHallDetailsResponse>> 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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user