Skip to content

Refactor and enhance entity mapping, repositories, and value objects#68

Merged
samuelzedec merged 13 commits intomainfrom
develop
Aug 25, 2025
Merged

Refactor and enhance entity mapping, repositories, and value objects#68
samuelzedec merged 13 commits intomainfrom
develop

Conversation

@samuelzedec
Copy link
Owner

  • Added RandomToken, Discount, Money, and Quantity value objects with corresponding validation, utility methods, and unit tests to improve encapsulation and reusability.
  • Introduced Invitation entity and repository with lifecycle operations and unit tests.
  • Improved modularity of the Company entity with new interfaces (IHasCompanyName, IHasTaxId, etc.).
  • Standardized entity configurations via BaseEntityConfiguration and reusable extension methods.
  • Streamlined repository and UnitOfWork support for Invitation.

…port

- Added `IInvitationRepository` to handle invitation entity persistence and lifecycle operations.
- Updated `IUserRepository` and `ICompanyRepository` with enhanced descriptions for better clarity.
- Extended `IUnitOfWork` to include support for `IInvitationRepository`.
- Updated dependency injection to register `IInvitationRepository`.
- Introduced `BaseEntityConfiguration` to standardize common entity configurations.
- Added extension methods for configuring reusable properties (e.g., TaxId, Email, Phone, FullName, CompanyName).
- Refactored `UserMap`, `InvitationMap`, and `CompanyMap` to inherit from `BaseEntityConfiguration` and utilize the extension methods.
- Enhanced maintainability and reduced code duplication across entity mappings.
…stants

- Introduced error messages for `Discount` (e.g., invalid percentage or fixed amount, greater than subtotal).
- Added `Money` error messages for handling negative values and invalid operations (summing or subtracting different currencies).
- Included a new error message for quantity validation.

WIP
…lidation

- Added `Money` value object to encapsulate monetary values and their operations.
- Supported operations include addition, subtraction, and multiplication with validation for currency consistency and negative values.
- Implemented exception handling for invalid operations (`InvalidMoneyException`, `InvalidSumException`, `InvalidSubtractionException`).
- Created comprehensive unit tests for `Money` ensuring behavior correctness.
- Added `IHasUnitPrice` interface for entities with unit price.
…ation

- Introduced `Quantity` value object to encapsulate quantities and related operations.
- Supported operations include addition, subtraction, and multiplication with validation against zero and negative values.
- Added factory methods for predefined quantities (`One`, `Zero`).
- Implemented `InvalidQuantityException` for handling invalid operations.
- Created `IHasQuantity` interface for objects requiring associated quantities.
- Added comprehensive unit tests to validate `Quantity` behavior and error scenarios.
- Introduced `Discount` value object to encapsulate percentage or fixed amount discounts with optional reasons.
- Added validation for invalid percentages and fixed amounts.
- Implemented `CalculateDiscount`, `HasDiscount`, `IsPercentage`, and `IsFixedAmount` utility methods.
- Created exceptions for invalid operations (`InvalidPercentageException`, `InvalidFixedAmountException`).
- Added `IHasDiscount` interface for entities requiring associated discounts.
- Developed comprehensive unit tests to ensure correctness of `Discount` operations and edge cases.
…port

- Implemented `IHasCompanyName`, `IHasTaxId`, `IHasEmail`, and `IHasPhone` interfaces in `Company` entity.
- Enhanced modularity and reusability of `Company` properties.
- Introduced `Invitation` entity with properties, methods, and `IHasEmail` and `IAggregateRoot` interfaces.
- Added `IInvitationRepository` and `InvitationRepository` for invitation persistence and lifecycle operations.
- Developed comprehensive unit tests for `Invitation` entity covering creation, permissions, status changes, and edge cases.
…oken` interface

- Introduced `RandomToken` value object to generate cryptographically secure, Base64-encoded random tokens.
- Implemented factory method `Create` for token creation.
- Added `IHasRandomToken` interface for entities requiring associated tokens.
- Developed comprehensive unit tests to validate token uniqueness, security, and behavior.
…iscount`, `UnitPrice`, and `Quantity`

- Introduced new extension methods to standardize configuration for `RandomToken`, `Discount`, `UnitPrice`, and `Quantity`.
- Enhanced consistency and reusability across entity mappings.

wip
- Migrated `Invitation` entity to use the new `RandomToken` value object for improved encapsulation and reusability.
- Updated `InvitationMap` to leverage standardized `ConfigureRandomToken` method for token configuration.
- Refactored unit tests to accommodate changes and verify `RandomToken` behavior.
- Removed legacy `GeneratePublicCode` method and associated properties.
- Added migrations for `Product`, `ProductCategory`, `Order`, and `OrderItem` entities.
- Introduced relationships, indexes, and constraints to support the product catalog and order management.
- Removed obsolete `CompanyIsNullException` as it is no longer required.
- Eliminated the `ToString` method from `Money` due to lack of usage and redundancy.
- Removed `ToString_WhenCalledWithFormat_ShouldReturnFormattedValue` test case in alignment with the method removal.
- Adjusted unit tests to reflect changes in `Money.Create` parameters.
@samuelzedec samuelzedec merged commit cd561cb into main Aug 25, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant