mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Tightens the metadata value object nullability and extracts their mappings
This commit is contained in:
1 parent
89886ebe22
commit
c0302ecc50
13 files changed
+76
-13
No files matched your search
@@ -87,7 +87,7 @@ class ReleaseInfo
|
||||
```csharp
|
||||
class LanguageInfo
|
||||
{
|
||||
ErrorOr<LanguageInfo> Create(string languageCode, string languageName, Optional<string> nativeName);
|
||||
LanguageInfo Create(string languageCode, string languageName, Optional<string> nativeName);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public static class GenreDtoMapping
|
||||
public static Result<Genre> ToDomainEntity(this GenreDto dto)
|
||||
{
|
||||
return Genre.Create(
|
||||
dto.Name
|
||||
dto.Name!
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public static class GenreEntityMapping
|
||||
public static Result<Genre> ToDomainEntity(this GenreEntity repositoryEntity)
|
||||
{
|
||||
return Genre.Create(
|
||||
repositoryEntity.Name ?? default
|
||||
repositoryEntity.Name!
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="LanguageInfoDto"/>.
|
||||
/// </summary>
|
||||
public static class LanguageInfoDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to <see cref="LanguageInfoDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The DTO to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="LanguageInfo"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<LanguageInfo> ToDomainEntity(this LanguageInfoDto dto)
|
||||
{
|
||||
return LanguageInfo.Create(
|
||||
dto.LanguageCode!,
|
||||
dto.LanguageName!,
|
||||
Optional<string>.FromNullable(dto.NativeName)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ReleaseInfoDto"/>.
|
||||
/// </summary>
|
||||
public static class ReleaseInfoDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to <see cref="ReleaseInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The DTO to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="ReleaseInfo"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<ReleaseInfo> ToDomainEntity(this ReleaseInfoDto dto)
|
||||
{
|
||||
return ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(dto.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(dto.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(dto.ReReleaseDate),
|
||||
Optional<int>.FromNullable(dto.ReReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(dto.ReleaseCountry),
|
||||
Optional<string>.FromNullable(dto.ReleaseVersion)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public static class TagDtoMapping
|
||||
public static Result<Tag> ToDomainEntity(this TagDto dto)
|
||||
{
|
||||
return Tag.Create(
|
||||
dto.Name
|
||||
dto.Name!
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public static class TagEntityMapping
|
||||
public static Result<Tag> ToDomainEntity(this TagEntity repositoryEntity)
|
||||
{
|
||||
return Tag.Create(
|
||||
repositoryEntity.Name ?? default
|
||||
repositoryEntity.Name!
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -44,14 +44,14 @@ public static class BookMetadataDtoMapping
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Result<Genre>> domainGenresResult = metadata.Genres is not null
|
||||
? [.. metadata.Genres.Select(genre => Genre.Create(genre.Name))]
|
||||
? [.. metadata.Genres.Select(genre => Genre.Create(genre.Name!))]
|
||||
: [];
|
||||
List<Error> genresErrors = [.. domainGenresResult.Where(genreResult => genreResult.IsFailure).SelectMany(genreResult => genreResult.Errors)];
|
||||
if (genresErrors.Count != 0)
|
||||
return genresErrors;
|
||||
|
||||
List<Result<Tag>> domainTagsResult = metadata.Tags is not null
|
||||
? [.. metadata.Tags.Select(tag => Tag.Create(tag.Name))]
|
||||
? [.. metadata.Tags.Select(tag => Tag.Create(tag.Name!))]
|
||||
: [];
|
||||
List<Error> tagsErrors = [.. domainTagsResult.Where(tagResult => tagResult.IsFailure).SelectMany(tagResult => tagResult.Errors)];
|
||||
if (tagsErrors.Count != 0)
|
||||
@@ -87,7 +87,7 @@ public static class BookMetadataDtoMapping
|
||||
return writtenContentMetadataResult.Errors;
|
||||
|
||||
List<Result<Isbn>> domainIsbnsResult = metadata.Isbns is not null
|
||||
? [.. metadata.Isbns.Where(isbn => isbn.Value is not null && isbn.Format is not null).Select(isbn => Isbn.Create(isbn.Value, (IsbnFormat)(int)isbn.Format!.Value))]
|
||||
? [.. metadata.Isbns.Where(isbn => isbn.Value is not null && isbn.Format is not null).Select(isbn => Isbn.Create(isbn.Value!, (IsbnFormat)(int)isbn.Format!.Value))]
|
||||
: [];
|
||||
List<Error> isbnsErrors = [.. domainIsbnsResult.Where(isbnResult => isbnResult.IsFailure).SelectMany(isbnResult => isbnResult.Errors)];
|
||||
if (isbnsErrors.Count != 0)
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ public static class IsbnDtoMapping
|
||||
public static Result<Isbn> ToDomainEntity(this IsbnDto dto)
|
||||
{
|
||||
return Isbn.Create(
|
||||
dto.Value,
|
||||
dto.Value!,
|
||||
dto.Format ?? IsbnFormat.Isbn13
|
||||
);
|
||||
}
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ public static class IsbnEntityMapping
|
||||
public static Result<Isbn> ToDomainEntity(this IsbnEntity repositoryEntity)
|
||||
{
|
||||
return Isbn.Create(
|
||||
repositoryEntity.Value ?? default,
|
||||
repositoryEntity.Value!,
|
||||
repositoryEntity.Format ?? default
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Genre : ValueObject
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Genre> Create(string? name)
|
||||
public static Result<Genre> Create(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.Errors.Metadata.GenreNameCannotBeEmpty;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Mood : ValueObject
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Mood"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Mood> Create(string? name)
|
||||
public static Result<Mood> Create(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.Errors.Metadata.MoodNameCannotBeEmpty;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Tag : ValueObject
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Tag> Create(string? name)
|
||||
public static Result<Tag> Create(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.Errors.Metadata.TagNameCannotBeEmpty;
|
||||
|
||||
Reference in new issue
Block a user