-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from SaintAngeLs/external_api_integration
Full integration with external API
- Loading branch information
Showing
115 changed files
with
1,838 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...Lecturer.Application/SwiftParcel.ExternalAPI.Lecturer.Application/Commands/CancelOrder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Convey.CQRS.Commands; | ||
|
||
namespace SwiftParcel.ExternalAPI.Lecturer.Application.Commands | ||
{ | ||
public class CancelOrder: ICommand | ||
{ | ||
public Guid OrderId { get; set; } | ||
public CancelOrder(Guid orderId) | ||
{ | ||
OrderId = orderId; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ecturer.Application/SwiftParcel.ExternalAPI.Lecturer.Application/Commands/ConfirmOrder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Convey.CQRS.Commands; | ||
|
||
namespace SwiftParcel.ExternalAPI.Lecturer.Application.Commands | ||
{ | ||
public class ConfirmOrder: ICommand | ||
{ | ||
public Guid OrderId { get; set; } | ||
public ConfirmOrder(Guid orderId) | ||
{ | ||
OrderId = orderId; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...Lecturer.Application/SwiftParcel.ExternalAPI.Lecturer.Application/Commands/CreateOrder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Convey.CQRS.Commands; | ||
using SwiftParcel.ExternalAPI.Lecturer.Core.Entities; | ||
|
||
namespace SwiftParcel.ExternalAPI.Lecturer.Application.Commands | ||
{ | ||
public class CreateOrder: ICommand | ||
{ | ||
public Guid OrderId { get; } | ||
public Guid CustomerId { get; } | ||
public Guid ParcelId { get; } | ||
public string Name { get; } | ||
public string Email { get; } | ||
public Address Address { get; } | ||
|
||
public CreateOrder(Guid orderId, Guid customerId, Guid parcelId, string name, string email, Address address) | ||
{ | ||
OrderId = orderId; | ||
CustomerId = customerId; | ||
ParcelId = parcelId; | ||
Name = name; | ||
Email = email; | ||
Address = address; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...tion/SwiftParcel.ExternalAPI.Lecturer.Application/Commands/Handlers/CancelOrderHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Convey.CQRS.Commands; | ||
using SwiftParcel.ExternalAPI.Lecturer.Application.Services.Clients; | ||
using SwiftParcel.ExternalAPI.Lecturer.Core.Repositories; | ||
using SwiftParcel.ExternalAPI.Lecturer.Application.Exceptions; | ||
using SwiftParcel.ExternalAPI.Lecturer.Core.Entities; | ||
|
||
namespace SwiftParcel.ExternalAPI.Lecturer.Application.Commands.Handlers | ||
{ | ||
public class CancelOrderHandler : ICommandHandler<CancelOrder> | ||
{ | ||
private readonly IIdentityManagerServiceClient _identityManagerServiceClient; | ||
private readonly IOfferSnippetRepository _offerSnippetRepository; | ||
private readonly IOffersServiceClient _officeServiceClient; | ||
|
||
public CancelOrderHandler(IIdentityManagerServiceClient identityManagerServiceClient, | ||
IOfferSnippetRepository offerSnippetRepository, IOffersServiceClient officeServiceClient) | ||
{ | ||
_identityManagerServiceClient = identityManagerServiceClient; | ||
_offerSnippetRepository = offerSnippetRepository; | ||
_officeServiceClient = officeServiceClient; | ||
} | ||
|
||
public async Task HandleAsync(CancelOrder command, CancellationToken cancellationToken) | ||
{ | ||
var offer = await _offerSnippetRepository.GetAsync(command.OrderId); | ||
if (offer is null) | ||
{ | ||
throw new OfferNotFoundException(command.OrderId); | ||
} | ||
if(offer.Status != OfferSnippetStatus.Approved) | ||
{ | ||
throw new OfferNotApprovedException(command.OrderId, offer.Status); | ||
} | ||
|
||
|
||
var token = await _identityManagerServiceClient.GetToken(); | ||
var response = await _officeServiceClient.DeleteCancelOffer(token, offer.OfferId.ToString()); | ||
if(response is null) | ||
{ | ||
throw new OffersServiceConnectionException(); | ||
} | ||
if(!response.IsSuccessStatusCode) | ||
{ | ||
throw new OffersServiceException(response.ReasonPhrase); | ||
} | ||
|
||
offer.Cancel(); | ||
await _offerSnippetRepository.UpdateAsync(offer); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ion/SwiftParcel.ExternalAPI.Lecturer.Application/Commands/Handlers/ConfirmOrderHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Convey.CQRS.Commands; | ||
using SwiftParcel.ExternalAPI.Lecturer.Application.Services.Clients; | ||
using SwiftParcel.ExternalAPI.Lecturer.Core.Repositories; | ||
using SwiftParcel.ExternalAPI.Lecturer.Application.Exceptions; | ||
using SwiftParcel.ExternalAPI.Lecturer.Core.Entities; | ||
|
||
namespace SwiftParcel.ExternalAPI.Lecturer.Application.Commands.Handlers | ||
{ | ||
public class ConfirmOrderHandler : ICommandHandler<ConfirmOrder> | ||
{ | ||
private readonly IIdentityManagerServiceClient _identityManagerServiceClient; | ||
private readonly IOfferSnippetRepository _offerSnippetRepository; | ||
private readonly IOffersServiceClient _officeServiceClient; | ||
|
||
public ConfirmOrderHandler(IIdentityManagerServiceClient identityManagerServiceClient, | ||
IOfferSnippetRepository offerSnippetRepository, IOffersServiceClient officeServiceClient) | ||
{ | ||
_identityManagerServiceClient = identityManagerServiceClient; | ||
_offerSnippetRepository = offerSnippetRepository; | ||
_officeServiceClient = officeServiceClient; | ||
} | ||
|
||
public async Task HandleAsync(ConfirmOrder command, CancellationToken cancellationToken) | ||
{ | ||
var offer = await _offerSnippetRepository.GetAsync(command.OrderId); | ||
if (offer is null) | ||
{ | ||
throw new OfferNotFoundException(command.OrderId); | ||
} | ||
if(offer.Status != OfferSnippetStatus.Approved) | ||
{ | ||
throw new OfferNotApprovedException(command.OrderId, offer.Status); | ||
} | ||
|
||
var token = await _identityManagerServiceClient.GetToken(); | ||
var response = await _officeServiceClient.PostConfirmOffer(token, offer.OfferId.ToString()); | ||
if(response is null) | ||
{ | ||
throw new OffersServiceConnectionException(); | ||
} | ||
if(!response.IsSuccessStatusCode) | ||
{ | ||
throw new OffersServiceException(response.ReasonPhrase); | ||
} | ||
|
||
offer.Confirm(); | ||
await _offerSnippetRepository.UpdateAsync(offer); | ||
} | ||
|
||
|
||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...tion/SwiftParcel.ExternalAPI.Lecturer.Application/Commands/Handlers/CreateOrderHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Convey.CQRS.Commands; | ||
using SwiftParcel.ExternalAPI.Lecturer.Application.Services.Clients; | ||
using SwiftParcel.ExternalAPI.Lecturer.Application.DTO; | ||
using SwiftParcel.ExternalAPI.Lecturer.Application.Exceptions; | ||
using SwiftParcel.ExternalAPI.Lecturer.Core.Repositories; | ||
using SwiftParcel.ExternalAPI.Lecturer.Core.Entities; | ||
|
||
namespace SwiftParcel.ExternalAPI.Lecturer.Application.Commands.Handlers | ||
{ | ||
public class CreateOrderHandler : ICommandHandler<CreateOrder> | ||
{ | ||
private readonly IIdentityManagerServiceClient _identityManagerServiceClient; | ||
private readonly IOffersServiceClient _offersServiceClient; | ||
private readonly IOfferSnippetRepository _offerSnippetRepository; | ||
|
||
public CreateOrderHandler(IIdentityManagerServiceClient identityManagerServiceClient, | ||
IOffersServiceClient offersServiceClient, IOfferSnippetRepository offerSnippetRepository) | ||
{ | ||
_identityManagerServiceClient = identityManagerServiceClient; | ||
_offersServiceClient = offersServiceClient; | ||
_offerSnippetRepository = offerSnippetRepository; | ||
} | ||
public async Task HandleAsync(CreateOrder command, CancellationToken cancellationToken) | ||
{ | ||
var token = await _identityManagerServiceClient.GetToken(); | ||
var response = await _offersServiceClient.PostAsync(token, new OfferRequestDto | ||
{ | ||
InquiryId = command.ParcelId, | ||
Name = command.Name, | ||
Email = command.Email, | ||
Address = new InquiryAddressDto | ||
{ | ||
HouseNumber = command.Address.BuildingNumber, | ||
ApartmentNumber = command.Address.ApartmentNumber, | ||
Street = command.Address.Street, | ||
City = command.Address.City, | ||
Country = command.Address.Country, | ||
ZipCode = command.Address.ZipCode | ||
} | ||
}); | ||
if(response == null) | ||
{ | ||
throw new OffersServiceConnectionException(); | ||
} | ||
if (!response.Response.IsSuccessStatusCode) | ||
{ | ||
throw new OffersServiceException(response.Response.ReasonPhrase); | ||
} | ||
|
||
var offerSnippet = new OfferSnippet(response.Result.OfferRequestId, null, command.CustomerId, | ||
response.Result.ValidTo, OfferSnippetStatus.WaitingForDecision); | ||
|
||
await _offerSnippetRepository.AddAsync(offerSnippet); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...alAPI.Lecturer.Application/SwiftParcel.ExternalAPI.Lecturer.Application/DTO/AddressDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using SwiftParcel.ExternalAPI.Lecturer.Core.Entities; | ||
|
||
namespace SwiftParcel.ExternalAPI.Lecturer.Application.DTO | ||
{ | ||
public class AddressDto | ||
{ | ||
public string Street { get; set; } | ||
public string BuildingNumber { get; set; } | ||
public string ApartmentNumber { get; set; } | ||
public string City { get; set; } | ||
public string ZipCode { get; set; } | ||
public string Country { get; set; } | ||
|
||
public AddressDto(string street, string buildingNumber, string apartmentNumber, string city, string zipCode, string country) | ||
{ | ||
Street = street; | ||
BuildingNumber = buildingNumber; | ||
ApartmentNumber = apartmentNumber; | ||
City = city; | ||
ZipCode = zipCode; | ||
Country = country; | ||
} | ||
|
||
public AddressDto(InquiryAddressDto address) | ||
{ | ||
Street = address.Street; | ||
BuildingNumber = address.HouseNumber; | ||
ApartmentNumber = address.ApartmentNumber; | ||
City = address.City; | ||
ZipCode = address.ZipCode; | ||
Country = address.Country; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...rnalAPI.Lecturer.Application/SwiftParcel.ExternalAPI.Lecturer.Application/DTO/OfferDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace SwiftParcel.ExternalAPI.Lecturer.Application.DTO | ||
{ | ||
public class OfferDto | ||
{ | ||
public Guid OfferId { get; set; } | ||
public DimensionDto Dimensions { get; set; } | ||
public InquiryAddressDto Source { get; set; } | ||
public InquiryAddressDto Destination { get; set; } | ||
public double Weight { get; set; } | ||
public string WeightUnit { get; set; } | ||
public DateTime PickupDate { get; set; } | ||
public DateTime DeliveryDate { get; set; } | ||
public DateTime ValidTo { get; set; } | ||
public bool DeliveryInWeekend { get; set; } | ||
public string Priority { get; set; } | ||
public bool VipPackage { get; set; } | ||
public List<PriceBreakDownItemDto> PriceBreakDown { get; set; } | ||
public double TotalPrice { get; set; } | ||
public string Currency { get; set; } | ||
public DateTime InquireDate { get; set; } | ||
public DateTime OfferRequestDate { get; set; } | ||
public DateTime DecisionDate { get; set; } | ||
public string OfferStatus { get; set; } | ||
public string BuyerName { get; set; } | ||
public InquiryAddressDto BuyerAddress { get; set; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
....Lecturer.Application/SwiftParcel.ExternalAPI.Lecturer.Application/DTO/OfferRequestDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace SwiftParcel.ExternalAPI.Lecturer.Application.DTO | ||
{ | ||
public class OfferRequestDto | ||
{ | ||
public Guid InquiryId { get; set; } | ||
public string Name { get; set; } | ||
public string Email { get; set; } | ||
public InquiryAddressDto Address { get; set; } | ||
} | ||
} |
Oops, something went wrong.