Skip to content

Commit

Permalink
feat: Add method for deleting documents
Browse files Browse the repository at this point in the history
  • Loading branch information
VMelnalksnis committed Nov 30, 2024
1 parent 43938ac commit fafc89b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ public async Task<Document<TFields>> Update<TFields>(int id, DocumentUpdate<TFie
return await UpdateCore<Document<TFields>, DocumentUpdate<TFields>>(id, document).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task Delete(int id)
{
using var response = await _httpClient.DeleteAsync(Routes.Documents.IdUri(id)).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeAsync().ConfigureAwait(false);
}

/// <inheritdoc />
public IAsyncEnumerable<CustomField> GetCustomFields(CancellationToken cancellationToken = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public interface IDocumentClient
/// <returns>The updated document.</returns>
Task<Document<TFields>> Update<TFields>(int id, DocumentUpdate<TFields> document);

/// <summary>Deletes the document with the specified id.</summary>
/// <param name="id">The id of the document to delete.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
Task Delete(int id);

/// <summary>Gets all custom fields.</summary>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>A collection of all custom fields.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

using NodaTime;
Expand Down Expand Up @@ -99,6 +100,14 @@ public async Task Create()
{
await Client.Tags.Delete(tag.Id);
}

await Client.Documents.Delete(id);

await FluentActions
.Awaiting(() => Client.Documents.Get(id))
.Should()
.ThrowExactlyAsync<HttpRequestException>()
.WithMessage("Response status code does not indicate success: 404 (Not Found).");
}

[Test]
Expand Down

0 comments on commit fafc89b

Please sign in to comment.