Skip to content

Commit

Permalink
Added download project files
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalii-bezuhlyi committed Jun 26, 2024
1 parent 802fc91 commit df1f3ce
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Apps.XtrfCustomerPortal/Actions/ProjectActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Apps.XtrfCustomerPortal.Utilities.Extensions;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Actions;
using Blackbird.Applications.Sdk.Common.Files;
using Blackbird.Applications.Sdk.Common.Invocation;
using Blackbird.Applications.SDK.Extensions.FileManagement.Interfaces;
using RestSharp;
Expand Down Expand Up @@ -124,6 +125,31 @@ public async Task<ProjectResponse> CreateProject([ActionParameter] CreateProject
return new ProjectResponse(projectDto);
}

[Action("Download project files", Description = "Download project translation files")]
public async Task<DownloadProjectFilesResponse> DownloadProjectFiles([ActionParameter] ProjectIdentifier projectIdentifier)
{
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 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
2 changes: 0 additions & 2 deletions Apps.XtrfCustomerPortal/Actions/QuoteActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
using Apps.XtrfCustomerPortal.Utilities.Extensions;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Actions;
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.Files;
using RestSharp;

namespace Apps.XtrfCustomerPortal.Actions;
Expand Down
67 changes: 67 additions & 0 deletions Apps.XtrfCustomerPortal/Models/Dtos/TaskFilesDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
namespace Apps.XtrfCustomerPortal.Models.Dtos;

public class TaskFilesDto
{
public int Id { get; set; }
public string IdNumber { get; set; }
public List<TaskFile> TasksFiles { get; set; }
public bool OutputFilesAsZipDownloadable { get; set; }

public class TaskFile
{
public int Id { get; set; }
public string IdNumber { get; set; }
public LanguageCombination LanguageCombination { get; set; }
public FileGroup InputWorkfiles { get; set; }
public FileGroup InputResources { get; set; }
public FileGroup? Output { get; set; }
public bool OutputFilesAsZipDownloadable { get; set; }
}

public class LanguageCombination
{
public Language SourceLanguage { get; set; }
public Language TargetLanguage { get; set; }
}

public class Language
{
public int Id { get; set; }
public string Symbol { get; set; }
public string Name { get; set; }
public string DisplayName { get; set; }
}

public class FileGroup
{
public string Name { get; set; }
public List<Directory> Directories { get; set; }
public List<File> Files { get; set; }
}

public class Directory
{
public string Name { get; set; }
public List<Directory> Directories { get; set; }
public List<File> Files { get; set; }
}

public class File
{
public string Name { get; set; }
public int Id { get; set; }
public bool Downloadable { get; set; }
public string Category { get; set; }
public bool Zip { get; set; }
public FileStats FileStats { get; set; }
}

public class FileStats
{
public int CharactersWithSpaces { get; set; }
public int CharactersWithoutSpaces { get; set; }
public int Words { get; set; }
public int Lines { get; set; }
public int Pages { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Blackbird.Applications.Sdk.Common.Files;

namespace Apps.XtrfCustomerPortal.Models.Responses.Projects;

public class DownloadProjectFilesResponse
{
public List<FileReference> Files { get; set; } = new();
}

0 comments on commit df1f3ce

Please sign in to comment.