DataInbox list
This commit is contained in:
@@ -4,6 +4,8 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DiunaBI.Infrastructure.Data;
|
||||
using DiunaBI.Domain.Entities;
|
||||
using DiunaBI.Application.DTOModels;
|
||||
using DiunaBI.Application.DTOModels.Common;
|
||||
|
||||
namespace DiunaBI.API.Controllers;
|
||||
|
||||
@@ -89,17 +91,91 @@ public class DataInboxController : Controller
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetAll()
|
||||
[Route("GetAll")]
|
||||
public IActionResult GetAll([FromQuery] int start, [FromQuery] int limit, [FromQuery] string? name, [FromQuery] string? source)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dataInbox = _db.DataInbox.AsNoTracking().ToList();
|
||||
_logger.LogDebug("DataInbox: Retrieved {Count} records", dataInbox.Count);
|
||||
return Ok(dataInbox);
|
||||
var query = _db.DataInbox.AsQueryable();
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
query = query.Where(x => x.Name.Contains(name));
|
||||
}
|
||||
|
||||
if (source != null)
|
||||
{
|
||||
query = query.Where(x => x.Source.Contains(source));
|
||||
}
|
||||
|
||||
var totalCount = query.Count();
|
||||
|
||||
var items = query
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Skip(start)
|
||||
.Take(limit)
|
||||
.AsNoTracking()
|
||||
.Select(x => new DataInboxDto
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
Source = x.Source,
|
||||
Data = x.Data,
|
||||
CreatedAt = x.CreatedAt
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var pagedResult = new PagedResult<DataInboxDto>
|
||||
{
|
||||
Items = items,
|
||||
TotalCount = totalCount,
|
||||
Page = (start / limit) + 1,
|
||||
PageSize = limit
|
||||
};
|
||||
|
||||
_logger.LogDebug("GetAll: Retrieved {Count} of {TotalCount} data inbox items (page {Page}) with filter name={Name}, source={Source}",
|
||||
items.Count, totalCount, pagedResult.Page, name, source);
|
||||
|
||||
return Ok(pagedResult);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "DataInbox: Error retrieving records");
|
||||
_logger.LogError(e, "GetAll: Error retrieving data inbox items");
|
||||
return BadRequest(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id:guid}")]
|
||||
public IActionResult Get(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dataInbox = _db.DataInbox
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
if (dataInbox == null)
|
||||
{
|
||||
_logger.LogWarning("Get: Data inbox item {Id} not found", id);
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var dto = new DataInboxDto
|
||||
{
|
||||
Id = dataInbox.Id,
|
||||
Name = dataInbox.Name,
|
||||
Source = dataInbox.Source,
|
||||
Data = dataInbox.Data,
|
||||
CreatedAt = dataInbox.CreatedAt
|
||||
};
|
||||
|
||||
_logger.LogDebug("Get: Retrieved data inbox item {Id} {Name}", id, dataInbox.Name);
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Get: Error retrieving data inbox item {Id}", id);
|
||||
return BadRequest(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user