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

feat: add restli delete method to soft delete aspect #133

Merged
merged 1 commit into from
Nov 9, 2021
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 @@ -17,6 +17,7 @@
import com.linkedin.restli.server.CreateResponse;
import com.linkedin.restli.server.PagingContext;
import com.linkedin.restli.server.PathKeys;
import com.linkedin.restli.server.UpdateResponse;
import com.linkedin.restli.server.annotations.PagingContextParam;
import com.linkedin.restli.server.annotations.RestMethod;
import com.linkedin.restli.server.annotations.ReturnEntity;
Expand Down Expand Up @@ -111,6 +112,22 @@ public Task<CreateResponse> create(@Nonnull ASPECT aspect) {
});
}

/**
* Soft deletes the latest version of aspect if it exists.
*
* @return {@link UpdateResponse} indicating the status code of the response.
*/
@RestMethod.Delete
@Nonnull
public Task<UpdateResponse> delete() {
return RestliUtils.toTask(() -> {
final URN urn = getUrn(getContext().getPathKeys());
final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext());
getLocalDAO().delete(urn, this._aspectClass, auditStamp);
return new UpdateResponse(HttpStatus.S_200_OK);
});
}

/**
* Similar to {@link #create(RecordTemplate)} but uses a create lambda instead.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ public void testCreate() {
verifyNoMoreInteractions(_mockLocalDAO);
}

@Test
public void testSoftDelete() {

runAndWait(_resource.delete());

// this should test that delete method of DAO is being called once
verify(_mockLocalDAO, times(1)).delete(eq(ENTITY_URN), eq(AspectFoo.class), any(AuditStamp.class));
verifyNoMoreInteractions(_mockLocalDAO);
}

@Test
public void testCreateViaLambda() {
AspectFoo foo = new AspectFoo().setValue("foo");
Expand Down