35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ListmonkIntegration.Services;
|
|
|
|
namespace ListmonkIntegration.Pages.api
|
|
{
|
|
[IgnoreAntiforgeryToken]
|
|
public class ListsModel : PageModel
|
|
{
|
|
private readonly IListmonkService _listmonkService;
|
|
private readonly ILogger<ListsModel> _logger;
|
|
|
|
public ListsModel(IListmonkService listmonkService, ILogger<ListsModel> logger)
|
|
{
|
|
_listmonkService = listmonkService;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task<IActionResult> OnGetAttributesAsync(int id)
|
|
{
|
|
try
|
|
{
|
|
_logger.LogInformation($"API: Getting attributes for list {id}");
|
|
var attributes = await _listmonkService.GetListAttributesAsync(id);
|
|
_logger.LogInformation($"API: Found {attributes.Count} attributes");
|
|
return new JsonResult(attributes);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error getting attributes");
|
|
return new JsonResult(new List<string>()) { StatusCode = 500 };
|
|
}
|
|
}
|
|
}
|
|
} |