mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-06 21:42:11 +00:00
Add server-side sorting to GetWorkOrderList
- Accept sortBy and sortDir query parameters - Supports sorting by: number, title, location, priority, status, createdDate, assignedTo, lastUpdated - Default sort: lastUpdated desc - Sort applied in SQL before pagination
This commit is contained in:
parent
091390fcad
commit
7d764f966d
1 changed files with 16 additions and 3 deletions
|
|
@ -369,7 +369,7 @@ namespace Api.SeaHavenIndustries.Controllers
|
||||||
// GET: api/WorkOrder/GetWorkOrderList
|
// GET: api/WorkOrder/GetWorkOrderList
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
[HttpGet("GetWorkOrderList")]
|
[HttpGet("GetWorkOrderList")]
|
||||||
public IActionResult GetWorkOrderList(string? search = "", int page = 1, int pageSize = 12)
|
public IActionResult GetWorkOrderList(string? search = "", int page = 1, int pageSize = 12, string? sortBy = "lastUpdated", string? sortDir = "desc")
|
||||||
{
|
{
|
||||||
search ??= "";
|
search ??= "";
|
||||||
|
|
||||||
|
|
@ -392,8 +392,21 @@ namespace Api.SeaHavenIndustries.Controllers
|
||||||
|
|
||||||
var totalCount = query.Count();
|
var totalCount = query.Count();
|
||||||
|
|
||||||
var data = query
|
var isAsc = sortDir?.ToLower() == "asc";
|
||||||
.OrderByDescending(w => w.Id)
|
IOrderedQueryable<WorkOrder> ordered = (sortBy?.ToLower()) switch
|
||||||
|
{
|
||||||
|
"number" => isAsc ? query.OrderBy(w => w.InternalWONumber) : query.OrderByDescending(w => w.InternalWONumber),
|
||||||
|
"title" => isAsc ? query.OrderBy(w => w.WorkerOrderTitle) : query.OrderByDescending(w => w.WorkerOrderTitle),
|
||||||
|
"location" => isAsc ? query.OrderBy(w => w.Locations != null ? w.Locations.Name : "") : query.OrderByDescending(w => w.Locations != null ? w.Locations.Name : ""),
|
||||||
|
"priority" => isAsc ? query.OrderBy(w => w.Priority) : query.OrderByDescending(w => w.Priority),
|
||||||
|
"status" => isAsc ? query.OrderBy(w => w.Status) : query.OrderByDescending(w => w.Status),
|
||||||
|
"createddate" => isAsc ? query.OrderBy(w => w.CreatedDate) : query.OrderByDescending(w => w.CreatedDate),
|
||||||
|
"assignedto" => isAsc ? query.OrderBy(w => w.AssignToUser != null ? w.AssignToUser.FirstName : "") : query.OrderByDescending(w => w.AssignToUser != null ? w.AssignToUser.FirstName : ""),
|
||||||
|
"lastupdated" => isAsc ? query.OrderBy(w => w.LastModificationTime) : query.OrderByDescending(w => w.LastModificationTime),
|
||||||
|
_ => query.OrderByDescending(w => w.Id)
|
||||||
|
};
|
||||||
|
|
||||||
|
var data = ordered
|
||||||
.Skip((page - 1) * pageSize)
|
.Skip((page - 1) * pageSize)
|
||||||
.Take(pageSize)
|
.Take(pageSize)
|
||||||
.Select(w => new
|
.Select(w => new
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue