-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create word and add some abtractions
- Loading branch information
Showing
38 changed files
with
628 additions
and
211 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/Core/EnglishNote.Application/Abtractions/IDateTimeProvider.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,6 @@ | ||
namespace EnglishNote.Application.Abtractions; | ||
public interface IDateTimeProvider | ||
{ | ||
DateTime UtcNow { get; } | ||
DateTime Now { get; } | ||
} |
5 changes: 5 additions & 0 deletions
5
src/Core/EnglishNote.Application/Abtractions/IGuidGenerator.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,5 @@ | ||
namespace EnglishNote.Application.Abtractions; | ||
public interface IGuidGenerator | ||
{ | ||
Guid NewGuid(); | ||
} |
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 |
---|---|---|
@@ -1,4 +1,2 @@ | ||
namespace EnglishNote.Application; | ||
internal interface IAssemblyMarker | ||
{ | ||
} | ||
internal interface IAssemblyMarker; |
11 changes: 7 additions & 4 deletions
11
src/Core/EnglishNote.Application/UseCases/Tags/CreateTag/CreateTagCommandHandler.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
20 changes: 20 additions & 0 deletions
20
src/Core/EnglishNote.Application/UseCases/Words/CreateWord/CreateWordCommand.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,20 @@ | ||
using EnglishNote.Application.Abtractions.Commands; | ||
using EnglishNote.Domain.AggregatesModel.Words; | ||
|
||
namespace EnglishNote.Application.UseCases.Words.CreateWord; | ||
public record CreateWordCommand(string WordText, | ||
List<WordPhoneticRequest> Phonetics, | ||
List<WordMeaningRequest> Meanings) : ICommand<Guid>; | ||
|
||
public record WordPhoneticRequest(string Text, | ||
string? Audio, | ||
string? CustomAudio); | ||
|
||
public record WordMeaningRequest(PartOfSpeech? PartOfSpeech, | ||
CefrLevel? CefrLevel, | ||
List<WorkDefinitionRequest> Definitions); | ||
|
||
public record WorkDefinitionRequest(string DefinitionText, | ||
List<string> Synonyms, | ||
List<string> Antonyms, | ||
List<string> Examples); |
47 changes: 47 additions & 0 deletions
47
src/Core/EnglishNote.Application/UseCases/Words/CreateWord/CreateWordCommandHandler.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,47 @@ | ||
using EnglishNote.Application.Abtractions; | ||
using EnglishNote.Application.Abtractions.Authentication; | ||
using EnglishNote.Application.Abtractions.Commands; | ||
using EnglishNote.Domain.AggregatesModel.Words; | ||
using Shared; | ||
|
||
namespace EnglishNote.Application.UseCases.Words.CreateWord; | ||
internal sealed class CreateWordCommandHandler(IGuidGenerator guidGenerator, | ||
IIdentityService identityService, | ||
IWordRepository wordRepository) : ICommandHandler<CreateWordCommand, Guid> | ||
{ | ||
public async Task<Result<Guid>> Handle(CreateWordCommand request, CancellationToken cancellationToken) | ||
{ | ||
var word = Word.Create(id: guidGenerator.NewGuid(), | ||
wordText: request.WordText, | ||
tagId: null, | ||
vocabularySetId: null, | ||
userId: identityService.GetUserIdentity(), | ||
null); | ||
|
||
foreach (var item in request.Phonetics) | ||
{ | ||
word.AddPhonetic(item.Text, item.Audio, item.CustomAudio); | ||
} | ||
|
||
foreach (var meaning in request.Meanings) | ||
{ | ||
if(meaning is null) continue; | ||
|
||
var mean = word.CreateAndAddMeaning(meaning.PartOfSpeech, meaning.CefrLevel); | ||
|
||
foreach (var definition in meaning.Definitions) | ||
{ | ||
if(definition is null) continue; | ||
|
||
word.AddDefinition(mean, | ||
definition.DefinitionText, | ||
definition.Synonyms, | ||
definition.Antonyms, | ||
definition.Examples); | ||
} | ||
} | ||
|
||
await wordRepository.AddAsync(word, cancellationToken); | ||
return word.Id; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Core/EnglishNote.Domain/AggregatesModel/Tags/ITagRepository.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
namespace EnglishNote.Domain.AggregatesModel.Tags; | ||
public interface ITagRepository | ||
{ | ||
Task AddAsync(Tag tag); | ||
Task AddAsync(Tag tag, CancellationToken cancellationToken = default); | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/Core/EnglishNote.Domain/AggregatesModel/Words/CefrLevel.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,10 @@ | ||
namespace EnglishNote.Domain.AggregatesModel.Words; | ||
public enum CefrLevel | ||
{ | ||
A1 = 1, | ||
A2 = 2, | ||
B1 = 3, | ||
B2 = 4, | ||
C1 = 5, | ||
C2 = 6, | ||
} |
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
5 changes: 5 additions & 0 deletions
5
src/Core/EnglishNote.Domain/AggregatesModel/Words/IWordRepository.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,5 @@ | ||
namespace EnglishNote.Domain.AggregatesModel.Words; | ||
public interface IWordRepository | ||
{ | ||
Task AddAsync(Word word, CancellationToken cancellationToken = default); | ||
} |
21 changes: 0 additions & 21 deletions
21
src/Core/EnglishNote.Domain/AggregatesModel/Words/Meaning.cs
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
src/Core/EnglishNote.Domain/AggregatesModel/Words/PartOfSpeech.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,12 @@ | ||
namespace EnglishNote.Domain.AggregatesModel.Words; | ||
public enum PartOfSpeech | ||
{ | ||
Noun = 1, | ||
Pronoun = 2, | ||
Verb = 3, | ||
Adjective = 4, | ||
Adverb = 5, | ||
Preposition = 6, | ||
Conjunction = 7, | ||
Interjection = 8 | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/Core/EnglishNote.Domain/AggregatesModel/Words/WordManner.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,7 @@ | ||
using EnglishNote.Domain.SeedWork; | ||
|
||
namespace EnglishNote.Domain.AggregatesModel.Words; | ||
public sealed class WordManner : DomainService | ||
{ | ||
|
||
} |
Oops, something went wrong.