Skip to content
Merged
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
41 changes: 26 additions & 15 deletions TestHosts/TestHosts/Controllers/PataPawaPrePaidController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
using System.Threading;
using System.Threading.Tasks;

internal static class FormKeys {
internal const String Key = "key";
internal const String Meter = "meter";
internal const String Amount = "amount";
internal const String UserName = "username";
internal const String Password = "password";

Check failure on line 20 in TestHosts/TestHosts/Controllers/PataPawaPrePaidController.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

TestHosts/TestHosts/Controllers/PataPawaPrePaidController.cs#L20

Hardcoded passwords are a security risk.
}

internal static class Responses {
internal const String Success = "success";
}

[Route("api/patapawaprepay")]
[ApiController]
public class PataPawaPrePaidController : ControllerBase{
Expand Down Expand Up @@ -86,7 +98,7 @@
Database.PataPawa.Transaction CreateSuccessfulTransaction(){
return new Database.PataPawa.Transaction{
Status = 0,
Messaage = "success",
Messaage = Responses.Success,
Vendor = "support",
MeterNumber = meter.MeterNumber,
ResultCode = "elec000",
Expand Down Expand Up @@ -126,7 +138,7 @@
}

private VendResponse CreateVendResponse(Database.PataPawa.Transaction transaction){
VendResponse response = new VendResponse{
VendResponse response = new() {
status = transaction.Status,
msg = transaction.Messaage,
transaction = new Transaction{
Expand Down Expand Up @@ -166,24 +178,23 @@
}

private async Task<IActionResult> HandleBalanceRequest(IFormCollection requestForm, CancellationToken cancellationToken){
String username = requestForm["username"].ToString();
String key = requestForm["key"].ToString();
String meter = requestForm["meter"].ToString();
String username = requestForm[FormKeys.UserName].ToString();
String key = requestForm[FormKeys.Key].ToString();

using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);

PrePayUser user = await resolvedContext.Context.PrePayUsers.SingleOrDefaultAsync(u => u.UserName == username && u.Key == key, cancellationToken);

BalanceResponse response = new BalanceResponse{
BalanceResponse response = new() {
status = 0,
msg = "success",
msg = Responses.Success,
balance = user.Balance.ToString(),
};
return this.Ok(response);
}

private async Task<IActionResult> HandleLastVendRequest(RequestType xlatedRequestType, IFormCollection requestForm, CancellationToken cancellationToken){
String meter = requestForm["meter"].ToString();
String meter = requestForm[FormKeys.Meter].ToString();

(PrePayMeter meterDetails, IActionResult result) meterValidation = await this.ValidateMeterDetails(meter, cancellationToken);
if (meterValidation.result != null)
Expand Down Expand Up @@ -213,8 +224,8 @@
}

private async Task<IActionResult> HandleLoginRequest(IFormCollection requestForm, CancellationToken cancellationToken){
String username = requestForm["username"].ToString();
String password = requestForm["password"].ToString();
String username = requestForm[FormKeys.UserName].ToString();
String password = requestForm[FormKeys.Password].ToString();

using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);

Expand All @@ -230,31 +241,31 @@

LoginResponse response = new LoginResponse{
status = 0,
msg = "success",
msg = Responses.Success,
balance = user.Balance.ToString(),
key = user.Key,
};
return this.Ok(response);
}

private async Task<IActionResult> HandleMeterRequest(IFormCollection requestForm, CancellationToken cancellationToken){
String meter = requestForm["meter"].ToString();
String meter = requestForm[FormKeys.Meter].ToString();

(PrePayMeter meterDetails, IActionResult result) meterValidation = await this.ValidateMeterDetails(meter, cancellationToken);
if (meterValidation.result != null)
return meterValidation.result;

MeterResponse response = new() {
status = 0,
msg = "success",
msg = Responses.Success,
customerName = meterValidation.meterDetails.CustomerName
};
return this.Ok(response);
}

private async Task<IActionResult> HandleVendRequest(IFormCollection requestForm, CancellationToken cancellationToken){
String meter = requestForm["meter"].ToString();
String amount = requestForm["amount"].ToString();
String meter = requestForm[FormKeys.Meter].ToString();
String amount = requestForm[FormKeys.Amount].ToString();

(PrePayMeter meterDetails, IActionResult result) meterValidation = await this.ValidateMeterDetails(meter, cancellationToken);
if (meterValidation.result != null)
Expand Down
Loading