Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 167 additions & 28 deletions Resources/Export template.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,167 @@
<?xml version="1.0" encoding="UTF-8" ?>
<people>
<person name="Mary" age="32">
<pets>
<pet name="Markiza" type="Cat" />
<pet name="Pushistik" type="Cat" />
<pet name="Belka" type="Dog" />
</pets>
</person>
<person name="Gary" age="18">
<pets>
<pet name="Norm" type="Dog" />
</pets>
</person>
<person name="Mike" age="24">
<pets>
<pet name="Bert" type="Parrot" />
<pet name="Gosha" type="Parrot" />
<pet name="Milka" type="Cat" />
</pets>
</person>
<person name="Alex" age="25">
<pets>
<pet name="Casper" type="Cat" />
<pet name="Charli" type="Dog" />
</pets>
</person>
</people>
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfPerson xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Person>
<Id>f2e84964-c5bc-4637-b819-212a307ad33a</Id>
<Name>Mary</Name>
<Age>32</Age>
<Pets>
<Pet>
<Id>601d3a39-db68-487c-8d5e-5b608fac6849</Id>
<Name>Pushistik</Name>
<Type>Cat</Type>
<PersonId>f2e84964-c5bc-4637-b819-212a307ad33a</PersonId>
</Pet>
<Pet>
<Id>09370b68-e63d-4b64-938d-ae7cf0caa13e</Id>
<Name>Markiza</Name>
<Type>Cat</Type>
<PersonId>f2e84964-c5bc-4637-b819-212a307ad33a</PersonId>
</Pet>
<Pet>
<Id>b2646460-feb3-4960-a8bb-e15b68348ffb</Id>
<Name>Belka</Name>
<Type>Dog</Type>
<PersonId>f2e84964-c5bc-4637-b819-212a307ad33a</PersonId>
</Pet>
</Pets>
</Person>
<Person>
<Id>a4c4c34e-1718-44e3-80df-2f02e205f1e6</Id>
<Name>Mary</Name>
<Age>32</Age>
<Pets>
<Pet>
<Id>7a28a977-ee8c-4b65-ab33-0a4ccec05eb8</Id>
<Name>Markiza</Name>
<Type>Cat</Type>
<PersonId>a4c4c34e-1718-44e3-80df-2f02e205f1e6</PersonId>
</Pet>
<Pet>
<Id>0f1bace7-0616-4486-a59a-98ded6a7c308</Id>
<Name>Belka</Name>
<Type>Dog</Type>
<PersonId>a4c4c34e-1718-44e3-80df-2f02e205f1e6</PersonId>
</Pet>
<Pet>
<Id>1c6051e3-22c8-493b-a3f8-afed132fe975</Id>
<Name>Pushistik</Name>
<Type>Cat</Type>
<PersonId>a4c4c34e-1718-44e3-80df-2f02e205f1e6</PersonId>
</Pet>
</Pets>
</Person>
<Person>
<Id>2c8ce6f3-ff9a-4abe-ab82-4ec26c3d05e9</Id>
<Name>Alex</Name>
<Age>25</Age>
<Pets>
<Pet>
<Id>c683f0e4-731b-4653-9164-567c4de27dae</Id>
<Name>Casper</Name>
<Type>Cat</Type>
<PersonId>2c8ce6f3-ff9a-4abe-ab82-4ec26c3d05e9</PersonId>
</Pet>
<Pet>
<Id>8ab97248-7514-49d1-a869-f72518c58b29</Id>
<Name>Charli</Name>
<Type>Dog</Type>
<PersonId>2c8ce6f3-ff9a-4abe-ab82-4ec26c3d05e9</PersonId>
</Pet>
</Pets>
</Person>
<Person>
<Id>ea99c9cc-5c83-44b1-ac9b-60eef3c96b4d</Id>
<Name>Mike</Name>
<Age>24</Age>
<Pets>
<Pet>
<Id>55b2c0a3-76da-4d2e-99b1-1b8328426fad</Id>
<Name>Milka</Name>
<Type>Cat</Type>
<PersonId>ea99c9cc-5c83-44b1-ac9b-60eef3c96b4d</PersonId>
</Pet>
<Pet>
<Id>7e5bd8a5-3d94-45fb-aa33-c0296ecb3920</Id>
<Name>Gosha</Name>
<Type>Parrot</Type>
<PersonId>ea99c9cc-5c83-44b1-ac9b-60eef3c96b4d</PersonId>
</Pet>
<Pet>
<Id>a67a1e86-deac-489d-9a0b-e287530f9e59</Id>
<Name>Bert</Name>
<Type>Parrot</Type>
<PersonId>ea99c9cc-5c83-44b1-ac9b-60eef3c96b4d</PersonId>
</Pet>
</Pets>
</Person>
<Person>
<Id>748e1051-b4ea-4f5d-ac99-915093cf1bac</Id>
<Name>Gary</Name>
<Age>18</Age>
<Pets>
<Pet>
<Id>f81f5335-2006-487f-b445-5b9f0c02bd73</Id>
<Name>Norm</Name>
<Type>Dog</Type>
<PersonId>748e1051-b4ea-4f5d-ac99-915093cf1bac</PersonId>
</Pet>
</Pets>
</Person>
<Person>
<Id>0807ce18-3cac-4f64-9f42-ac6cf9361ab6</Id>
<Name>Alex</Name>
<Age>25</Age>
<Pets>
<Pet>
<Id>6a5261f1-a476-45f7-b379-66788b130be5</Id>
<Name>Charli</Name>
<Type>Dog</Type>
<PersonId>0807ce18-3cac-4f64-9f42-ac6cf9361ab6</PersonId>
</Pet>
<Pet>
<Id>21bfdee3-bad3-489e-b14d-79f592dadc85</Id>
<Name>Casper</Name>
<Type>Cat</Type>
<PersonId>0807ce18-3cac-4f64-9f42-ac6cf9361ab6</PersonId>
</Pet>
</Pets>
</Person>
<Person>
<Id>161e9844-f647-48da-b144-cb9bb935fb66</Id>
<Name>Mike</Name>
<Age>24</Age>
<Pets>
<Pet>
<Id>01abf2c9-33ac-4374-a6aa-1a62d6df4f69</Id>
<Name>Bert</Name>
<Type>Parrot</Type>
<PersonId>161e9844-f647-48da-b144-cb9bb935fb66</PersonId>
</Pet>
<Pet>
<Id>674285de-fcf4-482f-9f84-ac3d7ba257a4</Id>
<Name>Gosha</Name>
<Type>Parrot</Type>
<PersonId>161e9844-f647-48da-b144-cb9bb935fb66</PersonId>
</Pet>
<Pet>
<Id>37147a9a-3b40-4114-aacb-cb669c391492</Id>
<Name>Milka</Name>
<Type>Cat</Type>
<PersonId>161e9844-f647-48da-b144-cb9bb935fb66</PersonId>
</Pet>
</Pets>
</Person>
<Person>
<Id>dd3c8807-8d2e-4561-bb89-ce832b5fa3fa</Id>
<Name>Gary</Name>
<Age>18</Age>
<Pets>
<Pet>
<Id>f61e6278-3223-4869-b9a7-46f1b61c7e93</Id>
<Name>Norm</Name>
<Type>Dog</Type>
<PersonId>dd3c8807-8d2e-4561-bb89-ce832b5fa3fa</PersonId>
</Pet>
</Pets>
</Person>
</ArrayOfPerson>
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public void ShouldThrowCriticalDependencyExceptionOnRetrieveAllWhenSqlExceptionO
broker.SelectAllPersons()).Throws(sqlException);

// when
Action retrieveAllPeopleAction = () =>
Action retrieveAllPersonAction = () =>
this.personService.RetrieveAllPersons();

PersonDependencyException actualPersonDependencyException =
Assert.Throws<PersonDependencyException>(retrieveAllPeopleAction);
Assert.Throws<PersonDependencyException>(retrieveAllPersonAction);

// then
actualPersonDependencyException.Should()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace xChanger.Api.Tests.Unit.Services.Foundations.Persons
public partial class PersonServiceTests
{
[Fact]
public void ShouldRetrieveAllPeople()
public void ShouldRetrieveAllPerson()
{
// given
IQueryable<Person> randomPerson = CreateRandomPersons();
Expand Down
6 changes: 3 additions & 3 deletions xChanger.Api/Brokers/Sheets/ISheetBroker.PersonXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace xChanger.Api.Brokers.Sheets
{
public partial interface ISheetBroker
{
ValueTask SavePeopleWithPetsToXmlFile(
IEnumerable<Person> peopleWithPets,
ValueTask SavePersonWithPetsToXmlFile(
IEnumerable<Person> personWithPets,
string filePath);

ValueTask<MemoryStream> RetrievePeopleWithPetsXmlFile(string filePath);
ValueTask<MemoryStream> RetrievePersonWithPetsXmlFile(string filePath);
}
}
8 changes: 4 additions & 4 deletions xChanger.Api/Brokers/Sheets/SheetBroker.PersonXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace xChanger.Api.Brokers.Sheets
{
public partial class SheetBroker
{
public async ValueTask SavePeopleWithPetsToXmlFile(
IEnumerable<Person> peopleWithPets,
public async ValueTask SavePersonWithPetsToXmlFile(
IEnumerable<Person> personWithPets,
string filePath)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Person>));
await using FileStream fileStream = new FileStream(filePath, FileMode.Create);
xmlSerializer.Serialize(fileStream, peopleWithPets);
xmlSerializer.Serialize(fileStream, personWithPets);
}

public async ValueTask<MemoryStream> RetrievePeopleWithPetsXmlFile(string filePath)
public async ValueTask<MemoryStream> RetrievePersonWithPetsXmlFile(string filePath)
{
byte[] fileBytes = await File.ReadAllBytesAsync(filePath);
return new MemoryStream(fileBytes);
Expand Down
15 changes: 13 additions & 2 deletions xChanger.Api/Brokers/Sheets/SheetBroker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@ public SheetBroker(IConfiguration configuration) =>

public void Dispose() { }

private string GetSheetLocationWithName() =>
this.configuration.GetConnectionString("SheetConnection");
private string GetSheetLocationWithName()
{
string folderPath = Path.Combine(Directory.GetCurrentDirectory(), "UploadedFiles");

if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}

string fileName = this.configuration.GetConnectionString("SheetConnection");
return Path.Combine(folderPath, fileName);
}


private FileInfo GetFileInfo() =>
new FileInfo(fileName: GetSheetLocationWithName());
Expand Down
65 changes: 65 additions & 0 deletions xChanger.Api/Controllers/PersonsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - -
// Copyright (c) Coalition of Good-Hearted Engineers
// Free to Use for Precise File Conversion
//- - - - - - - - - - - - - - - - - - - - - - - - - -

using Microsoft.AspNetCore.Mvc;
using RESTFulSense.Controllers;
using xChanger.Api.Models.Foundations.Persons.Exceptions;
using xChanger.Api.Models.Orchestrations;
using xChanger.Api.Services.Coordinations;
using xChanger.Api.Services.Orchestrations.Persons;
using xChanger.Api.Services.Processings.ExternalPersons;

namespace xChanger.Api.Controllers
{
public class PersonsController : RESTFulController
{
private readonly IExternalPersonInputProcessingService externalPersonInputProcessingService;
private readonly IExternalPersonWithPetsCoordinationService externalPersonWithPetsCoordinationService;
private readonly IPersonOrchestrationService personOrchestrationService;

public PersonsController(
IExternalPersonInputProcessingService externalPersonInputProcessingService,
IExternalPersonWithPetsCoordinationService externalPersonWithPetsCoordinationService,
IPersonOrchestrationService personOrchestrationService)
{
this.externalPersonInputProcessingService = externalPersonInputProcessingService;
this.externalPersonWithPetsCoordinationService = externalPersonWithPetsCoordinationService;
this.personOrchestrationService = personOrchestrationService;
}

[HttpPost("upload-and-store")]
public async ValueTask<ActionResult<List<PersonPet>>> UploadAndStorePerson(IFormFile file)
{
await this.externalPersonInputProcessingService.UploadExternalPersonFileAsync(file);

List<PersonPet> storedPerson =
await this.externalPersonWithPetsCoordinationService.CoordinateExternalPersonAsync();

return Ok(storedPerson);
}

[HttpGet("export/download")]
public async ValueTask<ActionResult> DownloadPersonWithPetsXml()
{
try
{
await this.personOrchestrationService.ExportAllPersonWithPetsToXmlAsync();

Stream xmlFileStream =
await this.personOrchestrationService.RetrievePersonWithPetsXmlFileAsync();

return File(xmlFileStream, "application/xml", "PersonWithPets.xml");
}
catch (PersonDependencyException personDependencyException)
{
return InternalServerError(personDependencyException.InnerException);
}
catch (PersonServiceException personServiceException)
{
return InternalServerError(personServiceException.InnerException);
}
}
}
}
Loading
Loading