42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SmallSoftwareContracts.AdapterContracts;
|
|
using SmallSoftwareContracts.Exceptions;
|
|
|
|
namespace SmallSoftwareWebApi.Controllers;
|
|
|
|
|
|
[Authorize]
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
public class SalariesController(ISalaryAdapter adapter) : ControllerBase
|
|
{
|
|
private readonly ISalaryAdapter _adapter = adapter;
|
|
|
|
[HttpGet]
|
|
public IActionResult GetRecords(DateTime fromDate, DateTime toDate)
|
|
{
|
|
return _adapter.GetListByPeriod(fromDate, toDate).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult GetWorkerRecords(string id, DateTime fromDate, DateTime toDate)
|
|
{
|
|
return _adapter.GetListByPeriodByWorker(fromDate, toDate, id).GetResponse(Request, Response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Calculate(DateTime date)
|
|
{
|
|
try
|
|
{
|
|
return _adapter.CalculateSalary(date).GetResponse(Request, Response);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, "Internal error");
|
|
}
|
|
}
|
|
} |