Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
HIAST-Clinics
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
almohanad.hafez
HIAST-Clinics
Commits
674add08
Commit
674add08
authored
Aug 25, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add notifications
parent
a8c67c7a
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
100 additions
and
67 deletions
+100
-67
Program.cs
Clinics.Backend/API/Program.cs
+7
-9
IDoctorsNotificationService.cs
...ions/Notifications/Doctors/IDoctorsNotificationService.cs
+8
-0
NewVisitNotification.cs
...ons/Doctors/NewVisitNotifications/NewVisitNotification.cs
+22
-0
INotification.cs
...d/Application/Abstractions/Notifications/INotification.cs
+5
-0
INotificationClient.cs
...ackend/Infrastructure/Abstractions/INotificationClient.cs
+9
-0
AssemblyReference.cs
Clinics.Backend/Infrastructure/AssemblyReference.cs
+8
-0
ServerTimeNotifier.cs
...re/BackgroundServices/Notifications/ServerTimeNotifier.cs
+0
-38
NotificationHub.cs
...ackend/Infrastructure/NotificationsHub/NotificationHub.cs
+0
-20
DoctorsNotificationsHub.cs
...frastructure/NotificationsHubs/DoctorsNotificationsHub.cs
+8
-0
ReceptionistsNotificationsHub.cs
...ucture/NotificationsHubs/ReceptionistsNotificationsHub.cs
+8
-0
DoctorsNotificationsService.cs
...ificationsServices/Doctors/DoctorsNotificationsService.cs
+25
-0
No files found.
Clinics.Backend/API/Program.cs
View file @
674add08
...
...
@@ -3,8 +3,8 @@ using API.Options.JWT;
using
API.SeedDatabaseHelper
;
using
Application.Behaviors
;
using
FluentValidation
;
using
Infrastructure
.BackgroundServices.Notifications
;
using
Infrastructure.Notifications
Service
;
using
Infrastructure
;
using
Infrastructure.Notifications
Hubs
;
using
MediatR
;
using
Microsoft.AspNetCore.Authentication.JwtBearer
;
using
Microsoft.EntityFrameworkCore
;
...
...
@@ -43,23 +43,20 @@ builder.Services.AddDbContext<ClinicsDbContext>(
#region Add SignalR
builder
.
Services
.
AddSignalR
();
// Background services:
//builder.Services.AddHostedService<ServerTimeNotifier>();
#endregion
#region Add CORS
builder
.
Services
.
AddCors
();
#endregion
#region Link interfaces implemented in
persistenc
e
#region Link interfaces implemented in
infrastructr
e
// Using Scrutor library
builder
.
Services
.
Scan
(
selector
=>
selector
.
FromAssemblies
(
Persistence
.
AssemblyReference
.
Assembly
// Add other assemblies here
.
FromAssemblies
(
Persistence
.
AssemblyReference
.
Assembly
,
Infrastructure
.
AssemblyReference
.
Assembly
)
.
AddClasses
(
false
)
.
AsImplementedInterfaces
()
...
...
@@ -142,7 +139,8 @@ if (app.Environment.IsDevelopment())
app
.
UseHttpsRedirection
();
#region Map notification HUB
app
.
MapHub
<
NotificationHub
>(
"api/Notifications"
);
app
.
MapHub
<
DoctorsNotificationsHub
>(
"api/Notifications/Doctors"
);
app
.
MapHub
<
ReceptionistsNotificationsHub
>(
"api/Notifications/Receptionists"
);
#endregion
#region CORS
...
...
Clinics.Backend/Application/Abstractions/Notifications/Doctors/IDoctorsNotificationService.cs
0 → 100644
View file @
674add08
using
Application.Abstractions.Notifications.Doctors.NewVisitNotifications
;
namespace
Application.Abstractions.Notifications.Doctors
;
public
interface
IDoctorsNotificationService
{
public
Task
SendNewVisitNotification
(
NewVisitNotification
notification
);
}
Clinics.Backend/Application/Abstractions/Notifications/Doctors/NewVisitNotifications/NewVisitNotification.cs
0 → 100644
View file @
674add08
namespace
Application.Abstractions.Notifications.Doctors.NewVisitNotifications
;
public
class
NewVisitNotification
:
INotification
{
private
NewVisitNotification
(
int
patientId
,
string
patientFullName
,
int
doctorId
,
int
doctorUserId
)
{
PatientId
=
patientId
;
PatientFullName
=
patientFullName
;
DoctorId
=
doctorId
;
DoctorUserId
=
doctorUserId
;
}
public
int
PatientId
{
get
;
set
;
}
public
string
PatientFullName
{
get
;
set
;
}
=
null
!;
public
int
DoctorId
{
get
;
set
;
}
public
int
DoctorUserId
{
get
;
set
;
}
public
static
NewVisitNotification
Create
(
int
patientId
,
string
patientFullName
,
int
doctorId
,
int
doctorUserId
)
{
return
new
NewVisitNotification
(
patientId
,
patientFullName
,
doctorId
,
doctorUserId
);
}
}
Clinics.Backend/Application/Abstractions/Notifications/INotification.cs
0 → 100644
View file @
674add08
namespace
Application.Abstractions.Notifications
;
public
interface
INotification
{
}
Clinics.Backend/Infrastructure/Abstractions/INotificationClient.cs
0 → 100644
View file @
674add08
using
Application.Abstractions.Notifications
;
namespace
Infrastructure.Abstractions
;
public
interface
INotificationClient
{
Task
ReceiveNotification
(
INotification
notification
);
}
Clinics.Backend/Infrastructure/AssemblyReference.cs
0 → 100644
View file @
674add08
using
System.Reflection
;
namespace
Infrastructure
;
public
class
AssemblyReference
{
public
static
readonly
Assembly
Assembly
=
typeof
(
AssemblyReference
).
Assembly
;
}
Clinics.Backend/Infrastructure/BackgroundServices/Notifications/ServerTimeNotifier.cs
deleted
100644 → 0
View file @
a8c67c7a
using
Infrastructure.NotificationsService
;
using
Microsoft.AspNetCore.SignalR
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Logging
;
namespace
Infrastructure.BackgroundServices.Notifications
;
public
class
ServerTimeNotifier
:
BackgroundService
{
private
static
readonly
TimeSpan
Period
=
TimeSpan
.
FromSeconds
(
3
);
#
region
CTOR
DI
private
readonly
ILogger
<
ServerTimeNotifier
>
_logger
;
private
readonly
IHubContext
<
NotificationHub
,
INotificationClient
>
_context
;
public
ServerTimeNotifier
(
ILogger
<
ServerTimeNotifier
>
logger
,
IHubContext
<
NotificationHub
,
INotificationClient
>
context
)
{
_logger
=
logger
;
_context
=
context
;
}
#
endregion
protected
override
async
Task
ExecuteAsync
(
CancellationToken
stoppingToken
)
{
using
var
timer
=
new
PeriodicTimer
(
Period
);
while
(!
stoppingToken
.
IsCancellationRequested
&&
await
timer
.
WaitForNextTickAsync
(
stoppingToken
))
{
var
dateTime
=
DateTime
.
Now
;
_logger
.
LogInformation
(
"Executing {Service} {Time}"
,
nameof
(
ServerTimeNotifier
),
dateTime
);
await
_context
.
Clients
.
All
.
ReceiveNotification
(
$"Server time =
{
dateTime
}
"
);
}
}
}
Clinics.Backend/Infrastructure/NotificationsHub/NotificationHub.cs
deleted
100644 → 0
View file @
a8c67c7a
using
Microsoft.AspNetCore.SignalR
;
namespace
Infrastructure.NotificationsService
;
public
class
NotificationHub
:
Hub
<
INotificationClient
>
{
public
override
async
Task
OnConnectedAsync
()
{
await
Clients
.
Client
(
Context
.
ConnectionId
).
ReceiveNotification
(
$"Connected successfully
{
Context
.
User
?.
Identity
?.
Name
}
"
);
await
base
.
OnConnectedAsync
();
}
}
public
interface
INotificationClient
{
Task
ReceiveNotification
(
string
message
);
}
\ No newline at end of file
Clinics.Backend/Infrastructure/NotificationsHubs/DoctorsNotificationsHub.cs
0 → 100644
View file @
674add08
using
Infrastructure.Abstractions
;
using
Microsoft.AspNetCore.SignalR
;
namespace
Infrastructure.NotificationsHubs
;
public
class
DoctorsNotificationsHub
:
Hub
<
INotificationClient
>
{
}
Clinics.Backend/Infrastructure/NotificationsHubs/ReceptionistsNotificationsHub.cs
0 → 100644
View file @
674add08
using
Infrastructure.Abstractions
;
using
Microsoft.AspNetCore.SignalR
;
namespace
Infrastructure.NotificationsHubs
;
public
class
ReceptionistsNotificationsHub
:
Hub
<
INotificationClient
>
{
}
Clinics.Backend/Infrastructure/NotificationsServices/Doctors/DoctorsNotificationsService.cs
0 → 100644
View file @
674add08
using
Application.Abstractions.Notifications.Doctors
;
using
Application.Abstractions.Notifications.Doctors.NewVisitNotifications
;
using
Infrastructure.Abstractions
;
using
Infrastructure.NotificationsHubs
;
using
Microsoft.AspNetCore.SignalR
;
namespace
Infrastructure.NotificationsServices.Doctors
;
public
class
DoctorsNotificationsService
:
IDoctorsNotificationService
{
#
region
CTOR
DI
private
readonly
IHubContext
<
DoctorsNotificationsHub
,
INotificationClient
>
_context
;
public
DoctorsNotificationsService
(
IHubContext
<
DoctorsNotificationsHub
,
INotificationClient
>
context
)
{
_context
=
context
;
}
#
endregion
public
async
Task
SendNewVisitNotification
(
NewVisitNotification
notification
)
{
await
_context
.
Clients
.
All
.
ReceiveNotification
(
notification
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment