Greenfield: Lightning addresses API (#4546)

* Greenfield: Lightning addresses API

* add docs

* Apply suggestions from code review

Co-authored-by: d11n <mail@dennisreimann.de>
This commit is contained in:
Andrew Camilleri
2023-01-23 10:11:34 +01:00
committed by GitHub
parent 9086822b94
commit 1d2bebf17a
9 changed files with 478 additions and 2 deletions

View File

@@ -60,8 +60,9 @@ public class LightningAddressService
public async Task<bool> Set(LightningAddressData data)
{
data.Username = NormalizeUsername(data.Username);
await using var context = _applicationDbContextFactory.CreateContext();
var result = (await GetCore(context, new LightningAddressQuery() { Usernames = new[] { data.Username } }))
var result = (await GetCore(context, new LightningAddressQuery() { Usernames = new[] { data.Username} }))
.FirstOrDefault();
if (result is not null)
{
@@ -73,7 +74,6 @@ public class LightningAddressService
context.Remove(result);
}
data.Username = NormalizeUsername(data.Username);
await context.AddAsync(data);
await context.SaveChangesAsync();
_memoryCache.Remove(GetKey(data.Username));
@@ -82,6 +82,7 @@ public class LightningAddressService
public async Task<bool> Remove(string username, string? storeId = null)
{
username = NormalizeUsername(username);
await using var context = _applicationDbContextFactory.CreateContext();
var x = (await GetCore(context, new LightningAddressQuery() { Usernames = new[] { username } })).FirstOrDefault();
if (x is null)