Skip to content

Commit

Permalink
Document base search, change constants
Browse files Browse the repository at this point in the history
  • Loading branch information
richardrandak committed Nov 3, 2020
1 parent c418b08 commit b890314
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion FortnoxAPILibrary.Tests/BaseConnectorTests.cs
Expand Up @@ -186,7 +186,7 @@ public void Test_AllInOnePage()
MyAssert.HasNoError(connector);
Assert.IsTrue(result.TotalPages > 1);

connector.Search.Page = APIConstants.AllInOnePage;
connector.Search.Limit = APIConstants.Unlimited;
var allInOneResult = connector.Find();
MyAssert.HasNoError(connector);

Expand Down
4 changes: 2 additions & 2 deletions FortnoxAPILibrary/APIConstants.cs
Expand Up @@ -26,11 +26,11 @@ public class APIConstants
public static int MaxLimit = 500; //Max limit

/// <summary>
/// Special value for Page field of search settings
/// Unlimited page size. This is special search settings not supported by the server API.
/// When used, connector will gather all available pages, and return it as a single large page.
/// Note that multiple HTTP requests may be send under the hood.
/// The properties like url or response content of a connector will contain only the last one.
/// </summary>
public static int AllInOnePage = -1; //All pages
public static int Unlimited = -1;
}
}
2 changes: 1 addition & 1 deletion FortnoxAPILibrary/SearchableEntityConnector.cs
Expand Up @@ -14,7 +14,7 @@ public class SearchableEntityConnector<TEntity, TEntitySubset, TSearchSettings>
internal async Task<EntityCollection<TEntitySubset>> BaseFind(params string[] indices)
{
var searchSettings = Search.Clone();
if (searchSettings.Page == APIConstants.AllInOnePage)
if (searchSettings.Limit == APIConstants.Unlimited)
return await GetAllInOnePage(searchSettings, indices);
else
return await GetSinglePage(searchSettings, indices);
Expand Down
36 changes: 35 additions & 1 deletion FortnoxAPILibrary/Searches/BaseSearch.cs
Expand Up @@ -3,33 +3,67 @@

namespace FortnoxAPILibrary
{
/// <summary>
/// Base settings for filtering search results.
/// More info at official <see href="https://developer.fortnox.se/general/parameters/">documentation</see>
/// </summary>
public class BaseSearch
{
/// <summary>
/// Limit search result to entities modified after specified date
/// </summary>
[SearchParameter]
public DateTime? LastModified { get; set; }

/// <summary>
/// Limit search result to entities relevant to specified financial year
/// </summary>
[SearchParameter("financialyear")]
public long? FinancialYearID { get; set; }

/// <summary>
/// Limit search result to entities relevant to financial year to which this date belongs.
/// Note, financial years don't overlap, therefore a date defines one (or none) financial year
/// </summary>
[SearchParameter]
public DateTime? FinancialYearDate { get; set; }

/// <summary>
/// Limits search result to entities with date (e.g. InvoiceDate) after specified date
/// Only available for invoices, orders, offers and vouchers.
/// </summary>
[SearchParameter]
public DateTime? FromDate { get; set; }

/// <summary>
/// Limits search result to entities with date (e.g. InvoiceDate) before specified date
/// Only available for invoices, orders, offers and vouchers.
/// </summary>
[SearchParameter]
public DateTime? ToDate { get; set; }


/// <summary>
/// Defines order for search result
/// </summary>
[SearchParameter]
public Sort.Order? SortOrder { get; set; }

/// <summary>
/// Defines page size for the search result. If undefined, API uses page size 100.
/// APIConstants.MaxLimit and APIConstants.Unlimited can be used.
/// </summary>
[SearchParameter]
public int? Limit { get; set; }

/// <summary>
/// Defines which page should be retrieved. If undefined, API uses page 1
/// </summary>
[SearchParameter]
public int? Page { get; set; }

/// <summary>
/// Skips specified amount of entities from search result. If undefined, API uses 0
/// </summary>
[SearchParameter]
public int? Offset { get; set; }

Expand Down

0 comments on commit b890314

Please sign in to comment.