Skip to content

VSN-2044 : Adding corrected version of Circuit update feature.

yassine.elazami a demandé de fusionner VSN-2044 vers develop

MR Description: Circuit Update Features

Overview

This merge request introduces full support for creating and updating Circuits within the system.
It covers the complete lifecycle of circuit persistence, including request DTOs, service and repository layers, validation logic, external contract retrieval, exception handling, and REST endpoint exposure.

The goal of this MR is to provide a clean, consistent, and validated way to manage circuits while removing legacy constraints (such as incremental IDs) and aligning the implementation with the domain-driven design principles used across the project.


Part 1: Circuit Creation (Save)

1. API Exposure

  • Added a new REST endpoint dedicated to creating a new circuit.
  • The endpoint follows existing REST conventions and integrates smoothly with the prepared services architecture.

2. Request DTO Definition

  • Introduced a Circuit Saving Request DTO to encapsulate all required data for circuit creation.
  • Removed all traces of incremental identifiers, ensuring that circuits are now handled exclusively using domain identifiers (UUIDs / business keys).

3. Service Layer Enhancements

  • Added a new saving method signature for circuit creation.
  • Moved the saving method signature and its implementation to the PreparedService, aligning circuit creation with preparation workflows.
  • Ensured service responsibilities are clearly separated and logically grouped.

4. Mapping Layer

  • Added a dedicated mapping method to transform SaveCircuit DTO → Circuit entity.
  • The mapper ensures:
    • Proper field transformation
    • Clean separation between transport and domain models
    • Future extensibility for additional circuit attributes

5. External Integrations

  • Added an external service call to retrieve contract information by its UUID.
  • Refactored contract fetching logic to rely strictly on identifiers instead of implicit assumptions.
  • Ensured circuit creation is now fully consistent with external contract references.

6. Validation and Exception Handling

  • Added circuit data validation prior to persistence to prevent invalid or incomplete data.
  • Introduced a circuit exception mapping enumeration, linking exception codes to user-readable messages.
  • Validation errors are now handled explicitly and consistently before saving a circuit.

7. Documentation

  • Updated the changelog to reflect all newly introduced circuit creation features.

Part 2: Circuit Update

1. Service Layer

  • Defined a new update method signature in the circuit service.
  • Implemented the update logic with clear separation between validation, retrieval, mapping, and persistence.

2. Mapping Enhancements

  • Added a specific update mapping in the circuit mapper.
  • Ensures only updatable fields are modified while preserving immutable circuit attributes.

3. Repository Layer

  • Added a repository method to fetch a circuit by its code.
  • This enables safe and deterministic circuit updates based on business identifiers.

4. Exception Handling

  • Introduced a new circuit exception dedicated to update-related error cases.
  • Implemented proper exception throwing when:
    • A circuit does not exist
    • An update violates business rules
  • Exception messages are centralized and consistent with the circuit exception mapping strategy.

5. API Exposure

  • Added a new REST endpoint for updating existing circuits.
  • Exposed the update feature through the circuits controller, following established endpoint patterns.

6. Documentation

  • Updated the changelog to document circuit update capabilities and related changes.

Impact & Benefits

  • Circuits can now be created and updated through well-defined, validated, and documented APIs.
  • Removal of incremental IDs improves data integrity and aligns with UUID-based domain modeling.
  • Validation and exception handling are centralized, reducing hidden runtime errors.
  • External contract dependencies are explicitly handled, increasing system robustness.
  • The overall circuit domain is now cleaner, more maintainable, and ready for future extensions.

Testing Notes

  • Circuit creation tested with valid and invalid payloads.
  • Validation rules verified to prevent incorrect data persistence.
  • Update scenarios tested for existing and non-existing circuits.
  • External contract retrieval validated through integration testing.

Notes for Reviewers

  • Please pay special attention to the mapping logic (Save / Update) to ensure no unintended field mutations.
  • Confirm that the exception messages align with functional expectations.
  • This MR intentionally restructures circuit persistence flow to remove legacy constraints and improve clarity.

Closes VSN-2044

Modification effectuée par yassine.elazami

Rapports de requête de fusion