Add controllers for the Get method #9

Merged
Wesser merged 33 commits from feat/controller-get into release/v1.0.0 2024-02-19 12:06:31 +03:00
Showing only changes of commit d02fb8becb - Show all commits

View File

@ -3,7 +3,6 @@ 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;
@ -12,7 +11,7 @@ using System.Threading.Tasks;
namespace Mirea.Api.Endpoint.Controllers.V1
{
public class LectureHallController(IMediator mediator, UberDbContext dbContext) : BaseControllerV1
public class LectureHallController(IMediator mediator) : BaseControllerV1
{
/// <summary>
/// Retrieves a list of all lecture halls.
@ -59,5 +58,27 @@ namespace Mirea.Api.Endpoint.Controllers.V1
CampusName = result.CampusName
});
}
/// <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("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[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
}));
}
}
}