using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Responses;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using PARR.Constants;
using PARR.DAL.Services.Interfaces;
namespace PARR.API.Controllers.V1
{
///
/// Периоды распределения РР
///
[Authorize(Roles = ParrRoles.Administrator.Role)]
public class DistributionPeriodController : BaseApiController
{
private readonly IDistributionPeriodService distributionPeriodService;
private readonly IMapper mapper;
public DistributionPeriodController(
IDistributionPeriodService distributionPeriodService,
IMapper mapper
)
{
this.distributionPeriodService = distributionPeriodService;
this.mapper = mapper;
}
///
/// Список периодов распределения
///
///
[HttpGet(ApiRoutes.DistributionPeriod.GetAll)]
public async Task GetAll()
{
var periods = await distributionPeriodService.Get()
.OrderBy(t => t.Name)
.ToListAsync();
if (!periods.Any())
return NoContent();
var response = mapper.Map>(periods);
return Ok(new Response>(response, true));
}
}
}