Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/external_api_integration' into e…
Browse files Browse the repository at this point in the history
…xternal_api
  • Loading branch information
an2508374 committed Jan 24, 2024
2 parents 0744541 + d3bccc2 commit b7fb5c4
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,56 @@ public class CreateOrder: ICommand
{
public Guid OrderId { get; }
public Guid CustomerId { get; }
public ParcelDto Parcel { get; }
public string SourceStreet { get; }
public string SourceBuildingNumber { get; }
public string SourceApartmentNumber { get; }
public string SourceCity { get; }
public string SourceZipCode { get; }
public string SourceCountry { get; }
public string DestinationStreet { get; }
public string DestinationBuildingNumber { get; }
public string DestinationApartmentNumber { get; }
public string DestinationCity { get; }
public string DestinationZipCode { get; }
public string DestinationCountry { get; }
public double Price { get; }
public double Width { get; }
public double Height { get; }
public double Depth { get; }
public double Weight { get; }
public DateTime DeliveryDate { get; }
public string Priority { get; }
public bool AtWeekend { get; }
public string Name { get; }
public string Email { get; }

public CreateOrder(Guid orderId, Guid customerId, ParcelDto parcel, string name, string email)
public CreateOrder(Guid orderId, Guid customerId, string sourceStreet, string sourceBuildingNumber, string sourceApartmentNumber, string sourceCity, string sourceZipCode, string sourceCountry, string destinationStreet, string destinationBuildingNumber, string destinationApartmentNumber, string destinationCity, string destinationZipCode, string destinationCountry, double price, double width, double height, double depth, double weight, DateTime deliveryDate, string priority, bool atWeekend, string name, string email)
{
OrderId = orderId;
CustomerId = customerId;
Parcel = parcel;
SourceStreet = sourceStreet;
SourceBuildingNumber = sourceBuildingNumber;
SourceApartmentNumber = sourceApartmentNumber;
SourceCity = sourceCity;
SourceZipCode = sourceZipCode;
SourceCountry = sourceCountry;
DestinationStreet = destinationStreet;
DestinationBuildingNumber = destinationBuildingNumber;
DestinationApartmentNumber = destinationApartmentNumber;
DestinationCity = destinationCity;
DestinationZipCode = destinationZipCode;
DestinationCountry = destinationCountry;
DestinationCity = destinationCity;
DestinationZipCode = destinationZipCode;
DestinationCountry = destinationCountry;
Price = price;
Width = width;
Height = height;
Depth = depth;
Weight = weight;
DeliveryDate = deliveryDate;
Priority = priority;
AtWeekend = atWeekend;
Name = name;
Email = email;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SwiftParcel.ExternalAPI.Baronomat.Application.DTO;

using SwiftParcel.ExternalAPI.Baronomat.Core.Entities;
public class OrderAddressDto
{
public int id { get; set; }
Expand All @@ -18,7 +20,10 @@ public OrderAddressDto(AddressDto address, string name, string email)
{
id = 0;
firstName = name.Split(' ')[0];
surname = name.Split(' ')[1];
if (name.Split(' ').Length > 1)
surname = name.Split(' ')[1];
else
surname = firstName;
country = address.Country;
city = address.City;
street = address.Street;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ public class OrderRequestDto

public OrderRequestDto(CreateOrder command)
{
SenderAddress = new OrderAddressDto(command.Parcel.Source, command.Name, command.Email);
RecipientAddress = new OrderAddressDto(command.Parcel.Destination, command.Name, command.Email);
PriceCents = (int)(command.Parcel.CalculatedPrice * 100);
ShipmentWidthMm = (int)(command.Parcel.Width * 1000);
ShipmentHeightMm = (int)(command.Parcel.Height * 1000);
ShipmentLengthMm = (int)(command.Parcel.Depth * 1000);
ShipmentWeightMg = (int)(command.Parcel.Weight * 1000);
DeliveryDate = command.Parcel.DeliveryDate.ToString("yyyy-MM-dd");
HighPriority = command.Parcel.Priority == "High";
WeekendDelivery = command.Parcel.AtWeekend;
var source = new AddressDto(command.SourceStreet, command.SourceBuildingNumber, command.SourceApartmentNumber, command.SourceCity, command.SourceZipCode, command.SourceCountry);
var destination = new AddressDto(command.DestinationStreet, command.DestinationBuildingNumber, command.DestinationApartmentNumber, command.DestinationCity, command.DestinationZipCode, command.DestinationCountry);
SenderAddress = new OrderAddressDto(source, command.Name, command.Email);
RecipientAddress = new OrderAddressDto(destination, command.Name, command.Email);
PriceCents = (int)(command.Price * 100);
ShipmentWidthMm = (int)(command.Width * 1000);
ShipmentHeightMm = (int)(command.Height * 1000);
ShipmentLengthMm = (int)(command.Depth * 1000);
ShipmentWeightMg = (int)(command.Weight * 1000);
DeliveryDate = command.DeliveryDate.ToString("yyyy-MM-dd");
HighPriority = command.Priority == "High";
WeekendDelivery = command.AtWeekend;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public object Map(Exception exception, object message)
},
OffersServiceConnectionException ex => message switch
{
CreateOrder m => new CreateOrderRejected(m.OrderId, m.CustomerId, m.Parcel.Id, ex.Message, ex.Code),
CreateOrder m => new CreateOrderRejected(m.OrderId, m.CustomerId, m.OrderId, ex.Message, ex.Code),
_ => null
},
OffersServiceException ex => message switch
{
CreateOrder m => new CreateOrderRejected(m.OrderId, m.CustomerId, m.Parcel.Id, ex.Message, ex.Code),
CreateOrder m => new CreateOrderRejected(m.OrderId, m.CustomerId, m.OrderId, ex.Message, ex.Code),
_ => null
},
OfferNotFoundException ex => message switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,52 @@ public class CreateOrderBaronomat: ICommand
{
public Guid OrderId { get; }
public Guid CustomerId { get; }
public ParcelDto Parcel { get; }
public string SourceStreet { get; }
public string SourceBuildingNumber { get; }
public string SourceApartmentNumber { get; }
public string SourceCity { get; }
public string SourceZipCode { get; }
public string SourceCountry { get; }
public string DestinationStreet { get; }
public string DestinationBuildingNumber { get; }
public string DestinationApartmentNumber { get; }
public string DestinationCity { get; }
public string DestinationZipCode { get; }
public string DestinationCountry { get; }
public double Price { get; }
public double Width { get; }
public double Height { get; }
public double Depth { get; }
public double Weight { get; }
public DateTime DeliveryDate { get; }
public string Priority { get; }
public bool AtWeekend { get; }
public string Name { get; }
public string Email { get; }

public CreateOrderBaronomat(CreateOrder command, ParcelDto parcel)
{
OrderId = command.OrderId;
CustomerId = command.CustomerId;
Parcel = parcel;
SourceStreet = parcel.Source.Street;
SourceBuildingNumber = parcel.Source.BuildingNumber;
SourceApartmentNumber = parcel.Source.ApartmentNumber;
SourceCity = parcel.Source.City;
SourceZipCode = parcel.Source.ZipCode;
SourceCountry = parcel.Source.Country;
DestinationStreet = parcel.Destination.Street;
DestinationBuildingNumber = parcel.Destination.BuildingNumber;
DestinationApartmentNumber = parcel.Destination.ApartmentNumber;
DestinationCity = parcel.Destination.City;
DestinationZipCode = parcel.Destination.ZipCode;
DestinationCountry = parcel.Destination.Country;
Width = parcel.Width;
Height = parcel.Height;
Depth = parcel.Depth;
Weight = parcel.Weight;
DeliveryDate = parcel.DeliveryDate;
Priority = parcel.Priority.ToString();
AtWeekend = parcel.AtWeekend;
Name = command.Name;
Email = command.Email;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public async Task HandleAsync(CreateOrderBaronomat command, CancellationToken ca
var response = await _baronomatApiServiceClient.PostOfferAsync(command);
if (response == null)
{
throw new LecturerApiServiceConnectionException();
throw new BaronomatApiServiceConnectionException();
}
if (!response.IsSuccessStatusCode)
{
throw new LecturerApiServiceException(response.ReasonPhrase);
throw new BaronomatApiServiceException(response.ReasonPhrase);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SwiftParcel.Services.Orders.Application.Exceptions
{
public class BaronomatApiServiceConnectionException: AppException
{
public override string Code { get; } = "baronomat_api_service_connection_error";
public BaronomatApiServiceConnectionException(): base("Baronomat api service connection error.")
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SwiftParcel.Services.Orders.Application.Exceptions
{
public class BaronomatApiServiceException: AppException
{
public override string Code { get; } = "baronomat_api_service_error";
public string ReasonPhrase { get; }
public BaronomatApiServiceException(string reasonPhrase): base($"Baronomat api service error, reason: {reasonPhrase}.")
{
ReasonPhrase = reasonPhrase;
}
}
}

0 comments on commit b7fb5c4

Please sign in to comment.