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