feat(core): DELETE entity endpoint#59
Open
RVANDO12 wants to merge 13 commits into
Open
Conversation
335308c to
c45d3c5
Compare
d94a090 to
f065994
Compare
feat(core): add DELETE endpoint - rebase feat(core): add fully delete and cleanup action
973a251 to
d0cb5aa
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new DELETE /api/v1/entities/{templateIdentifier}/{entityIdentifier} endpoint to remove an entity, and introduces relation-cleanup logic intended to remove incoming references from other entities. It also updates OpenAPI/docs and adds both integration and unit tests around the deletion workflow.
Changes:
- Add a DELETE endpoint in
EntityControllerwith Swagger metadata and documentation updates. - Implement domain-level deletion orchestration in
EntityService, including cleanup of parent-entity relations referencing the deleted entity. - Extend the persistence port/adapter and repository with new methods (
findEntitiesRelated,deleteByTemplateIdentifierAndIdentifier) and add tests for the new behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/EntityControllerTest.java | Adds integration tests for DELETE endpoint behavior (status codes, relation cleanup, auth/CSRF). |
| src/test/java/com/decathlon/idp_core/domain/service/entity/EntityServiceTest.java | Adds unit tests validating relation-cleanup behavior during deletion. |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/repository/JpaEntityRepository.java | Adds JPA query to find entities referencing a target identifier and a delete method by template+identifier. |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/PostgresEntityAdapter.java | Implements new persistence port methods by delegating to the JPA repository. |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/EntityController.java | Adds @DeleteMapping endpoint and OpenAPI responses for entity deletion. |
| src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/configuration/SwaggerDescription.java | Adds Swagger description constants for the DELETE endpoint. |
| src/main/java/com/decathlon/idp_core/domain/service/entity/EntityService.java | Adds deleteEntity(...) and relation-cleanup logic prior to repository deletion. |
| src/main/java/com/decathlon/idp_core/domain/port/EntityRepositoryPort.java | Extends the domain persistence port for relation lookup + deletion by template+identifier. |
| docs/src/static/swagger.yaml | Documents the new DELETE operation in the static OpenAPI spec. |
| docs/src/concepts/entities.md | Documents how to delete an entity and describes cascade cleanup behavior. |
evebrnd
requested changes
Jun 3, 2026
|
evebrnd
reviewed
Jun 4, 2026
evebrnd
reviewed
Jun 4, 2026
evebrnd
approved these changes
Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



PR Description
https://decathlon.atlassian.net/browse/CPDE-2935
DELETE/api/v1/entities/{templateIdentifier}/{entityIdentifier}@WithMockUser) and a valid CSRF token.204 No Content: Successful deletion or relation cleanup completed.401 Unauthorized: Missing or invalid authentication token.403 Forbidden: Missing CSRF token or insufficient rights.404 Not Found: Entity or template does not exist.500 Internal Server Error: Unexpected server failure (e.g., blank path parameters).What this PR Provides
. Rule 1 (Optional relationship): If the parent entity points to the deleted entity, and this relationship required: false in its Template, the relationship is simply removed from the parent entity in the database.
. Rule 2 (Mandatory relationship): If the parent entity points to the deleted entity, and the relationship required: true, and it was the only target entity (to_many cardinality: false or array became empty), the deletion prime on relation and the relations was updated after deletion of entity.
Review
The reviewer must double-check these points:
How to Test
2. Test Setup & Prerequisites
To thoroughly validate the deletion workflow and its side effects (cascading relation cleanups), you must establish a multi-entity relational lifecycle model.
Step 1: Ensure an Entity Template Exists
An entity cannot exist without a valid parent schema template.
EntityTemplate(e.g.,web-service) that defines the necessary schema properties and relation definitions.Step 2: Create the Target Entity (The Entity to Delete)
This entity will be the target of the
DELETErequest.POST /api/v1/entities/web-servicerequest.{ "name": "Relation Target Entity", "identifier": "relation-target-entity", "properties": { "applicationName": "catalog-api", "ownerEmail": "owner@example.com", "port": "8080", "environment": "DEV", "version": "1.2.3", "teamName": "platform-team", "baseUrl": "[https://catalog.example.com](https://catalog.example.com)", "protocol": "HTTP", "programmingLanguage": "JAVA" } }201 Created.Step 3: Create the Source Entity with a Multi-Relation Link
To test the cascading relational cleanup, a second entity must be created that declares a dependency or relation pointing to the target entity created in Step 2.
POST /api/v1/entities/web-servicerequest.{ "name": "Relation Source Entity", "identifier": "relation-source-entity", "properties": { "applicationName": "source-api", "ownerEmail": "source@example.com", "port": "9090" }, "relations": [ { "name": "database", "target_entity_identifiers": ["relation-target-entity"] } ] }201 Created.3. Test Execution Workflow
Once the environment state is prepared, execute the deletion process sequentially.
Step 4: Execute the DELETE Request
Perform the destructive action on the target entity identifier while supplying appropriate mock authentication and CSRF protection headers.
DELETE /api/v1/entities/web-service/relation-target-entity4. Verification & Assertions
A successful test must guarantee data consistency across three distinct structural checks:
Step 5: Assert Deletion Success
204 No Content.Step 6: Verify Target Non-Existence (Read-After-Delete)
GET /api/v1/entities/web-service/relation-target-entity.404 Not Foundstatus code, ensuring that the record has been fully removed from active storage.Step 7: Verify Relationship Cleanup on the Source Entity
This is the critical functional boundary validation. The source entity itself must not be deleted, but its internal metadata array mapping the relation to the target entity must be automatically scrubbed.
GET /api/v1/entities/web-service/relation-source-entity.200 OK(the source entity still safely exists).relationsblock must not contain the string"identifier":"relation-target-entity". The database layer must cleanly un-link the reference.Breaking changes
N/A