using System.Collections.Generic; using Luticate2.Auth.Utils.Dbo; using Luticate2.Auth.Utils.Dbo.Pagination; using Luticate2.Auth.Utils.Dbo.Result; namespace Luticate2.Auth.Utils.Business.Pagination { public static class LuOrderByParser { public static LuResult Parse(string data) { if (data == null) { data = ""; } data = data.Trim(); if (data != "") { var dbo = new LuOrderByDbo {OrderByFields = new List()}; var fields = data.Split(','); foreach (var field in fields) { if (field == "") { return LuResult.Error(LuStatus.InputError.ToInt(), $"LuOrderByParser: {data}", "Empty order by field"); } var orderByField = new LuOrderByFieldDbo(); // TODO parse // var split = field.Split(':'); // if (split.Length > 2 || split.Length == 0) // { // return LuResult.Error(LuStatus.InputError.ToInt(), // $"LuOrderByParser: {data}", "Invalid order by field syntax"); // } // orderByField.Field = LuFieldDbo.Make(split[0]); // var order = split.Length == 2 ? split[1].ToLower() : "asc"; // if (order == "asc") // { // orderByField.Asc = true; // } // else if (order == "desc") // { // orderByField.Asc = false; // } // else // { // return LuResult.Error(LuStatus.InputError.ToInt(), // $"LuOrderByParser: {data}", "Empty order by field order"); // } dbo.OrderByFields.Add(orderByField); } return LuResult.Ok(dbo); } return LuResult.Error(LuStatus.InputError.ToInt(), "Order by is empty or missing", ""); } } }