60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using Asp.Versioning;
|
|
using MediatR;
|
|
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;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Mirea.Api.Endpoint.Controllers.V1;
|
|
|
|
[ApiVersion("1.0")]
|
|
[CacheMaxAge(true)]
|
|
public class CampusController(IMediator mediator) : BaseController
|
|
{
|
|
/// <summary>
|
|
/// Gets basic information about campuses.
|
|
/// </summary>
|
|
/// <returns>Basic information about campuses.</returns>
|
|
[HttpGet]
|
|
public async Task<ActionResult<List<CampusBasicInfoResponse>>> Get()
|
|
{
|
|
var result = await mediator.Send(new GetCampusBasicInfoListQuery());
|
|
|
|
return Ok(result.Campuses
|
|
.Select(c => new CampusBasicInfoResponse()
|
|
{
|
|
Id = c.Id,
|
|
CodeName = c.CodeName,
|
|
FullName = c.FullName
|
|
})
|
|
);
|
|
}
|
|
|
|
/// <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()
|
|
{
|
|
Id = id
|
|
});
|
|
|
|
return Ok(new CampusDetailsResponse()
|
|
{
|
|
Id = result.Id,
|
|
CodeName = result.CodeName,
|
|
FullName = result.FullName,
|
|
Address = result.Address
|
|
});
|
|
}
|
|
} |