Skip to content

Commit

Permalink
get any txns that match provided metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
srkirkland committed Nov 6, 2023
1 parent fc61138 commit 8f80ff8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Sloth.Api/Controllers/v2/TransactionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,35 @@ public async Task<IList<Transaction>> GetByKfsKey(string id)
return transactions;
}

/// <summary>
/// Fetch Transactions by Metadata
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
[HttpGet("metadata/{key}/{value}")]
[ProducesResponseType(typeof(IList<Transaction>), 200)]
public async Task<IList<Transaction>> GetByMetadata(string key, string value)
{
var teamId = GetTeamId();

if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
{
return new List<Transaction>();
}

var transactions = await _context.Transactions
.Where(t => t.Source.Team.Id == teamId)
.Include(t => t.Creator)
.Include(t => t.Transfers)
.Include(t => t.Metadata)
.Where(t => t.Metadata.Any(m => m.Name == key && m.Value == value))
.AsNoTracking()
.ToListAsync();

return transactions;
}

// TODO: just for testing, remove later

/// <summary>
Expand Down

0 comments on commit 8f80ff8

Please sign in to comment.