Skip to content

Commit

Permalink
feat: include skip/take and script on dictionary find.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzzerd authored Nov 7, 2023
1 parent 28b1ba5 commit a5e2a47
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
22 changes: 12 additions & 10 deletions src/FMData.Rest/FileMakerRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,25 @@ public async Task<IResponse> LogoutAsync()
#endregion

#region Special Implementations
/// <summary>
/// General purpose Find Request method. Supports additional syntaxes like the { "omit" : "true" } operation.
/// This method returns a strongly typed <see cref="IEnumerable{T}"/> but accepts a the more flexible <see cref="Dictionary{TKey, TValue}"/> request parameters.
/// </summary>
/// <typeparam name="T">the type of response objects to return.</typeparam>
/// <param name="layout">The layout to perform the find request on.</param>
/// <param name="req">The find request dictionary.</param>
/// <returns>An <see cref="IEnumerable{T}"/> matching the request parameters.</returns>
/// <remarks>Can't be a relay method, since we have to process the data specially to get our output</remarks>
public override async Task<IEnumerable<T>> FindAsync<T>(string layout, Dictionary<string, string> req)
/// <inheritdoc />
public override async Task<IEnumerable<T>> FindAsync<T>(
string layout,
Dictionary<string, string> req,
int skip,
int take,
string script,
string scriptParameter)
{
if (string.IsNullOrEmpty(layout)) throw new ArgumentException("Layout is required on the request.");

var fmdataRequest = new FindRequest<Dictionary<string, string>> { Layout = layout };

fmdataRequest.AddQuery(req, false);

fmdataRequest.SetLimit(take).SetOffset(skip);

fmdataRequest.SetScript(scriptName: script, scriptParameter: scriptParameter);

var response = await ExecuteRequestAsync(HttpMethod.Post, FindEndpoint(layout), fmdataRequest).ConfigureAwait(false);

if (response.StatusCode == HttpStatusCode.NotFound)
Expand Down
13 changes: 9 additions & 4 deletions src/FMData.Xml/FileMakerXmlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,15 @@ public override Task<IFindResponse<Dictionary<string, string>>> SendAsync(IFindR
{
throw new NotImplementedException();
}
/// <summary>
/// Finds records using a layout and a dictionary of strings as criteria.
/// </summary>
public override Task<IEnumerable<T>> FindAsync<T>(string layout, Dictionary<string, string> req)

/// <inheritdoc />
public override Task<IEnumerable<T>> FindAsync<T>(
string layout,
Dictionary<string, string> req,
int skip,
int take,
string script,
string scriptParameter)
{
throw new NotImplementedException();
}
Expand Down
18 changes: 17 additions & 1 deletion src/FMData/FileMakerApiClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,23 @@ public virtual async Task<IEnumerable<T>> SendAsync<T>(
/// <param name="layout">The layout to perform the request on.</param>
/// <param name="req">The dictionary of key/value pairs to find against.</param>
/// <returns></returns>
public abstract Task<IEnumerable<T>> FindAsync<T>(string layout, Dictionary<string, string> req);
public virtual Task<IEnumerable<T>> FindAsync<T>(
string layout, Dictionary<string, string> req) => FindAsync<T>(
layout: layout,
req: req,
skip: 0,
take: 100,
script: null,
scriptParameter: null);

/// <inheritdoc />
public abstract Task<IEnumerable<T>> FindAsync<T>(
string layout,
Dictionary<string, string> req,
int skip,
int take,
string script,
string scriptParameter);

/// <summary>
/// Get a single record by FileMaker RecordId
Expand Down
21 changes: 21 additions & 0 deletions src/FMData/IFileMakerApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ public interface IFileMakerApiClient
/// <param name="req"></param>
/// <returns></returns>
Task<IEnumerable<T>> FindAsync<T>(string layout, Dictionary<string, string> req);

/// <summary>
/// General purpose Find Request method. Supports additional syntaxes like the { "omit" : "true" } operation.
/// This method returns a strongly typed <see cref="IEnumerable{T}"/> but accepts a the more flexible <see cref="Dictionary{TKey, TValue}"/> request parameters.
/// </summary>
/// <typeparam name="T">the type of response objects to return.</typeparam>
/// <param name="layout">The layout to perform the find request on.</param>
/// <param name="req">The find request dictionary.</param>
/// <param name="skip">The number of records to skip.</param>
/// <param name="take">The number of records to return.</param>
/// <param name="script">The name of a script to run (or null)</param>
/// <param name="scriptParameter">The script parameter value (or null)</param>
/// <returns>An <see cref="IEnumerable{T}"/> matching the request parameters.</returns>
/// <remarks>Can't be a relay method, since we have to process the data specially to get our output</remarks>
Task<IEnumerable<T>> FindAsync<T>(
string layout,
Dictionary<string, string> req,
int skip,
int take,
string script,
string scriptParameter);
#endregion

#region Edit
Expand Down

0 comments on commit a5e2a47

Please sign in to comment.