Skip to content

Commit

Permalink
refactor(UTXOTag): make Outpoint property non-nullable to enforce dat…
Browse files Browse the repository at this point in the history
…a integrity

refactor(IUTXOTagRepository): rename GetTagByKeyAndOutpoint to GetByKeyAndOutpoint for consistency

feat(IUTXOTagRepository): add GetByKeyValue method to query UTXOTags by key and value
  • Loading branch information
markettes committed Jun 28, 2024
1 parent eb8f9f7 commit 1ff1f20
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Data/Models/UTXOTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public class UTXOTag : Entity
public string Value { get; set; }

// Outpoint of the UTXO in format "hash-index"
public string? Outpoint { get; set; }
public string Outpoint { get; set; }
}
4 changes: 3 additions & 1 deletion src/Data/Repositories/Interfaces/IUTXOTagRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ public interface IUTXOTagRepository
{
Task<UTXOTag?> GetByOutpoint(string outpoint);

Task<UTXOTag?> GetTagByKeyAndOutpoint(string key, string outpoint);
Task<UTXOTag?> GetByKeyAndOutpoint(string key, string outpoint);

Task<List<UTXOTag>> GetByKeyValue(string key, string value);

Task<(bool, string?)> AddAsync(UTXOTag type);

Expand Down
10 changes: 9 additions & 1 deletion src/Data/Repositories/UTXOTagRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@ public UTXOTagRepository(IRepository<UTXOTag> repository,
return await applicationDbContext.UTXOTags.FirstOrDefaultAsync(x => x.Outpoint == outpoint);
}

public async Task<UTXOTag?> GetTagByKeyAndOutpoint(string key, string outpoint)
public async Task<UTXOTag?> GetByKeyAndOutpoint(string key, string outpoint)
{
await using var applicationDbContext = await _dbContextFactory.CreateDbContextAsync();

return await applicationDbContext.UTXOTags.FirstOrDefaultAsync(x => x.Key == key && x.Outpoint == outpoint);
}

public Task<List<UTXOTag>> GetByKeyValue(string key, string value)
{
using var applicationDbContext = _dbContextFactory.CreateDbContext();

return applicationDbContext.UTXOTags
.Where(x => x.Key == key && x.Value == value).ToListAsync();
}

public async Task<(bool, string?)> AddAsync(UTXOTag type)
{
await using var applicationDbContext = await _dbContextFactory.CreateDbContextAsync();
Expand Down

0 comments on commit 1ff1f20

Please sign in to comment.