Domain модели

This commit is contained in:
2026-05-31 22:41:59 +03:00
parent daeae92a75
commit e691f14e5d
6 changed files with 106 additions and 9 deletions

25
.vscode/launch.json vendored
View File

@@ -21,6 +21,31 @@
"name": ".NET Core Attach", "name": ".NET Core Attach",
"type": "coreclr", "type": "coreclr",
"request": "attach" "request": "attach"
},
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md.
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/ApiServer/bin/Debug/net10.0/ApiServer.dll",
"args": [],
"cwd": "${workspaceFolder}/src/ApiServer",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
} }
] ]
} }

6
.vscode/tasks.json vendored
View File

@@ -7,7 +7,7 @@
"type": "process", "type": "process",
"args": [ "args": [
"build", "build",
"${workspaceFolder}/src/Console/Console.csproj", "${workspaceFolder}/src/ApiServer/ApiServer.csproj",
"/property:GenerateFullPaths=true", "/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign" "/consoleloggerparameters:NoSummary;ForceNoAlign"
], ],
@@ -19,7 +19,7 @@
"type": "process", "type": "process",
"args": [ "args": [
"publish", "publish",
"${workspaceFolder}/src/Console/Console.csproj", "${workspaceFolder}/src/ApiServer/ApiServer.csproj",
"/property:GenerateFullPaths=true", "/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign" "/consoleloggerparameters:NoSummary;ForceNoAlign"
], ],
@@ -33,7 +33,7 @@
"watch", "watch",
"run", "run",
"--project", "--project",
"${workspaceFolder}/src/Console/Console.csproj" "${workspaceFolder}/src/ApiServer/ApiServer.csproj"
], ],
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
} }

View File

@@ -1,6 +0,0 @@
namespace Domain;
public class Class1
{
}

View File

@@ -0,0 +1,24 @@
namespace Domain.Entities;
/// <summary>
/// Блюдо из меню (GetMenu / MenuItem).
/// </summary>
public sealed class Dish
{
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; } = [];
}

View File

@@ -0,0 +1,37 @@
namespace Domain.Entities;
/// <summary>
/// Заказ (SendOrder).
/// </summary>
public sealed class Order
{
private readonly List<OrderItem> _items = [];
public Guid Id { get; }
public IReadOnlyCollection<OrderItem> Items => _items;
public Order(Guid? id = null)
{
Id = id ?? Guid.NewGuid();
}
public void AddItem(string menuItemId, decimal quantity)
{
ArgumentException.ThrowIfNullOrWhiteSpace(menuItemId);
if (quantity <= 0)
{
throw new ArgumentOutOfRangeException(
nameof(quantity),
quantity,
"Количество должно быть больше нуля.");
}
_items.Add(new OrderItem
{
MenuItemId = menuItemId,
Quantity = quantity,
});
}
}

View File

@@ -0,0 +1,17 @@
namespace Domain.Entities;
/// <summary>
/// Позиция заказа (SendOrder / MenuItems).
/// </summary>
public sealed class OrderItem
{
/// <summary>
/// Идентификатор блюда на сервере (<see cref="Dish.Id"/>).
/// </summary>
public required string MenuItemId { get; init; }
/// <summary>
/// Количество. Для весовых блюд допускаются дробные значения.
/// </summary>
public decimal Quantity { get; init; }
}