- Implemented tests for RouterConfig, RoutingOptions, StaticInstanceConfig, and RouterConfigOptions to ensure default values are set correctly. - Added tests for RouterConfigProvider to validate configurations and ensure defaults are returned when no file is specified. - Created tests for ConfigValidationResult to check success and error scenarios. - Developed tests for ServiceCollectionExtensions to verify service registration for RouterConfig. - Introduced UdpTransportTests to validate serialization, connection, request-response, and error handling in UDP transport. - Added scripts for signing authority gaps and hashing DevPortal SDK snippets.
65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using StellaOps.Microservice;
|
|
|
|
namespace Examples.Inventory.Microservice.Endpoints;
|
|
|
|
/// <summary>
|
|
/// Request model for getting a single inventory item.
|
|
/// </summary>
|
|
public sealed record GetItemRequest
|
|
{
|
|
public required string Sku { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Response model for a single inventory item with details.
|
|
/// </summary>
|
|
public sealed record GetItemResponse
|
|
{
|
|
public required string Sku { get; init; }
|
|
public required string Name { get; init; }
|
|
public required string Description { get; init; }
|
|
public required string Category { get; init; }
|
|
public required int QuantityOnHand { get; init; }
|
|
public required int ReorderPoint { get; init; }
|
|
public required decimal UnitPrice { get; init; }
|
|
public required string Location { get; init; }
|
|
public required DateTime LastUpdated { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Endpoint for getting a single inventory item by SKU.
|
|
/// Demonstrates path parameter extraction.
|
|
/// </summary>
|
|
[StellaEndpoint("GET", "/items/{sku}", TimeoutSeconds = 10)]
|
|
public sealed class GetItemEndpoint : IStellaEndpoint<GetItemRequest, GetItemResponse>
|
|
{
|
|
private readonly ILogger<GetItemEndpoint> _logger;
|
|
|
|
public GetItemEndpoint(ILogger<GetItemEndpoint> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public Task<GetItemResponse> HandleAsync(
|
|
GetItemRequest request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
_logger.LogInformation("Fetching inventory item {Sku}", request.Sku);
|
|
|
|
// Simulate item lookup
|
|
return Task.FromResult(new GetItemResponse
|
|
{
|
|
Sku = request.Sku,
|
|
Name = "Widget A",
|
|
Description = "A high-quality widget for general purpose use",
|
|
Category = "widgets",
|
|
QuantityOnHand = 100,
|
|
ReorderPoint = 25,
|
|
UnitPrice = 9.99m,
|
|
Location = "Warehouse A, Aisle 3, Shelf 2",
|
|
LastUpdated = DateTime.UtcNow.AddHours(-2)
|
|
});
|
|
}
|
|
}
|