Adds the capability of adding a Book via API

This commit is contained in:
BinaryAlley committed 2024-08-24 22:11:55 +03:00
1 parent 6459b6f2c2
commit 0eb7b453f6
61 files changed
+1276 -255

No files matched your search

@@ -71,8 +71,8 @@ public abstract class BaseMetadata : ValueObject
/// </summary>
/// <param name="title">The title of the element to which this metadata object belongs to.</param>
/// <param name="originalTitle">The optional original title of the element to which this metadata object belongs to.</param>
/// <param name="releaseInfo">The optional release information of the media item.</param>
/// <param name="description">The optional description of the element to which this metadata object belongs to.</param>
/// <param name="releaseInfo">The optional release information of the media item.</param>
/// <param name="genres">The list of genres of the element to which this metadata object belongs to.</param>
/// <param name="tags">The list of tags of the element to which this metadata object belongs to.</param>
/// <param name="language">The optional language of the element to which this metadata object belongs to.</param>
@@ -81,8 +81,8 @@ public abstract class BaseMetadata : ValueObject
protected BaseMetadata(
string title,
Optional<string> originalTitle,
ReleaseInfo releaseInfo,
Optional<string> description,
ReleaseInfo releaseInfo,
List<Genre> genres,
List<Tag> tags,
Optional<LanguageInfo> language,
@@ -90,8 +90,8 @@ public abstract class BaseMetadata : ValueObject
{
Title = title ?? throw new ArgumentNullException(nameof(title));
OriginalTitle = originalTitle;
ReleaseInfo = releaseInfo;
Description = description;
ReleaseInfo = releaseInfo;
_genres = genres;
_tags = tags;
Language = language;
@@ -105,8 +105,8 @@ public abstract class BaseMetadata : ValueObject
{
yield return Title;
yield return OriginalTitle;
yield return ReleaseInfo;
yield return Description;
yield return ReleaseInfo;
foreach (var genre in _genres)
yield return genre;
foreach (var tag in _tags)
@@ -36,7 +36,7 @@ public class Genre : ValueObject
/// </summary>
/// <param name="name">The value of the genre.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Genre"/> or an error message.
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Genre"/>, or an error message.
/// </returns>
public static ErrorOr<Genre> Create(string name)
{
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using System.Diagnostics;
@@ -38,8 +37,6 @@ public class LanguageInfo : ValueObject
/// <param name="languageCode">The ISO 639-1 two-letter language code.</param>
/// <param name="languageName">The full name of the language in English.</param>
/// <param name="nativeName">The optional native name of the language.</param>
/// <exception cref="ArgumentNullException">Thrown if languageCode or languageName is null.</exception>
/// <exception cref="ArgumentException">Thrown if languageCode is not a valid ISO 639-1 code.</exception>
private LanguageInfo(string languageCode, string languageName, Optional<string> nativeName)
{
LanguageCode = languageCode.ToLowerInvariant();
@@ -56,7 +53,7 @@ public class LanguageInfo : ValueObject
/// <param name="languageName">The full name of the language in English.</param>
/// <param name="nativeName">The optional native name of the language.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="LanguageInfo"/> or an error message.
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="LanguageInfo"/>, or an error message.
/// </returns>
public static ErrorOr<LanguageInfo> Create(string languageCode, string languageName, Optional<string> nativeName)
{
@@ -1,6 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using System.Diagnostics;
@@ -12,28 +10,23 @@ namespace Lumina.Domain.Common.ValueObjects.Metadata;
/// Value Object for the rating of a media element.
/// </summary>
[DebuggerDisplay("{Value}/{MaxValue}")]
public class Rating : ValueObject
public abstract class Rating : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the numeric value of the rating.
/// </summary>
public decimal Value { get; }
public decimal Value { get; private set; }
/// <summary>
/// Gets the maximum possible rating value.
/// </summary>
public decimal MaxValue { get; }
/// <summary>
/// Gets the optional source of the rating (e.g., "IMDB", "Rotten Tomatoes").
/// </summary>
public Optional<VideoRatingSource> Source { get; }
public decimal MaxValue { get; private set; }
/// <summary>
/// Gets the optional number of votes or reviews this rating is based on.
/// </summary>
public Optional<int> VoteCount { get; }
public Optional<int> VoteCount { get; private set; }
#endregion
#region ====================================================================== CTOR =====================================================================================
@@ -42,37 +35,16 @@ public class Rating : ValueObject
/// </summary>
/// <param name="value">The numeric value of the rating.</param>
/// <param name="maxValue">The maximum possible rating value.</param>
/// <param name="source">The optional source of the rating.</param>
/// <param name="voteCount">The optional number of votes or reviews.</param>
private Rating(decimal value, decimal maxValue, Optional<VideoRatingSource> source, Optional<int> voteCount)
protected Rating(decimal value, decimal maxValue, Optional<int> voteCount)
{
Value = value;
MaxValue = maxValue;
Source = source;
VoteCount = voteCount;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="Rating"/> class.
/// </summary>
/// <param name="value">The numeric value of the rating.</param>
/// <param name="maxValue">The maximum possible rating value.</param>
/// <param name="source">The optional source of the rating.</param>
/// <param name="voteCount">The optional number of votes or reviews.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Rating"/> or an error message.
/// </returns>
public static ErrorOr<Rating> Create(decimal value, decimal maxValue, Optional<VideoRatingSource> source, Optional<int> voteCount)
{
if (maxValue < 0 || value < 0)
return Errors.Errors.Metadata.RatingMustBePositive;
if (value > maxValue)
return Errors.Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue;
return new Rating(value, maxValue, source, voteCount);
}
/// <summary>
/// Returns the rating as a percentage.
/// </summary>
@@ -81,28 +53,5 @@ public class Rating : ValueObject
{
return (Value / MaxValue) * 100;
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
yield return MaxValue;
yield return Source;
yield return VoteCount;
}
/// <summary>
/// Customized ToString() method.
/// </summary>
/// <returns>Custom string value showing relevant data for current class.</returns>
public override string ToString()
{
string baseString = $"{Value}/{MaxValue}";
if (Source.HasValue)
baseString += $" ({Source.Value})";
if (VoteCount.HasValue)
baseString += $" [{VoteCount.Value} votes]";
return baseString;
}
#endregion
}
@@ -84,7 +84,7 @@ public class ReleaseInfo : ValueObject
/// <param name="releaseCountry">The optional country or region of release.</param>
/// <param name="releaseVersion">The optional release version or edition.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="ReleaseInfo"/> or an error message.
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="ReleaseInfo"/>, or an error message.
/// </returns>
public static ErrorOr<ReleaseInfo> Create(
Optional<DateOnly> originalReleaseDate,
@@ -36,7 +36,7 @@ public class Tag : ValueObject
/// </summary>
/// <param name="name">The value of the tag.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Tag"/> or an error message.
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Tag"/>, or an error message.
/// </returns>
public static ErrorOr<Tag> Create(string name)
{