mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 17:11:10 +00:00
Adds the capability of adding a Book via API
This commit is contained in:
1 parent
6459b6f2c2
commit
0eb7b453f6
61 files changed
+1276
-255
No files matched your search
@@ -1,27 +0,0 @@
|
||||
namespace Lumina.Domain.Common.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the various roles of media contributors across different types of media.
|
||||
/// </summary>
|
||||
public enum MediaContributorRole
|
||||
{
|
||||
/// <summary>
|
||||
/// A person who portrays a character in a performance, typically in films, television shows, or theater productions.
|
||||
/// </summary>
|
||||
Actor,
|
||||
|
||||
/// <summary>
|
||||
/// The person responsible for overseeing and directing the production of a film, play, television show, or other performing art.
|
||||
/// </summary>
|
||||
Director,
|
||||
|
||||
/// <summary>
|
||||
/// A person who uses their voice to produce musical sounds, typically with a melody and often with lyrics in songs.
|
||||
/// </summary>
|
||||
Singer,
|
||||
|
||||
/// <summary>
|
||||
/// The creator or originator of a written work, such as a book, article, or other literary piece.
|
||||
/// </summary>
|
||||
Author
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public readonly struct Optional<T>
|
||||
{
|
||||
get
|
||||
{
|
||||
return HasValue ? _value! : throw new InvalidOperationException("Optional has no value.");
|
||||
return HasValue ? _value! : default!;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -34,10 +34,11 @@ public readonly struct Optional<T>
|
||||
/// Initializes a new instance of the <see cref="Optional{T}"/> structure.
|
||||
/// </summary>
|
||||
/// <param name="value">The value represented by this structure.</param>
|
||||
public Optional(T value)
|
||||
/// <param name="hasValue"><see langword="true"/> if <paramref name="value"/> is not <see langword="null"/>, <see langword="false"/>otherwise.</param>
|
||||
private Optional(T? value, bool hasValue)
|
||||
{
|
||||
_value = value;
|
||||
HasValue = true;
|
||||
HasValue = hasValue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -48,7 +49,47 @@ public readonly struct Optional<T>
|
||||
/// <param name="value">The value to be converted.</param>
|
||||
public static implicit operator Optional<T>(T value)
|
||||
{
|
||||
return new Optional<T>(value);
|
||||
return Some(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="Optional{T}"/> with a value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap in the <see cref="Optional{T}"/>.</param>
|
||||
/// <returns>An <see cref="Optional{T}"/> containing the specified value.</returns>
|
||||
public static Optional<T> Some(T value)
|
||||
{
|
||||
return new Optional<T>(value, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="Optional{T}"/> with no value.
|
||||
/// </summary>
|
||||
/// <returns>An empty <see cref="Optional{T}"/>.</returns>
|
||||
public static Optional<T> None()
|
||||
{
|
||||
return new(default, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="Optional{T}"/> from a nullable reference type.
|
||||
/// </summary>
|
||||
/// <param name="value">The nullable value to convert.</param>
|
||||
/// <returns>An <see cref="Optional{T}"/> representing the nullable value.</returns>
|
||||
public static Optional<T> FromNullable(T? value)
|
||||
{
|
||||
return value is null ? None() : Some(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="Optional{T}"/> from a nullable value type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TValue">The underlying value type.</typeparam>
|
||||
/// <param name="value">The nullable value to convert.</param>
|
||||
/// <returns>An <see cref="Optional{T}"/> representing the nullable value.</returns>
|
||||
public static Optional<T> FromNullable<TValue>(TValue? value) where TValue : struct, T
|
||||
{
|
||||
return value.HasValue ? Some(value.Value) : None();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user