Skip to content

Commit 0b03d04

Browse files
Merge pull request #18 from TransactionProcessing/task/#15_patapawapostpaiddevelopercontroller
Add developer controller
2 parents 5f66b3f + 3426c0b commit 0b03d04

4 files changed

Lines changed: 72 additions & 10 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System;
3+
using TestHosts.Database.TestBank;
4+
5+
namespace TestHosts.Controllers
6+
{
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using Database.PataPawa;
10+
using Newtonsoft.Json;
11+
using Shared.General;
12+
13+
[Route("api/developer")]
14+
[ApiController]
15+
public class DeveloperController : ControllerBase
16+
{
17+
private readonly Func<String, PataPawaContext> ContextResolver;
18+
19+
public DeveloperController(Func<String, PataPawaContext> contextResolver) {
20+
this.ContextResolver = contextResolver;
21+
}
22+
23+
[HttpPost]
24+
[Route("patapawapostpay/createbill")]
25+
public async Task<IActionResult> CreateHostConfiguration([FromBody] CreatePataPawaPostPayBill request,
26+
CancellationToken cancellationToken)
27+
{
28+
String connectionString = ConfigurationReader.GetConnectionString("PataPawaReadModel");
29+
PataPawaContext context = this.ContextResolver(connectionString);
30+
31+
Guid billIdentifier = Guid.NewGuid();
32+
33+
// TODO: check for a duplicate bill??
34+
35+
await context.PostPaidBills.AddAsync(new PostPaidBill {
36+
Amount = request.Amount,
37+
AccountNumber = request.AccountNumber,
38+
DueDate = request.DueDate,
39+
AccountName = request.AccountName,
40+
IsFullyPaid = false,
41+
PostPaidBillId = billIdentifier
42+
},
43+
cancellationToken);
44+
45+
await context.SaveChangesAsync(cancellationToken);
46+
47+
return this.Ok(new
48+
{
49+
billIdentifier
50+
});
51+
}
52+
}
53+
54+
public class CreatePataPawaPostPayBill
55+
{
56+
[JsonProperty("due_date")]
57+
public DateTime DueDate { get; set; }
58+
[JsonProperty("amount")]
59+
public Decimal Amount { get; set; }
60+
61+
[JsonProperty("account_number")]
62+
public String AccountNumber { get; set; }
63+
[JsonProperty("account_name")]
64+
public String AccountName { get; set; }
65+
66+
}
67+
}

TestHosts/TestHosts/Startup.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,15 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
138138
endpoints.MapControllers();
139139
});
140140

141-
// Configure an explicit none credential type for WSHttpBinding as it defaults to Windows which requires extra configuration in ASP.NET
142-
var myWSHttpBinding = new WSHttpBinding(SecurityMode.Transport);
143-
myWSHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
144-
145141
app.UseServiceModel(builder => {
146142
builder.AddService<PataPawaPostPayService>((serviceOptions) => {
147143
serviceOptions.DebugBehavior.IncludeExceptionDetailInFaults = true;
148144
})
149145
// Add a BasicHttpBinding at a specific endpoint
150146
.AddServiceEndpoint<PataPawaPostPayService, IPataPawaPostPayService>(new BasicHttpBinding(), "/PataPawaPostPayService/basichttp");
151-
// Add a WSHttpBinding with Transport Security for TLS
152-
//.AddServiceEndpoint<PataPawaPrePayService, IPataPawaPrePayService>(myWSHttpBinding, "/EchoService/WSHttps");
153-
});
147+
});
154148

155-
var serviceMetadataBehavior = app.ApplicationServices.GetRequiredService<CoreWCF.Description.ServiceMetadataBehavior>();
149+
ServiceMetadataBehavior serviceMetadataBehavior = app.ApplicationServices.GetRequiredService<CoreWCF.Description.ServiceMetadataBehavior>();
156150
serviceMetadataBehavior.HttpGetEnabled = true;
157151

158152

TestHosts/TestHosts/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
}
88
},
99
"ConnectionStrings": {
10-
"TestBankReadModel": "server=192.168.0.133,1433;user id=sa;password=sp1ttal;database=TestBankReadModel"
10+
"TestBankReadModel": "server=192.168.0.133,1433;user id=sa;password=sp1ttal;database=TestBankReadModel",
11+
"PataPawaReadModel": "server=localhost;user id=sa;password=sp1ttal;database=PataPawaReadModel"
1112
},
1213
"AllowedHosts": "*"
1314
}

TestHosts/TestHosts/hosting.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"urls": "http://*:9000;https://*:9001"
2+
"urls": "http://*:9000"
33
}

0 commit comments

Comments
 (0)