limit book query results

main
Paul Schneider 9 years ago
parent 94556bcb77
commit a77a9954f1
1 changed files with 15 additions and 5 deletions

@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging;
namespace Yavsc.Controllers namespace Yavsc.Controllers
{ {
using System;
using Yavsc.Model; using Yavsc.Model;
using Yavsc.Models; using Yavsc.Models;
using Yavsc.Models.Booking; using Yavsc.Models.Booking;
@ -27,12 +28,19 @@ namespace Yavsc.Controllers
} }
// GET: api/BookQueryApi // GET: api/BookQueryApi
/// <summary>
/// Book queries, by creation order
/// </summary>
/// <param name="maxId">returned Ids must be lower than this value</param>
/// <returns>book queries</returns>
[HttpGet] [HttpGet]
public IEnumerable<BookQueryProviderView> GetCommands() public IEnumerable<BookQueryProviderView> GetCommands(long maxId=long.MaxValue)
{ {
var uid = User.GetUserId(); var uid = User.GetUserId();
var result = _context.Commands.Include(c => c.Location) var now = DateTime.Now;
.Include(c => c.Client).Where(c => c.PerformerId == uid).
var result = _context.Commands.Include(c => c.Location).
Include(c => c.Client).Where(c => c.PerformerId == uid && c.Id < maxId && c.EventDate > now).
Select(c => new BookQueryProviderView Select(c => new BookQueryProviderView
{ {
Client = new ClientProviderView { UserName = c.Client.UserName, UserId = c.ClientId }, Client = new ClientProviderView { UserName = c.Client.UserName, UserId = c.ClientId },
@ -40,7 +48,9 @@ namespace Yavsc.Controllers
EventDate = c.EventDate, EventDate = c.EventDate,
Id = c.Id, Id = c.Id,
Previsional = c.Previsional Previsional = c.Previsional
}); }).
OrderBy(c=>c.Id).
Take(25);
return result; return result;
} }

Loading…