auto.bus_api/Server/Controllers/TicketGroupController.cs
cuqmbr 63cc9a9edc refactor: make TicketGroup the main controller for ticket data retrieval
remove CRUD from TicketGroup, remove Ticket Controller and Service
2023-05-24 10:58:37 +03:00

48 lines
1.4 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Server.Services;
using SharedModels.QueryParameters.Objects;
namespace Server.Controllers;
[Authorize]
[Route("api/ticketGroups")]
[ApiController]
public class TicketGroupController : ControllerBase
{
private readonly ITicketGroupManagementService _ticketGroupManagementService;
public TicketGroupController(ITicketGroupManagementService ticketGroupManagementService)
{
_ticketGroupManagementService = ticketGroupManagementService;
}
[HttpGet]
public async Task<IActionResult> GetTicketGroups([FromQuery] TicketGroupParameters parameters)
{
var result = await _ticketGroupManagementService.GetTicketGroups(parameters);
if (!result.isSucceed)
{
return result.actionResult;
}
Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata));
return Ok(result.ticketGroups);
}
[HttpGet("{id}")]
public async Task<IActionResult> GetTicketGroup(int id, [FromQuery] string? fields)
{
var result = await _ticketGroupManagementService.GetTicketGroup(id, fields);
if (!result.isSucceed)
{
return result.actionResult;
}
return Ok(result.ticketGroup);
}
}