Init
This commit is contained in:
12
Prefab.Web.Client/Models/Shared/MoneyModel.cs
Normal file
12
Prefab.Web.Client/Models/Shared/MoneyModel.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Prefab.Web.Client.Models.Shared;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a monetary amount with its associated currency.
|
||||
/// </summary>
|
||||
public sealed class MoneyModel
|
||||
{
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
public string Currency { get; set; } = "USD";
|
||||
}
|
||||
|
||||
28
Prefab.Web.Client/Models/Shared/NavMenuModel.cs
Normal file
28
Prefab.Web.Client/Models/Shared/NavMenuModel.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace Prefab.Web.Client.Models.Shared;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the navigation menu payload exposed by the gateway.
|
||||
/// </summary>
|
||||
/// <param name="Depth">Requested depth used when building the menu.</param>
|
||||
/// <param name="MaxItemsPerColumn">Maximum number of child links per column.</param>
|
||||
/// <param name="Columns">Menu columns sourced from root categories.</param>
|
||||
public sealed record NavMenuModel(int Depth, int MaxItemsPerColumn, IReadOnlyList<NavMenuColumnModel> Columns);
|
||||
|
||||
/// <summary>
|
||||
/// Represents an individual column in the navigation menu.
|
||||
/// </summary>
|
||||
/// <param name="Root">The root category anchoring the column.</param>
|
||||
/// <param name="Items">Featured child categories.</param>
|
||||
/// <param name="HasMore">Whether additional children exist beyond the truncated list.</param>
|
||||
/// <param name="SeeAllUrl">Link to view the full set of categories for the root.</param>
|
||||
public sealed record NavMenuColumnModel(NavMenuLinkModel Root, IReadOnlyList<NavMenuLinkModel> Items, bool HasMore, string SeeAllUrl);
|
||||
|
||||
/// <summary>
|
||||
/// Represents a navigable link within the menu.
|
||||
/// </summary>
|
||||
/// <param name="Id">Identifier of the item.</param>
|
||||
/// <param name="Name">Display name.</param>
|
||||
/// <param name="Slug">Slug used for routing.</param>
|
||||
/// <param name="IsLeaf">True when the link represents a terminal category.</param>
|
||||
/// <param name="Url">Absolute or relative navigation target.</param>
|
||||
public sealed record NavMenuLinkModel(string Id, string Name, string Slug, bool IsLeaf, string Url);
|
||||
71
Prefab.Web.Client/Models/Shared/Result.cs
Normal file
71
Prefab.Web.Client/Models/Shared/Result.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
namespace Prefab.Web.Client.Models.Shared;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using FluentValidation;
|
||||
|
||||
public sealed class ResultProblem
|
||||
{
|
||||
public string? Title { get; init; }
|
||||
|
||||
public string? Detail { get; init; }
|
||||
|
||||
public int? StatusCode { get; init; }
|
||||
|
||||
public IReadOnlyDictionary<string, string[]>? Errors { get; init; }
|
||||
|
||||
public static ResultProblem FromValidation(ValidationException exception)
|
||||
{
|
||||
var errors = exception.Errors
|
||||
.GroupBy(error => string.IsNullOrWhiteSpace(error.PropertyName) ? string.Empty : error.PropertyName)
|
||||
.ToDictionary(
|
||||
group => group.Key,
|
||||
group => group.Select(error => error.ErrorMessage ?? string.Empty).ToArray());
|
||||
|
||||
return new ResultProblem
|
||||
{
|
||||
Title = "Validation failed.",
|
||||
Detail = "Request did not satisfy validation rules.",
|
||||
StatusCode = (int)HttpStatusCode.BadRequest,
|
||||
Errors = errors
|
||||
};
|
||||
}
|
||||
|
||||
public static ResultProblem Unexpected(string title, Exception exception, HttpStatusCode statusCode = HttpStatusCode.InternalServerError) =>
|
||||
new()
|
||||
{
|
||||
Title = title,
|
||||
Detail = exception.Message,
|
||||
StatusCode = (int)statusCode
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the outcome of an operation that produces a value of type <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The payload type returned when the operation succeeds.</typeparam>
|
||||
public sealed class Result<T>
|
||||
{
|
||||
public Result()
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsSuccess => Problem is null;
|
||||
|
||||
public ResultProblem? Problem { get; init; }
|
||||
|
||||
public int? StatusCode => Problem?.StatusCode;
|
||||
|
||||
public T? Value { get; init; }
|
||||
|
||||
public static Result<T> Success(T value) => new()
|
||||
{
|
||||
Value = value ?? throw new ArgumentNullException(nameof(value))
|
||||
};
|
||||
|
||||
public static Result<T> Failure(ResultProblem problem) => new()
|
||||
{
|
||||
Problem = problem ?? throw new ArgumentNullException(nameof(problem))
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user