LayersController fix
This commit is contained in:
@@ -4,6 +4,8 @@ using Google.Apis.Sheets.v4;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DiunaBI.Application.DTOModels;
|
||||
using DiunaBI.Application.DTOModels.Common;
|
||||
using DiunaBI.Domain.Entities;
|
||||
using DiunaBI.Infrastructure.Data;
|
||||
using DiunaBI.Infrastructure.Services;
|
||||
@@ -39,29 +41,58 @@ public class LayersController : Controller
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetAll(int start, int limit, string? name, LayerType? type)
|
||||
[Route("")]
|
||||
public IActionResult GetAll([FromQuery] int start, [FromQuery] int limit, [FromQuery] string? name, [FromQuery] Domain.Entities.LayerType? type)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = _db.Layers.Where(x => !x.IsDeleted);
|
||||
var query = _db.Layers.Where(x => !x.IsDeleted);
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
response = response.Where(x => x.Name != null && x.Name.Contains(name));
|
||||
query = query.Where(x => x.Name != null && x.Name.Contains(name));
|
||||
}
|
||||
|
||||
if (type != null)
|
||||
if (type.HasValue)
|
||||
{
|
||||
response = response.Where(x => x.Type == type);
|
||||
query = query.Where(x => x.Type == type.Value);
|
||||
}
|
||||
|
||||
var result = response
|
||||
var totalCount = query.Count();
|
||||
|
||||
var items = query
|
||||
.OrderByDescending(x => x.Number)
|
||||
.Skip(start).Take(limit).AsNoTracking().ToList();
|
||||
.Skip(start)
|
||||
.Take(limit)
|
||||
.AsNoTracking()
|
||||
.Select(x => new LayerDto
|
||||
{
|
||||
Id = x.Id,
|
||||
Number = x.Number,
|
||||
Name = x.Name,
|
||||
Type = (Application.DTOModels.LayerType)x.Type,
|
||||
CreatedAt = x.CreatedAt,
|
||||
ModifiedAt = x.ModifiedAt,
|
||||
CreatedById = x.CreatedById,
|
||||
ModifiedById = x.ModifiedById,
|
||||
IsDeleted = x.IsDeleted,
|
||||
IsCancelled = x.IsCancelled,
|
||||
ParentId = x.ParentId
|
||||
})
|
||||
.ToList();
|
||||
|
||||
_logger.LogDebug("GetAll: Retrieved {Count} layers with filter name={Name}, type={Type}",
|
||||
result.Count, name, type);
|
||||
var pagedResult = new PagedResult<LayerDto>
|
||||
{
|
||||
Items = items,
|
||||
TotalCount = totalCount,
|
||||
Page = (start / limit) + 1,
|
||||
PageSize = limit
|
||||
};
|
||||
|
||||
return Ok(result);
|
||||
_logger.LogDebug("GetAll: Retrieved {Count} of {TotalCount} layers (page {Page}) with filter name={Name}, type={Type}",
|
||||
items.Count, totalCount, pagedResult.Page, name, type);
|
||||
|
||||
return Ok(pagedResult);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user