Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanded Support for Non-Default ID Type in AuditableEntitiesByCreatedOnBetweenSpec #866

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7832d4e
[Enhancement](AuidiableEntitiesByCreatedOnBetweenSpec) extended behav…
baranacikgoz May 19, 2023
41701ce
Merge branch 'fullstackhero:main' into main
baranacikgoz Jul 11, 2023
0f619dc
used projection to improve performance
baranacikgoz Jul 11, 2023
0088cf9
eliminated AuditTrails since we dont use it
baranacikgoz Jul 11, 2023
6d500dc
return empty list
baranacikgoz Jul 11, 2023
d7b2bc6
refactored DbContext constructor parameters
baranacikgoz Jul 11, 2023
41725c0
removed shared database multitenancy since we use separate databases
baranacikgoz Jul 11, 2023
a659c5e
added EntityFrameworkCore.Exceptions.Postgresql package to get strong…
baranacikgoz Jul 11, 2023
15595a5
Used System.Text.Json instead of Newtonsoft for better performance
baranacikgoz Jul 11, 2023
2c91983
eliminated ISoftDelete since we dont use it
baranacikgoz Jul 11, 2023
63b3fee
added example chargeAggregate for event sourcing
baranacikgoz Jul 11, 2023
4c72fbd
eliminated ISoftDelete global query since we dont use it
baranacikgoz Jul 11, 2023
ae820be
updated docker conf
baranacikgoz Jul 13, 2023
7beef3f
disabled built-in docker support
baranacikgoz Jul 13, 2023
249cead
updated docker conf
baranacikgoz Jul 13, 2023
a9864bf
added compose file
baranacikgoz Jul 13, 2023
0c7dc83
allowed any on cors
baranacikgoz Jul 13, 2023
ad249f2
updated connection strings
baranacikgoz Jul 15, 2023
7b7cdd1
base implementation of push notification
baranacikgoz Jul 15, 2023
bb0c50f
implemented push notifications
baranacikgoz Jul 18, 2023
fa52be0
Merge branch 'main' into Feat-pushNotification
baranacikgoz Jul 18, 2023
3f49594
Merge pull request #1 from baranacikgoz/Feat-pushNotification
baranacikgoz Jul 18, 2023
a8739c7
solved dependency injection error
baranacikgoz Jul 18, 2023
74859c9
solved json errors in oneSignal service
baranacikgoz Jul 18, 2023
e4915e0
refactored names of push notifications related classes & interfaces
baranacikgoz Jul 18, 2023
445ae53
removed demo push notification send api
baranacikgoz Jul 18, 2023
726fc67
chore: changed solution name to prevent conflicts
baranacikgoz Jul 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use the official .NET 7 SDK image as the build environment
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env

# Set the working directory to /app
WORKDIR /app

# Copy the .csproj files and restore dependencies
COPY *.sln .
COPY src/Core/Domain/*.csproj .Domain/
COPY src/Core/Application/*.csproj .Application/
COPY src/Infrastructure/*.csproj .Infrastructure/
COPY src/Host/*.csproj .Host/

# Copy the remaining source code and build the application
COPY . ./
RUN dotnet publish -c Release -o out

# Use the official runtime image for .NET 7
FROM mcr.microsoft.com/dotnet/aspnet:7.0

# Set the working directory to /app
WORKDIR /app

# Copy the built application from the build environment
COPY --from=build-env /app/out .

# Set the entry point to run the Web API DLL file
ENTRYPOINT ["dotnet", "FSH.WebApi.Host.dll"]
3 changes: 1 addition & 2 deletions FSH.WebApi.sln → MaviArge.WebApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
docker-compose.yml = docker-compose.yml
dotnet.ruleset = dotnet.ruleset
FSH.WebApi.nuspec = FSH.WebApi.nuspec
global.json = global.json
icon.png = icon.png
LICENSE = LICENSE
README.md = README.md
Expand All @@ -51,7 +50,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Migrators.Oracle", "src\Mig
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "src\Core\Shared\Shared.csproj", "{5B986063-2160-4F86-AF1D-7F97671146C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Migrators.SqLite", "src\Migrators\Migrators.SqLite\Migrators.SqLite.csproj", "{4881A50F-5C2B-4381-81FD-3ECA11450016}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Migrators.SqLite", "src\Migrators\Migrators.SqLite\Migrators.SqLite.csproj", "{4881A50F-5C2B-4381-81FD-3ECA11450016}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
50 changes: 50 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: '3.8'
name: maviarge-tenant-demo-backend-setup
services:
dotnet-webapi:
image: baranacikgoz/maviarge-tenant-demo-amd64
container_name: dotnet-webapi
networks:
- maviarge
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:5100;http://+:5010
- ASPNETCORE_HTTPS_PORT=5100
- ASPNETCORE_Kestrel__Certificates__Default__Password=password!
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/cert.pfx
- DatabaseSettings__ConnectionString=Server=postgres;Port=5432;Database=postgres;User Id=postgres;Password=postgres
- HangfireSettings__Storage__ConnectionString=Server=postgres;Port=5432;Database=postgres;User Id=postgres;Password=postgres
- DatabaseSettings__DBProvider=postgresql
- HangfireSettings__Storage__StorageProvider=postgresql
volumes:
- ~/.aspnet/https:/https:ro
ports:
- 5100:5100
- 5010:5010
depends_on:
- postgres
restart: on-failure
postgres:
container_name: tenant-demo-postgres
image: postgres:15-alpine
networks:
- maviarge
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- PGPORT=5432
ports:
- 12998:5432
volumes:
- postgres-data:/data/db
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 10s
timeout: 5s
retries: 5

volumes:
postgres-data:
networks:
maviarge:
name: maviarge
22 changes: 22 additions & 0 deletions docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.9'

services:
tenant-demo-postgres:
container_name: tenant-demo-postgres
image: postgres:15-alpine
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- PGPORT=5432
ports:
- 12999:5432
volumes:
- tenant-demo-postgres-data:/data/db
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 10s
timeout: 5s
retries: 5

volumes:
tenant-demo-postgres-data:
3 changes: 3 additions & 0 deletions src/Core/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="EventSourcing\" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions src/Core/Application/Catalog/Charges/ChargeProjection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSH.WebApi.Application.Catalog.Charges;

//public class ChargeProjection :

Check warning on line 9 in src/Core/Application/Catalog/Charges/ChargeProjection.cs

View workflow job for this annotation

GitHub Actions / Build

Single line comment should begin with a space
//{

Check warning on line 10 in src/Core/Application/Catalog/Charges/ChargeProjection.cs

View workflow job for this annotation

GitHub Actions / Build

Single line comment should begin with a space
//}

Check warning on line 11 in src/Core/Application/Catalog/Charges/ChargeProjection.cs

View workflow job for this annotation

GitHub Actions / Build

Single line comment should begin with a space
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using FSH.WebApi.Application.Multitenancy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSH.WebApi.Application.Common.PushNotifications;

public interface IPushNotificationServiceFactory : ITransientService
{
IPushNotificationsService Create();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSH.WebApi.Application.Common.PushNotifications;

public interface IPushNotificationsService : ITransientService
{
Task SendTo(string userId, PushNotificationType notificationType);

Task SendToAll(PushNotificationType notificationType);

Task SendToActiveUsers(PushNotificationType notificationType);

Task SendToInactiveUsers(PushNotificationType notificationType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSH.WebApi.Application.Common.PushNotifications;

public interface IPushNotificationsTemplateFactory : ITransientService
{
(string HeadingEN, string HeadingTR, string ContentEN, string ContentTR) Create(PushNotificationType notificationType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSH.WebApi.Application.Common.PushNotifications.OneSignal;

public interface IOneSignalService : IPushNotificationsService
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSH.WebApi.Application.Common.PushNotifications;

public enum PushNotificationType
{
ChargeCompletedNotification,
ChargeStoppedWithErrorNotification,
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ public class AuditableEntitiesByCreatedOnBetweenSpec<T> : Specification<T>
{
public AuditableEntitiesByCreatedOnBetweenSpec(DateTime from, DateTime until) =>
Query.Where(e => e.CreatedOn >= from && e.CreatedOn <= until);
}
}

public class AuditableEntitiesByCreatedOnBetweenSpec<T, TIdType> : Specification<T>
where T : AuditableEntity<TIdType>
{
public AuditableEntitiesByCreatedOnBetweenSpec(DateTime from, DateTime until) =>
Query.Where(e => e.CreatedOn >= from && e.CreatedOn <= until);
}
1 change: 1 addition & 0 deletions src/Core/Application/Multitenancy/CreateTenantRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class CreateTenantRequest : IRequest<string>
public string? ConnectionString { get; set; }
public string AdminEmail { get; set; } = default!;
public string? Issuer { get; set; }
public TenantPushNotificationInfo? PushNotificationInfo { get; set; }
}

public class CreateTenantRequestHandler : IRequestHandler<CreateTenantRequest, string>
Expand Down
9 changes: 9 additions & 0 deletions src/Core/Application/Multitenancy/ITenantService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
public interface ITenantService
{
Task<List<TenantDto>> GetAllAsync();

Task<bool> ExistsWithIdAsync(string id);

Task<bool> ExistsWithNameAsync(string name);

Task<TenantDto> GetByIdAsync(string id);

Task<string> CreateAsync(CreateTenantRequest request, CancellationToken cancellationToken);

Task<string> ActivateAsync(string id);

Task<string> DeactivateAsync(string id);

Task<string> UpdateSubscription(string id, DateTime extendedExpiryDate);

Task<string> UpdatePushNotificationInfo(string id, TenantPushNotificationInfo pushNotificationInfo);
}
1 change: 1 addition & 0 deletions src/Core/Application/Multitenancy/TenantDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class TenantDto
public bool IsActive { get; set; }
public DateTime ValidUpto { get; set; }
public string? Issuer { get; set; }
public TenantPushNotificationInfo? PushNotificationInfo { get; set; }
}
14 changes: 14 additions & 0 deletions src/Core/Application/Multitenancy/TenantPushNotificationInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSH.WebApi.Application.Multitenancy;

public sealed record TenantPushNotificationInfo(PushNotificationProvider Provider, string AppId, string Name, string AuthKey, string IconUrl);

public enum PushNotificationProvider
{
OneSignal = 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSH.WebApi.Application.Multitenancy;
public sealed record UpdatePushNotificationInfoRequest(string Id, TenantPushNotificationInfo PushNotificationInfo)
: IRequest<string>;

public class UpdatePushNotificationInfoRequestValidator : CustomValidator<UpdatePushNotificationInfoRequest>
{
public UpdatePushNotificationInfoRequestValidator() =>
RuleFor(t => t.Id)
.NotEmpty();
}

public class UpdatePushNotificationInfoRequestHandler : IRequestHandler<UpdatePushNotificationInfoRequest, string>
{
private readonly ITenantService _tenantService;

public UpdatePushNotificationInfoRequestHandler(ITenantService tenantService) => _tenantService = tenantService;

public Task<string> Handle(UpdatePushNotificationInfoRequest request, CancellationToken cancellationToken) =>
_tenantService.UpdatePushNotificationInfo(request.Id, request.PushNotificationInfo);
}
43 changes: 43 additions & 0 deletions src/Core/Domain/Catalog/ChargeAggregate/Charge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using FSH.WebApi.Domain.Catalog.ChargeAggregate.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSH.WebApi.Domain.Catalog.ChargeAggregate;

public class Charge
{
public Charge(Guid id, Guid userId, int meterValue)
{
Id = id;
UserId = userId;
MeterValue = meterValue;
}

public Guid Id { get; private set; }
public Guid UserId { get; private set; }
public int MeterValue { get; private set; }
public ChargeStatus Status { get; private set; } = ChargeStatus.Initiated;

public ChargeInitiatedEvent InitiateCharge()
{
return new ChargeInitiatedEvent(Id, UserId);
}

public ChargeStartedEvent StartCharge()
{
return new ChargeStartedEvent(Id);
}

public ChargeReceivedMeterValueEvent ReceiveMeterValue(int meterValue)
{
return new ChargeReceivedMeterValueEvent(Id, meterValue);
}

public ChargeStoppedEvent StopCharge()
{
return new ChargeStoppedEvent(Id);
}
}
14 changes: 14 additions & 0 deletions src/Core/Domain/Catalog/ChargeAggregate/ChargeStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSH.WebApi.Domain.Catalog.ChargeAggregate;

public enum ChargeStatus
{
Initiated = 1,
Active = 2,
Stopped = 3,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSH.WebApi.Domain.Catalog.ChargeAggregate.Events;

public class ChargeInitiatedEvent : DomainEvent
{
public ChargeInitiatedEvent(Guid chargeId, Guid userId)
{
ChargeId = chargeId;
UserId = userId;
}

public Guid ChargeId { get; }
public Guid UserId { get; }
}
Loading
Loading