83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
|
using EgwCoreLib.Lux.Data.Services.Sales;
|
|
|
|
namespace Lux.API.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class ReportController : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Costruttore metodo
|
|
/// </summary>
|
|
/// <param name="offService"></param>
|
|
public ReportController(IOfferService offService)
|
|
{
|
|
_offService = offService;
|
|
// Configurazione serializzatore JSON per risolvere errore di loop circolare
|
|
JSSettings = new JsonSerializerSettings()
|
|
{
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
|
};
|
|
}
|
|
|
|
private JsonSerializerSettings JSSettings;
|
|
|
|
private IOfferService _offService;
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
/// <summary>
|
|
/// Chiamata GET: riceve ELENCO Offerte dato periodo
|
|
/// GET: api/report/offert-list/?from=2026-01-01&to=2026-04-01
|
|
/// </summary>
|
|
/// <param name="id">id univoco img</param>
|
|
/// <returns></returns>
|
|
[HttpGet("offert-list")]
|
|
public async Task<IActionResult> OffertList(DateTime from, DateTime to)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// recupera dal DB l'offerta con le righe relative
|
|
List<OfferModel> offData = await _offService.GetFiltAsync(from, to);
|
|
|
|
sw.Stop();
|
|
Log.Info($"OffertList | {from} --> {to} | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
|
return Ok(offData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiamata GET: riceve OffertID, restituisce Json offerta + righe
|
|
/// GET: api/report/offert/1
|
|
/// </summary>
|
|
/// <param name="id">id univoco img</param>
|
|
/// <returns></returns>
|
|
[HttpGet("offert/{id}")]
|
|
public async Task<IActionResult> Offert(int id)
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
// recupera dal DB l'offerta con le righe relative
|
|
OfferModel? offData = await _offService.GetByIdAsync(id);
|
|
|
|
sw.Stop();
|
|
Log.Info($"Offert | {id} | {sw.Elapsed.TotalMilliseconds:N3} ms");
|
|
return Ok(offData);
|
|
//string jsonRes = JsonConvert.SerializeObject(offData, JSSettings);
|
|
//return Ok(jsonRes);
|
|
}
|
|
|
|
[HttpGet("version")]
|
|
public string version()
|
|
{
|
|
var version = Assembly
|
|
.GetExecutingAssembly()
|
|
.GetName()
|
|
.Version?
|
|
.ToString() ?? "unknown";
|
|
|
|
return version;
|
|
}
|
|
}
|
|
}
|