-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
117 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,7 @@ | |
else | ||
{ | ||
<div class="d-flex justify-content-center"> | ||
<Spinner /> | ||
@* <Spinner /> *@ | ||
</div> | ||
} | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using CSharpFunctionalExtensions; | ||
|
||
using My1kWordsEe.Models; | ||
using My1kWordsEe.Services.Db; | ||
|
||
namespace My1kWordsEe.Services.Cqs | ||
{ | ||
public class RedoSampleWordCommand | ||
{ | ||
private readonly AzureStorageClient azureBlobService; | ||
private readonly AddSampleWordCommand addSampleWordCommand; | ||
private readonly DeleteSampleSentenceCommand deleteSampleSentenceCommand; | ||
|
||
public RedoSampleWordCommand( | ||
AzureStorageClient azureBlobService, | ||
AddSampleWordCommand addSampleWordCommand, | ||
DeleteSampleSentenceCommand deleteSampleSentenceCommand) | ||
{ | ||
this.azureBlobService = azureBlobService; | ||
this.addSampleWordCommand = addSampleWordCommand; | ||
this.deleteSampleSentenceCommand = deleteSampleSentenceCommand; | ||
} | ||
|
||
public async Task<Result<SampleWord>> Invoke(string eeWord) | ||
{ | ||
if (!eeWord.ValidateWord()) | ||
{ | ||
return Result.Failure<SampleWord>("Not an Estonian word"); | ||
} | ||
|
||
(await azureBlobService.GetWordData(eeWord)).Deconstruct( | ||
out bool _, | ||
out bool isBlobAccessFailure, | ||
out Maybe<SampleWord> savedWord, | ||
out string blobAccessError); | ||
|
||
if (isBlobAccessFailure) | ||
{ | ||
return Result.Failure<SampleWord>(blobAccessError); | ||
} | ||
|
||
var redoTask = this.addSampleWordCommand.Invoke(eeWord); | ||
|
||
if (savedWord.HasValue) | ||
{ | ||
await Parallel.ForEachAsync(savedWord.Value.Samples, async (sample, ct) => | ||
{ | ||
if (ct.IsCancellationRequested) { return; } | ||
await deleteSampleSentenceCommand.Invoke(sample); | ||
}); | ||
} | ||
|
||
return await redoTask; | ||
} | ||
} | ||
} |