From e3d74c373e741764552cd2064dcbcdd208eaabc4 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sat, 17 Feb 2024 14:22:29 +0300 Subject: [PATCH] feat: add controller for lecture hall --- .../Controllers/V1/LectureHallController.cs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Endpoint/Controllers/V1/LectureHallController.cs diff --git a/Endpoint/Controllers/V1/LectureHallController.cs b/Endpoint/Controllers/V1/LectureHallController.cs new file mode 100644 index 0000000..4ccede5 --- /dev/null +++ b/Endpoint/Controllers/V1/LectureHallController.cs @@ -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 + { + /// + /// Retrieves a list of all lecture halls. + /// + /// A list of lecture halls. + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + 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}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [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 + }); + } + } +}