-
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.
- Loading branch information
1 parent
c9e70b0
commit aac3ade
Showing
3 changed files
with
45 additions
and
9 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
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
34 changes: 34 additions & 0 deletions
34
My1kWordsEe/Services/Cqs/Favorites/ReorderFavoritesCommand.cs
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,34 @@ | ||
using CSharpFunctionalExtensions; | ||
|
||
using My1kWordsEe.Models; | ||
using My1kWordsEe.Services.Db; | ||
|
||
namespace My1kWordsEe.Services.Cqs | ||
{ | ||
public class ReorderFavoritesCommand | ||
{ | ||
private readonly GetFavoritesQuery getFavoritesCommand; | ||
private readonly AzureStorageClient azureBlobService; | ||
|
||
public ReorderFavoritesCommand( | ||
GetFavoritesQuery getFavoritesCommand, | ||
AzureStorageClient azureBlobService) | ||
{ | ||
this.getFavoritesCommand = getFavoritesCommand; | ||
this.azureBlobService = azureBlobService; | ||
} | ||
|
||
public async Task<Result<Favorites>> Invoke(string userId, IEnumerable<SampleWord> sampleWords) | ||
{ | ||
return await this.getFavoritesCommand.Invoke(userId).Bind(async favorites => | ||
{ | ||
var reorderedFavorites = new Favorites( | ||
userId: favorites.UserId, | ||
words: sampleWords.ToDictionary(w => w.EeWord), | ||
sentences: favorites.Sentences); | ||
return await this.azureBlobService.SaveFavorites(reorderedFavorites).Bind(_ => | ||
Result.Success(reorderedFavorites)); | ||
}); | ||
} | ||
} | ||
} |