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
f22d57e6
Commit
f22d57e6
authored
Aug 26, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add change doctor status by user id command
parent
1ac4a103
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
9 deletions
+82
-9
ChangeStatusByUserIdCommand.cs
...mands/ChangeStatusByUserId/ChangeStatusByUserIdCommand.cs
+9
-0
ChangeStatusByUserIdHandler.cs
...mands/ChangeStatusByUserId/ChangeStatusByUserIdHandler.cs
+46
-0
SendWaitingListRecordToDoctorHandler.cs
...istRecordToDoctor/SendWaitingListRecordToDoctorHandler.cs
+1
-1
Doctor.cs
Clinics.Backend/Domain/Entities/People/Doctors/Doctor.cs
+14
-7
DoctorsController.cs
...ics.Backend/Presentation/Controllers/DoctorsController.cs
+12
-1
No files found.
Clinics.Backend/Application/Doctors/Commands/ChangeStatusByUserId/ChangeStatusByUserIdCommand.cs
0 → 100644
View file @
f22d57e6
using
Application.Abstractions.CQRS.Commands
;
namespace
Application.Doctors.Commands.ChangeStatusByUserId
;
public
class
ChangeStatusByUserIdCommand
:
ICommand
{
public
int
UserId
{
get
;
set
;
}
public
string
Status
{
get
;
set
;
}
=
null
!;
}
Clinics.Backend/Application/Doctors/Commands/ChangeStatusByUserId/ChangeStatusByUserIdHandler.cs
0 → 100644
View file @
f22d57e6
using
Application.Abstractions.CQRS.Commands
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
namespace
Application.Doctors.Commands.ChangeStatusByUserId
;
public
class
ChangeStatusByUserIdHandler
:
CommandHandlerBase
<
ChangeStatusByUserIdCommand
>
{
#
region
CTOR
DI
private
readonly
IDoctorsRepository
_doctorsRepository
;
private
readonly
IUserRepository
_userRepository
;
public
ChangeStatusByUserIdHandler
(
IUnitOfWork
unitOfWork
,
IDoctorsRepository
doctorsRepository
,
IUserRepository
userRepository
)
:
base
(
unitOfWork
)
{
_doctorsRepository
=
doctorsRepository
;
_userRepository
=
userRepository
;
}
#
endregion
public
override
async
Task
<
Result
>
HandleHelper
(
ChangeStatusByUserIdCommand
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
user
and
get
doctor
var
doctorUserFromPersistenceResult
=
await
_userRepository
.
GetDoctorUserByIdAsync
(
request
.
UserId
);
if
(
doctorUserFromPersistenceResult
.
IsFailure
)
return
Result
.
Failure
(
doctorUserFromPersistenceResult
.
Error
);
var
doctor
=
doctorUserFromPersistenceResult
.
Value
.
Doctor
;
#
endregion
#
region
2.
Change
status
var
changeStatusResult
=
doctor
.
ChangeStatusTo
(
request
.
Status
);
if
(
changeStatusResult
.
IsFailure
)
return
Result
.
Failure
(
changeStatusResult
.
Error
);
#
endregion
#
region
3.
Persist
changes
var
updateResult
=
await
_doctorsRepository
.
UpdateAsync
(
doctor
);
if
(
updateResult
.
IsFailure
)
return
Result
.
Failure
(
updateResult
.
Error
);
#
endregion
return
Result
.
Success
();
}
}
Clinics.Backend/Application/WaitingList/Commands/SendWaitingListRecordToDoctor/SendWaitingListRecordToDoctorHandler.cs
View file @
f22d57e6
...
...
@@ -42,7 +42,7 @@ public class SendWaitingListRecordToDoctorHandler : CommandHandlerBase<SendWaiti
if
(
doctorFromPersistence
.
IsFailure
)
return
Result
.
Failure
(
doctorFromPersistence
.
Error
);
var
doctor
=
doctorFromPersistence
.
Value
;
doctor
.
ChangeStatusTo
(
DoctorStatuses
.
Working
);
doctor
.
ChangeStatusTo
(
DoctorStatuses
.
Working
.
Name
);
var
changeStatusResult
=
await
_doctorsRepository
.
UpdateAsync
(
doctor
);
if
(
changeStatusResult
.
IsFailure
)
return
Result
.
Failure
(
changeStatusResult
.
Error
);
...
...
Clinics.Backend/Domain/Entities/People/Doctors/Doctor.cs
View file @
f22d57e6
...
...
@@ -72,14 +72,21 @@ public sealed class Doctor : Entity
#
endregion
#
region
Change
status
public
Result
ChangeStatusTo
(
DoctorStatus
status
)
public
Result
ChangeStatusTo
(
string
status
)
{
if
(
status
==
DoctorStatuses
.
Available
||
status
==
DoctorStatuses
.
Busy
||
status
==
DoctorStatuses
.
Working
)
{
Status
=
status
;
var
Available
=
DoctorStatuses
.
Available
;
var
Busy
=
DoctorStatuses
.
Busy
;
var
Working
=
DoctorStatuses
.
Working
;
if
(
status
==
Available
.
Name
)
Status
=
Available
;
else
if
(
status
==
Busy
.
Name
)
Status
=
Busy
;
else
if
(
status
==
Working
.
Name
)
Status
=
Working
;
else
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
Result
.
Success
();
}
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
}
#
endregion
...
...
Clinics.Backend/Presentation/Controllers/DoctorsController.cs
View file @
f22d57e6
using
Application.Doctors.Queries.GetAllDoctors
;
using
Application.Doctors.Commands.ChangeStatusByUserId
;
using
Application.Doctors.Queries.GetAllDoctors
;
using
Application.Doctors.Queries.GetStatusByUserId
;
using
Application.Employees.Queries.GetAvailable
;
using
Domain.Entities.Identity.UserRoles
;
...
...
@@ -51,4 +52,14 @@ public class DoctorsController : ApiController
return
HandleFailure
(
result
);
return
Ok
(
result
.
Value
);
}
//[Authorize(Roles = Roles.DoctorName)]
[
HttpPost
(
"Status"
)]
public
async
Task
<
IActionResult
>
ChangeStatusByUserId
([
FromBody
]
ChangeStatusByUserIdCommand
command
)
{
var
result
=
await
_sender
.
Send
(
command
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
();
}
}
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