Skip to content

Commit

Permalink
Minor API validation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Jul 12, 2024
1 parent 609c025 commit a5a2199
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
8 changes: 4 additions & 4 deletions Tzkt.Api/Controllers/OperationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5196,7 +5196,7 @@ public async Task<ActionResult<IEnumerable<MigrationOperation>>> GetMigrations(
/// <returns></returns>
[HttpGet("migrations/{id:long}")]
public async Task<ActionResult<MigrationOperation>> GetMigrationById(
[Required][Min(0)] long id,
[Required][Min64(0)] long id,
MichelineFormat micheline = MichelineFormat.Json,
Symbols quote = Symbols.None)
{
Expand Down Expand Up @@ -5333,7 +5333,7 @@ public async Task<ActionResult<IEnumerable<RevelationPenaltyOperation>>> GetReve
/// <returns></returns>
[HttpGet("revelation_penalties/{id:long}")]
public async Task<ActionResult<RevelationPenaltyOperation>> GetRevelationPenaltyById(
[Required][Min(0)] long id,
[Required][Min64(0)] long id,
Symbols quote = Symbols.None)
{
var query = ResponseCacheService.BuildKey(Request.Path.Value,
Expand Down Expand Up @@ -5500,7 +5500,7 @@ public async Task<ActionResult<IEnumerable<BakingOperation>>> GetBaking(
/// <returns></returns>
[HttpGet("baking/{id:long}")]
public async Task<ActionResult<BakingOperation>> GetBakingById(
[Required][Min(0)] long id,
[Required][Min64(0)] long id,
Symbols quote = Symbols.None)
{
var query = ResponseCacheService.BuildKey(Request.Path.Value,
Expand Down Expand Up @@ -5636,7 +5636,7 @@ public async Task<ActionResult<IEnumerable<EndorsingRewardOperation>>> GetEndors
/// <returns></returns>
[HttpGet("endorsing_rewards/{id:long}")]
public async Task<ActionResult<EndorsingRewardOperation>> GetEndorsingRewardById(
[Required][Min(0)] long id,
[Required][Min64(0)] long id,
Symbols quote = Symbols.None)
{
var query = ResponseCacheService.BuildKey(Request.Path.Value,
Expand Down
2 changes: 1 addition & 1 deletion Tzkt.Api/Parameters/SrCommitmentFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class SrCommitmentFilter : INormalizable
lastLevel == null &&
lastTime == null &&
status == null &&
predecessor.Empty;
(predecessor == null || predecessor.Empty);

public string Normalize(string name)
{
Expand Down
6 changes: 3 additions & 3 deletions Tzkt.Api/Parameters/SrGameFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public class SrGameFilter : INormalizable
public TimestampParameter lastTime { get; set; }

[OpenApiIgnore]
public bool Empty =>
public bool Empty =>
id == null &&
rollup == null &&
initiator == null &&
initiatorCommitment.Empty &&
(initiatorCommitment == null || initiatorCommitment.Empty) &&
opponent == null &&
opponentCommitment.Empty &&
(opponentCommitment == null || opponentCommitment.Empty) &&
firstLevel == null &&
firstTime == null &&
lastLevel == null &&
Expand Down
4 changes: 2 additions & 2 deletions Tzkt.Api/Parameters/SrGameInfoFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public class SrGameInfoFilter : INormalizable
public bool Empty =>
id == null &&
initiator == null &&
initiatorCommitment.Empty &&
(initiatorCommitment == null || initiatorCommitment.Empty) &&
opponent == null &&
opponentCommitment.Empty;
(opponentCommitment == null || opponentCommitment.Empty);

public string Normalize(string name)
{
Expand Down
19 changes: 19 additions & 0 deletions Tzkt.Api/Validation/Min64Attribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace System.ComponentModel.DataAnnotations
{
public sealed class Min64Attribute : ValidationAttribute
{
readonly long Minimum;

public Min64Attribute(long minimum)
{
Minimum = minimum;
}

protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
return value != null && (long)value < Minimum
? new ValidationResult($"The value must be greater than or equal to {Minimum}.")
: ValidationResult.Success;
}
}
}

0 comments on commit a5a2199

Please sign in to comment.