Skip to content

Commit 5d3762b

Browse files
Merge pull request #273 from TransactionProcessing/task/#254_pos_emulator
First Cut of Merchant Pos
2 parents c08ffb9 + fd03f16 commit 5d3762b

27 files changed

Lines changed: 1721 additions & 14 deletions

.github/workflows/createrelease.yml

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ jobs:
2828
run: |
2929
dotnet restore TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}
3030
dotnet restore TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}
31+
dotnet restore TransactionProcessing.MerchantPos/TransactionProcessing.MerchantPos.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}
3132
3233
- name: Build Code
3334
run: |
3435
dotnet build TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI.sln --configuration Release
36+
dotnet build TransactionProcessor.MerchantPos/TransactionProcessor.MerchantPos.sln --configuration Release
3537
3638
- name: Publish API
3739
run: |
3840
dotnet publish "TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI.csproj" --configuration Release --output TransactionProcessor.HealthChecksUI/publishOutput -r win-x64 --self-contained
39-
41+
dotnet publish "TransactionProcessor.MerchantPos/TransactionProcessor.MerchantPos/TransactionProcessor.MerchantPos.csproj" --configuration Release --output TransactionProcessor.MerchantPos/publishOutput -r win-x64 --self-contained
42+
4043
- name: Build Release Package (Health Check UI)
4144
run: |
4245
cd /home/runner/work/SupportTools/SupportTools/TransactionProcessor.HealthChecksUI/publishOutput
@@ -48,6 +51,18 @@ jobs:
4851
with:
4952
name: healthchecksui
5053
path: /home/runner/work/SupportTools/SupportTools/TransactionProcessor.HealthChecksUI/healthchecksui.zip
54+
55+
- name: Build Release Package (Merchant Pos)
56+
run: |
57+
cd /home/runner/work/SupportTools/SupportTools/TransactionProcessor.MerchantPos/publishOutput
58+
zip -r ../merchantpos.zip ./*
59+
echo "Zip file created at: $(realpath ../merchantpos.zip)"
60+
61+
- name: Upload the artifact (Merchant Pos)
62+
uses: actions/upload-artifact@v4.4.0
63+
with:
64+
name: merchantpos
65+
path: /home/runner/work/SupportTools/SupportTools/TransactionProcessor.MerchantPos/merchantpos.zip
5166

5267
deploystaging:
5368
runs-on: [stagingserver, windows]
@@ -61,7 +76,7 @@ jobs:
6176
with:
6277
name: healthchecksui
6378

64-
- name: Remove existing Windows service
79+
- name: Remove existing Windows service (Health Check UI)
6580
run: |
6681
$serviceName = "Transaction Processing - Health Checks UI"
6782
# Check if the service exists
@@ -70,18 +85,39 @@ jobs:
7085
sc.exe delete $serviceName
7186
}
7287
73-
- name: Unzip the files
88+
- name: Unzip the files (Health Check UI)
7489
run: |
7590
Expand-Archive -Path healthchecksui.zip -DestinationPath "C:\txnproc\transactionprocessing\healthchecksui" -Force
7691
77-
- name: Install as a Windows service
92+
- name: Install as a Windows service (Health Check UI)
7893
run: |
7994
$serviceName = "Transaction Processing - Health Checks UI"
8095
$servicePath = "C:\txnproc\transactionprocessing\healthchecksui\TransactionProcessor.HealthChecksUI.exe"
8196
8297
New-Service -Name $serviceName -BinaryPathName $servicePath -Description $serviceName -DisplayName $serviceName -StartupType Automatic
83-
Start-Service -Name $serviceName
98+
Start-Service -Name $serviceName
99+
100+
- name: Remove existing Windows service (Merchant Pos)
101+
run: |
102+
$serviceName = "Transaction Processing - Merchant Pos"
103+
# Check if the service exists
104+
if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
105+
Stop-Service -Name $serviceName
106+
sc.exe delete $serviceName
107+
}
108+
109+
- name: Unzip the files (Merchant Pos)
110+
run: |
111+
Expand-Archive -Path merchantpos.zip -DestinationPath "C:\txnproc\transactionprocessing\merchantpos" -Force
84112
113+
- name: Install as a Windows service (Merchant Pos)
114+
run: |
115+
$serviceName = "Transaction Processing - Merchant Pos"
116+
$servicePath = "C:\txnproc\transactionprocessing\merchantpos\TransactionProcessor.MerchantPos.exe"
117+
118+
New-Service -Name $serviceName -BinaryPathName $servicePath -Description $serviceName -DisplayName $serviceName -StartupType Automatic
119+
Start-Service -Name $serviceName
120+
85121
deployproduction:
86122
runs-on: [productionserver, windows]
87123
needs: [build, deploystaging]
@@ -94,7 +130,7 @@ jobs:
94130
with:
95131
name: healthchecksui
96132

97-
- name: Remove existing Windows service
133+
- name: Remove existing Windows service (Health Check UI)
98134
run: |
99135
$serviceName = "Transaction Processing - Health Checks UI"
100136
# Check if the service exists
@@ -103,14 +139,35 @@ jobs:
103139
sc.exe delete $serviceName
104140
}
105141
106-
- name: Unzip the files
142+
- name: Unzip the files (Health Check UI)
107143
run: |
108144
Expand-Archive -Path healthchecksui.zip -DestinationPath "C:\txnproc\transactionprocessing\healthchecksui" -Force
109145
110-
- name: Install as a Windows service
146+
- name: Install as a Windows service (Health Check UI)
111147
run: |
112148
$serviceName = "Transaction Processing - Health Checks UI"
113149
$servicePath = "C:\txnproc\transactionprocessing\healthchecksui\TransactionProcessor.HealthChecksUI.exe"
114150
115151
New-Service -Name $serviceName -BinaryPathName $servicePath -Description $serviceName -DisplayName $serviceName -StartupType Automatic
116-
Start-Service -Name $serviceName
152+
Start-Service -Name $serviceName
153+
154+
- name: Remove existing Windows service (Merchant Pos)
155+
run: |
156+
$serviceName = "Transaction Processing - Merchant Pos"
157+
# Check if the service exists
158+
if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
159+
Stop-Service -Name $serviceName
160+
sc.exe delete $serviceName
161+
}
162+
163+
- name: Unzip the files (Merchant Pos)
164+
run: |
165+
Expand-Archive -Path merchantpos.zip -DestinationPath "C:\txnproc\transactionprocessing\merchantpos" -Force
166+
167+
- name: Install as a Windows service (Merchant Pos)
168+
run: |
169+
$serviceName = "Transaction Processing - Merchant Pos"
170+
$servicePath = "C:\txnproc\transactionprocessing\merchantpos\TransactionProcessor.MerchantPos.exe"
171+
172+
New-Service -Name $serviceName -BinaryPathName $servicePath -Description $serviceName -DisplayName $serviceName -StartupType Automatic
173+
Start-Service -Name $serviceName

.github/workflows/pullrequest.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ jobs:
2525
run: |
2626
dotnet restore TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}
2727
dotnet restore TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}
28+
dotnet restore TransactionProcessing.MerchantPos/TransactionProcessing.MerchantPos.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}
29+
2830
2931
- name: Build Code
3032
run: |
3133
dotnet build TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI.sln --configuration Release
3234
dotnet build TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.sln --configuration Release
35+
dotnet build TransactionProcessing.MerchantPos/TransactionProcessing.MerchantPos.sln --configuration Release

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,6 @@ MigrationBackup/
352352
.ionide/
353353
/TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI/appsettings.development.json
354354
/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/appsettings.development.json
355+
/TransactionProcessing.MerchantPos/merchant.db
356+
/TransactionProcessing.MerchantPos/merchant.db-shm
357+
/TransactionProcessing.MerchantPos/merchant.db-wal
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.ComponentModel.DataAnnotations.Schema;
3+
4+
namespace MerchantPos.EF.Models
5+
{
6+
public class Merchant
7+
{
8+
[Key]
9+
public Guid MerchantId { get; set; }
10+
public String MerchantName { get; set; }
11+
public Decimal Balance { get; set; }
12+
public DateTime LastEndOfDayDateTime { get; set; }
13+
public DateTime LastLogonDateTime { get; set; }
14+
public Int32 TransactionNumber { get; set; }
15+
}
16+
17+
public class OperatorTotal
18+
{
19+
[Key]
20+
public int Id { get; set; }
21+
public Guid MerchantId { get; set; }
22+
public Guid OperatorId { get; set; }
23+
public Guid ContractId { get; set; }
24+
public Decimal Total { get; set; }
25+
public Int32 TotalCount { get; set; }
26+
}
27+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
using MerchantPos.EF.Models;
2+
using Microsoft.EntityFrameworkCore;
3+
4+
namespace MerchantPos.EF.Persistence
5+
{
6+
public interface IEfRepository
7+
{
8+
Task<List<Merchant>> GetAllMerchants();
9+
Task<Decimal> GetBalance(Guid merchantId);
10+
Task<Merchant> CreateMerchantRecord(Guid merchantId, String merchantName);
11+
Task UpdateBalance(Guid merchantId, String merchantName, Decimal balance);
12+
Task UpdateLastEndOfDay(Guid merchantId, String merchantName, DateTime lastEndOfDayDateTime);
13+
Task UpdateLastLogon(Guid merchantId, String merchantName, DateTime lastLogonDateTime);
14+
Task UpdateTotals(Guid merchantId, Guid operatorId, Guid contractId, Decimal amount);
15+
Task<List<OperatorTotal>> GetTotals(Guid merchantId);
16+
Task ClearTotals(Guid merchantId);
17+
Task<Merchant> GetMerchant(Guid merchantId);
18+
19+
Task IncrementTransactionNumber(Guid merchantId, String merchantName);
20+
}
21+
22+
public class EfRepository : IEfRepository
23+
{
24+
private readonly MerchantDbContext _db;
25+
26+
public EfRepository(MerchantDbContext db)
27+
{
28+
_db = db;
29+
}
30+
31+
public async Task<Merchant> CreateMerchantRecord(Guid merchantId,
32+
String merchantName) {
33+
Merchant merchant = new Merchant();
34+
merchant.MerchantId = merchantId;
35+
merchant.MerchantName = merchantName;
36+
merchant.Balance = 0;
37+
merchant.TransactionNumber = 0;
38+
merchant.LastEndOfDayDateTime = DateTime.MinValue;
39+
merchant.LastLogonDateTime = DateTime.MinValue;
40+
_db.Merchants.Add(merchant);
41+
await _db.SaveChangesAsync();
42+
return merchant;
43+
}
44+
45+
public async Task UpdateBalance(Guid merchantId,String merchantName, Decimal balance)
46+
{
47+
Merchant? entry = await this.GetMerchant(merchantId);
48+
49+
if (entry == null) {
50+
entry = await this.CreateMerchantRecord(merchantId, merchantName);
51+
}
52+
53+
entry.MerchantName = merchantName;
54+
entry.Balance = balance;
55+
56+
await _db.SaveChangesAsync();
57+
}
58+
59+
public async Task<Merchant?> GetMerchant(Guid merchantId)
60+
{
61+
return await _db.Merchants.FindAsync(merchantId);
62+
}
63+
64+
public async Task IncrementTransactionNumber(Guid merchantId,
65+
String merchantName) {
66+
Merchant? entry = await this.GetMerchant(merchantId);
67+
68+
if (entry == null)
69+
{
70+
entry = await this.CreateMerchantRecord(merchantId, merchantName);
71+
}
72+
73+
Int32 nextTransactionNumber = entry.TransactionNumber + 1;
74+
if (nextTransactionNumber == 9999) {
75+
nextTransactionNumber = 1;
76+
}
77+
entry.TransactionNumber = nextTransactionNumber;
78+
await _db.SaveChangesAsync();
79+
}
80+
81+
public async Task UpdateLastEndOfDay(Guid merchantId, String merchantName, DateTime lastEndOfDayDateTime)
82+
{
83+
Merchant? entry = await this.GetMerchant(merchantId);
84+
85+
if (entry == null)
86+
{
87+
entry = await this.CreateMerchantRecord(merchantId, merchantName);
88+
}
89+
entry.LastEndOfDayDateTime = lastEndOfDayDateTime;
90+
91+
await _db.SaveChangesAsync();
92+
}
93+
94+
public async Task UpdateLastLogon(Guid merchantId,
95+
String merchantName,
96+
DateTime lastLogonDateTime) {
97+
Merchant? entry = await this.GetMerchant(merchantId);
98+
99+
if (entry == null)
100+
{
101+
entry = await this.CreateMerchantRecord(merchantId, merchantName);
102+
}
103+
entry.LastLogonDateTime = lastLogonDateTime;
104+
105+
await _db.SaveChangesAsync();
106+
}
107+
108+
109+
public async Task<List<Merchant>> GetAllMerchants() {
110+
var entries = await _db.Merchants.ToListAsync();
111+
return entries.ToList();
112+
}
113+
114+
public async Task<decimal> GetBalance(Guid merchantId)
115+
{
116+
Merchant? entry = await this.GetMerchant(merchantId);
117+
return entry?.Balance ?? 0;
118+
}
119+
120+
public async Task<DateTime> GetLastEndOfDay(Guid merchantId)
121+
{
122+
Merchant? entry = await this.GetMerchant(merchantId);
123+
return entry?.LastEndOfDayDateTime ?? DateTime.MinValue;
124+
}
125+
126+
public async Task UpdateTotals(Guid merchantId, Guid operatorId, Guid contractId, decimal amount)
127+
{
128+
OperatorTotal? entry = await _db.OperatorTotals
129+
.SingleOrDefaultAsync(o => o.MerchantId == merchantId && o.OperatorId == operatorId
130+
&& o.ContractId == contractId);
131+
132+
if (entry == null)
133+
{
134+
entry = new OperatorTotal
135+
{
136+
MerchantId = merchantId,
137+
OperatorId = operatorId,
138+
ContractId = contractId,
139+
Total = amount
140+
};
141+
_db.OperatorTotals.Add(entry);
142+
}
143+
else
144+
{
145+
entry.Total += amount;
146+
}
147+
148+
await _db.SaveChangesAsync();
149+
}
150+
151+
public async Task<List<OperatorTotal>> GetTotals(Guid merchantId)
152+
{
153+
return await _db.OperatorTotals
154+
.Where(o => o.MerchantId == merchantId)
155+
.ToListAsync();
156+
}
157+
158+
public async Task ClearTotals(Guid merchantId)
159+
{
160+
IQueryable<OperatorTotal> rows = _db.OperatorTotals.Where(o => o.MerchantId == merchantId);
161+
_db.OperatorTotals.RemoveRange(rows);
162+
await _db.SaveChangesAsync();
163+
}
164+
}
165+
}
166+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using MerchantPos.EF.Models;
3+
4+
namespace MerchantPos.EF.Persistence
5+
{
6+
public class MerchantDbContext : DbContext
7+
{
8+
public MerchantDbContext(DbContextOptions<MerchantDbContext> opts) : base(opts) { }
9+
10+
public DbSet<Merchant> Merchants { get; set; }
11+
public DbSet<OperatorTotal> OperatorTotals { get; set; }
12+
13+
protected override void OnModelCreating(ModelBuilder modelBuilder)
14+
{
15+
modelBuilder.Entity<Merchant>().HasKey(m => m.MerchantId);
16+
modelBuilder.Entity<OperatorTotal>().HasIndex(o => new { o.MerchantId, o.OperatorId });
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)