форматирование моделей
This commit is contained in:
@@ -1,24 +1,28 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Domain.Entities;
|
namespace Domain.Entities;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Блюдо из меню (GetMenu / MenuItem).
|
/// Блюдо из меню (GetMenu / MenuItem).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Dish
|
public sealed record Dish(
|
||||||
|
string Id,
|
||||||
|
string Article,
|
||||||
|
string Name,
|
||||||
|
decimal Price,
|
||||||
|
bool IsWeighted,
|
||||||
|
string FullPath,
|
||||||
|
IReadOnlyList<string> Barcodes)
|
||||||
{
|
{
|
||||||
public required string Id { get; init; }
|
private bool PrintMembers(StringBuilder builder)
|
||||||
|
{
|
||||||
/// <summary>
|
builder.Append($"Id = {Id}, ");
|
||||||
/// Артикул блюда. Используется при вводе заказа с клавиатуры.
|
builder.Append($"Article = {Article}, ");
|
||||||
/// </summary>
|
builder.Append($"Name = {Name}, ");
|
||||||
public required string Article { get; init; }
|
builder.Append($"Price = {Price}, ");
|
||||||
|
builder.Append($"IsWeighted = {IsWeighted}, ");
|
||||||
public required string Name { get; init; }
|
builder.Append($"FullPath = {FullPath}, ");
|
||||||
|
builder.Append($"Barcodes = [{string.Join(", ", Barcodes)}]");
|
||||||
public decimal Price { get; init; }
|
return true;
|
||||||
|
}
|
||||||
public bool IsWeighted { get; init; }
|
|
||||||
|
|
||||||
public required string FullPath { get; init; }
|
|
||||||
|
|
||||||
public IReadOnlyList<string> Barcodes { get; init; } = [];
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,18 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Domain.Entities;
|
namespace Domain.Entities;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Заказ (SendOrder).
|
/// Заказ (SendOrder).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Order
|
public sealed record Order(Guid Id, IReadOnlyList<OrderItem> Items)
|
||||||
{
|
{
|
||||||
private readonly List<OrderItem> _items = [];
|
public Order()
|
||||||
|
: this(Guid.NewGuid(), [])
|
||||||
public Guid Id { get; }
|
|
||||||
|
|
||||||
public IReadOnlyCollection<OrderItem> Items => _items;
|
|
||||||
|
|
||||||
public Order(Guid? id = null)
|
|
||||||
{
|
{
|
||||||
Id = id ?? Guid.NewGuid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddItem(string id, decimal quantity)
|
public Order AddItem(string id, decimal quantity)
|
||||||
{
|
{
|
||||||
ArgumentException.ThrowIfNullOrWhiteSpace(id);
|
ArgumentException.ThrowIfNullOrWhiteSpace(id);
|
||||||
|
|
||||||
@@ -28,10 +24,15 @@ public sealed class Order
|
|||||||
"Количество должно быть больше нуля.");
|
"Количество должно быть больше нуля.");
|
||||||
}
|
}
|
||||||
|
|
||||||
_items.Add(new OrderItem
|
var items = Items.ToList();
|
||||||
{
|
items.Add(new OrderItem(id, quantity));
|
||||||
Id = id,
|
return this with { Items = items };
|
||||||
Quantity = quantity,
|
}
|
||||||
});
|
|
||||||
|
private bool PrintMembers(StringBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Append($"Id = {Id}, ");
|
||||||
|
builder.Append($"Items = [{string.Join(", ", Items)}]");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,4 @@ namespace Domain.Entities;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Позиция заказа (SendOrder / MenuItems).
|
/// Позиция заказа (SendOrder / MenuItems).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class OrderItem
|
public sealed record OrderItem(string Id, decimal Quantity);
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Идентификатор блюда на сервере (<see cref="Dish.Id"/>).
|
|
||||||
/// </summary>
|
|
||||||
public required string Id { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Количество. Для весовых блюд допускаются дробные значения.
|
|
||||||
/// </summary>
|
|
||||||
public decimal Quantity { get; init; }
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user