You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.4 KiB
41 lines
1.4 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using Application.Domain.Entities;
|
|
using Infrastructure.API;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace IoTCenter.API
|
|
{
|
|
[Route("api/v1/[controller]")]
|
|
[ApiController]
|
|
public class IoTController : ControllerBase
|
|
{
|
|
private readonly IRepository<Node> _nodeRepo;
|
|
private readonly IRepository<Device> _deviceRepo;
|
|
|
|
public IoTController(IRepository<Node> nodeRepo, IRepository<Device> deviceRepo)
|
|
{
|
|
this._nodeRepo = nodeRepo;
|
|
this._deviceRepo = deviceRepo;
|
|
}
|
|
|
|
// GET api/v1/[controller]/nodes[?pageSize=10&pageIndex=1]
|
|
[HttpGet]
|
|
[Route("nodes")]
|
|
[ProducesResponseType(typeof(PaginatedItemsViewModel<Node>), (int)HttpStatusCode.OK)]
|
|
[ProducesResponseType(typeof(IEnumerable<Node>), (int)HttpStatusCode.OK)]
|
|
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
|
public IActionResult Nodes([FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
|
{
|
|
var query = this._nodeRepo.ReadOnlyTable();
|
|
var totalItems = query.Count();
|
|
var itemsOnPage = query.OrderBy(o => o.Name).ThenBy(o => o.CreateOn).Paged(pageIndex, pageSize);
|
|
|
|
var model = new PaginatedItemsViewModel<Node>(pageIndex, pageSize, totalItems, itemsOnPage);
|
|
return Ok(model);
|
|
}
|
|
}
|
|
} |