-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[diyuan] add FlightOrderRequest & Service Bus Queue
- Loading branch information
1 parent
0a9cb0c
commit 5a5011b
Showing
22 changed files
with
212 additions
and
65 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
TravelManagement.Migration/20211223150900_CreateFlightOrderRequestsTable.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 @@ | ||
using FluentMigrator; | ||
|
||
namespace TravelManagement.Migration | ||
{ | ||
[Migration(20211224150900)] | ||
public class CreateFlightOrderRequestsTable: FluentMigrator.Migration | ||
{ | ||
private const string TABLE_NAME = "flight_order_requests"; | ||
|
||
public override void Up() | ||
{ | ||
Create.Table(TABLE_NAME) | ||
.WithColumn("id").AsInt64().PrimaryKey().Identity() | ||
.WithColumn("user_id").AsInt64().NotNullable() | ||
.WithColumn("flight_number").AsString().NotNullable() | ||
.WithColumn("amount").AsDecimal().NotNullable() | ||
.WithColumn("departure_date").AsDateTime() | ||
.WithColumn("created_at").AsDateTime().NotNullable() | ||
.WithColumn("expired_at").AsDateTime().NotNullable(); | ||
} | ||
|
||
public override void Down() | ||
{ | ||
Delete.Table(TABLE_NAME); | ||
} | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
TravelManagement.Migration/20211223150900_CreateOrdersTable.cs
This file was deleted.
Oops, something went wrong.
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
19 changes: 19 additions & 0 deletions
19
TravelManagement.Test/ControllerFacts/FlightOrderControllerFact.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,19 @@ | ||
using System.Threading.Tasks; | ||
using TravelManagement.Application.Dtos; | ||
using TravelManagement.Infrastructure.Utils; | ||
using TravelManagement.Test.ControllerFactsSetup; | ||
using Xunit; | ||
|
||
namespace TravelManagement.Test.ControllerFacts | ||
{ | ||
public class FlightOrderControllerFact : ControllerFactBase | ||
{ | ||
[Fact] | ||
public async Task should_return_ok() | ||
{ | ||
var httpContent = RequestUtils.ToHttpContent(new CreateFlightOrderRequest()); | ||
var httpResponseMessage = await HttpClient.PostAsync("flight-orders", httpContent); | ||
httpResponseMessage.EnsureSuccessStatusCode(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
7 changes: 7 additions & 0 deletions
7
TravelManagement/Application/Dtos/CreateFlightOrderRequest.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,7 @@ | ||
namespace TravelManagement.Application.Dtos | ||
{ | ||
public class CreateFlightOrderRequest | ||
{ | ||
|
||
} | ||
} |
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,9 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace TravelManagement.Application.Providers | ||
{ | ||
public interface IMessageSender | ||
{ | ||
Task Send(object messageBody); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
TravelManagement/Application/Providers/ServiceBusMessageSender.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 System; | ||
using System.Threading.Tasks; | ||
using Azure.Messaging.ServiceBus; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
|
||
namespace TravelManagement.Application.Providers | ||
{ | ||
public class ServiceBusMessageSender : IMessageSender | ||
{ | ||
private readonly ServiceBusSender _sender; | ||
private readonly ILogger<ServiceBusMessageSender> _logger; | ||
|
||
public ServiceBusMessageSender(ServiceBusSender sender, ILogger<ServiceBusMessageSender> logger) | ||
{ | ||
_sender = sender; | ||
_logger = logger; | ||
} | ||
|
||
public async Task Send(object messageBody) | ||
{ | ||
try | ||
{ | ||
var serviceBusMessage = new ServiceBusMessage(JsonConvert.SerializeObject(messageBody)); | ||
await _sender.SendMessageAsync(serviceBusMessage); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(ex, $"Fail to send messages to Azure Service Bus: {JsonConvert.SerializeObject(messageBody)}"); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
TravelManagement/Application/Services/FlightOrderService.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 TravelManagement.Application.Services | ||
{ | ||
public class FlightOrderService | ||
{ | ||
public long CreateFlightOrderRequest() | ||
{ | ||
return 1L; | ||
} | ||
} | ||
} |
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,15 @@ | ||
using System; | ||
|
||
namespace TravelManagement.Domain.Models | ||
{ | ||
public class FlightOrderRequest | ||
{ | ||
public virtual long Id { get; set; } | ||
public virtual long UserId { get; set; } | ||
public virtual string FlightNumber { get; set; } | ||
public virtual decimal Amount { get; set; } | ||
public virtual DateTime DepartureDate { get; set; } | ||
public virtual DateTime CreatedAt { get; set; } | ||
public virtual DateTime ExpiredAt { get; set; } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...t/Domain/Repositories/IOrderRepository.cs → ...sitories/IFlightOrderRequestRepository.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
10 changes: 10 additions & 0 deletions
10
TravelManagement/Domain/Services/FlightOrderDomainService.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 TravelManagement.Domain.Services | ||
{ | ||
public class FlightOrderDomainService | ||
{ | ||
public long CreateFlightOrderRequest() | ||
{ | ||
return 1L; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
TravelManagement/Infrastructure/Mappings/FlightOrderRequestMapping.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,15 @@ | ||
using FluentNHibernate.Mapping; | ||
using TravelManagement.Domain.Models; | ||
|
||
namespace TravelManagement.Infrastructure.Mappings | ||
{ | ||
public class FlightOrderRequestMapping : ClassMap<FlightOrderRequest> | ||
{ | ||
public FlightOrderRequestMapping() | ||
{ | ||
Table("flight_order_requests"); | ||
Id(o => o.Id).GeneratedBy.Identity(); | ||
Map(f => f.UserId).Column("user_id").Not.Nullable(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Net.Http; | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
|
||
namespace TravelManagement.Infrastructure.Utils | ||
{ | ||
public static class RequestUtils | ||
{ | ||
public static StringContent ToHttpContent(object? request) | ||
{ | ||
var serializeRequest = JsonConvert.SerializeObject(request); | ||
return new StringContent(serializeRequest, Encoding.UTF8, "application/json"); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
TravelManagement/Interface/Controllers/FlightOrderController.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,30 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Mvc; | ||
using TravelManagement.Application.Dtos; | ||
using TravelManagement.Application.Providers; | ||
using TravelManagement.Domain.Models; | ||
|
||
namespace TravelManagement.Interface.Controllers | ||
{ | ||
[ApiController] | ||
public class FlightOrderController : ControllerBase | ||
{ | ||
private readonly IMessageSender _messageSender; | ||
|
||
public FlightOrderController(IMessageSender messageSender) | ||
{ | ||
_messageSender = messageSender; | ||
} | ||
|
||
[HttpPost("flight-orders")] | ||
public OkResult CreateFlightOrderRequest(CreateFlightOrderRequest request) | ||
{ | ||
_messageSender.Send(new FlightOrderRequest | ||
{ | ||
Amount = new decimal(123.45), | ||
DepartureDate = DateTime.UtcNow | ||
}); | ||
return Ok(); | ||
} | ||
} | ||
} |
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
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