feat: add controller for group
This commit is contained in:
parent
aad3c74fba
commit
14aedf9d46
68
Endpoint/Controllers/V1/GroupController.cs
Normal file
68
Endpoint/Controllers/V1/GroupController.cs
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupDetails;
|
||||||
|
using Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
public class GroupController(IMediator mediator) : BaseControllerV1
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves a list of groups.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="page">The page number for pagination (optional).</param>
|
||||||
|
/// <param name="pageSize">The page size for pagination (optional).</param>
|
||||||
|
/// <returns>A list of groups.</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[BadRequestResponse]
|
||||||
|
public async Task<ActionResult<List<GroupResponse>>> Get([FromQuery] int? page, [FromQuery] int? pageSize)
|
||||||
|
{
|
||||||
|
var result = await mediator.Send(new GetGroupListQuery()
|
||||||
|
{
|
||||||
|
Page = page,
|
||||||
|
PageSize = pageSize
|
||||||
|
});
|
||||||
|
|
||||||
|
return Ok(result.Groups
|
||||||
|
.Select(g => new GroupResponse()
|
||||||
|
{
|
||||||
|
Id = g.Id,
|
||||||
|
Name = g.Name,
|
||||||
|
FacultyId = g.FacultyId
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves detailed information about a specific group.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The ID of the group to retrieve.</param>
|
||||||
|
/// <returns>Detailed information about the group.</returns>
|
||||||
|
[HttpGet("{id:int}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[BadRequestResponse]
|
||||||
|
[NotFoundResponse]
|
||||||
|
public async Task<ActionResult<GroupDetailsResponse>> GetDetails(int id)
|
||||||
|
{
|
||||||
|
var result = await mediator.Send(new GetGroupInfoQuery()
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
});
|
||||||
|
|
||||||
|
return Ok(new GroupDetailsResponse()
|
||||||
|
{
|
||||||
|
Id = result.Id,
|
||||||
|
Name = result.Name,
|
||||||
|
FacultyId = result.FacultyId,
|
||||||
|
FacultyName = result.Faculty
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user