forked from ac10n/tzkt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
213 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc.ModelBinding; | ||
|
||
namespace Tzkt.Api | ||
{ | ||
public class ContractTagsBinder : IModelBinder | ||
{ | ||
public Task BindModelAsync(ModelBindingContext bindingContext) | ||
{ | ||
var model = bindingContext.ModelName; | ||
var hasValue = false; | ||
|
||
if (!bindingContext.TryGetContractTags($"{model}", ref hasValue, out var value)) | ||
return Task.CompletedTask; | ||
|
||
if (!bindingContext.TryGetContractTags($"{model}.eq", ref hasValue, out var eq)) | ||
return Task.CompletedTask; | ||
|
||
if (!bindingContext.TryGetContractTags($"{model}.any", ref hasValue, out var any)) | ||
return Task.CompletedTask; | ||
|
||
if (!bindingContext.TryGetContractTags($"{model}.all", ref hasValue, out var all)) | ||
return Task.CompletedTask; | ||
|
||
if (!hasValue) | ||
{ | ||
bindingContext.Result = ModelBindingResult.Success(null); | ||
return Task.CompletedTask; | ||
} | ||
|
||
bindingContext.Result = ModelBindingResult.Success(new ContractTagsParameter | ||
{ | ||
Eq = value ?? eq, | ||
Any = any, | ||
All = all | ||
}); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Mvc; | ||
using NJsonSchema.Annotations; | ||
|
||
namespace Tzkt.Api | ||
{ | ||
[ModelBinder(BinderType = typeof(ContractTagsBinder))] | ||
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")] | ||
[JsonSchemaExtensionData("x-tzkt-query-parameter", "fa1,fa12,fa2")] | ||
public class ContractTagsParameter | ||
{ | ||
/// <summary> | ||
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \ | ||
/// Specify a comma-separated list of contract tags to get contracts with exactly the same set of tags. | ||
/// Avoid using this mode and use `.any` or `.all` instead, because it may not work as expected due to internal 'hidden' tags. | ||
/// | ||
/// Example: `?tags=fa2` or `?tags=fa1,fa12`. | ||
/// </summary> | ||
[JsonSchemaType(typeof(List<string>))] | ||
public int? Eq { get; set; } | ||
|
||
/// <summary> | ||
/// **Has any** filter mode. \ | ||
/// Specify a comma-separated list of contract tags to get contracts where at least one of the specified tags is presented. | ||
/// | ||
/// Example: `?tags.any=fa2` or `?tags.any=fa1,fa12`. | ||
/// </summary> | ||
[JsonSchemaType(typeof(List<string>))] | ||
public int? Any { get; set; } | ||
|
||
/// <summary> | ||
/// **Has all** filter mode. \ | ||
/// Specify a comma-separated list of contract tags to get contracts where all of the specified tags are presented. | ||
/// | ||
/// Example: `?tags.all=fa2` or `?tags.all=fa1,fa12`. | ||
/// </summary> | ||
[JsonSchemaType(typeof(List<string>))] | ||
public int? All { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.