diff --git a/.github/workflows/publish-package-pipeline.yml b/.github/workflows/publish-package-pipeline.yml index 1581233..9185b1a 100644 --- a/.github/workflows/publish-package-pipeline.yml +++ b/.github/workflows/publish-package-pipeline.yml @@ -7,6 +7,12 @@ on: - development paths: - 'Artifacts/Comanda.Internal.Contracts/**' + pull_request: + branches: + - master + - development + paths: + - 'Artifacts/Comanda.Internal.Contracts/**' jobs: publish: @@ -38,11 +44,8 @@ jobs: if [[ "${GITHUB_REF}" == "refs/heads/master" ]]; then VERSION="${BASE_VERSION}.${GITHUB_RUN_NUMBER}" - elif [[ "${GITHUB_REF}" == "refs/heads/development" ]]; then - VERSION="${BASE_VERSION}-beta.${GITHUB_RUN_NUMBER}" else - echo "branch not configured for publication" - exit 1 + VERSION="${BASE_VERSION}-beta.${GITHUB_RUN_NUMBER}" fi echo "use version: $VERSION" @@ -51,4 +54,4 @@ jobs: echo "package_version=$VERSION" >> $GITHUB_OUTPUT - name: push package to nuget - run: dotnet nuget push ./output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate + run: dotnet nuget push ./output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate \ No newline at end of file diff --git a/Artifacts/Comanda.Internal.Contracts/Source/Clients/OrderClient.cs b/Artifacts/Comanda.Internal.Contracts/Source/Clients/OrderClient.cs index 293d173..173a11d 100644 --- a/Artifacts/Comanda.Internal.Contracts/Source/Clients/OrderClient.cs +++ b/Artifacts/Comanda.Internal.Contracts/Source/Clients/OrderClient.cs @@ -8,8 +8,7 @@ public sealed class OrderClient(HttpClient httpClient) : IOrderClient PropertyNameCaseInsensitive = true }; - public async Task>> GetOrdersAsync( - OrdersFetchParameters parameters, CancellationToken cancellation = default) + public async Task>> GetOrdersAsync(OrdersFetchParameters parameters, CancellationToken cancellation = default) { var queryString = QueryParametersParser.ToQueryString(parameters); @@ -62,8 +61,7 @@ public async Task>> GetOrdersAsync( return Result>.Success(result); } - public async Task> CreateOrderAsync( - OrderCreationScheme parameters, CancellationToken cancellation = default) + public async Task> CreateOrderAsync(OrderCreationScheme parameters, CancellationToken cancellation = default) { var response = await httpClient.PostAsJsonAsync("orders", parameters, cancellation); var content = await response.Content.ReadAsStringAsync(cancellation); diff --git a/Artifacts/Comanda.Internal.Contracts/Source/Transport/Internal/Orders/OrderCreationScheme.cs b/Artifacts/Comanda.Internal.Contracts/Source/Transport/Internal/Orders/OrderCreationScheme.cs index cde8d44..891e025 100644 --- a/Artifacts/Comanda.Internal.Contracts/Source/Transport/Internal/Orders/OrderCreationScheme.cs +++ b/Artifacts/Comanda.Internal.Contracts/Source/Transport/Internal/Orders/OrderCreationScheme.cs @@ -4,6 +4,7 @@ public sealed record OrderCreationScheme : IDispatchable> { public Fulfillment Fulfillment { get; init; } public Priority Priority { get; init; } + public Address? Address { get; init; } = default!; public Metadata Metadata { get; init; } = default!; public IEnumerable Items { get; init; } = []; } diff --git a/Artifacts/Comanda.Internal.Contracts/Source/Transport/Internal/Orders/OrderScheme.cs b/Artifacts/Comanda.Internal.Contracts/Source/Transport/Internal/Orders/OrderScheme.cs index f26592b..a9e62ab 100644 --- a/Artifacts/Comanda.Internal.Contracts/Source/Transport/Internal/Orders/OrderScheme.cs +++ b/Artifacts/Comanda.Internal.Contracts/Source/Transport/Internal/Orders/OrderScheme.cs @@ -5,6 +5,7 @@ public sealed record OrderScheme public string Identifier { get; init; } = default!; public string Code { get; init; } = default!; + public Address? Address { get; init; } = default!; public Status Status { get; init; } public Priority Priority { get; init; } public Fulfillment Fulfillment { get; init; } diff --git a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Mappers/OrderMapper.cs b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Mappers/OrderMapper.cs index b1ce359..4a8d814 100644 --- a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Mappers/OrderMapper.cs +++ b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Mappers/OrderMapper.cs @@ -7,6 +7,7 @@ public static Order AsOrder(this OrderCreationScheme scheme, Code code) var order = new Order { Code = code, + Address = scheme.Address, Fulfillment = scheme.Fulfillment, Priority = scheme.Priority, Metadata = scheme.Metadata, @@ -47,6 +48,7 @@ public static Order AsOrder(this OrderCreationScheme scheme, Code code) { Identifier = order.Id, Code = order.Code.Identifier, + Address = order.Address, Priority = order.Priority, Status = order.Status, Fulfillment = order.Fulfillment, diff --git a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Payloads/Order/OrderCreationScheme.cs b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Payloads/Order/OrderCreationScheme.cs index 19f68ed..ffd1729 100644 --- a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Payloads/Order/OrderCreationScheme.cs +++ b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Payloads/Order/OrderCreationScheme.cs @@ -4,6 +4,7 @@ public sealed record OrderCreationScheme : IDispatchable> { public Fulfillment Fulfillment { get; init; } public Priority Priority { get; init; } + public Address? Address { get; init; } = default!; public Metadata Metadata { get; init; } = default!; public IEnumerable Items { get; init; } = []; } diff --git a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Payloads/Order/OrderScheme.cs b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Payloads/Order/OrderScheme.cs index 2d1faad..f899343 100644 --- a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Payloads/Order/OrderScheme.cs +++ b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Payloads/Order/OrderScheme.cs @@ -5,6 +5,7 @@ public sealed record OrderScheme public string Identifier { get; init; } = default!; public string Code { get; init; } = default!; + public Address? Address { get; init; } = default!; public Status Status { get; init; } public Priority Priority { get; init; } public Fulfillment Fulfillment { get; init; } diff --git a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Usings.cs b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Usings.cs index 43601d3..d25a2e0 100644 --- a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Usings.cs +++ b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Usings.cs @@ -11,6 +11,7 @@ global using Comanda.Orders.Application.Payloads.Order; global using Comanda.Orders.Application.Mappers; +global using HttpsRichardy.Internal.Essentials.Utilities; global using HttpsRichardy.Internal.Essentials.Patterns; global using HttpsRichardy.Internal.Essentials.Filtering; global using HttpsRichardy.Internal.Essentials.Concepts; diff --git a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Validators/OrderCreationSchemeValidator.cs b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Validators/OrderCreationSchemeValidator.cs index 9c30fcc..51acb31 100644 --- a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Validators/OrderCreationSchemeValidator.cs +++ b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Application/Validators/OrderCreationSchemeValidator.cs @@ -12,6 +12,11 @@ public OrderCreationSchemeValidator() .IsInEnum() .WithMessage("fulfillment must be a valid enum value."); + RuleFor(order => order.Address) + .NotNull() + .WithMessage("address must be provided when fulfillment is delivery.") + .When(order => order.Fulfillment == Fulfillment.Delivery); + RuleFor(order => order.Priority) .IsInEnum() .WithMessage("priority must be a valid enum value."); @@ -20,6 +25,31 @@ public OrderCreationSchemeValidator() .NotNull() .WithMessage("metadata must be provided."); + When(order => order.Fulfillment == Fulfillment.Delivery && order.Address is not null, () => + { + RuleFor(order => order.Address!.Street) + .NotEmpty() + .WithMessage("The street field is required and cannot be empty."); + + RuleFor(order => order.Address!.Number) + .NotEmpty() + .WithMessage("The number field is required and represents the street number of the address."); + + RuleFor(order => order.Address!.City) + .NotEmpty() + .WithMessage("The city field is required and cannot be empty."); + + RuleFor(order => order.Address!.State) + .NotEmpty() + .WithMessage("The state field is required and cannot be empty."); + + RuleFor(order => order.Address!.ZipCode) + .NotEmpty() + .WithMessage("The zip code field is required.") + .Matches(ExpressionPatterns.Cep) + .WithMessage("The zip code is invalid. It must match the Brazilian postal code format."); + }); + When(order => order.Metadata is not null, () => { RuleFor(order => order.Metadata!.MerchantId) diff --git a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Domain/Entities/Order.cs b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Domain/Aggregates/Order.cs similarity index 90% rename from Boundaries/Comanda.Orders/Source/Comanda.Orders.Domain/Entities/Order.cs rename to Boundaries/Comanda.Orders/Source/Comanda.Orders.Domain/Aggregates/Order.cs index e3960de..98225e4 100644 --- a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Domain/Entities/Order.cs +++ b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Domain/Aggregates/Order.cs @@ -4,6 +4,8 @@ public sealed class Order : Aggregate { public Code Code { get; set; } = default!; public Metadata Metadata { get; set; } = default!; + public Address? Address { get; set; } = default!; + public Status Status { get; set; } = Status.Pending; public Priority Priority { get; set; } = Priority.Normal; public Fulfillment Fulfillment { get; set; } = Fulfillment.Unspecified; diff --git a/Boundaries/Comanda.Orders/Source/Comanda.Orders.Domain/Concepts/Address.cs b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Domain/Concepts/Address.cs new file mode 100644 index 0000000..255454c --- /dev/null +++ b/Boundaries/Comanda.Orders/Source/Comanda.Orders.Domain/Concepts/Address.cs @@ -0,0 +1,15 @@ +namespace Comanda.Orders.Domain.Concepts; + +public sealed record Address : IValueObject
+{ + public string Street { get; init; } = default!; + public string Number { get; init; } = default!; + public string City { get; init; } = default!; + + public string State { get; init; } = default!; + public string ZipCode { get; init; } = default!; + public string Neighborhood { get; init; } = default!; + + public string? Complement { get; init; } + public string? Reference { get; init; } +}