Skip to content

Commit

Permalink
Fixed delete endpoint for EntityRelations
Browse files Browse the repository at this point in the history
  • Loading branch information
clorenz authored and morpheus-87 committed Dec 6, 2024
1 parent 6ff0b2a commit 82e79c3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import de.digitalcollections.model.list.filtering.Filtering;
import de.digitalcollections.model.list.paging.PageRequest;
import de.digitalcollections.model.list.paging.PageResponse;
import io.github.dbmdz.metadata.server.business.api.service.exceptions.ConflictException;
import io.github.dbmdz.metadata.server.business.api.service.exceptions.ServiceException;
import io.github.dbmdz.metadata.server.business.api.service.identifiable.entity.relation.EntityToEntityRelationService;
import io.github.dbmdz.metadata.server.controller.ParameterHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -107,18 +105,12 @@ List<EntityRelation> saveEntityRelationsForSubject(

@Operation(summary = "Delete an entity relation")
@DeleteMapping(
value =
"/v6/entities/{subjectuuid: "
+ ParameterHelper.UUID_PATTERN
+ "}/{predicate}/{objectuuid: "
+ ParameterHelper.UUID_PATTERN
+ "}",
value = "/v6/entities/relations/{subjectuuid}/{predicate}/{objectuuid}",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Void> deleteByUuid(
public ResponseEntity<Void> deleteByUuidsAndPredicate(
@Parameter(description = "UUID of the subject") @PathVariable("subjectuuid") UUID subjectUuid,
@Parameter(description = "predicate") @PathVariable("predicate") String predicate,
@Parameter(description = "UUID of the object") @PathVariable("objectuuid") UUID objectUuid)
throws ConflictException, ServiceException {
@Parameter(description = "UUID of the object") @PathVariable("objectuuid") UUID objectUuid) {
EntityRelation example =
EntityRelation.builder()
.subject(Entity.builder().uuid(subjectUuid).build())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.dbmdz.metadata.server.controller.identifiable.entity.relation;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

import de.digitalcollections.model.identifiable.entity.Entity;
import de.digitalcollections.model.identifiable.entity.relation.EntityRelation;
import io.github.dbmdz.metadata.server.business.api.service.identifiable.entity.relation.EntityToEntityRelationService;
import io.github.dbmdz.metadata.server.controller.BaseControllerTest;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;

@WebMvcTest(EntityRelationController.class)
@DisplayName("The EntityRelation controller")
class EntityRelationControllerTest extends BaseControllerTest {

@MockBean private EntityToEntityRelationService entityRelationService;

@DisplayName("can delete an EntityRelation")
@ParameterizedTest
@ValueSource(
strings = {
"/v6/entities/relations/8fe24c2a-ee3d-4f3f-bc4b-c78b6c132afd/is_realized_with/d2206b4c-910f-4dbe-b496-c0a5c0449ee7"
})
public void listOfRelatedEntities(String path) throws Exception {
EntityRelation expectedEntityRelationToDelete =
EntityRelation.builder()
.subject(Entity.builder().uuid("8fe24c2a-ee3d-4f3f-bc4b-c78b6c132afd").build())
.predicate("is_realized_with")
.object(Entity.builder().uuid("d2206b4c-910f-4dbe-b496-c0a5c0449ee7").build())
.build();
when(entityRelationService.delete(eq(expectedEntityRelationToDelete))).thenReturn(1);

testDeleteSuccessful(path);
}
}

0 comments on commit 82e79c3

Please sign in to comment.