diff --git a/Sloth.Api/Controllers/v2/TransactionsController.cs b/Sloth.Api/Controllers/v2/TransactionsController.cs index bcf4d22a..23d8bd40 100644 --- a/Sloth.Api/Controllers/v2/TransactionsController.cs +++ b/Sloth.Api/Controllers/v2/TransactionsController.cs @@ -156,6 +156,35 @@ public async Task> GetByKfsKey(string id) return transactions; } + /// + /// Fetch Transactions by Metadata + /// + /// + /// + /// + [HttpGet("metadata/{key}/{value}")] + [ProducesResponseType(typeof(IList), 200)] + public async Task> GetByMetadata(string key, string value) + { + var teamId = GetTeamId(); + + if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value)) + { + return new List(); + } + + 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 ///