-
-
Notifications
You must be signed in to change notification settings - Fork 5
Feat document type and storage path #298
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
Open
CodingAlias
wants to merge
5
commits into
VMelnalksnis:master
Choose a base branch
from
CodingAlias:feat-DocumentTypeAndStoragePath
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ce24f7a
feat: Add method to fetch documents by tag ID
CodingAlias d5270f5
feat: added support for DocumentType and StoragePath APIs
CodingAlias 4610768
feat: added support for DocumentType and StoragePath APIs
CodingAlias c9f3a82
Merge remote-tracking branch 'origin/feat-DocumentTypeAndStoragePath'…
CodingAlias 42b7794
(a) Add method to get documents with custom fields by tag ID
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
source/VMelnalksnis.PaperlessDotNet/DocumentTypes/DocumentType.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright 2022 Valters Melnalksnis | ||
| // Licensed under the Apache License 2.0. | ||
| // See LICENSE file in the project root for full license information. | ||
|
|
||
| using NodaTime; | ||
|
|
||
| using VMelnalksnis.PaperlessDotNet.Correspondents; | ||
|
|
||
| namespace VMelnalksnis.PaperlessDotNet.DocumentTypes; | ||
|
|
||
| /// <summary>A type of document with whom documents were exchanged with.</summary> | ||
| public sealed class DocumentType | ||
| { | ||
| /// <summary>Gets or sets the id of the document type.</summary> | ||
| public int Id { get; set; } | ||
|
|
||
| /// <summary>Gets or sets the normalized <see cref="Name"/> - lowercased and with whitespace replaced with '-'.</summary> | ||
| public string Slug { get; set; } = null!; | ||
|
|
||
| /// <summary>Gets or sets the name of the document type.</summary> | ||
| public string Name { get; set; } = null!; | ||
|
|
||
| /// <summary>Gets or sets the pattern by which to match the document type to documents.</summary> | ||
| public string MatchingPattern { get; set; } = null!; | ||
|
|
||
| /// <summary>Gets or sets the id of the matching algorithm used to match the document type to documents.</summary> | ||
| public MatchingAlgorithm MatchingAlgorithm { get; set; } = null!; | ||
|
|
||
| /// <summary>Gets or sets a value indicating whether to ignore case when matching the document type to documents.</summary> | ||
| public bool IsInsensitive { get; set; } | ||
|
|
||
| /// <summary>Gets or sets the number of documents with the document type.</summary> | ||
| public int DocumentCount { get; set; } | ||
| } |
77 changes: 77 additions & 0 deletions
77
source/VMelnalksnis.PaperlessDotNet/DocumentTypes/DocumentTypeClient.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Copyright 2022 Valters Melnalksnis | ||
| // Licensed under the Apache License 2.0. | ||
| // See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Net.Http; | ||
| using System.Net.Http.Json; | ||
| using System.Text.Json; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| using VMelnalksnis.PaperlessDotNet.Serialization; | ||
|
|
||
| namespace VMelnalksnis.PaperlessDotNet.DocumentTypes; | ||
|
|
||
| /// <inheritdoc /> | ||
| public sealed class DocumentTypeClient : IDocumentTypeClient | ||
| { | ||
| private readonly HttpClient _httpClient; | ||
| private readonly JsonSerializerOptions _options; | ||
|
|
||
| /// <summary>Initializes a new instance of the <see cref="DocumentTypeClient"/> class.</summary> | ||
| /// <param name="httpClient">Http client configured for making requests to the Paperless API.</param> | ||
| /// <param name="serializerOptions">Paperless specific instance of <see cref="JsonSerializerOptions"/>.</param> | ||
| public DocumentTypeClient(HttpClient httpClient, PaperlessJsonSerializerOptions serializerOptions) | ||
| { | ||
| _httpClient = httpClient; | ||
| _options = serializerOptions.Options; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public IAsyncEnumerable<DocumentType> GetAll(CancellationToken cancellationToken = default) | ||
| { | ||
| return GetAllCore(Routes.DocumentTypes.Uri, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public IAsyncEnumerable<DocumentType> GetAll(int pageSize, CancellationToken cancellationToken = default) | ||
| { | ||
| return GetAllCore(Routes.DocumentTypes.PagedUri(pageSize), cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public Task<DocumentType?> Get(int id, CancellationToken cancellationToken = default) | ||
| { | ||
| return _httpClient.GetFromJsonAsync( | ||
| Routes.DocumentTypes.IdUri(id), | ||
| _options.GetTypeInfo<DocumentType>(), | ||
| cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public Task<DocumentType> Create(DocumentTypeCreation documentType) | ||
| { | ||
| return _httpClient.PostAsJsonAsync( | ||
| Routes.DocumentTypes.Uri, | ||
| documentType, | ||
| _options.GetTypeInfo<DocumentTypeCreation>(), | ||
| _options.GetTypeInfo<DocumentType>()); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task Delete(int id) | ||
| { | ||
| using var response = await _httpClient.DeleteAsync(Routes.DocumentTypes.IdUri(id)).ConfigureAwait(false); | ||
| await response.EnsureSuccessStatusCodeAsync().ConfigureAwait(false); | ||
| } | ||
|
|
||
| private IAsyncEnumerable<DocumentType> GetAllCore(Uri requestUri, CancellationToken cancellationToken) | ||
| { | ||
| return _httpClient.GetPaginated( | ||
| requestUri, | ||
| _options.GetTypeInfo<PaginatedList<DocumentType>>(), | ||
| cancellationToken); | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
source/VMelnalksnis.PaperlessDotNet/DocumentTypes/DocumentTypeCreation.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Copyright 2022 Valters Melnalksnis | ||
| // Licensed under the Apache License 2.0. | ||
| // See LICENSE file in the project root for full license information. | ||
|
|
||
| using VMelnalksnis.PaperlessDotNet.Correspondents; | ||
|
|
||
| namespace VMelnalksnis.PaperlessDotNet.DocumentTypes; | ||
|
|
||
| /// <summary>Information needed to create a new <see cref="DocumentType"/>.</summary> | ||
| public sealed class DocumentTypeCreation | ||
| { | ||
| /// <summary>Initializes a new instance of the <see cref="DocumentTypeCreation"/> class.</summary> | ||
| /// <param name="name">The name of the document type.</param> | ||
| public DocumentTypeCreation(string name) | ||
| { | ||
| Name = name; | ||
| } | ||
|
|
||
| /// <inheritdoc cref="DocumentType.Slug"/> | ||
| public string? Slug { get; set; } | ||
|
|
||
| /// <inheritdoc cref="DocumentType.Name"/> | ||
| public string Name { get; set; } | ||
|
|
||
| /// <inheritdoc cref="DocumentType.MatchingPattern"/> | ||
| public string? Match { get; set; } | ||
|
|
||
| /// <inheritdoc cref="DocumentType.MatchingAlgorithm"/> | ||
| public MatchingAlgorithm? MatchingAlgorithm { get; set; } | ||
|
|
||
| /// <inheritdoc cref="DocumentType.IsInsensitive"/> | ||
| public bool? IsInsensitive { get; set; } | ||
| } |
40 changes: 40 additions & 0 deletions
40
source/VMelnalksnis.PaperlessDotNet/DocumentTypes/IDocumentTypeClient.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright 2022 Valters Melnalksnis | ||
| // Licensed under the Apache License 2.0. | ||
| // See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace VMelnalksnis.PaperlessDotNet.DocumentTypes; | ||
|
|
||
| /// <summary>Paperless API client for working with correspondents.</summary> | ||
| public interface IDocumentTypeClient | ||
| { | ||
| /// <summary>Gets all document types.</summary> | ||
| /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> | ||
| /// <returns>A enumerable which will asynchronously iterate over all available pages of document types.</returns> | ||
| IAsyncEnumerable<DocumentType> GetAll(CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary>Gets all document types.</summary> | ||
| /// <param name="pageSize">The number of document types to get in a single request.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> | ||
| /// <returns>A enumerable which will asynchronously iterate over all available pages of document types.</returns> | ||
| IAsyncEnumerable<DocumentType> GetAll(int pageSize, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary>Gets the document type with the specified id.</summary> | ||
| /// <param name="id">The id of the document type to get.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> | ||
| /// <returns>The document type with the specified id if it exists; otherwise <see langword="null"/>.</returns> | ||
| Task<DocumentType?> Get(int id, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary>Creates a new document type.</summary> | ||
| /// <param name="documentType">The correspondent to create.</param> | ||
| /// <returns>The created correspondent.</returns> | ||
| Task<DocumentType> Create(DocumentTypeCreation documentType); | ||
|
|
||
| /// <summary>Deletes a document type.</summary> | ||
| /// <param name="id">The id of the document type to delete.</param> | ||
| /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> | ||
| Task Delete(int id); | ||
| } |
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
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
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
40 changes: 40 additions & 0 deletions
40
source/VMelnalksnis.PaperlessDotNet/StoragePaths/IStoragePathClient.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright 2022 Valters Melnalksnis | ||
| // Licensed under the Apache License 2.0. | ||
| // See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace VMelnalksnis.PaperlessDotNet.StoragePaths; | ||
|
|
||
| /// <summary>Paperless API client for working with correspondents.</summary> | ||
| public interface IStoragePathClient | ||
| { | ||
| /// <summary>Gets all storage paths.</summary> | ||
| /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> | ||
| /// <returns>A enumerable which will asynchronously iterate over all available pages of storage paths.</returns> | ||
| IAsyncEnumerable<StoragePath> GetAll(CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary>Gets all storage paths.</summary> | ||
| /// <param name="pageSize">The number of storage paths to get in a single request.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> | ||
| /// <returns>A enumerable which will asynchronously iterate over all available pages of storage paths.</returns> | ||
| IAsyncEnumerable<StoragePath> GetAll(int pageSize, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary>Gets the storage path with the specified id.</summary> | ||
| /// <param name="id">The id of the storage path to get.</param> | ||
| /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> | ||
| /// <returns>The storage path with the specified id if it exists; otherwise <see langword="null"/>.</returns> | ||
| Task<StoragePath?> Get(int id, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary>Creates a new storage path.</summary> | ||
| /// <param name="storagePath">The correspondent to create.</param> | ||
| /// <returns>The created correspondent.</returns> | ||
| Task<StoragePath> Create(StoragePathCreation storagePath); | ||
|
|
||
| /// <summary>Deletes a storage path.</summary> | ||
| /// <param name="id">The id of the storage path to delete.</param> | ||
| /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> | ||
| Task Delete(int id); | ||
| } |
37 changes: 37 additions & 0 deletions
37
source/VMelnalksnis.PaperlessDotNet/StoragePaths/StoragePath.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Copyright 2022 Valters Melnalksnis | ||
| // Licensed under the Apache License 2.0. | ||
| // See LICENSE file in the project root for full license information. | ||
|
|
||
| using NodaTime; | ||
|
|
||
| using VMelnalksnis.PaperlessDotNet.Correspondents; | ||
|
|
||
| namespace VMelnalksnis.PaperlessDotNet.StoragePaths; | ||
|
|
||
| /// <summary>A type of document with whom documents were exchanged with.</summary> | ||
| public sealed class StoragePath | ||
| { | ||
| /// <summary>Gets or sets the id of the storage path.</summary> | ||
| public int Id { get; set; } | ||
|
|
||
| /// <summary>Gets or sets the normalized <see cref="Name"/> - lowercased and with whitespace replaced with '-'.</summary> | ||
| public string Slug { get; set; } = null!; | ||
|
|
||
| /// <summary>Gets or sets the name of the storage path.</summary> | ||
| public string Name { get; set; } = null!; | ||
|
|
||
| /// <summary>Gets or sets the path of the storage path.</summary> | ||
| public string Path { get; set; } = null!; | ||
|
|
||
| /// <summary>Gets or sets the pattern by which to match the storage path to documents.</summary> | ||
| public string MatchingPattern { get; set; } = null!; | ||
|
|
||
| /// <summary>Gets or sets the id of the matching algorithm used to match the storage path to documents.</summary> | ||
| public MatchingAlgorithm MatchingAlgorithm { get; set; } = null!; | ||
|
|
||
| /// <summary>Gets or sets a value indicating whether to ignore case when matching the storage path to documents.</summary> | ||
| public bool IsInsensitive { get; set; } | ||
|
|
||
| /// <summary>Gets or sets the number of documents with the storage path.</summary> | ||
| public int DocumentCount { get; set; } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to also add
DocumentTypeCreationandStoragePathCreation