LayersController fix
This commit is contained in:
10
src/Backend/.vscode/launch.json
vendored
10
src/Backend/.vscode/launch.json
vendored
@@ -34,9 +34,13 @@
|
|||||||
"launchBrowser": {
|
"launchBrowser": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"args": "${auto-detect-url}",
|
"args": "${auto-detect-url}",
|
||||||
"osx": "open -a 'Google Chrome' ${auto-detect-url}",
|
"browser": [
|
||||||
"linux": "google-chrome ${auto-detect-url}",
|
{
|
||||||
"windows": "cmd /c start chrome ${auto-detect-url}"
|
"osx": "Google Chrome",
|
||||||
|
"linux": "chrome",
|
||||||
|
"windows": "chrome"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ using Google.Apis.Sheets.v4;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using DiunaBI.Application.DTOModels;
|
||||||
|
using DiunaBI.Application.DTOModels.Common;
|
||||||
using DiunaBI.Domain.Entities;
|
using DiunaBI.Domain.Entities;
|
||||||
using DiunaBI.Infrastructure.Data;
|
using DiunaBI.Infrastructure.Data;
|
||||||
using DiunaBI.Infrastructure.Services;
|
using DiunaBI.Infrastructure.Services;
|
||||||
@@ -39,29 +41,58 @@ public class LayersController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[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
|
try
|
||||||
{
|
{
|
||||||
var response = _db.Layers.Where(x => !x.IsDeleted);
|
var query = _db.Layers.Where(x => !x.IsDeleted);
|
||||||
|
|
||||||
if (name != null)
|
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)
|
.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}",
|
var pagedResult = new PagedResult<LayerDto>
|
||||||
result.Count, name, type);
|
{
|
||||||
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class LayerService
|
|||||||
|
|
||||||
public async Task<PagedResult<LayerDto>> GetLayersAsync(LayerFilterRequest filterRequest)
|
public async Task<PagedResult<LayerDto>> GetLayersAsync(LayerFilterRequest filterRequest)
|
||||||
{
|
{
|
||||||
var query = $"/api/Layers?start={filterRequest.Page}&limit={filterRequest.Page}";
|
var query = $"/Layers?start={filterRequest.Page}&limit={filterRequest.PageSize}";
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(filterRequest.Search))
|
if (!string.IsNullOrEmpty(filterRequest.Search))
|
||||||
query += $"&name={Uri.EscapeDataString(filterRequest.Search)}";
|
query += $"&name={Uri.EscapeDataString(filterRequest.Search)}";
|
||||||
|
|||||||
5
src/Backend/RESTRequests/test.rest
Normal file
5
src/Backend/RESTRequests/test.rest
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
GET http://localhost:5400/tests/ping
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
GET https://morska.diunabi.com/api/tests/ping
|
||||||
Reference in New Issue
Block a user