feat: add controller for faculty
This commit is contained in:
parent
1caaa4759e
commit
aad3c74fba
73
Endpoint/Controllers/V1/FacultyController.cs
Normal file
73
Endpoint/Controllers/V1/FacultyController.cs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyDetails;
|
||||||
|
using Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList;
|
||||||
|
using Mirea.Api.Dto.Responses;
|
||||||
|
using Mirea.Api.Endpoint.Common.Attributes;
|
||||||
|
using Swashbuckle.AspNetCore.Annotations;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Mirea.Api.Endpoint.Controllers.V1
|
||||||
|
{
|
||||||
|
public class FacultyController(IMediator mediator) : BaseControllerV1
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a paginated list of faculties.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="page">Page number. Start from 0.</param>
|
||||||
|
/// <param name="pageSize">Number of items per page.</param>
|
||||||
|
/// <returns>Paginated list of faculties.</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[BadRequestResponse]
|
||||||
|
public async Task<ActionResult<List<FacultyResponse>>> Get(
|
||||||
|
[SwaggerDefault("0")][SwaggerSchema(Nullable = true)][FromQuery] int? page,
|
||||||
|
[SwaggerDefault("25")][SwaggerSchema(Nullable = true)][FromQuery] int? pageSize)
|
||||||
|
{
|
||||||
|
var result = await mediator.Send(new GetFacultyListQuery()
|
||||||
|
{
|
||||||
|
Page = page,
|
||||||
|
PageSize = pageSize
|
||||||
|
});
|
||||||
|
|
||||||
|
return Ok(result.Faculties
|
||||||
|
.Select(f => new FacultyResponse()
|
||||||
|
{
|
||||||
|
Id = f.Id,
|
||||||
|
Name = f.Name,
|
||||||
|
CampusId = f.CampusId
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets details of a specific faculty by ID.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Faculty ID.</param>
|
||||||
|
/// <returns>Details of the specified faculty.</returns>
|
||||||
|
[HttpGet("{id:int}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[BadRequestResponse]
|
||||||
|
[NotFoundResponse]
|
||||||
|
public async Task<ActionResult<FacultyDetailsResponse>> GetDetails(
|
||||||
|
[SwaggerDefault("1")] int id)
|
||||||
|
{
|
||||||
|
var result = await mediator.Send(new GetFacultyInfoQuery()
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
});
|
||||||
|
|
||||||
|
return Ok(new FacultyDetailsResponse()
|
||||||
|
{
|
||||||
|
Id = result.Id,
|
||||||
|
Name = result.Name,
|
||||||
|
CampusId = result.CampusId,
|
||||||
|
CampusCode = result.CampusCode,
|
||||||
|
CampusName = result.CampusName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user