MireaBackend/Endpoint/Controllers/V1/CampusController.cs

60 lines
1.7 KiB
C#
Raw Normal View History

2024-09-18 06:00:07 +03:00
using Asp.Versioning;
using MediatR;
2024-01-28 06:05:54 +03:00
using Microsoft.AspNetCore.Mvc;
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Attributes;
using System.Collections.Generic;
using System.Linq;
2024-01-28 06:05:54 +03:00
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 CampusController(IMediator mediator) : BaseController
2024-01-28 06:05:54 +03:00
{
2024-05-28 07:09:40 +03:00
/// <summary>
/// Gets basic information about campuses.
/// </summary>
/// <returns>Basic information about campuses.</returns>
[HttpGet]
public async Task<ActionResult<List<CampusBasicInfoResponse>>> Get()
2024-01-28 06:05:54 +03:00
{
2024-05-28 07:09:40 +03:00
var result = await mediator.Send(new GetCampusBasicInfoListQuery());
2024-01-28 06:05:54 +03:00
2024-05-28 07:09:40 +03:00
return Ok(result.Campuses
.Select(c => new CampusBasicInfoResponse()
{
Id = c.Id,
CodeName = c.CodeName,
FullName = c.FullName
})
);
}
2024-01-28 06:05:54 +03:00
2024-05-28 07:09:40 +03:00
/// <summary>
/// Gets details of a specific campus by ID.
/// </summary>
/// <param name="id">Campus ID.</param>
/// <returns>Details of the specified campus.</returns>
[HttpGet("{id:int}")]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<CampusDetailsResponse>> GetDetails(int id)
{
var result = await mediator.Send(new GetCampusDetailsQuery()
2024-01-28 06:05:54 +03:00
{
2024-05-28 07:09:40 +03:00
Id = id
});
2024-01-28 06:05:54 +03:00
2024-05-28 07:09:40 +03:00
return Ok(new CampusDetailsResponse()
{
Id = result.Id,
CodeName = result.CodeName,
FullName = result.FullName,
Address = result.Address
});
2024-01-28 06:05:54 +03:00
}
2024-05-28 07:09:40 +03:00
}