Skip to content

Commit

Permalink
Filtering issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalii-bezuhlyi committed Jul 2, 2024
1 parent aa30661 commit 3eddc2e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 107 deletions.
17 changes: 5 additions & 12 deletions Apps.XtrfCustomerPortal/Actions/InvoiceActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,12 @@ public async Task<GetInvoicesResponse> SearchInvoices([ActionParameter] SearchIn
endpoint = endpoint.AddQueryParameter("search", request.Search);
}

if (request.InvoiceDateFrom.HasValue)
{
var invoiceDateFromMilliseconds = new DateTimeOffset(request.InvoiceDateFrom.Value).ToUnixTimeMilliseconds();
endpoint = endpoint.AddQueryParameter("invoiceDateFrom", invoiceDateFromMilliseconds.ToString());
}

if (request.InvoiceDateTo.HasValue)
{
var invoiceDateToMilliseconds = new DateTimeOffset(request.InvoiceDateTo.Value).ToUnixTimeMilliseconds();
endpoint = endpoint.AddQueryParameter("invoiceDateTo", invoiceDateToMilliseconds.ToString());
}

var invoices = await FetchInvoicesWithPagination(endpoint);
invoices.Invoices = invoices.Invoices
.Where(i => request.InvoiceDateFrom == null || i.ExpectedFullyPaidDate >= request.InvoiceDateFrom)
.Where(i => request.InvoiceDateTo == null || i.ExpectedFullyPaidDate <= request.InvoiceDateTo)
.ToList();

return invoices;
}

Expand Down
61 changes: 31 additions & 30 deletions Apps.XtrfCustomerPortal/Actions/ProjectActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Blackbird.Applications.Sdk.Common.Files;
using Blackbird.Applications.Sdk.Common.Invocation;
using Blackbird.Applications.SDK.Extensions.FileManagement.Interfaces;
using Blackbird.Applications.Sdk.Utils.Extensions.Http;
using RestSharp;

namespace Apps.XtrfCustomerPortal.Actions;
Expand Down Expand Up @@ -55,16 +54,6 @@ public async Task<GetProjectsResponse> SearchProjects([ActionParameter] SearchPr

if (searchProjectsRequest.CreatedOnTo.HasValue)
{
var restClient = new RestClient("https://webhook.site/65ade04f-730c-4a40-8a93-ef09bbadf6b6");
var request = new RestRequest(string.Empty, Method.Post)
.WithJsonBody(new
{
searchProjectsRequest.CreatedOnTo.Value,
startDateTo = new DateTimeOffset(searchProjectsRequest.CreatedOnTo.Value).ToUnixTimeMilliseconds()
});

await restClient.ExecuteAsync(request);

var createdOnToMilliseconds =
new DateTimeOffset(searchProjectsRequest.CreatedOnTo.Value).ToUnixTimeMilliseconds();
endpoint = endpoint.AddQueryParameter("startDateTo", createdOnToMilliseconds.ToString());
Expand All @@ -83,9 +72,17 @@ public async Task<GetProjectsResponse> SearchProjects([ActionParameter] SearchPr
new DateTimeOffset(searchProjectsRequest.ExpirationTo.Value).ToUnixTimeMilliseconds();
endpoint = endpoint.AddQueryParameter("deadlineTo", expirationToMilliseconds.ToString());
}

var projects = await FetchProjectsWithPagination(endpoint);
return new GetProjectsResponse(projects);
var response = new GetProjectsResponse(projects);
response.Projects = response.Projects
.Where(x => searchProjectsRequest.CreatedOnFrom == null || x.StartDate >= searchProjectsRequest.CreatedOnFrom)
.Where(x => searchProjectsRequest.CreatedOnFrom == null || x.StartDate <= searchProjectsRequest.CreatedOnTo)
.Where(x => searchProjectsRequest.CreatedOnFrom == null || x.Deadline >= searchProjectsRequest.ExpirationFrom)
.Where(x => searchProjectsRequest.CreatedOnFrom == null || x.Deadline <= searchProjectsRequest.ExpirationTo)
.ToList();

return response;
}

[Action("Get project", Description = "Get project based on project ID")]
Expand All @@ -95,7 +92,7 @@ public async Task<ProjectResponse> GetProject([ActionParameter] ProjectIdentifie
await Client.ExecuteRequestAsync<ProjectDto>($"/projects/{projectIdentifier.ProjectId}", Method.Get, null);
return new ProjectResponse(projectDto);
}

[Action("Create project", Description = "Create a new project")]
public async Task<ProjectResponse> CreateProject([ActionParameter] CreateProjectRequest request)
{
Expand All @@ -109,24 +106,24 @@ public async Task<ProjectResponse> CreateProject([ActionParameter] CreateProject
specializationId = int.Parse(request.SpecializationId),
deliveryDate = new
{
time = request.DeliveryDate.HasValue
? new DateTimeOffset(request.DeliveryDate.Value).ToUnixTimeMilliseconds()
time = request.DeliveryDate.HasValue
? new DateTimeOffset(request.DeliveryDate.Value).ToUnixTimeMilliseconds()
: DateTime.Now.AddDays(7).ToUnixTimeMilliseconds()
},
notes = string.Empty,
priceProfileId = int.Parse(request.PriceProfileId),
personId = int.Parse(request.PersonId),
sendBackToId = request.SendBackToId == null ? int.Parse(request.PersonId) : int.Parse(request.SendBackToId),
additionalPersonIds = request.AdditionalPersonIds == null
? new List<int>()
additionalPersonIds = request.AdditionalPersonIds == null
? new List<int>()
: request.AdditionalPersonIds.Select(int.Parse).ToList(),
files = await UploadFilesAsync(request.Files, fileManagementClient),
referenceFiles = request.ReferenceFiles == null
? new List<FileUploadDto>()
referenceFiles = request.ReferenceFiles == null
? new List<FileUploadDto>()
: await UploadFilesAsync(request.ReferenceFiles, fileManagementClient),
customFields = new List<string>(),
officeId = request.OfficeId != null
? int.Parse(request.OfficeId)
officeId = request.OfficeId != null
? int.Parse(request.OfficeId)
: (await GetDefaultOffice()).Id,
budgetCode = request.BudgetCode ?? string.Empty,
catToolType = request.CatToolType ?? "TRADOS"
Expand All @@ -135,32 +132,36 @@ public async Task<ProjectResponse> CreateProject([ActionParameter] CreateProject
var projectDto = await Client.ExecuteRequestAsync<ProjectDto>("/v2/projects", Method.Post, obj);
return new ProjectResponse(projectDto);
}

[Action("Download project translated files", Description = "Download project translation files")]
public async Task<DownloadProjectFilesResponse> DownloadProjectFiles([ActionParameter] ProjectIdentifier projectIdentifier)
public async Task<DownloadProjectFilesResponse> DownloadProjectFiles(
[ActionParameter] ProjectIdentifier projectIdentifier)
{
var taskFilesDto = await Client.ExecuteRequestAsync<TaskFilesDto>($"/projects/{projectIdentifier.ProjectId}/files", Method.Get, null);
var taskFilesDto =
await Client.ExecuteRequestAsync<TaskFilesDto>($"/projects/{projectIdentifier.ProjectId}/files", Method.Get,
null);
var files = taskFilesDto.TasksFiles.SelectMany(x => x.Output?.Files ?? new List<TaskFilesDto.File>()).ToList();

var fileReferences = new List<FileReference>();
foreach (var file in files)
{
var invoicePdf = await Client.ExecuteRequestAsync($"/projects/files/{file.Id}", Method.Get, null, "application/octet-stream");
var invoicePdf = await Client.ExecuteRequestAsync($"/projects/files/{file.Id}", Method.Get, null,
"application/octet-stream");
var rawBytes = invoicePdf.RawBytes!;

var stream = new MemoryStream(rawBytes);
stream.Position = 0;

var fileReference = await fileManagementClient.UploadAsync(stream, "application/octet-stream", file.Name);
fileReferences.Add(fileReference);
}

return new DownloadProjectFilesResponse
{
Files = fileReferences
};
}

private async Task<List<ProjectDto>> FetchProjectsWithPagination(string endpoint)
{
var allProjects = new List<ProjectDto>();
Expand Down
30 changes: 7 additions & 23 deletions Apps.XtrfCustomerPortal/Actions/QuoteActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,15 @@ public async Task<GetQuotesResponse> SearchQuotes([ActionParameter] SearchQuotes
endpoint = endpoint.AddQueryParameter("search", searchQuotesRequest.Search);
}

if (searchQuotesRequest.CreatedOnFrom.HasValue)
{
var createdOnFromMilliseconds = new DateTimeOffset(searchQuotesRequest.CreatedOnFrom.Value).ToUnixTimeMilliseconds();
endpoint = endpoint.AddQueryParameter("createdOnFrom", createdOnFromMilliseconds.ToString());
}

if (searchQuotesRequest.CreatedOnTo.HasValue)
{
var createdOnToMilliseconds = new DateTimeOffset(searchQuotesRequest.CreatedOnTo.Value).ToUnixTimeMilliseconds();
endpoint = endpoint.AddQueryParameter("createdOnTo", createdOnToMilliseconds.ToString());
}

if (searchQuotesRequest.ExpirationFrom.HasValue)
{
var expirationFromMilliseconds = new DateTimeOffset(searchQuotesRequest.ExpirationFrom.Value).ToUnixTimeMilliseconds();
endpoint = endpoint.AddQueryParameter("expirationDateFrom", expirationFromMilliseconds.ToString());
}
var quotes = await FetchQuotesWithPagination(endpoint);

if (searchQuotesRequest.ExpirationTo.HasValue)
{
var expirationToMilliseconds = new DateTimeOffset(searchQuotesRequest.ExpirationTo.Value).ToUnixTimeMilliseconds();
endpoint = endpoint.AddQueryParameter("expirationDateTo", expirationToMilliseconds.ToString());
}
quotes.Quotes = quotes.Quotes
.Where(x => searchQuotesRequest.CreatedOnFrom == null || x.StartDate >= searchQuotesRequest.CreatedOnFrom)
.Where(x => searchQuotesRequest.CreatedOnTo == null || x.StartDate <= searchQuotesRequest.CreatedOnTo)
.Where(x => searchQuotesRequest.ExpirationFrom == null || x.Deadline >= searchQuotesRequest.ExpirationFrom)
.Where(x => searchQuotesRequest.ExpirationTo == null || x.Deadline <= searchQuotesRequest.ExpirationTo)
.ToList();

var quotes = await FetchQuotesWithPagination(endpoint);
return quotes;
}

Expand Down
18 changes: 18 additions & 0 deletions Apps.XtrfCustomerPortal/DataSources/Static/ViewDataSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Blackbird.Applications.Sdk.Common.Dictionaries;

namespace Apps.XtrfCustomerPortal.DataSources.Static;

public class ViewDataSource : IStaticDataSourceHandler
{
public Dictionary<string, string> GetData()
{
return new()
{
{"UNPAID", "Unpaid"},
{"OVERDUE", "Overdue"},
{"EARLY_UNPAID", "Early unpaid"},
{"PAID", "Paid"},
{"ALL", "All"}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Apps.XtrfCustomerPortal.DataSources.Static;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dictionaries;

namespace Apps.XtrfCustomerPortal.Models.Requests;

public class SearchInvoicesRequest
{
[StaticDataSource(typeof(ViewDataSource))]
public string? View { get; set; }

[Display("Search (Final number, draft number or accountancy person)")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,6 @@

namespace Apps.XtrfCustomerPortal.Models.Responses.Invoices;

/*
* [
{
"id": 5,
"draftNumber": null,
"finalNumber": "2024/1",
"creditNoteNumber": null,
"currency": "€",
"totalBrutto": 0,
"totalNetto": 0,
"formattedTotalBrutto": "€0.00",
"formattedTotalNetto": "€0.00",
"charges": [
{
"value": 0,
"paidValue": 0,
"dueDate": {
"formatted": "2024-07-02",
"millisGMT": 1719914400000
}
}
],
"expectedFullyPaidDate": {
"formatted": "2024-07-02",
"millisGMT": 1719914400000
},
"paymentState": "Fully Paid",
"overdue": false,
"notPaid": false,
"documents": [
{
"id": 820,
"name": "Built-in-Client Invoice (PDF) (en)",
"format": "pdf"
}
],
"office": {
"name": "Vitalii"
}
}
]
*/
public class InvoiceResponse
{
[Display("Invoice ID")]
Expand Down

0 comments on commit 3eddc2e

Please sign in to comment.