2024-01-28 06:05:54 +03:00
|
|
|
|
using MediatR;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
|
|
|
|
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
|
2024-02-16 23:56:45 +03:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
namespace Mirea.Api.Endpoint.Controllers.V1
|
|
|
|
|
{
|
|
|
|
|
public class CampusController(IMediator mediator) : BaseControllerV1
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets basic information about campuses.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Basic information about campuses.</returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-02-17 09:09:18 +03:00
|
|
|
|
public async Task<ActionResult<List<CampusBasicInfoResponse>>> Get()
|
2024-01-28 06:05:54 +03:00
|
|
|
|
{
|
|
|
|
|
var result = await mediator.Send(new GetCampusBasicInfoListQuery());
|
|
|
|
|
|
2024-02-16 23:56:45 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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}")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
[BadRequestResponse]
|
|
|
|
|
[NotFoundResponse]
|
2024-02-16 23:56:45 +03:00
|
|
|
|
public async Task<ActionResult<CampusDetailsResponse>> GetDetails(int id)
|
2024-01-28 06:05:54 +03:00
|
|
|
|
{
|
|
|
|
|
var result = await mediator.Send(new GetCampusDetailsQuery()
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-16 23:56:45 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|