Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed delete endpoint for EntityRelations #217

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading