Skip to content

Commit

Permalink
Merge pull request #80 from skbkontur/ka-0000-add-patch--methods
Browse files Browse the repository at this point in the history
add patch dc and document methods
  • Loading branch information
elizShtol authored Dec 6, 2024
2 parents b1c2a36 + a1c66fa commit f0571b7
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Threading.Tasks;
using Kontur.Extern.Api.Client.Model.DocflowFiltering;
using Kontur.Extern.Api.Client.Models.Docflows;
using Kontur.Extern.Api.Client.Models.Docflows.Documents;
using Microsoft.AspNetCore.JsonPatch;

namespace Kontur.Extern.Api.Client.End2EndTests.Client.TestContext
{
Expand All @@ -25,6 +27,12 @@ public Task<IReadOnlyList<IDocflow>> ListByFilter(Guid accountId, DocflowFilterB
public Task<IDocflowWithDocuments?> GetDocflowOrNull(Guid accountId, Guid docflowId) =>
konturExtern.Accounts.WithId(accountId).Docflows.WithId(docflowId).TryGetAsync();

public Task<IDocflowWithDocuments> PatchDocflow(Guid accountId, Guid docflowId, JsonPatchDocument<IDocflowWithDocuments> patch) =>
konturExtern.Accounts.WithId(accountId).Docflows.WithId(docflowId).PatchAsync(patch);

public Task<Document> PatchDocument(Guid accountId, Guid docflowId, Guid documentId, JsonPatchDocument<Document> patch) =>
konturExtern.Accounts.WithId(accountId).Docflows.WithId(docflowId).Documents.WithId(documentId).PatchAsync(patch);

public Task<IDocflowWithDocuments> GetDocflow(Guid accountId, Guid docflowId) =>
konturExtern.Accounts.WithId(accountId).Docflows.WithId(docflowId).GetAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public HttpRequestFactory(

public IPayloadHttpRequest Put(Uri url) => CreateHttpRequest(Request.Put(url));

public IPayloadHttpRequest Patch(Uri url) => CreateHttpRequest(Request.Patch(url));

public IPayloadHttpRequest Post(Uri url) => CreateHttpRequest(Request.Post(url));

public IHttpRequest Delete(Uri url) => CreateHttpRequest(Request.Delete(url));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.JsonPatch;

namespace Kontur.Extern.Api.Client.Http
{
Expand Down Expand Up @@ -108,6 +109,26 @@ public static async Task<TResponseDto> PostAsync<TResponseDto>(this IHttpRequest
return await response.GetMessageAsync<TResponseDto>().ConfigureAwait(false);
}

public static async Task<TResponseDto> PatchAsync<TRequestDto, TResponseDto>(this IHttpRequestFactory httpRequestFactory, string url, TRequestDto requestDto, TimeoutSpecification timeout = default)
{
if (url == null)
throw new ArgumentNullException(nameof(url));

return await PatchAsync<TRequestDto, TResponseDto>(httpRequestFactory, url.ToUrl(), requestDto, timeout).ConfigureAwait(false);
}

public static async Task<TResponseDto> PatchAsync<TRequestDto, TResponseDto>(this IHttpRequestFactory httpRequestFactory, Uri url, TRequestDto requestDto, TimeoutSpecification timeout = default)
{
if (requestDto is null)
throw new ArgumentNullException(nameof(requestDto));

var response = await httpRequestFactory.Patch(url)
.WithObject(requestDto)
.SendAsync(timeout).ConfigureAwait(false);

return await response.GetMessageAsync<TResponseDto>().ConfigureAwait(false);
}

public static async Task<IHttpResponse> RawPostAsync<TRequestDto>(
this IHttpRequestFactory httpRequestFactory,
Uri url,
Expand Down
1 change: 1 addition & 0 deletions src/Kontur.Extern.Api.Client.Http/IHttpRequestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface IHttpRequestFactory
IHttpRequest Get(Uri url);
IPayloadHttpRequest Put(Uri url);
IPayloadHttpRequest Post(Uri url);
IPayloadHttpRequest Patch (Uri url);
IHttpRequest Delete(Uri url);
IPayloadHttpRequest Verb(string method, Uri url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.2.0" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="6.0.10" />
<PackageReference Include="System.Text.Encodings.Web" Version="5.0.1" />
<PackageReference Include="System.Text.Json" Version="5.0.2" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Kontur.Extern.Api.Client.Models.Docflows.Documents;
using Kontur.Extern.Api.Client.Http;
using Kontur.Extern.Api.Client.Models.Docflows.DocumentsRequests;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.JsonPatch.Operations;
using Vostok.Clusterclient.Core.Model;

// ReSharper disable CommentTypo
Expand Down Expand Up @@ -85,6 +87,16 @@ public Task<Document> GetDocumentAsync(Guid accountId, Guid docflowId, Guid docu
public Task<Document?> TryGetDocumentAsync(Guid accountId, Guid docflowId, Guid documentId, TimeSpan? timeout = null) =>
http.TryGetAsync<Document>($"/v1/{accountId}/docflows/{docflowId}/documents/{documentId}", timeout);

public Task<Document> PatchDocumentAsync(Guid accountId, Guid docflowId, Guid documentId, JsonPatchDocument<Document> patch, TimeSpan? timeout = null)
{
return http.PatchAsync<List<Operation<Document>>, Document>($"/v1/{accountId}/docflows/{docflowId}/documents/{documentId}", patch.Operations, timeout);
}

public Task<IDocflowWithDocuments> PatchDocflowAsync(Guid accountId, Guid docflowId, JsonPatchDocument<IDocflowWithDocuments> patch, TimeSpan? timeout = null)
{
return http.PatchAsync<List<Operation<IDocflowWithDocuments>>, IDocflowWithDocuments>($"/v1/{accountId}/docflows/{docflowId}", patch.Operations, timeout);
}

public Task<DocflowDocumentDescription> GetDocumentDescriptionAsync(
Guid accountId,
Guid docflowId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Kontur.Extern.Api.Client.Models.Docflows;
using Kontur.Extern.Api.Client.Models.Docflows.Documents;
using Kontur.Extern.Api.Client.Models.Docflows.DocumentsRequests;
using Microsoft.AspNetCore.JsonPatch;

namespace Kontur.Extern.Api.Client.ApiLevel.Clients.Docflows
{
Expand Down Expand Up @@ -137,6 +138,28 @@ Task<IDocflowWithDocuments> GetInventoryDocflowAsync(
/// <returns>Документ из документооборота или null</returns>
Task<Document?> TryGetDocumentAsync(Guid accountId, Guid docflowId, Guid documentId, TimeSpan? timeout = null);


/// <summary>
/// Изменение реквизитов документа требования
/// </summary>
/// <param name="accountId">Идентификатор учетной записи</param>
/// <param name="docflowId">Идентификатор документооборота</param>
/// <param name="documentId">Идентификатор документа</param>
/// <param name="patch">Список операций для изменения реквизитов</param>
/// <param name="timeout"></param>
/// <returns>Документ из документооборота</returns>
Task<Document> PatchDocumentAsync(Guid accountId, Guid docflowId, Guid documentId, JsonPatchDocument<Document> patch, TimeSpan? timeout = null);

/// <summary>
/// Изменение реквизитов документооборота
/// </summary>
/// <param name="accountId">Идентификатор учетной записи</param>
/// <param name="docflowId">Идентификатор документооборота</param>
/// <param name="patch">Список операций для изменения реквизитов</param>
/// <param name="timeout"></param>
/// <returns>Документооборот</returns>
Task<IDocflowWithDocuments> PatchDocflowAsync(Guid accountId, Guid docflowId, JsonPatchDocument<IDocflowWithDocuments> patch, TimeSpan? timeout = null);

/// <summary>
/// Получение описания документа
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Kontur.Extern.Api.Client/Client/DocflowPathExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Kontur.Extern.Api.Client.Models.Docflows;
using Kontur.Extern.Api.Client.Models.Docflows.DocumentsRequests;
using Kontur.Extern.Api.Client.Paths;
using Microsoft.AspNetCore.JsonPatch;

namespace Kontur.Extern.Api.Client
{
Expand All @@ -23,6 +24,12 @@ public static Task<IDocflowWithDocuments> GetAsync(this in DocflowPath path, Tim
return apiClient.Docflows.TryGetDocflowAsync(path.AccountId, path.DocflowId, timeout);
}

public static Task<IDocflowWithDocuments> PatchAsync(this in DocflowPath path, JsonPatchDocument<IDocflowWithDocuments> patch, TimeSpan? timeout = null)
{
var apiClient = path.Services.Api;
return apiClient.Docflows.PatchDocflowAsync(path.AccountId, path.DocflowId, patch, timeout);
}

public static Task<DocumentsRequest> GenerateDocumentsRequestAsync(this in DocflowPath path, CertificateContent certificate, TimeSpan? timeout = null)
{
var apiClient = path.Services.Api;
Expand Down
7 changes: 7 additions & 0 deletions src/Kontur.Extern.Api.Client/Client/DocumentPathExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Kontur.Extern.Api.Client.Models.Docflows.Documents.Replies;
using Kontur.Extern.Api.Client.Paths;
using Kontur.Extern.Api.Client.Primitives;
using Microsoft.AspNetCore.JsonPatch;

namespace Kontur.Extern.Api.Client
{
Expand All @@ -30,6 +31,12 @@ public static Task<Document> GetAsync(this in DocumentPath path, TimeSpan? timeo
var apiClient = path.Services.Api;
return apiClient.Docflows.GetDocumentAsync(path.AccountId, path.DocflowId, path.DocumentId, timeout);
}

public static Task<Document> PatchAsync(this in DocumentPath path, JsonPatchDocument<Document> patch, TimeSpan? timeout = null)
{
var apiClient = path.Services.Api;
return apiClient.Docflows.PatchDocumentAsync(path.AccountId, path.DocflowId, path.DocumentId, patch, timeout);
}

public static IEntityList<IDocflow> RelatedDocflowsList(this in DocumentPath path, DocflowFilterBuilder? filterBuilder = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="6.0.10" />
<PackageReference Include="JetBrains.Annotations" Version="2021.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ public abstract class DocflowDescription
/// Идентификатор черновика документооборота, если он был создан через API
/// </summary>
public Guid? OriginalDraftId { get; set; }

/// <summary>
/// Реквизиты документооборота
/// </summary>
public DocflowRequisites? Requisites { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using Kontur.Extern.Api.Client.Models.Docflows.Documents.Requisites;

namespace Kontur.Extern.Api.Client.Models.Docflows.Descriptions;

[PublicAPI]
[SuppressMessage("ReSharper", "CommentTypo")]
public class DocflowRequisites
{
/// <summary>
/// Комментарий к документообороту
/// </summary>
public Comment? Comment { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using Kontur.Extern.Api.Client.Common.Time;
using Kontur.Extern.Api.Client.Models.Numbers;
Expand Down Expand Up @@ -39,5 +41,117 @@ public class DemandAttachmentRequisites : DocflowDocumentRequisites
/// Список ИНН, содержащихся в требовании
/// </summary>
public string[] DemandInnList { get; set; } = null!;

/// <summary>
/// Наименование налогового органа
/// </summary>
public string? TaxDepartmentName { get; set; }

/// <summary>
/// Наименование мероприятия налогового контроля
/// </summary>
public string? TaxEventName { get; set; }

/// <summary>
/// Комментарий
/// </summary>
public Comment? Comment { get; set; }

/// <summary>
/// Метки
/// </summary>
public List<Label>? Labels { get; set; }

/// <summary>
/// Список ответственных
/// <remarks>На данный момент список может быть либо пустым, либо состоять из одного ответственного</remarks>
/// </summary>
public List<Assignee> Assignees { get; set; } = null!;

/// <summary>
/// Статус требования
/// </summary>
public DemandStatus DemandStatus { get; set; }
}

[PublicAPI]
[SuppressMessage("ReSharper", "CommentTypo")]
public class Comment
{
/// <summary>
/// Текст комментария
/// </summary>
public string Text { get; set; } = null!;

/// <summary>
/// Цвет комментария для веб-интерфейса Контур.Экстерна
/// </summary>
public CommentColor Color { get; set; }
}

[PublicAPI]
public enum CommentColor
{
None,
Red,
Violet,
Gray,
Yellow,
Green,
Blue
}

[PublicAPI]
[SuppressMessage("ReSharper", "CommentTypo")]
public class Label
{
/// <summary>
/// Текст метки
/// </summary>
public string Name { get; set; } = null!;
}

[PublicAPI]
[SuppressMessage("ReSharper", "CommentTypo")]
public class Assignee
{
/// <summary>
/// Идентификатор
/// </summary>
public Guid Id { get; set; }

/// <summary>
/// Адрес электронной почты
/// </summary>
public string? Email { get; set; }

/// <summary>
/// Имя
/// </summary>
public string? FirstName { get; set; }

/// <summary>
/// Отчество
/// </summary>
public string? MiddleName { get; set; }

/// <summary>
/// Фамилия
/// </summary>
public string? LastName { get; set; }
}

[PublicAPI]
[SuppressMessage("ReSharper", "CommentTypo")]
public enum DemandStatus
{
/// <summary>
/// В работе
/// </summary>
InProgress,
/// <summary>
/// Выполнено
/// </summary>
Done,
}
}

0 comments on commit f0571b7

Please sign in to comment.