diff --git a/.github/workflows/stable-release.yml b/.github/workflows/stable-release.yml
index 0287c75..a103e4c 100644
--- a/.github/workflows/stable-release.yml
+++ b/.github/workflows/stable-release.yml
@@ -10,34 +10,34 @@ jobs:
runs-on: ubuntu-latest
steps:
- - name: Checkout
- uses: actions/checkout@v2
- with:
- fetch-depth: 0
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
- - name: Docker meta
- id: meta
- uses: docker/metadata-action@v3
- with:
- images: etherna/etherna-credit
- tags: |
- type=semver,pattern=v{{major}}
- type=semver,pattern=v{{major}}.{{minor}}
- type=semver,pattern=v{{version}}
+ - name: Docker meta
+ id: meta
+ uses: docker/metadata-action@v5
+ with:
+ images: etherna/etherna-credit
+ tags: |
+ type=semver,pattern=v{{major}}
+ type=semver,pattern=v{{major}}.{{minor}}
+ type=semver,pattern=v{{version}}
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v1
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v3
- - name: Login to DockerHub
- uses: docker/login-action@v1
- with:
- username: ${{ secrets.DOCKER_USERNAME }}
- password: ${{ secrets.DOCKER_PASSWORD }}
+ - name: Login to DockerHub
+ uses: docker/login-action@v3
+ with:
+ username: ${{ secrets.DOCKER_USERNAME }}
+ password: ${{ secrets.DOCKER_PASSWORD }}
- - name: Build and push
- uses: docker/build-push-action@v2
- with:
- context: .
- push: true
- tags: ${{ steps.meta.outputs.tags }}
- labels: ${{ steps.meta.outputs.labels }}
\ No newline at end of file
+ - name: Build and push
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ push: true
+ tags: ${{ steps.meta.outputs.tags }}
+ labels: ${{ steps.meta.outputs.labels }}
\ No newline at end of file
diff --git a/.github/workflows/unstable-release.yml b/.github/workflows/unstable-release.yml
index 087a8dc..9715538 100644
--- a/.github/workflows/unstable-release.yml
+++ b/.github/workflows/unstable-release.yml
@@ -3,41 +3,39 @@ name: Unstable release on Docker Hub
on:
push:
branches:
- - dev
- - 'hotfix/**'
- - 'release/**'
+ - dev
jobs:
build:
runs-on: ubuntu-latest
steps:
- - name: Checkout
- uses: actions/checkout@v2
- with:
- fetch-depth: 0
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
- - name: Docker meta
- id: meta
- uses: docker/metadata-action@v3
- with:
- images: etherna/etherna-credit
- tags: |
- type=ref,event=branch
+ - name: Docker meta
+ id: meta
+ uses: docker/metadata-action@v5
+ with:
+ images: etherna/etherna-credit
+ tags: |
+ type=ref,event=branch
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v1
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v3
- - name: Login to DockerHub
- uses: docker/login-action@v1
- with:
- username: ${{ secrets.DOCKER_USERNAME }}
- password: ${{ secrets.DOCKER_PASSWORD }}
+ - name: Login to DockerHub
+ uses: docker/login-action@v3
+ with:
+ username: ${{ secrets.DOCKER_USERNAME }}
+ password: ${{ secrets.DOCKER_PASSWORD }}
- - name: Build and push
- uses: docker/build-push-action@v2
- with:
- context: .
- push: true
- tags: ${{ steps.meta.outputs.tags }}
- labels: ${{ steps.meta.outputs.labels }}
\ No newline at end of file
+ - name: Build and push
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ push: true
+ tags: ${{ steps.meta.outputs.tags }}
+ labels: ${{ steps.meta.outputs.labels }}
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index 29808f2..83b2f2c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,9 +3,11 @@ WORKDIR /app
EXPOSE 80
EXPOSE 443
-FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
-RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
-RUN apt-get install -y nodejs
+FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
+RUN curl -SLO https://deb.nodesource.com/nsolid_setup_deb.sh
+RUN chmod 500 nsolid_setup_deb.sh
+RUN ./nsolid_setup_deb.sh 20
+RUN apt-get install nodejs -y
WORKDIR /src
COPY . .
RUN dotnet restore "EthernaCredit.sln"
diff --git a/EthernaCredit.sln b/EthernaCredit.sln
index eba90ca..2fb72ac 100644
--- a/EthernaCredit.sln
+++ b/EthernaCredit.sln
@@ -13,7 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
.gitignore = .gitignore
Dockerfile = Dockerfile
- EthernaCredit.sln.licenseheader = EthernaCredit.sln.licenseheader
LICENSE = LICENSE
nuget.config = nuget.config
README.md = README.md
@@ -35,6 +34,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\unstable-release.yml = .github\workflows\unstable-release.yml
EndProjectSection
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{17CA394F-7E22-4654-A7E6-93D2DDD49C4F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EthernaCredit.Persistence.Tests", "test\EthernaCredit.Persistence.Tests\EthernaCredit.Persistence.Tests.csproj", "{D6BF7556-84A4-4DC4-9120-BDFE249E1D45}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -57,6 +60,10 @@ Global
{270D03AE-3F41-4EC6-9FB8-10E050F7384F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{270D03AE-3F41-4EC6-9FB8-10E050F7384F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{270D03AE-3F41-4EC6-9FB8-10E050F7384F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D6BF7556-84A4-4DC4-9120-BDFE249E1D45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D6BF7556-84A4-4DC4-9120-BDFE249E1D45}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D6BF7556-84A4-4DC4-9120-BDFE249E1D45}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D6BF7556-84A4-4DC4-9120-BDFE249E1D45}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -69,6 +76,7 @@ Global
{FD6B74E2-E724-4CAA-9888-51B366BFBCEE} = {E57379A3-D247-4A43-9EC9-FB300A683E12}
{270D03AE-3F41-4EC6-9FB8-10E050F7384F} = {FD6B74E2-E724-4CAA-9888-51B366BFBCEE}
{64A1A3D7-3D00-43B2-B358-096DB512A6E7} = {9D5E69FC-70B7-41B0-89B4-72893F5C8822}
+ {D6BF7556-84A4-4DC4-9120-BDFE249E1D45} = {17CA394F-7E22-4654-A7E6-93D2DDD49C4F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EE6C260F-4757-4FA4-A87D-50DEC21FA9EE}
diff --git a/EthernaCredit.sln.DotSettings b/EthernaCredit.sln.DotSettings
new file mode 100644
index 0000000..29becb3
--- /dev/null
+++ b/EthernaCredit.sln.DotSettings
@@ -0,0 +1,18 @@
+
+ Copyright 2021-present Etherna Sa
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ True
+ True
+ True
+ True
\ No newline at end of file
diff --git a/EthernaCredit.sln.licenseheader b/EthernaCredit.sln.licenseheader
deleted file mode 100644
index 6c2b744..0000000
--- a/EthernaCredit.sln.licenseheader
+++ /dev/null
@@ -1,47 +0,0 @@
-extensions: designer.cs generated.cs
-extensions: .cs .cpp .h
-// Copyright 2021-present Etherna Sagl
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-extensions: .cshtml
-@* * Copyright 2021-present Etherna Sagl
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*@
-
-extensions: .xml .config .xsd
-
diff --git a/src/EthernaCredit.Domain/EthernaCredit.Domain.csproj b/src/EthernaCredit.Domain/EthernaCredit.Domain.csproj
index bd99e2a..ba99494 100644
--- a/src/EthernaCredit.Domain/EthernaCredit.Domain.csproj
+++ b/src/EthernaCredit.Domain/EthernaCredit.Domain.csproj
@@ -1,10 +1,10 @@
- net6.0
+ net8.0
Etherna.CreditSystem.Domain
- Etherna Sagl
+ Etherna Sa
true
enable
@@ -14,8 +14,8 @@
-
-
+
+
diff --git a/src/EthernaCredit.Services/Settings/ApplicationSettings.cs b/src/EthernaCredit.Domain/Events/AdminUpdateUserBalanceEvent.cs
similarity index 63%
rename from src/EthernaCredit.Services/Settings/ApplicationSettings.cs
rename to src/EthernaCredit.Domain/Events/AdminUpdateUserBalanceEvent.cs
index fe5f23d..f82b2aa 100644
--- a/src/EthernaCredit.Services/Settings/ApplicationSettings.cs
+++ b/src/EthernaCredit.Domain/Events/AdminUpdateUserBalanceEvent.cs
@@ -1,25 +1,25 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-namespace Etherna.CreditSystem.Services.Settings
+using Etherna.CreditSystem.Domain.Models.OperationLogs;
+using Etherna.DomainEvents;
+
+namespace Etherna.CreditSystem.Domain.Events
{
- public class ApplicationSettings
+ public class AdminUpdateUserBalanceEvent(AdminUpdateOperationLog operationLog) : IDomainEvent
{
- // Fields.
- string? _assemblyVersion;
-
// Properties.
- public string AssemblyVersion { get => _assemblyVersion ?? "1.0.0"; set => _assemblyVersion = value; }
+ public AdminUpdateOperationLog OperationLog { get; } = operationLog;
}
-}
+}
\ No newline at end of file
diff --git a/src/EthernaCredit.Domain/Events/UserDepositEvent.cs b/src/EthernaCredit.Domain/Events/UserDepositEvent.cs
index 6c48329..bc6503e 100644
--- a/src/EthernaCredit.Domain/Events/UserDepositEvent.cs
+++ b/src/EthernaCredit.Domain/Events/UserDepositEvent.cs
@@ -1,33 +1,24 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-using Etherna.CreditSystem.Domain.Models;
+using Etherna.CreditSystem.Domain.Models.OperationLogs;
using Etherna.DomainEvents;
namespace Etherna.CreditSystem.Domain.Events
{
- public class UserDepositEvent : IDomainEvent
+ public class UserDepositEvent(DepositOperationLog operationLog) : IDomainEvent
{
- // Constructor.
- public UserDepositEvent(decimal amount, User user)
- {
- Amount = amount;
- User = user;
- }
-
- // Properties.
- public decimal Amount { get; }
- public User User { get; }
+ public DepositOperationLog OperationLog { get; } = operationLog;
}
}
diff --git a/src/EthernaCredit.Domain/Events/UserWithdrawEvent.cs b/src/EthernaCredit.Domain/Events/UserWithdrawEvent.cs
index 85430b3..8c2eb0b 100644
--- a/src/EthernaCredit.Domain/Events/UserWithdrawEvent.cs
+++ b/src/EthernaCredit.Domain/Events/UserWithdrawEvent.cs
@@ -1,33 +1,24 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-using Etherna.CreditSystem.Domain.Models;
+using Etherna.CreditSystem.Domain.Models.OperationLogs;
using Etherna.DomainEvents;
namespace Etherna.CreditSystem.Domain.Events
{
- public class UserWithdrawEvent : IDomainEvent
+ public class UserWithdrawEvent(WithdrawOperationLog operationLog) : IDomainEvent
{
- // Constructor.
- public UserWithdrawEvent(decimal amount, User user)
- {
- Amount = amount;
- User = user;
- }
-
- // Properties.
- public decimal Amount { get; }
- public User User { get; }
+ public WithdrawOperationLog OperationLog { get; } = operationLog;
}
}
diff --git a/src/EthernaCredit.Domain/ICreditDbContext.cs b/src/EthernaCredit.Domain/ICreditDbContext.cs
index d88c005..a01ee84 100644
--- a/src/EthernaCredit.Domain/ICreditDbContext.cs
+++ b/src/EthernaCredit.Domain/ICreditDbContext.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,8 +21,8 @@ namespace Etherna.CreditSystem.Domain
{
public interface ICreditDbContext : IDbContext
{
- ICollectionRepository OperationLogs { get; }
- ICollectionRepository Users { get; }
+ IRepository OperationLogs { get; }
+ IRepository Users { get; }
IEventDispatcher EventDispatcher { get; }
}
diff --git a/src/EthernaCredit.Domain/ICreditDbContextInternal.cs b/src/EthernaCredit.Domain/ICreditDbContextInternal.cs
index 5dd0e14..6141a77 100644
--- a/src/EthernaCredit.Domain/ICreditDbContextInternal.cs
+++ b/src/EthernaCredit.Domain/ICreditDbContextInternal.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,6 +24,6 @@ namespace Etherna.CreditSystem.Domain
///
public interface ICreditDbContextInternal : ICreditDbContext
{
- ICollectionRepository UserBalances { get; }
+ IRepository UserBalances { get; }
}
}
diff --git a/src/EthernaCredit.Domain/ISharedDbContext.cs b/src/EthernaCredit.Domain/ISharedDbContext.cs
index a384e29..3adc435 100644
--- a/src/EthernaCredit.Domain/ISharedDbContext.cs
+++ b/src/EthernaCredit.Domain/ISharedDbContext.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,6 +23,6 @@ namespace Etherna.CreditSystem.Domain
///
public interface ISharedDbContext : IDbContext
{
- ICollectionRepository UsersInfo { get; }
+ IRepository UsersInfo { get; }
}
}
diff --git a/src/EthernaCredit.Domain/Models/EntityModelBase.cs b/src/EthernaCredit.Domain/Models/EntityModelBase.cs
index 0bf03ae..46c4ff5 100644
--- a/src/EthernaCredit.Domain/Models/EntityModelBase.cs
+++ b/src/EthernaCredit.Domain/Models/EntityModelBase.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,12 +22,12 @@ namespace Etherna.CreditSystem.Domain.Models
public abstract class EntityModelBase : ModelBase, IEntityModel
{
private DateTime _creationDateTime;
- private readonly List _events = new();
+ private readonly HashSet _events = new();
// Constructors and dispose.
protected EntityModelBase()
{
- _creationDateTime = DateTime.Now;
+ _creationDateTime = DateTime.UtcNow;
}
public virtual void DisposeForDelete() { }
diff --git a/src/EthernaCredit.Domain/Models/ModelBase.cs b/src/EthernaCredit.Domain/Models/ModelBase.cs
index 9eaa945..2cddf07 100644
--- a/src/EthernaCredit.Domain/Models/ModelBase.cs
+++ b/src/EthernaCredit.Domain/Models/ModelBase.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit.Domain/Models/OperationLogBase.cs b/src/EthernaCredit.Domain/Models/OperationLogBase.cs
index 198734d..5355c16 100644
--- a/src/EthernaCredit.Domain/Models/OperationLogBase.cs
+++ b/src/EthernaCredit.Domain/Models/OperationLogBase.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,7 +21,7 @@ public abstract class OperationLogBase : EntityModelBase
{
// Constructors.
protected OperationLogBase(
- decimal amount,
+ XDaiBalance amount,
string author,
User user)
{
@@ -32,7 +32,7 @@ protected OperationLogBase(
protected OperationLogBase() { }
// Properties.
- public virtual Decimal128 Amount { get; protected set; }
+ public virtual XDaiBalance Amount { get; protected set; }
public virtual string Author { get; protected set; } = default!;
public abstract string OperationName { get; }
public virtual User User { get; protected set; } = default!;
diff --git a/src/EthernaCredit.Domain/Models/OperationLogs/AdminUpdateOperationLog.cs b/src/EthernaCredit.Domain/Models/OperationLogs/AdminUpdateOperationLog.cs
new file mode 100644
index 0000000..77fbd68
--- /dev/null
+++ b/src/EthernaCredit.Domain/Models/OperationLogs/AdminUpdateOperationLog.cs
@@ -0,0 +1,37 @@
+// Copyright 2021-present Etherna Sa
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+
+namespace Etherna.CreditSystem.Domain.Models.OperationLogs
+{
+ public class AdminUpdateOperationLog : OperationLogBase
+ {
+ // Constructors.
+ public AdminUpdateOperationLog(
+ XDaiBalance amount,
+ string author,
+ string reason,
+ User user)
+ : base(amount, author, user)
+ {
+ Reason = reason ?? throw new ArgumentNullException(nameof(reason));
+ }
+ protected AdminUpdateOperationLog() { }
+
+ // Properties.
+ public override string OperationName => "Admin update";
+ public virtual string Reason { get; protected set; } = default!;
+ }
+}
\ No newline at end of file
diff --git a/src/EthernaCredit.Domain/Models/OperationLogs/DepositOperationLog.cs b/src/EthernaCredit.Domain/Models/OperationLogs/DepositOperationLog.cs
index d596386..44a7de2 100644
--- a/src/EthernaCredit.Domain/Models/OperationLogs/DepositOperationLog.cs
+++ b/src/EthernaCredit.Domain/Models/OperationLogs/DepositOperationLog.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,7 +18,7 @@ public class DepositOperationLog : OperationLogBase
{
// Constructors.
public DepositOperationLog(
- decimal amount,
+ XDaiBalance amount,
string author,
User user)
: base(amount, author, user)
diff --git a/src/EthernaCredit.Domain/Models/OperationLogs/UpdateOperationLog.cs b/src/EthernaCredit.Domain/Models/OperationLogs/UpdateOperationLog.cs
index 1395b82..7a0a4a0 100644
--- a/src/EthernaCredit.Domain/Models/OperationLogs/UpdateOperationLog.cs
+++ b/src/EthernaCredit.Domain/Models/OperationLogs/UpdateOperationLog.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,17 +20,20 @@ public class UpdateOperationLog : OperationLogBase
{
// Constructors.
public UpdateOperationLog(
- decimal amount,
+ XDaiBalance amount,
string author,
+ bool isApplied,
string reason,
User user)
: base(amount, author, user)
{
+ IsApplied = isApplied;
Reason = reason ?? throw new ArgumentNullException(nameof(reason));
}
protected UpdateOperationLog() { }
// Properties.
+ public virtual bool IsApplied { get; protected set; }
public override string OperationName => "Service update";
public virtual string Reason { get; protected set; } = default!;
}
diff --git a/src/EthernaCredit.Domain/Models/OperationLogs/WelcomeCreditDepositOperationLog.cs b/src/EthernaCredit.Domain/Models/OperationLogs/WelcomeCreditDepositOperationLog.cs
index 2bf11a8..e113683 100644
--- a/src/EthernaCredit.Domain/Models/OperationLogs/WelcomeCreditDepositOperationLog.cs
+++ b/src/EthernaCredit.Domain/Models/OperationLogs/WelcomeCreditDepositOperationLog.cs
@@ -1,4 +1,18 @@
-namespace Etherna.CreditSystem.Domain.Models.OperationLogs
+// Copyright 2021-present Etherna Sa
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Etherna.CreditSystem.Domain.Models.OperationLogs
{
public class WelcomeCreditDepositOperationLog : OperationLogBase
{
diff --git a/src/EthernaCredit.Domain/Models/OperationLogs/WithdrawOperationLog.cs b/src/EthernaCredit.Domain/Models/OperationLogs/WithdrawOperationLog.cs
index 552a453..6290f1a 100644
--- a/src/EthernaCredit.Domain/Models/OperationLogs/WithdrawOperationLog.cs
+++ b/src/EthernaCredit.Domain/Models/OperationLogs/WithdrawOperationLog.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,7 +18,7 @@ public class WithdrawOperationLog : OperationLogBase
{
// Constructors.
public WithdrawOperationLog(
- decimal amount,
+ XDaiBalance amount,
string author,
User user)
: base(amount, author, user)
diff --git a/src/EthernaCredit.Domain/Models/User.cs b/src/EthernaCredit.Domain/Models/User.cs
index 2942052..2d824a0 100644
--- a/src/EthernaCredit.Domain/Models/User.cs
+++ b/src/EthernaCredit.Domain/Models/User.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,8 +22,7 @@ public class User : EntityModelBase
// Constructors.
public User(UserSharedInfo sharedInfo)
{
- if (sharedInfo is null)
- throw new ArgumentNullException(nameof(sharedInfo));
+ ArgumentNullException.ThrowIfNull(sharedInfo, nameof(sharedInfo));
SharedInfoId = sharedInfo.Id;
}
diff --git a/src/EthernaCredit.Domain/Models/UserAgg/UserBalance.cs b/src/EthernaCredit.Domain/Models/UserAgg/UserBalance.cs
index 238910f..83d3f22 100644
--- a/src/EthernaCredit.Domain/Models/UserAgg/UserBalance.cs
+++ b/src/EthernaCredit.Domain/Models/UserAgg/UserBalance.cs
@@ -1,20 +1,17 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-using Etherna.MongoDB.Bson;
-using System;
-
namespace Etherna.CreditSystem.Domain.Models.UserAgg
{
///
@@ -24,7 +21,7 @@ namespace Etherna.CreditSystem.Domain.Models.UserAgg
public class UserBalance : EntityModelBase
{
// Constructors.
- public UserBalance(User user, Decimal128 welcomeCredit)
+ public UserBalance(User user, XDaiBalance welcomeCredit)
{
Credit = welcomeCredit;
User = user;
@@ -32,7 +29,7 @@ public UserBalance(User user, Decimal128 welcomeCredit)
protected UserBalance() { }
// Properties.
- public virtual Decimal128 Credit { get; protected set; }
+ public virtual XDaiBalance Credit { get; protected set; }
public virtual User User { get; protected set; } = default!;
}
}
diff --git a/src/EthernaCredit.Domain/Models/UserAgg/UserSharedInfo.cs b/src/EthernaCredit.Domain/Models/UserAgg/UserSharedInfo.cs
index 695a35b..dd75e66 100644
--- a/src/EthernaCredit.Domain/Models/UserAgg/UserSharedInfo.cs
+++ b/src/EthernaCredit.Domain/Models/UserAgg/UserSharedInfo.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit.Domain/Models/XDaiBalance.cs b/src/EthernaCredit.Domain/Models/XDaiBalance.cs
new file mode 100644
index 0000000..53383c4
--- /dev/null
+++ b/src/EthernaCredit.Domain/Models/XDaiBalance.cs
@@ -0,0 +1,79 @@
+// Copyright 2021-present Etherna Sa
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using Etherna.MongoDB.Bson;
+using System;
+using System.Globalization;
+
+namespace Etherna.CreditSystem.Domain.Models;
+
+public struct XDaiBalance : IEquatable
+{
+ // Consts.
+ public const int DecimalPrecision = 18;
+
+ // Fields.
+ private readonly decimal _balance;
+
+ // Constructors.
+ public XDaiBalance(decimal balance)
+ {
+ _balance = decimal.Round(balance, DecimalPrecision)
+ / 1.000000000000000000000000000000000m; //remove final zeros
+ }
+
+ // Methods.
+ public int CompareTo(XDaiBalance other) => _balance.CompareTo(other._balance);
+ public override bool Equals(object? obj) =>
+ obj is XDaiBalance xDaiObj &&
+ Equals(xDaiObj);
+ public bool Equals(XDaiBalance other) => _balance == other._balance;
+ public XDaiBalance FromDecimal(decimal value) => new(value);
+ public XDaiBalance FromDouble(double value) => new((decimal)value);
+ public XDaiBalance FromInt32(int value) => new(value);
+ public override int GetHashCode() => _balance.GetHashCode();
+ public decimal ToDecimal() => _balance;
+ public override string ToString() => _balance.ToString(CultureInfo.InvariantCulture);
+
+ // Static methods.
+ public static XDaiBalance Add(XDaiBalance left, XDaiBalance right) => left + right;
+ public static XDaiBalance Decrement(XDaiBalance balance)=> --balance;
+ public static XDaiBalance Divide(XDaiBalance left, XDaiBalance right) => left / right;
+ public static XDaiBalance Increment(XDaiBalance balance) => ++balance;
+ public static XDaiBalance Multiply(XDaiBalance left, XDaiBalance right) => left * right;
+ public static XDaiBalance Negate(XDaiBalance balance) => -balance;
+ public static XDaiBalance Subtract(XDaiBalance left, XDaiBalance right) => left - right;
+
+ // Operator methods.
+ public static XDaiBalance operator +(XDaiBalance left, XDaiBalance right) => new(left._balance + right._balance);
+ public static XDaiBalance operator -(XDaiBalance left, XDaiBalance right) => new(left._balance - right._balance);
+ public static XDaiBalance operator *(XDaiBalance left, XDaiBalance right) => new(left._balance * right._balance);
+ public static XDaiBalance operator /(XDaiBalance left, XDaiBalance right) => new(left._balance / right._balance);
+ public static bool operator ==(XDaiBalance left, XDaiBalance right) => left.Equals(right);
+ public static bool operator !=(XDaiBalance left, XDaiBalance right) => !(left == right);
+ public static bool operator >(XDaiBalance left, XDaiBalance right) => left._balance > right._balance;
+ public static bool operator <(XDaiBalance left, XDaiBalance right) => left._balance < right._balance;
+ public static bool operator >=(XDaiBalance left, XDaiBalance right) => left._balance >= right._balance;
+ public static bool operator <=(XDaiBalance left, XDaiBalance right) => left._balance <= right._balance;
+ public static XDaiBalance operator -(XDaiBalance value) => new(-value._balance);
+ public static XDaiBalance operator ++(XDaiBalance value) => new(value._balance + 1);
+ public static XDaiBalance operator --(XDaiBalance value) => new(value._balance - 1);
+
+ // Implicit conversion operator methods.
+ public static implicit operator XDaiBalance(decimal value) => new(value);
+ public static implicit operator XDaiBalance(double value) => new((decimal)value);
+ public static implicit operator XDaiBalance(int value) => new(value);
+
+ public static explicit operator decimal(XDaiBalance value) => value.ToDecimal();
+}
\ No newline at end of file
diff --git a/src/EthernaCredit.Domain/Properties/AssemblyInfo.cs b/src/EthernaCredit.Domain/Properties/AssemblyInfo.cs
index 9a314b2..f3cc56e 100644
--- a/src/EthernaCredit.Domain/Properties/AssemblyInfo.cs
+++ b/src/EthernaCredit.Domain/Properties/AssemblyInfo.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -13,5 +13,7 @@
// limitations under the License.
using System;
+using System.Runtime.CompilerServices;
-[assembly: CLSCompliant(false)]
\ No newline at end of file
+[assembly: CLSCompliant(false)]
+[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
\ No newline at end of file
diff --git a/src/EthernaCredit.Persistence/CreditDbContext.cs b/src/EthernaCredit.Persistence/CreditDbContext.cs
index 90dde01..8e7bee6 100644
--- a/src/EthernaCredit.Persistence/CreditDbContext.cs
+++ b/src/EthernaCredit.Persistence/CreditDbContext.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,6 +21,7 @@
using Etherna.MongODM.Core;
using Etherna.MongODM.Core.Repositories;
using Etherna.MongODM.Core.Serialization;
+using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -37,17 +38,19 @@ public class CreditDbContext : DbContext, ICreditDbContextInternal, IEventDispat
// Constructor.
public CreditDbContext(
- IEventDispatcher eventDispatcher)
+ IEventDispatcher eventDispatcher,
+ ILogger logger)
+ : base(logger)
{
EventDispatcher = eventDispatcher;
}
// Properties.
//repositories
- public ICollectionRepository OperationLogs { get; } =
- new DomainCollectionRepository("logs");
- public ICollectionRepository Users { get; } = new DomainCollectionRepository(
- new CollectionRepositoryOptions("users")
+ public IRepository OperationLogs { get; } =
+ new DomainRepository("logs");
+ public IRepository Users { get; } = new DomainRepository(
+ new RepositoryOptions("users")
{
IndexBuilders = new[]
{
@@ -56,8 +59,8 @@ public CreditDbContext(
});
//internal repositories
- public ICollectionRepository UserBalances { get; } = new DomainCollectionRepository(
- new CollectionRepositoryOptions("userBalances")
+ public IRepository UserBalances { get; } = new DomainRepository(
+ new RepositoryOptions("userBalances")
{
IndexBuilders = new[]
{
@@ -76,17 +79,19 @@ where t.GetInterfaces().Contains(typeof(IModelMapsCollector))
select Activator.CreateInstance(t) as IModelMapsCollector;
// Methods.
- public override Task SaveChangesAsync(CancellationToken cancellationToken = default)
+ public override async Task SaveChangesAsync(CancellationToken cancellationToken = default)
{
+ var changedEntityModels = ChangedModelsList.OfType().ToArray();
+
+ // Save changes.
+ await base.SaveChangesAsync(cancellationToken);
+
// Dispatch events.
- foreach (var model in ChangedModelsList.Where(m => m is EntityModelBase)
- .Select(m => (EntityModelBase)m))
+ foreach (var model in changedEntityModels)
{
- EventDispatcher.DispatchAsync(model.Events);
+ await EventDispatcher.DispatchAsync(model.Events);
model.ClearEvents();
}
-
- return base.SaveChangesAsync(cancellationToken);
}
}
}
diff --git a/src/EthernaCredit.Persistence/EthernaCredit.Persistence.csproj b/src/EthernaCredit.Persistence/EthernaCredit.Persistence.csproj
index b4e35fa..6fb250f 100644
--- a/src/EthernaCredit.Persistence/EthernaCredit.Persistence.csproj
+++ b/src/EthernaCredit.Persistence/EthernaCredit.Persistence.csproj
@@ -1,10 +1,10 @@
- net6.0
+ net8.0
Etherna.CreditSystem.Persistence
- Etherna Sagl
+ Etherna Sa
true
enable
diff --git a/src/EthernaCredit.Persistence/IEventDispatcherDbContext.cs b/src/EthernaCredit.Persistence/IEventDispatcherDbContext.cs
index 34f507a..c9cf799 100644
--- a/src/EthernaCredit.Persistence/IEventDispatcherDbContext.cs
+++ b/src/EthernaCredit.Persistence/IEventDispatcherDbContext.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit.Persistence/ModelMaps/Credit/ModelBaseMap.cs b/src/EthernaCredit.Persistence/ModelMaps/Credit/ModelBaseMap.cs
index fc3c834..d91c395 100644
--- a/src/EthernaCredit.Persistence/ModelMaps/Credit/ModelBaseMap.cs
+++ b/src/EthernaCredit.Persistence/ModelMaps/Credit/ModelBaseMap.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,14 +21,14 @@
namespace Etherna.CreditSystem.Persistence.ModelMaps.Credit
{
- class ModelBaseMap : IModelMapsCollector
+ internal sealed class ModelBaseMap : IModelMapsCollector
{
public void Register(IDbContext dbContext)
{
// register class maps.
- dbContext.SchemaRegistry.AddModelMapsSchema("92a5e4a2-6b0c-46b7-aac7-70380deda7b4");
- dbContext.SchemaRegistry.AddModelMapsSchema("155af6aa-92d1-4d8b-b000-5b5464f84dc7");
- dbContext.SchemaRegistry.AddModelMapsSchema>("a0fddc7f-b64d-43b0-a40d-389b3fb21b67",
+ dbContext.MapRegistry.AddModelMap("92a5e4a2-6b0c-46b7-aac7-70380deda7b4");
+ dbContext.MapRegistry.AddModelMap("155af6aa-92d1-4d8b-b000-5b5464f84dc7");
+ dbContext.MapRegistry.AddModelMap>("a0fddc7f-b64d-43b0-a40d-389b3fb21b67",
mm =>
{
mm.AutoMap();
diff --git a/src/EthernaCredit.Persistence/ModelMaps/Credit/OperationLogMap.cs b/src/EthernaCredit.Persistence/ModelMaps/Credit/OperationLogMap.cs
index 0a4636b..1b22aaa 100644
--- a/src/EthernaCredit.Persistence/ModelMaps/Credit/OperationLogMap.cs
+++ b/src/EthernaCredit.Persistence/ModelMaps/Credit/OperationLogMap.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -14,31 +14,39 @@
using Etherna.CreditSystem.Domain.Models;
using Etherna.CreditSystem.Domain.Models.OperationLogs;
+using Etherna.CreditSystem.Persistence.Serializers;
using Etherna.MongoDB.Bson;
-using Etherna.MongoDB.Bson.Serialization.Serializers;
using Etherna.MongODM.Core;
using Etherna.MongODM.Core.Extensions;
using Etherna.MongODM.Core.Serialization;
namespace Etherna.CreditSystem.Persistence.ModelMaps.Credit
{
- class OperationLogMap : IModelMapsCollector
+ internal sealed class OperationLogMap : IModelMapsCollector
{
public void Register(IDbContext dbContext)
{
- dbContext.SchemaRegistry.AddModelMapsSchema("780ae0cc-070a-4099-a4c0-0494304e4093",
+ dbContext.MapRegistry.AddModelMap("780ae0cc-070a-4099-a4c0-0494304e4093", //dev (pre v0.3.0), published for WAM event
mm =>
{
mm.AutoMap();
// Set members with custom serializers.
- mm.SetMemberSerializer(l => l.Amount, new Decimal128Serializer(BsonType.Decimal128));
+ mm.SetMemberSerializer(l => l.Amount, new XDaiBalanceSerializer(BsonType.Decimal128));
mm.SetMemberSerializer(l => l.User, UserMap.ReferenceSerializer(dbContext));
});
- dbContext.SchemaRegistry.AddModelMapsSchema("7fc7abe8-9a55-40a2-90ce-f3cba34bc005");
- dbContext.SchemaRegistry.AddModelMapsSchema("74e021d4-6d86-4deb-b952-0c328839cfe2");
- dbContext.SchemaRegistry.AddModelMapsSchema("ba82b71f-1d41-45e2-a56b-d3293ea74c3a");
- dbContext.SchemaRegistry.AddModelMapsSchema("b0ffe059-c985-4f3d-8677-238ab9551ec3");
+ dbContext.MapRegistry.AddModelMap("3610fd2e-5f43-490b-bcfc-435a970a59cf"); //v0.3.12
+ dbContext.MapRegistry.AddModelMap("7fc7abe8-9a55-40a2-90ce-f3cba34bc005"); //dev (pre v0.3.0), published for WAM event
+ dbContext.MapRegistry.AddModelMap("74e021d4-6d86-4deb-b952-0c328839cfe2", //dev (pre v0.3.0), published for WAM event
+ mm =>
+ {
+ mm.AutoMap();
+
+ // Set default values.
+ mm.GetMemberMap(l => l.IsApplied).SetDefaultValue(true).SetIgnoreIfDefault(true);
+ });
+ dbContext.MapRegistry.AddModelMap("ba82b71f-1d41-45e2-a56b-d3293ea74c3a"); //v0.3.9
+ dbContext.MapRegistry.AddModelMap("b0ffe059-c985-4f3d-8677-238ab9551ec3"); //dev (pre v0.3.0), published for WAM event
}
}
}
diff --git a/src/EthernaCredit.Persistence/ModelMaps/Credit/UserMap.cs b/src/EthernaCredit.Persistence/ModelMaps/Credit/UserMap.cs
index f698370..c7ab68f 100644
--- a/src/EthernaCredit.Persistence/ModelMaps/Credit/UserMap.cs
+++ b/src/EthernaCredit.Persistence/ModelMaps/Credit/UserMap.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -14,6 +14,7 @@
using Etherna.CreditSystem.Domain.Models;
using Etherna.CreditSystem.Domain.Models.UserAgg;
+using Etherna.CreditSystem.Persistence.Serializers;
using Etherna.MongoDB.Bson;
using Etherna.MongoDB.Bson.Serialization.Serializers;
using Etherna.MongODM.Core;
@@ -23,18 +24,18 @@
namespace Etherna.CreditSystem.Persistence.ModelMaps.Credit
{
- class UserMap : IModelMapsCollector
+ internal sealed class UserMap : IModelMapsCollector
{
public void Register(IDbContext dbContext)
{
- dbContext.SchemaRegistry.AddModelMapsSchema("0ff83163-b49f-4182-895d-bed59e73a976");
- dbContext.SchemaRegistry.AddModelMapsSchema("873c5ee4-122b-4021-8dc9-524b9f50b73b",
+ dbContext.MapRegistry.AddModelMap("0ff83163-b49f-4182-895d-bed59e73a976"); //dev (pre v0.3.0), published for WAM event
+ dbContext.MapRegistry.AddModelMap("873c5ee4-122b-4021-8dc9-524b9f50b73b", //dev (pre v0.3.0), published for WAM event
mm =>
{
mm.AutoMap();
// Set members with custom serializers.
- mm.SetMemberSerializer(b => b.Credit, new Decimal128Serializer(BsonType.Decimal128));
+ mm.SetMemberSerializer(b => b.Credit, new XDaiBalanceSerializer(BsonType.Decimal128));
mm.SetMemberSerializer(b => b.User, ReferenceSerializer(dbContext));
});
}
@@ -43,19 +44,17 @@ public void Register(IDbContext dbContext)
/// The document reference with only Id.
///
public static ReferenceSerializer ReferenceSerializer(
- IDbContext dbContext,
- bool useCascadeDelete = false) =>
+ IDbContext dbContext) =>
new(dbContext, config =>
{
- config.UseCascadeDelete = useCascadeDelete;
- config.AddModelMapsSchema("485440e2-ce18-4c40-a8ca-31280fbb22ed");
- config.AddModelMapsSchema("bac86f72-a3d9-4ccc-bb43-9af68d6d5c03", mm => { });
- config.AddModelMapsSchema>("f1cc0691-f879-4036-a994-fe92b6d39cfb", mm =>
+ config.AddModelMap("485440e2-ce18-4c40-a8ca-31280fbb22ed");
+ config.AddModelMap("bac86f72-a3d9-4ccc-bb43-9af68d6d5c03", mm => { });
+ config.AddModelMap>("f1cc0691-f879-4036-a994-fe92b6d39cfb", mm =>
{
mm.MapIdMember(m => m.Id);
mm.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
});
- config.AddModelMapsSchema("b309c982-f30f-46ad-b076-c6030c8dbcd8", mm => { });
+ config.AddModelMap("b309c982-f30f-46ad-b076-c6030c8dbcd8", mm => { });
});
}
}
diff --git a/src/EthernaCredit.Persistence/ModelMaps/Shared/ModelBaseMap.cs b/src/EthernaCredit.Persistence/ModelMaps/Shared/ModelBaseMap.cs
index 88443f8..8342b11 100644
--- a/src/EthernaCredit.Persistence/ModelMaps/Shared/ModelBaseMap.cs
+++ b/src/EthernaCredit.Persistence/ModelMaps/Shared/ModelBaseMap.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,14 +21,14 @@
namespace Etherna.CreditSystem.Persistence.ModelMaps.Shared
{
- class ModelBaseMap : IModelMapsCollector
+ internal sealed class ModelBaseMap : IModelMapsCollector
{
public void Register(IDbContext dbContext)
{
// register class maps.
- dbContext.SchemaRegistry.AddModelMapsSchema("d517f32d-cc45-4d21-8a99-27dca658bde5");
- dbContext.SchemaRegistry.AddModelMapsSchema("4c17bb54-af84-4a21-83ae-cb1050b721f5");
- dbContext.SchemaRegistry.AddModelMapsSchema>("e5e834e0-30cc-42a8-a1a2-9d5c79d35485",
+ dbContext.MapRegistry.AddModelMap("d517f32d-cc45-4d21-8a99-27dca658bde5");
+ dbContext.MapRegistry.AddModelMap("4c17bb54-af84-4a21-83ae-cb1050b721f5");
+ dbContext.MapRegistry.AddModelMap>("e5e834e0-30cc-42a8-a1a2-9d5c79d35485",
modelMap =>
{
modelMap.AutoMap();
diff --git a/src/EthernaCredit.Persistence/ModelMaps/Shared/UserSharedInfoMap.cs b/src/EthernaCredit.Persistence/ModelMaps/Shared/UserSharedInfoMap.cs
index 833ad2b..79cfef5 100644
--- a/src/EthernaCredit.Persistence/ModelMaps/Shared/UserSharedInfoMap.cs
+++ b/src/EthernaCredit.Persistence/ModelMaps/Shared/UserSharedInfoMap.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,11 +18,11 @@
namespace Etherna.CreditSystem.Persistence.ModelMaps.Shared
{
- class UserSharedInfoMap : IModelMapsCollector
+ internal sealed class UserSharedInfoMap : IModelMapsCollector
{
public void Register(IDbContext dbContext)
{
- dbContext.SchemaRegistry.AddModelMapsSchema("6d0d2ee1-6aa3-42ea-9833-ac592bfc6613", mm =>
+ dbContext.MapRegistry.AddModelMap("6d0d2ee1-6aa3-42ea-9833-ac592bfc6613", mm =>
{
mm.AutoMap();
diff --git a/src/EthernaCredit.Persistence/Properties/AssemblyInfo.cs b/src/EthernaCredit.Persistence/Properties/AssemblyInfo.cs
index 9a314b2..8999d26 100644
--- a/src/EthernaCredit.Persistence/Properties/AssemblyInfo.cs
+++ b/src/EthernaCredit.Persistence/Properties/AssemblyInfo.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit.Persistence/Repositories/DomainGridFSRepository.cs b/src/EthernaCredit.Persistence/Repositories/DomainGridFSRepository.cs
deleted file mode 100644
index 7f47f83..0000000
--- a/src/EthernaCredit.Persistence/Repositories/DomainGridFSRepository.cs
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright 2021-present Etherna Sagl
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-using Etherna.DomainEvents;
-using Etherna.DomainEvents.Events;
-using Etherna.MongODM.Core;
-using Etherna.MongODM.Core.Domain.Models;
-using Etherna.MongODM.Core.Repositories;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace Etherna.CreditSystem.Persistence.Repositories
-{
- public class DomainGridFSRepository :
- GridFSRepository
- where TModel : class, IFileModel
- {
- // Constructors and initialization.
- public DomainGridFSRepository(string name)
- : base(name)
- { }
-
- public DomainGridFSRepository(GridFSRepositoryOptions options)
- : base(options)
- { }
-
- public override void Initialize(IDbContext dbContext)
- {
- if (dbContext is not IEventDispatcherDbContext)
- throw new InvalidOperationException($"DbContext needs to implement {nameof(IEventDispatcherDbContext)}");
-
- base.Initialize(dbContext);
- }
-
- // Properties.
- public IEventDispatcher EventDispatcher => ((IEventDispatcherDbContext)DbContext).EventDispatcher;
-
- // Methods.
- public override async Task CreateAsync(IEnumerable models, CancellationToken cancellationToken = default)
- {
- await base.CreateAsync(models, cancellationToken);
-
- // Dispatch created events.
- await EventDispatcher.DispatchAsync(
- models.Select(m => new EntityCreatedEvent(m)));
- }
-
- public override async Task CreateAsync(TModel model, CancellationToken cancellationToken = default)
- {
- await base.CreateAsync(model, cancellationToken);
-
- // Dispatch created event.
- await EventDispatcher.DispatchAsync(
- new EntityCreatedEvent(model));
- }
-
- public override async Task DeleteAsync(TModel model, CancellationToken cancellationToken = default)
- {
- await base.DeleteAsync(model, cancellationToken);
-
- // Dispatch deleted event.
- await EventDispatcher.DispatchAsync(
- new EntityDeletedEvent(model));
- }
- }
-}
diff --git a/src/EthernaCredit.Persistence/Repositories/DomainCollectionRepository.cs b/src/EthernaCredit.Persistence/Repositories/DomainRepository.cs
similarity index 57%
rename from src/EthernaCredit.Persistence/Repositories/DomainCollectionRepository.cs
rename to src/EthernaCredit.Persistence/Repositories/DomainRepository.cs
index 53756f8..5a25d19 100644
--- a/src/EthernaCredit.Persistence/Repositories/DomainCollectionRepository.cs
+++ b/src/EthernaCredit.Persistence/Repositories/DomainRepository.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,6 +16,7 @@
using Etherna.DomainEvents;
using Etherna.DomainEvents.Events;
using Etherna.MongODM.Core.Repositories;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -23,16 +24,16 @@
namespace Etherna.CreditSystem.Persistence.Repositories
{
- public class DomainCollectionRepository :
- CollectionRepository
+ public class DomainRepository :
+ Repository
where TModel : EntityModelBase
{
// Constructors and initialization.
- public DomainCollectionRepository(string name)
+ public DomainRepository(string name)
: base(name)
{ }
- public DomainCollectionRepository(CollectionRepositoryOptions options)
+ public DomainRepository(RepositoryOptions options)
: base(options)
{ }
@@ -42,28 +43,59 @@ public DomainCollectionRepository(CollectionRepositoryOptions options)
// Methods.
public override async Task CreateAsync(IEnumerable models, CancellationToken cancellationToken = default)
{
+ ArgumentNullException.ThrowIfNull(models, nameof(models));
+
+ // Create entity.
await base.CreateAsync(models, cancellationToken);
- // Dispatch created events.
+ // Dispatch events.
if (EventDispatcher != null)
- await EventDispatcher.DispatchAsync(
- models.Select(m => new EntityCreatedEvent(m)));
+ {
+ //created event
+ await EventDispatcher.DispatchAsync(models.Select(m => new EntityCreatedEvent(m)));
+
+ //custom events
+ foreach (var model in models)
+ {
+ await EventDispatcher.DispatchAsync(model.Events);
+ model.ClearEvents();
+ }
+ }
}
public override async Task CreateAsync(TModel model, CancellationToken cancellationToken = default)
{
+ ArgumentNullException.ThrowIfNull(model, nameof(model));
+
+ // Create entity.
await base.CreateAsync(model, cancellationToken);
- // Dispatch created event.
+ // Dispatch events.
if (EventDispatcher != null)
- await EventDispatcher.DispatchAsync(
- new EntityCreatedEvent(model));
+ {
+ //created event
+ await EventDispatcher.DispatchAsync(new EntityCreatedEvent(model));
+
+ //custom events
+ await EventDispatcher.DispatchAsync(model.Events);
+ model.ClearEvents();
+ }
}
public override async Task DeleteAsync(TModel model, CancellationToken cancellationToken = default)
{
+ ArgumentNullException.ThrowIfNull(model, nameof(model));
+
+ // Delete entity.
await base.DeleteAsync(model, cancellationToken);
+ // Dispatch custom events.
+ if (EventDispatcher != null)
+ {
+ await EventDispatcher.DispatchAsync(model.Events);
+ model.ClearEvents();
+ }
+
// Dispatch deleted event.
if (EventDispatcher != null)
await EventDispatcher.DispatchAsync(
diff --git a/src/EthernaCredit.Persistence/Serializers/XDaiBalanceSerializer.cs b/src/EthernaCredit.Persistence/Serializers/XDaiBalanceSerializer.cs
new file mode 100644
index 0000000..69aac5b
--- /dev/null
+++ b/src/EthernaCredit.Persistence/Serializers/XDaiBalanceSerializer.cs
@@ -0,0 +1,95 @@
+// Copyright 2021-present Etherna Sa
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using Etherna.CreditSystem.Domain.Models;
+using Etherna.MongoDB.Bson;
+using Etherna.MongoDB.Bson.Serialization;
+using Etherna.MongoDB.Bson.Serialization.Options;
+using Etherna.MongoDB.Bson.Serialization.Serializers;
+
+namespace Etherna.CreditSystem.Persistence.Serializers
+{
+ public class XDaiBalanceSerializer : StructSerializerBase, IRepresentationConfigurable, IRepresentationConverterConfigurable
+ {
+ // Fields.
+ private readonly Decimal128Serializer balanceSerializer;
+
+ // Constructors.
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public XDaiBalanceSerializer()
+ : this(BsonType.String)
+ { }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The representation.
+ public XDaiBalanceSerializer(BsonType representation)
+ : this(representation, new RepresentationConverter(false, false))
+ { }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The representation.
+ /// The converter.
+ public XDaiBalanceSerializer(BsonType representation, RepresentationConverter converter)
+ {
+ balanceSerializer = new Decimal128Serializer(representation, converter);
+ }
+
+ // Properties.
+ public RepresentationConverter Converter => balanceSerializer.Converter;
+ public BsonType Representation => balanceSerializer.Representation;
+
+ // Methods.
+ public override XDaiBalance Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
+ {
+ var value = balanceSerializer.Deserialize(context, args);
+ return new XDaiBalance(Decimal128.ToDecimal(value));
+ }
+
+ public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, XDaiBalance value) =>
+ balanceSerializer.Serialize(context, args, new Decimal128(value.ToDecimal()));
+
+ ///
+ /// Returns a serializer that has been reconfigured with the specified item serializer.
+ ///
+ /// The converter.
+ /// The reconfigured serializer.
+ public XDaiBalanceSerializer WithConverter(RepresentationConverter converter) =>
+ converter == Converter ?
+ this :
+ new XDaiBalanceSerializer(Representation, converter);
+
+ ///
+ /// Returns a serializer that has been reconfigured with the specified representation.
+ ///
+ /// The representation.
+ /// The reconfigured serializer.
+ public XDaiBalanceSerializer WithRepresentation(BsonType representation) =>
+ representation == Representation ?
+ this :
+ new XDaiBalanceSerializer(representation, Converter);
+
+ // Explicit interface implementations.
+ IBsonSerializer IRepresentationConverterConfigurable.WithConverter(RepresentationConverter converter) =>
+ WithConverter(converter);
+
+ IBsonSerializer IRepresentationConfigurable.WithRepresentation(BsonType representation) =>
+ WithRepresentation(representation);
+ }
+}
\ No newline at end of file
diff --git a/src/EthernaCredit.Persistence/SharedDbContext.cs b/src/EthernaCredit.Persistence/SharedDbContext.cs
index 96c5d96..7b00f36 100644
--- a/src/EthernaCredit.Persistence/SharedDbContext.cs
+++ b/src/EthernaCredit.Persistence/SharedDbContext.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,8 +33,8 @@ public class SharedDbContext : DbContext, ISharedDbContext
// Properties.
//repositories
- public ICollectionRepository UsersInfo { get; } = new DomainCollectionRepository(
- new CollectionRepositoryOptions("usersInfo")
+ public IRepository UsersInfo { get; } = new DomainRepository(
+ new RepositoryOptions("usersInfo")
{
IndexBuilders = new[]
{
diff --git a/src/EthernaCredit.Services/Domain/IUserService.cs b/src/EthernaCredit.Services/Domain/IUserService.cs
index 0af6e2a..17c149d 100644
--- a/src/EthernaCredit.Services/Domain/IUserService.cs
+++ b/src/EthernaCredit.Services/Domain/IUserService.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,10 +23,10 @@ public interface IUserService
Task<(User, UserSharedInfo)> FindUserAsync(string address);
Task<(User, UserSharedInfo)> FindUserAsync(UserSharedInfo userSharedInfo);
Task FindUserSharedInfoByAddressAsync(string address);
- Task GetUserBalanceAsync(string address);
- Task GetUserBalanceAsync(User user);
+ Task GetUserBalanceAsync(string address);
+ Task GetUserBalanceAsync(User user);
Task<(User?, UserSharedInfo?)> TryFindUserAsync(string address);
Task TryFindUserSharedInfoByAddressAsync(string address);
- Task TryIncrementUserBalanceAsync(User user, decimal amount, bool allowBalanceDecreaseNegative);
+ Task TryIncrementUserBalanceAsync(User user, XDaiBalance amount, bool allowBalanceDecreaseNegative);
}
}
\ No newline at end of file
diff --git a/src/EthernaCredit.Services/Domain/UserService.cs b/src/EthernaCredit.Services/Domain/UserService.cs
index 586e9bf..7fdb164 100644
--- a/src/EthernaCredit.Services/Domain/UserService.cs
+++ b/src/EthernaCredit.Services/Domain/UserService.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,7 +16,6 @@
using Etherna.CreditSystem.Domain.Models;
using Etherna.CreditSystem.Domain.Models.OperationLogs;
using Etherna.CreditSystem.Domain.Models.UserAgg;
-using Etherna.MongoDB.Bson;
using Etherna.MongoDB.Driver;
using Etherna.MongoDB.Driver.Linq;
using Nethereum.Util;
@@ -26,7 +25,7 @@
namespace Etherna.CreditSystem.Services.Domain
{
- class UserService : IUserService
+ internal sealed class UserService : IUserService
{
// Consts.
private const decimal DefaultWelcomeCredit = 0.1M;
@@ -95,7 +94,7 @@ public async Task FindUserSharedInfoByAddressAsync(string addres
.FirstAsync());
}
- public async Task GetUserBalanceAsync(string address)
+ public async Task GetUserBalanceAsync(string address)
{
var (user, _) = await TryFindUserAsync(address);
if (user is null)
@@ -104,10 +103,10 @@ public async Task GetUserBalanceAsync(string address)
return await GetUserBalanceAsync(user);
}
- public async Task GetUserBalanceAsync(User user)
+ public async Task GetUserBalanceAsync(User user)
{
var userBalance = await creditDbContext.UserBalances.FindOneAsync(balance => balance.User.Id == user.Id);
- return Decimal128.ToDecimal(userBalance.Credit);
+ return userBalance.Credit;
}
public async Task<(User?, UserSharedInfo?)> TryFindUserAsync(string address)
@@ -125,7 +124,7 @@ public async Task GetUserBalanceAsync(User user)
catch (InvalidOperationException) { return null; }
}
- public async Task TryIncrementUserBalanceAsync(User user, decimal amount, bool allowBalanceDecreaseNegative)
+ public async Task TryIncrementUserBalanceAsync(User user, XDaiBalance amount, bool allowBalanceDecreaseNegative)
{
if (user.HasUnlimitedCredit)
return true;
@@ -135,7 +134,7 @@ public async Task TryIncrementUserBalanceAsync(User user, decimal amount,
var balanceResult = await creditDbContext.UserBalances.AccessToCollectionAsync(collection =>
collection.FindOneAndUpdateAsync(
balance => balance.User.Id == user.Id,
- Builders.Update.Inc(balance => balance.Credit, new Decimal128(amount))));
+ Builders.Update.Inc(balance => balance.Credit, amount)));
return balanceResult is not null;
}
@@ -144,8 +143,8 @@ public async Task TryIncrementUserBalanceAsync(User user, decimal amount,
var balanceResult = await creditDbContext.UserBalances.AccessToCollectionAsync(collection =>
collection.FindOneAndUpdateAsync(
balance => balance.User.Id == user.Id &&
- balance.Credit >= new Decimal128(-amount), //verify disponibility
- Builders.Update.Inc(balance => balance.Credit, new Decimal128(amount))));
+ balance.Credit >= -amount, //verify disponibility
+ Builders.Update.Inc(balance => balance.Credit, amount)));
return balanceResult is not null;
}
diff --git a/src/EthernaCredit.Services/EthernaCredit.Services.csproj b/src/EthernaCredit.Services/EthernaCredit.Services.csproj
index 378c710..c6e1007 100644
--- a/src/EthernaCredit.Services/EthernaCredit.Services.csproj
+++ b/src/EthernaCredit.Services/EthernaCredit.Services.csproj
@@ -1,11 +1,11 @@
- net6.0
+ net8.0
true
Etherna.CreditSystem.Services
- Etherna Sagl
+ Etherna Sa
true
enable
@@ -18,10 +18,10 @@
+
-
-
-
+
+
diff --git a/src/EthernaCredit.Services/EventHandlers/OnUserDepositThenSendEmailHandler.cs b/src/EthernaCredit.Services/EventHandlers/OnUserDepositThenSendEmailHandler.cs
index 0ac2503..908aa27 100644
--- a/src/EthernaCredit.Services/EventHandlers/OnUserDepositThenSendEmailHandler.cs
+++ b/src/EthernaCredit.Services/EventHandlers/OnUserDepositThenSendEmailHandler.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,24 +17,24 @@
using Etherna.CreditSystem.Domain.Events;
using Etherna.CreditSystem.Services.Views.Emails;
using Etherna.DomainEvents;
-using Etherna.ServicesClient.Clients.Sso;
+using Etherna.ServicesClient.Internal;
using System.Threading.Tasks;
namespace Etherna.CreditSystem.Services.EventHandlers
{
- class OnUserDepositThenSendEmailHandler : EventHandlerBase
+ internal sealed class OnUserDepositThenSendEmailHandler : EventHandlerBase
{
// Fields.
private readonly IEmailSender emailSender;
private readonly IRazorViewRenderer razorViewRenderer;
- private readonly IServiceSsoClient serviceSsoClient;
+ private readonly IEthernaInternalSsoClient serviceSsoClient;
private readonly ISharedDbContext sharedDbContext;
// Constructor.
public OnUserDepositThenSendEmailHandler(
IEmailSender emailSender,
IRazorViewRenderer razorViewRenderer,
- IServiceSsoClient serviceSsoClient,
+ IEthernaInternalSsoClient serviceSsoClient,
ISharedDbContext sharedDbContext)
{
this.emailSender = emailSender;
@@ -47,7 +47,8 @@ public OnUserDepositThenSendEmailHandler(
public override async Task HandleAsync(UserDepositEvent @event)
{
// Get user shared info.
- var userSharedInfo = await sharedDbContext.UsersInfo.FindOneAsync(@event.User.SharedInfoId);
+ var userSharedInfo = await sharedDbContext.UsersInfo.FindOneAsync(
+ @event.OperationLog.User.SharedInfoId);
// Get user email.
var contacts = await serviceSsoClient.ServiceInteract.ContactsAsync(userSharedInfo.EtherAddress);
diff --git a/src/EthernaCredit.Services/EventHandlers/OnUserWithdrawThenSendEmailHandler.cs b/src/EthernaCredit.Services/EventHandlers/OnUserWithdrawThenSendEmailHandler.cs
index 72caa2d..86eda6a 100644
--- a/src/EthernaCredit.Services/EventHandlers/OnUserWithdrawThenSendEmailHandler.cs
+++ b/src/EthernaCredit.Services/EventHandlers/OnUserWithdrawThenSendEmailHandler.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,24 +17,24 @@
using Etherna.CreditSystem.Domain.Events;
using Etherna.CreditSystem.Services.Views.Emails;
using Etherna.DomainEvents;
-using Etherna.ServicesClient.Clients.Sso;
+using Etherna.ServicesClient.Internal;
using System.Threading.Tasks;
namespace Etherna.CreditSystem.Services.EventHandlers
{
- class OnUserWithdrawThenSendEmailHandler : EventHandlerBase
+ internal sealed class OnUserWithdrawThenSendEmailHandler : EventHandlerBase
{
// Fields.
private readonly IEmailSender emailSender;
private readonly IRazorViewRenderer razorViewRenderer;
- private readonly IServiceSsoClient serviceSsoClient;
+ private readonly IEthernaInternalSsoClient serviceSsoClient;
private readonly ISharedDbContext sharedDbContext;
// Constructor.
public OnUserWithdrawThenSendEmailHandler(
IEmailSender emailSender,
IRazorViewRenderer razorViewRenderer,
- IServiceSsoClient serviceSsoClient,
+ IEthernaInternalSsoClient serviceSsoClient,
ISharedDbContext sharedDbContext)
{
this.emailSender = emailSender;
@@ -47,7 +47,8 @@ public OnUserWithdrawThenSendEmailHandler(
public override async Task HandleAsync(UserWithdrawEvent @event)
{
// Get user shared info.
- var userSharedInfo = await sharedDbContext.UsersInfo.FindOneAsync(@event.User.SharedInfoId);
+ var userSharedInfo = await sharedDbContext.UsersInfo.FindOneAsync(
+ @event.OperationLog.User.SharedInfoId);
// Get user email.
var contacts = await serviceSsoClient.ServiceInteract.ContactsAsync(userSharedInfo.EtherAddress);
diff --git a/src/EthernaCredit.Services/Properties/AssemblyInfo.cs b/src/EthernaCredit.Services/Properties/AssemblyInfo.cs
index 9a314b2..8999d26 100644
--- a/src/EthernaCredit.Services/Properties/AssemblyInfo.cs
+++ b/src/EthernaCredit.Services/Properties/AssemblyInfo.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit.Services/ServiceCollectionExtensions.cs b/src/EthernaCredit.Services/ServiceCollectionExtensions.cs
index b49c217..3ea95ed 100644
--- a/src/EthernaCredit.Services/ServiceCollectionExtensions.cs
+++ b/src/EthernaCredit.Services/ServiceCollectionExtensions.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit.Services/Settings/SsoServerSettings.cs b/src/EthernaCredit.Services/Settings/SsoServerSettings.cs
index bcf07f9..f4bda56 100644
--- a/src/EthernaCredit.Services/Settings/SsoServerSettings.cs
+++ b/src/EthernaCredit.Services/Settings/SsoServerSettings.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit.Services/Tasks/Queues.cs b/src/EthernaCredit.Services/Tasks/Queues.cs
index cc38275..c4bf04d 100644
--- a/src/EthernaCredit.Services/Tasks/Queues.cs
+++ b/src/EthernaCredit.Services/Tasks/Queues.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit.Services/Views/Emails/DepositConfirmation.cshtml b/src/EthernaCredit.Services/Views/Emails/DepositConfirmation.cshtml
index a2a6e71..645b7cc 100644
--- a/src/EthernaCredit.Services/Views/Emails/DepositConfirmation.cshtml
+++ b/src/EthernaCredit.Services/Views/Emails/DepositConfirmation.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/EthernaCredit.Services/Views/Emails/DepositConfirmation.cshtml.cs b/src/EthernaCredit.Services/Views/Emails/DepositConfirmation.cshtml.cs
index 0c4fe84..20981de 100644
--- a/src/EthernaCredit.Services/Views/Emails/DepositConfirmation.cshtml.cs
+++ b/src/EthernaCredit.Services/Views/Emails/DepositConfirmation.cshtml.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit.Services/Views/Emails/WithdrawalConfirmation.cshtml b/src/EthernaCredit.Services/Views/Emails/WithdrawalConfirmation.cshtml
index 1230100..e4c26ee 100644
--- a/src/EthernaCredit.Services/Views/Emails/WithdrawalConfirmation.cshtml
+++ b/src/EthernaCredit.Services/Views/Emails/WithdrawalConfirmation.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/EthernaCredit.Services/Views/Emails/WithdrawalConfirmation.cshtml.cs b/src/EthernaCredit.Services/Views/Emails/WithdrawalConfirmation.cshtml.cs
index b2ec39a..8f2c06f 100644
--- a/src/EthernaCredit.Services/Views/Emails/WithdrawalConfirmation.cshtml.cs
+++ b/src/EthernaCredit.Services/Views/Emails/WithdrawalConfirmation.cshtml.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit.Services/Views/Emails/_ViewImports.cshtml b/src/EthernaCredit.Services/Views/Emails/_ViewImports.cshtml
index eb3102e..20d84d0 100644
--- a/src/EthernaCredit.Services/Views/Emails/_ViewImports.cshtml
+++ b/src/EthernaCredit.Services/Views/Emails/_ViewImports.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/EthernaCredit.Services/Views/Emails/_ViewStart.cshtml b/src/EthernaCredit.Services/Views/Emails/_ViewStart.cshtml
index 7a1e266..c1f6ed4 100644
--- a/src/EthernaCredit.Services/Views/Emails/_ViewStart.cshtml
+++ b/src/EthernaCredit.Services/Views/Emails/_ViewStart.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/EthernaCredit/Areas/Account/Pages/Login.cshtml b/src/EthernaCredit/Areas/Account/Pages/Login.cshtml
index 706cf35..5398442 100644
--- a/src/EthernaCredit/Areas/Account/Pages/Login.cshtml
+++ b/src/EthernaCredit/Areas/Account/Pages/Login.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/EthernaCredit/Areas/Account/Pages/Login.cshtml.cs b/src/EthernaCredit/Areas/Account/Pages/Login.cshtml.cs
index 438ae08..c171c61 100644
--- a/src/EthernaCredit/Areas/Account/Pages/Login.cshtml.cs
+++ b/src/EthernaCredit/Areas/Account/Pages/Login.cshtml.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit/Areas/Account/Pages/Logout.cshtml b/src/EthernaCredit/Areas/Account/Pages/Logout.cshtml
index 8f078db..9941770 100644
--- a/src/EthernaCredit/Areas/Account/Pages/Logout.cshtml
+++ b/src/EthernaCredit/Areas/Account/Pages/Logout.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/EthernaCredit/Areas/Account/Pages/Logout.cshtml.cs b/src/EthernaCredit/Areas/Account/Pages/Logout.cshtml.cs
index e31b1aa..fd7cf40 100644
--- a/src/EthernaCredit/Areas/Account/Pages/Logout.cshtml.cs
+++ b/src/EthernaCredit/Areas/Account/Pages/Logout.cshtml.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit/Areas/Admin/Pages/Index.cshtml b/src/EthernaCredit/Areas/Admin/Pages/Index.cshtml
index 412a5bf..868c473 100644
--- a/src/EthernaCredit/Areas/Admin/Pages/Index.cshtml
+++ b/src/EthernaCredit/Areas/Admin/Pages/Index.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/EthernaCredit/Areas/Admin/Pages/Index.cshtml.cs b/src/EthernaCredit/Areas/Admin/Pages/Index.cshtml.cs
index d4bb624..eaec366 100644
--- a/src/EthernaCredit/Areas/Admin/Pages/Index.cshtml.cs
+++ b/src/EthernaCredit/Areas/Admin/Pages/Index.cshtml.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit/Areas/Admin/Pages/Users/AdminUpdateUserBalance.cshtml b/src/EthernaCredit/Areas/Admin/Pages/Users/AdminUpdateUserBalance.cshtml
new file mode 100644
index 0000000..141ec7e
--- /dev/null
+++ b/src/EthernaCredit/Areas/Admin/Pages/Users/AdminUpdateUserBalance.cshtml
@@ -0,0 +1,69 @@
+@page
+@model Etherna.CreditSystem.Areas.Admin.Pages.Users.AdminUpdateUserBalanceModel
+@{
+ ViewData["Title"] = "Update user balance";
+}
+
+
+
+
+
+
@ViewData["Title"]
+
+
+
+
+
+
diff --git a/src/EthernaCredit/Areas/Admin/Pages/Users/AdminUpdateUserBalance.cshtml.cs b/src/EthernaCredit/Areas/Admin/Pages/Users/AdminUpdateUserBalance.cshtml.cs
new file mode 100644
index 0000000..fe64569
--- /dev/null
+++ b/src/EthernaCredit/Areas/Admin/Pages/Users/AdminUpdateUserBalance.cshtml.cs
@@ -0,0 +1,111 @@
+// Copyright 2021-present Etherna Sa
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using Etherna.Authentication;
+using Etherna.CreditSystem.Domain;
+using Etherna.CreditSystem.Domain.Events;
+using Etherna.CreditSystem.Domain.Models;
+using Etherna.CreditSystem.Domain.Models.OperationLogs;
+using Etherna.CreditSystem.Services.Domain;
+using Etherna.DomainEvents;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using System.ComponentModel.DataAnnotations;
+using System.Threading.Tasks;
+
+namespace Etherna.CreditSystem.Areas.Admin.Pages.Users
+{
+ public class AdminUpdateUserBalanceModel : PageModel
+ {
+ // Models.
+ public class InputModel
+ {
+ [Required]
+ public XDaiBalance ChangeAmount { get; set; } //TODO: Use model binder
+
+ [Required]
+ public string Reason { get; set; } = default!;
+ }
+
+ // Fields.
+ private readonly ICreditDbContext creditDbContext;
+ private readonly IEthernaOpenIdConnectClient ethernaOidcClient;
+ private readonly IEventDispatcher eventDispatcher;
+ private readonly IUserService userService;
+
+ // Constructor.
+ public AdminUpdateUserBalanceModel(
+ ICreditDbContext creditDbContext,
+ IEthernaOpenIdConnectClient ethernaOidcClient,
+ IEventDispatcher eventDispatcher,
+ IUserService userService)
+ {
+ this.creditDbContext = creditDbContext;
+ this.ethernaOidcClient = ethernaOidcClient;
+ this.eventDispatcher = eventDispatcher;
+ this.userService = userService;
+ }
+
+ // Properties.
+ [BindProperty]
+ public InputModel Input { get; set; } = default!;
+
+ public XDaiBalance CurrentBalance { get; private set; }
+ public string Id { get; private set; } = default!;
+
+ // Methods.
+ public async Task OnGetAsync(string id)
+ {
+ await InitializeAsync(id);
+ }
+
+ public async Task OnPostAsync(string id)
+ {
+ if (!ModelState.IsValid)
+ {
+ await InitializeAsync(id);
+ return Page();
+ }
+
+ // Get data.
+ var currentUserAddress = await ethernaOidcClient.GetEtherAddressAsync();
+
+ // Update balance.
+ var user = await creditDbContext.Users.FindOneAsync(id);
+ await userService.TryIncrementUserBalanceAsync(user, Input.ChangeAmount, true);
+
+ // Report log.
+ var adminUpdateLog = new AdminUpdateOperationLog(
+ Input.ChangeAmount,
+ currentUserAddress,
+ Input.Reason,
+ user);
+ await creditDbContext.OperationLogs.CreateAsync(adminUpdateLog);
+
+ // Dispatch event.
+ await eventDispatcher.DispatchAsync(new AdminUpdateUserBalanceEvent(adminUpdateLog));
+
+ return RedirectToPage("User", new { id });
+ }
+
+ // Helpers.
+ private async Task InitializeAsync(string id)
+ {
+ var user = await creditDbContext.Users.FindOneAsync(id);
+
+ Id = id;
+ CurrentBalance = await userService.GetUserBalanceAsync(user);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/EthernaCredit/Areas/Admin/Pages/Users/Index.cshtml b/src/EthernaCredit/Areas/Admin/Pages/Users/Index.cshtml
index 97f8358..d5003e1 100644
--- a/src/EthernaCredit/Areas/Admin/Pages/Users/Index.cshtml
+++ b/src/EthernaCredit/Areas/Admin/Pages/Users/Index.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -71,7 +71,6 @@
@user.Balance.ToFinancialString(
allowedDecimals: 4,
- suffixSymbol: " CHF",
usePlusSign: true) |
@user.HasUnlimitedCredit |
diff --git a/src/EthernaCredit/Areas/Admin/Pages/Users/Index.cshtml.cs b/src/EthernaCredit/Areas/Admin/Pages/Users/Index.cshtml.cs
index 9c092f5..8b654f9 100644
--- a/src/EthernaCredit/Areas/Admin/Pages/Users/Index.cshtml.cs
+++ b/src/EthernaCredit/Areas/Admin/Pages/Users/Index.cshtml.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,12 +38,10 @@ public class InputModel
public class UserDto
{
- public UserDto(User user, UserSharedInfo userSharedInfo, decimal balance)
+ public UserDto(User user, UserSharedInfo userSharedInfo, XDaiBalance balance)
{
- if (user is null)
- throw new ArgumentNullException(nameof(user));
- if (userSharedInfo is null)
- throw new ArgumentNullException(nameof(userSharedInfo));
+ ArgumentNullException.ThrowIfNull(user, nameof(user));
+ ArgumentNullException.ThrowIfNull(userSharedInfo, nameof(userSharedInfo));
Id = user.Id;
Balance = balance;
@@ -52,7 +50,7 @@ public UserDto(User user, UserSharedInfo userSharedInfo, decimal balance)
}
public string Id { get; }
- public decimal Balance { get; }
+ public XDaiBalance Balance { get; }
public string EtherAddress { get; }
public bool HasUnlimitedCredit { get; }
}
@@ -78,7 +76,7 @@ public IndexModel(
public InputModel Input { get; set; } = default!;
public int CurrentPage { get; private set; }
- public int MaxPage { get; private set; }
+ public long MaxPage { get; private set; }
public List Users { get; } = new();
// Methods.
diff --git a/src/EthernaCredit/Areas/Admin/Pages/Users/User.cshtml b/src/EthernaCredit/Areas/Admin/Pages/Users/User.cshtml
index 554b45c..8188635 100644
--- a/src/EthernaCredit/Areas/Admin/Pages/Users/User.cshtml
+++ b/src/EthernaCredit/Areas/Admin/Pages/Users/User.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -90,10 +90,10 @@
diff --git a/src/EthernaCredit/Areas/Admin/Pages/Users/User.cshtml.cs b/src/EthernaCredit/Areas/Admin/Pages/Users/User.cshtml.cs
index 038b921..93d0c02 100644
--- a/src/EthernaCredit/Areas/Admin/Pages/Users/User.cshtml.cs
+++ b/src/EthernaCredit/Areas/Admin/Pages/Users/User.cshtml.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -13,6 +13,7 @@
// limitations under the License.
using Etherna.CreditSystem.Domain;
+using Etherna.CreditSystem.Domain.Models;
using Etherna.CreditSystem.Services.Domain;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
@@ -50,7 +51,7 @@ public UserModel(
// Properties.
public string Id { get; private set; } = default!;
- public decimal Balance { get; private set; }
+ public XDaiBalance Balance { get; private set; }
[Display(Name = "Ethereum address")]
public string? EtherAddress { get; private set; }
diff --git a/src/EthernaCredit/Areas/Admin/Pages/_ViewImports.cshtml b/src/EthernaCredit/Areas/Admin/Pages/_ViewImports.cshtml
index 31c9c75..433ba76 100644
--- a/src/EthernaCredit/Areas/Admin/Pages/_ViewImports.cshtml
+++ b/src/EthernaCredit/Areas/Admin/Pages/_ViewImports.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/EthernaCredit/Areas/Admin/Pages/_ViewStart.cshtml b/src/EthernaCredit/Areas/Admin/Pages/_ViewStart.cshtml
index abf2015..adec094 100644
--- a/src/EthernaCredit/Areas/Admin/Pages/_ViewStart.cshtml
+++ b/src/EthernaCredit/Areas/Admin/Pages/_ViewStart.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/EthernaCredit/Areas/Api/ApiHostingStartup.cs b/src/EthernaCredit/Areas/Api/ApiHostingStartup.cs
index 0ec385d..13650e4 100644
--- a/src/EthernaCredit/Areas/Api/ApiHostingStartup.cs
+++ b/src/EthernaCredit/Areas/Api/ApiHostingStartup.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,12 +27,11 @@ public class ApiHostingStartup : IHostingStartup
public void Configure(IWebHostBuilder builder)
{
- if (builder is null)
- throw new ArgumentNullException(nameof(builder));
+ ArgumentNullException.ThrowIfNull(builder, nameof(builder));
builder.ConfigureServices((context, services) => {
- var currentType = typeof(Startup).GetTypeInfo();
+ var currentType = typeof(Program).GetTypeInfo();
var servicesNamespace = $"{currentType.Namespace}.{ServicesSubNamespace}";
// Register services.
@@ -40,9 +39,7 @@ public void Configure(IWebHostBuilder builder)
where t.IsClass && t.Namespace == servicesNamespace && t.DeclaringType == null
select t)
{
- var serviceInterfaceType = serviceType.GetInterface($"I{serviceType.Name}");
- if (serviceInterfaceType is null)
- throw new InvalidOperationException();
+ var serviceInterfaceType = serviceType.GetInterface($"I{serviceType.Name}") ?? throw new InvalidOperationException();
services.AddScoped(serviceInterfaceType, serviceType);
}
});
diff --git a/src/EthernaCredit/Areas/Api/Controllers/ServiceInteractController.cs b/src/EthernaCredit/Areas/Api/Controllers/ServiceInteractController.cs
index a945c8d..66a4320 100644
--- a/src/EthernaCredit/Areas/Api/Controllers/ServiceInteractController.cs
+++ b/src/EthernaCredit/Areas/Api/Controllers/ServiceInteractController.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -80,12 +80,17 @@ public Task> GetServiceOpLogsWithUserAsync(
///
/// The user address
/// The amount to be updated. Positive for credit, negative for debit
+ /// True if credit update needs to be applied to user balance
/// The update reason description
[HttpPut("users/{address}/credit/balance")]
[SimpleExceptionFilter]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
- public Task RegisterBalanceUpdateAsync([Required] string address, [Required] decimal amount, [Required] string reason) =>
- service.RegisterBalanceUpdateAsync(address, amount, reason);
+ public Task RegisterBalanceUpdateAsync(
+ [Required] string address,
+ [Required] decimal amount,
+ [Required] string reason,
+ bool isApplied = true) =>
+ service.RegisterBalanceUpdateAsync(address, amount, isApplied, reason);
}
}
diff --git a/src/EthernaCredit/Areas/Api/Controllers/UserController.cs b/src/EthernaCredit/Areas/Api/Controllers/UserController.cs
index 0706596..05a4fc4 100644
--- a/src/EthernaCredit/Areas/Api/Controllers/UserController.cs
+++ b/src/EthernaCredit/Areas/Api/Controllers/UserController.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,10 +15,8 @@
using Etherna.CreditSystem.Areas.Api.DtoModels;
using Etherna.CreditSystem.Areas.Api.Services;
using Etherna.CreditSystem.Attributes;
-using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
-using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
@@ -28,7 +26,6 @@ namespace Etherna.CreditSystem.Areas.Api.Controllers
[ApiController]
[ApiVersion("0.3")]
[Route("api/v{api-version:apiVersion}/[controller]")]
- [Authorize]
public class UserController : ControllerBase
{
// Fields.
@@ -49,6 +46,7 @@ public UserController(IUserControllerService service)
[HttpGet("address")]
[SimpleExceptionFilter]
[ProducesResponseType(StatusCodes.Status200OK)]
+ [Produces("application/json")] //force because of https://github.com/RicoSuter/NSwag/issues/4132
public Task GetAddressAsync() =>
service.GetAddressAsync();
diff --git a/src/EthernaCredit/Areas/Api/DtoModels/CreditDto.cs b/src/EthernaCredit/Areas/Api/DtoModels/CreditDto.cs
index bd969fc..ce95ad8 100644
--- a/src/EthernaCredit/Areas/Api/DtoModels/CreditDto.cs
+++ b/src/EthernaCredit/Areas/Api/DtoModels/CreditDto.cs
@@ -1,24 +1,26 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
+using Etherna.CreditSystem.Domain.Models;
+
namespace Etherna.CreditSystem.Areas.Api.DtoModels
{
public class CreditDto
{
- public CreditDto(decimal balance, bool isUnlimited)
+ public CreditDto(XDaiBalance balance, bool isUnlimited)
{
- Balance = balance;
+ Balance = balance.ToDecimal();
IsUnlimited = isUnlimited;
}
diff --git a/src/EthernaCredit/Areas/Api/DtoModels/OperationLogDto.cs b/src/EthernaCredit/Areas/Api/DtoModels/OperationLogDto.cs
index 93fdfad..3ad5c17 100644
--- a/src/EthernaCredit/Areas/Api/DtoModels/OperationLogDto.cs
+++ b/src/EthernaCredit/Areas/Api/DtoModels/OperationLogDto.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,7 +15,6 @@
using Etherna.CreditSystem.Domain.Models;
using Etherna.CreditSystem.Domain.Models.OperationLogs;
using Etherna.CreditSystem.Domain.Models.UserAgg;
-using Etherna.MongoDB.Bson;
using System;
namespace Etherna.CreditSystem.Areas.Api.DtoModels
@@ -24,12 +23,10 @@ public class OperationLogDto
{
public OperationLogDto(OperationLogBase operationLog, UserSharedInfo userSharedInfo)
{
- if (operationLog is null)
- throw new ArgumentNullException(nameof(operationLog));
- if (userSharedInfo is null)
- throw new ArgumentNullException(nameof(userSharedInfo));
+ ArgumentNullException.ThrowIfNull(operationLog, nameof(operationLog));
+ ArgumentNullException.ThrowIfNull(userSharedInfo, nameof(userSharedInfo));
- Amount = Decimal128.ToDecimal(operationLog.Amount);
+ Amount = operationLog.Amount.ToDecimal();
Author = operationLog.Author;
CreationDateTime = operationLog.CreationDateTime;
OperationName = operationLog.OperationName;
@@ -38,6 +35,7 @@ public OperationLogDto(OperationLogBase operationLog, UserSharedInfo userSharedI
switch (operationLog)
{
case UpdateOperationLog updateLog:
+ IsApplied = updateLog.IsApplied;
Reason = updateLog.Reason;
break;
}
@@ -46,6 +44,7 @@ public OperationLogDto(OperationLogBase operationLog, UserSharedInfo userSharedI
public decimal Amount { get; }
public string Author { get; }
public DateTime CreationDateTime { get; }
+ public bool? IsApplied { get; }
public string OperationName { get; }
public string? Reason { get; }
public string UserAddress { get; }
diff --git a/src/EthernaCredit/Areas/Api/Services/IServiceInteractControllerService.cs b/src/EthernaCredit/Areas/Api/Services/IServiceInteractControllerService.cs
index e8d824a..7109849 100644
--- a/src/EthernaCredit/Areas/Api/Services/IServiceInteractControllerService.cs
+++ b/src/EthernaCredit/Areas/Api/Services/IServiceInteractControllerService.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -13,6 +13,7 @@
// limitations under the License.
using Etherna.CreditSystem.Areas.Api.DtoModels;
+using Etherna.CreditSystem.Domain.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -30,7 +31,8 @@ Task> GetServiceOpLogsWithUserAsync(
Task RegisterBalanceUpdateAsync(
string address,
- decimal amount,
+ XDaiBalance amount,
+ bool isApplied,
string reason);
}
}
\ No newline at end of file
diff --git a/src/EthernaCredit/Areas/Api/Services/IUserControllerService.cs b/src/EthernaCredit/Areas/Api/Services/IUserControllerService.cs
index 7754358..0595899 100644
--- a/src/EthernaCredit/Areas/Api/Services/IUserControllerService.cs
+++ b/src/EthernaCredit/Areas/Api/Services/IUserControllerService.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit/Areas/Api/Services/ServiceInteractControllerService.cs b/src/EthernaCredit/Areas/Api/Services/ServiceInteractControllerService.cs
index 2c7c4f1..36bdb61 100644
--- a/src/EthernaCredit/Areas/Api/Services/ServiceInteractControllerService.cs
+++ b/src/EthernaCredit/Areas/Api/Services/ServiceInteractControllerService.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,7 +18,6 @@
using Etherna.CreditSystem.Domain.Models;
using Etherna.CreditSystem.Domain.Models.OperationLogs;
using Etherna.CreditSystem.Services.Domain;
-using Etherna.MongoDB.Bson;
using Etherna.MongoDB.Driver;
using Etherna.MongoDB.Driver.Linq;
using System;
@@ -82,7 +81,8 @@ public async Task GetUserCreditAsync(string address)
public async Task RegisterBalanceUpdateAsync(
string address,
- decimal amount,
+ XDaiBalance amount,
+ bool isApplied,
string reason)
{
var clientId = await ethernaOidcClient.GetClientIdAsync();
@@ -91,9 +91,12 @@ public async Task RegisterBalanceUpdateAsync(
var (user, _) = await userService.FindUserAsync(address);
// Apply update (balance can go negative).
- var result = await userService.TryIncrementUserBalanceAsync(user, amount, true);
- if (!result)
- throw new InvalidOperationException();
+ if (isApplied)
+ {
+ var result = await userService.TryIncrementUserBalanceAsync(user, amount, true);
+ if (!result)
+ throw new InvalidOperationException();
+ }
// Create or update log.
var updatedLog = await dbContext.OperationLogs.AccessToCollectionAsync(collection =>
@@ -101,13 +104,14 @@ public async Task RegisterBalanceUpdateAsync(
Builders.Filter.OfType(
log => log.Author == clientId &&
log.CreationDateTime >= DateTime.Now.Date &&
+ log.IsApplied == isApplied &&
log.Reason == reason &&
log.User.Id == user.Id),
- Builders.Update.Inc(log => log.Amount, new Decimal128(amount))));
+ Builders.Update.Inc(log => log.Amount, amount)));
if (updatedLog is null) //if a previous log didn't exist
{
- var withdrawLog = new UpdateOperationLog(amount, clientId, reason, user);
+ var withdrawLog = new UpdateOperationLog(amount, clientId, isApplied, reason, user);
await dbContext.OperationLogs.CreateAsync(withdrawLog);
}
}
diff --git a/src/EthernaCredit/Areas/Api/Services/UserControllerService.cs b/src/EthernaCredit/Areas/Api/Services/UserControllerService.cs
index d3f5fe5..80af602 100644
--- a/src/EthernaCredit/Areas/Api/Services/UserControllerService.cs
+++ b/src/EthernaCredit/Areas/Api/Services/UserControllerService.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/src/EthernaCredit/Areas/Deposit/Pages/DepositProcess.cshtml b/src/EthernaCredit/Areas/Deposit/Pages/DepositProcess.cshtml
index 91112eb..f7633a7 100644
--- a/src/EthernaCredit/Areas/Deposit/Pages/DepositProcess.cshtml
+++ b/src/EthernaCredit/Areas/Deposit/Pages/DepositProcess.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,11 +24,11 @@
@if (Model.SucceededResult)
{
-
An amount of @Model.DepositAmount.ToFinancialString(suffixSymbol: " CHF") has been deposited to your account
+
An amount of @Model.DepositAmount.ToFinancialString() has been deposited to your account
}
else
{
-
Sorry, we was not able to deposit an amount of @Model.DepositAmount.ToFinancialString(suffixSymbol: " CHF") to your account
+
Sorry, we was not able to deposit an amount of @Model.DepositAmount.ToFinancialString() to your account
}
Return to account
diff --git a/src/EthernaCredit/Areas/Deposit/Pages/DepositProcess.cshtml.cs b/src/EthernaCredit/Areas/Deposit/Pages/DepositProcess.cshtml.cs
index aa01599..5140963 100644
--- a/src/EthernaCredit/Areas/Deposit/Pages/DepositProcess.cshtml.cs
+++ b/src/EthernaCredit/Areas/Deposit/Pages/DepositProcess.cshtml.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,6 +15,7 @@
using Etherna.Authentication;
using Etherna.CreditSystem.Domain;
using Etherna.CreditSystem.Domain.Events;
+using Etherna.CreditSystem.Domain.Models;
using Etherna.CreditSystem.Domain.Models.OperationLogs;
using Etherna.CreditSystem.Services.Domain;
using Etherna.DomainEvents;
@@ -48,7 +49,7 @@ public DepositProcessModel(
}
// Properties.
- public decimal DepositAmount { get; set; }
+ public XDaiBalance DepositAmount { get; set; }
public bool SucceededResult { get; set; }
// Methods
@@ -57,14 +58,18 @@ public IActionResult OnGet() =>
public async Task OnPostAsync(string amount)
{
- if (amount is null)
- throw new ArgumentNullException(nameof(amount));
+ ArgumentNullException.ThrowIfNull(amount, nameof(amount));
// Get data.
- DepositAmount = decimal.Parse(amount.Trim('$'), CultureInfo.InvariantCulture);
+ DepositAmount = decimal.Parse(amount, CultureInfo.InvariantCulture);
var (user, userSharedInfo) = await userService.FindUserAsync(await ethernaOidcClient.GetEtherAddressAsync());
// Preliminary check.
+ if (DepositAmount <= 0)
+ {
+ SucceededResult = false;
+ return;
+ }
if (user.HasUnlimitedCredit) //disable deposit if unlimited credit
{
SucceededResult = false;
@@ -79,8 +84,7 @@ public async Task OnPostAsync(string amount)
await dbContext.OperationLogs.CreateAsync(depositLog);
// Dispatch event.
- await eventDispatcher.DispatchAsync(new UserDepositEvent(
- DepositAmount, user));
+ await eventDispatcher.DispatchAsync(new UserDepositEvent(depositLog));
SucceededResult = true;
}
diff --git a/src/EthernaCredit/Areas/Deposit/Pages/_ViewImports.cshtml b/src/EthernaCredit/Areas/Deposit/Pages/_ViewImports.cshtml
index 10b9fa4..02a642d 100644
--- a/src/EthernaCredit/Areas/Deposit/Pages/_ViewImports.cshtml
+++ b/src/EthernaCredit/Areas/Deposit/Pages/_ViewImports.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/EthernaCredit/Areas/Deposit/Pages/_ViewStart.cshtml b/src/EthernaCredit/Areas/Deposit/Pages/_ViewStart.cshtml
index cf01ba6..8fde5c2 100644
--- a/src/EthernaCredit/Areas/Deposit/Pages/_ViewStart.cshtml
+++ b/src/EthernaCredit/Areas/Deposit/Pages/_ViewStart.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/EthernaCredit/Areas/Manage/Pages/Deposit.cshtml b/src/EthernaCredit/Areas/Manage/Pages/Deposit.cshtml
index 3d6018d..8dbd17a 100644
--- a/src/EthernaCredit/Areas/Manage/Pages/Deposit.cshtml
+++ b/src/EthernaCredit/Areas/Manage/Pages/Deposit.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,12 +27,12 @@
diff --git a/src/EthernaCredit/Areas/Manage/Pages/Logs.cshtml.cs b/src/EthernaCredit/Areas/Manage/Pages/Logs.cshtml.cs
index 67eb795..e087a94 100644
--- a/src/EthernaCredit/Areas/Manage/Pages/Logs.cshtml.cs
+++ b/src/EthernaCredit/Areas/Manage/Pages/Logs.cshtml.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -47,7 +47,7 @@ public LogsModel(
// Properties.
public int CurrentPage { get; private set; }
- public int MaxPage { get; private set; }
+ public long MaxPage { get; private set; }
public IEnumerable Logs { get; private set; } = Array.Empty();
// Methods.
diff --git a/src/EthernaCredit/Areas/Manage/Pages/ManageNavPages.cs b/src/EthernaCredit/Areas/Manage/Pages/ManageNavPages.cs
index f6d461e..8a9b83c 100644
--- a/src/EthernaCredit/Areas/Manage/Pages/ManageNavPages.cs
+++ b/src/EthernaCredit/Areas/Manage/Pages/ManageNavPages.cs
@@ -1,11 +1,11 @@
-// Copyright 2021-present Etherna Sagl
-//
+// Copyright 2021-present Etherna Sa
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,32 +28,28 @@ public static class ManageNavPages
// Methods.
public static string? StatusNavClass(ViewContext viewContext)
{
- if (viewContext is null)
- throw new ArgumentNullException(nameof(viewContext));
+ ArgumentNullException.ThrowIfNull(viewContext, nameof(viewContext));
return PageNavClass(viewContext, Status);
}
public static string? LogsNavClass(ViewContext viewContext)
{
- if (viewContext is null)
- throw new ArgumentNullException(nameof(viewContext));
+ ArgumentNullException.ThrowIfNull(viewContext, nameof(viewContext));
return PageNavClass(viewContext, Logs);
}
public static string? DepositNavClass(ViewContext viewContext)
{
- if (viewContext is null)
- throw new ArgumentNullException(nameof(viewContext));
+ ArgumentNullException.ThrowIfNull(viewContext, nameof(viewContext));
return PageNavClass(viewContext, Deposit);
}
public static string? WithdrawNavClass(ViewContext viewContext)
{
- if (viewContext is null)
- throw new ArgumentNullException(nameof(viewContext));
+ ArgumentNullException.ThrowIfNull(viewContext, nameof(viewContext));
return PageNavClass(viewContext, Withdraw);
}
diff --git a/src/EthernaCredit/Areas/Manage/Pages/Withdraw.cshtml b/src/EthernaCredit/Areas/Manage/Pages/Withdraw.cshtml
index 6e0560f..6e1c8fd 100644
--- a/src/EthernaCredit/Areas/Manage/Pages/Withdraw.cshtml
+++ b/src/EthernaCredit/Areas/Manage/Pages/Withdraw.cshtml
@@ -1,4 +1,4 @@
-@* * Copyright 2021-present Etherna Sagl
+@* * Copyright 2021-present Etherna Sa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,8 @@
@if (Model.CanWithdraw)
{
How much do you want to withdraw from your account? (
- min: @Model.MinLimit.ToFinancialString(roundMode: MidpointRounding.ToZero, suffixSymbol: " CHF"),
- max: @Model.MaxLimit.ToFinancialString(roundMode: MidpointRounding.ToZero, suffixSymbol: " CHF"))
+ min: @Model.MinLimit.ToFinancialString(roundMode: MidpointRounding.ToZero),
+ max: @Model.MaxLimit.ToFinancialString(roundMode: MidpointRounding.ToZero))