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
f89e1817
Commit
f89e1817
authored
Aug 23, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add update doctor user commands
parent
ac879c28
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
232 additions
and
1 deletion
+232
-1
UpdateDoctorPersonalInfoCommand.cs
...dateDoctorPersonalInfo/UpdateDoctorPersonalInfoCommand.cs
+11
-0
UpdateDoctorPersonalInfoHandler.cs
...dateDoctorPersonalInfo/UpdateDoctorPersonalInfoHandler.cs
+42
-0
UpdateDoctorUserCommand.cs
...sers/Commands/UpdateDoctorUser/UpdateDoctorUserCommand.cs
+10
-0
UpdateDoctorUserHandler.cs
...sers/Commands/UpdateDoctorUser/UpdateDoctorUserHandler.cs
+55
-0
User.cs
Clinics.Backend/Domain/Entities/Identity/Users/User.cs
+10
-0
PersonalInfo.cs
...ics.Backend/Domain/Entities/People/Shared/PersonalInfo.cs
+14
-1
IUserRepository.cs
Clinics.Backend/Domain/Repositories/IUserRepository.cs
+12
-0
UserRepository.cs
....Backend/Persistence/Repositories/Users/UserRepository.cs
+55
-0
UsersController.cs
Clinics.Backend/Presentation/Controllers/UsersController.cs
+23
-0
No files found.
Clinics.Backend/Application/Users/Commands/UpdateDoctorPersonalInfo/UpdateDoctorPersonalInfoCommand.cs
0 → 100644
View file @
f89e1817
using
Application.Abstractions.CQRS.Commands
;
namespace
Application.Users.Commands.UpdateDoctorPersonalInfo
;
public
class
UpdateDoctorPersonalInfoCommand
:
ICommand
{
public
int
Id
{
get
;
set
;
}
public
string
FirstName
{
get
;
set
;
}
=
null
!;
public
string
MiddleName
{
get
;
set
;
}
=
null
!;
public
string
LastName
{
get
;
set
;
}
=
null
!;
}
Clinics.Backend/Application/Users/Commands/UpdateDoctorPersonalInfo/UpdateDoctorPersonalInfoHandler.cs
0 → 100644
View file @
f89e1817
using
Application.Abstractions.CQRS.Commands
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
namespace
Application.Users.Commands.UpdateDoctorPersonalInfo
;
public
class
UpdateDoctorPersonalInfoHandler
:
CommandHandlerBase
<
UpdateDoctorPersonalInfoCommand
>
{
#
region
CTOR
DI
private
readonly
IUserRepository
_userRepository
;
public
UpdateDoctorPersonalInfoHandler
(
IUnitOfWork
unitOfWork
,
IUserRepository
userRepository
)
:
base
(
unitOfWork
)
{
_userRepository
=
userRepository
;
}
#
endregion
public
override
async
Task
<
Result
>
HandleHelper
(
UpdateDoctorPersonalInfoCommand
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
user
from
database
var
userFromDbResult
=
await
_userRepository
.
GetDoctorUserByIdAsync
(
request
.
Id
);
if
(
userFromDbResult
.
IsFailure
)
return
Result
.
Failure
(
userFromDbResult
.
Error
);
#
endregion
#
region
2.
Update
personal
info
var
updateResult
=
userFromDbResult
.
Value
.
Doctor
.
PersonalInfo
.
UpdateDetails
(
request
.
FirstName
,
request
.
MiddleName
,
request
.
LastName
);
if
(
updateResult
.
IsFailure
)
return
Result
.
Failure
(
updateResult
.
Error
);
#
endregion
#
region
3.
Save
changes
var
saveChangesResult
=
await
_userRepository
.
UpdateDoctorUserAsync
(
userFromDbResult
.
Value
);
if
(
saveChangesResult
.
IsFailure
)
return
Result
.
Failure
(
saveChangesResult
.
Error
);
#
endregion
return
Result
.
Success
();
}
}
Clinics.Backend/Application/Users/Commands/UpdateDoctorUser/UpdateDoctorUserCommand.cs
0 → 100644
View file @
f89e1817
using
Application.Abstractions.CQRS.Commands
;
namespace
Application.Users.Commands.UpdateDoctorUser
;
public
class
UpdateDoctorUserCommand
:
ICommand
{
public
int
Id
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
=
null
!;
public
string
?
Password
{
get
;
set
;
}
=
null
;
}
Clinics.Backend/Application/Users/Commands/UpdateDoctorUser/UpdateDoctorUserHandler.cs
0 → 100644
View file @
f89e1817
using
Application.Abstractions.CQRS.Commands
;
using
Domain.Errors
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
namespace
Application.Users.Commands.UpdateDoctorUser
;
public
class
UpdateDoctorUserHandler
:
CommandHandlerBase
<
UpdateDoctorUserCommand
>
{
#
region
CROR
DI
private
readonly
IUserRepository
_userRepository
;
public
UpdateDoctorUserHandler
(
IUnitOfWork
unitOfWork
,
IUserRepository
userRepository
)
:
base
(
unitOfWork
)
{
_userRepository
=
userRepository
;
}
#
endregion
public
override
async
Task
<
Result
>
HandleHelper
(
UpdateDoctorUserCommand
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
user
from
Db
var
userFromDbResult
=
await
_userRepository
.
GetDoctorUserByIdAsync
(
request
.
Id
);
if
(
userFromDbResult
.
IsFailure
)
return
Result
.
Failure
(
userFromDbResult
.
Error
);
var
user
=
userFromDbResult
.
Value
;
#
endregion
#
region
2.
Check
unique
username
var
uniqueUserNameResult
=
await
_userRepository
.
IsUserNameAvailableAsunc
(
request
.
UserName
);
if
(
uniqueUserNameResult
.
IsFailure
)
return
Result
.
Failure
(
uniqueUserNameResult
.
Error
);
if
(
uniqueUserNameResult
.
Value
==
false
)
return
Result
.
Failure
(
IdentityErrors
.
TakenUserName
);
#
endregion
#
region
3.
change
username
var
updateUserNameResult
=
await
_userRepository
.
ChangeUserName
(
user
.
User
,
request
.
UserName
);
if
(
updateUserNameResult
.
IsFailure
)
return
Result
.
Failure
(
updateUserNameResult
.
Error
);
#
endregion
#
region
4.
Change
password
if
(
request
.
Password
is
not
null
)
{
var
updatePasswordResult
=
await
_userRepository
.
ChangePassword
(
user
.
User
,
request
.
Password
);
if
(
updatePasswordResult
.
IsFailure
)
return
Result
.
Failure
(
updatePasswordResult
.
Error
);
}
#
endregion
return
Result
.
Success
();
}
}
Clinics.Backend/Domain/Entities/Identity/Users/User.cs
View file @
f89e1817
...
...
@@ -63,5 +63,15 @@ public sealed class User : Entity
}
#
endregion
#
region
Update
userName
public
Result
UpdateUserName
(
string
userName
)
{
if
(
userName
is
null
)
return
Result
.
Failure
(
DomainErrors
.
InvalidValuesError
);
UserName
=
userName
;
return
Result
.
Success
();
}
#
endregion
#
endregion
}
Clinics.Backend/Domain/Entities/People/Shared/PersonalInfo.cs
View file @
f89e1817
using
Domain.Primitives
;
using
Domain.Errors
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.People.Shared
;
...
...
@@ -50,5 +51,17 @@ public sealed class PersonalInfo : Entity
}
#
endregion
#
region
Update
details
public
Result
UpdateDetails
(
string
firstName
,
string
middleName
,
string
lastName
)
{
if
(
firstName
is
null
||
middleName
is
null
||
lastName
is
null
)
return
Result
.
Failure
(
DomainErrors
.
InvalidValuesError
);
FirstName
=
firstName
;
MiddleName
=
middleName
;
LastName
=
lastName
;
return
Result
.
Success
();
}
#
endregion
#
endregion
}
Clinics.Backend/Domain/Repositories/IUserRepository.cs
View file @
f89e1817
...
...
@@ -17,6 +17,14 @@ public interface IUserRepository : IRepository<User>
public
Task
<
Result
<
bool
>>
IsUserNameAvailableAsunc
(
string
userName
);
#
endregion
#
region
Change
password
public
Task
<
Result
>
ChangePassword
(
User
user
,
string
password
);
#
endregion
#
region
Change
username
public
Task
<
Result
>
ChangeUserName
(
User
user
,
string
userName
);
#
endregion
#
region
Doctor
users
#
region
Get
doctor
user
by
user
name
full
...
...
@@ -36,6 +44,10 @@ public interface IUserRepository : IRepository<User>
public
Task
<
Result
<
DoctorUser
>>
RegisterDoctorAsync
(
DoctorUser
doctorUser
);
#
endregion
#
region
Update
doctor
user
public
Task
<
Result
>
UpdateDoctorUserAsync
(
DoctorUser
doctorUser
);
#
endregion
#
endregion
#
region
Receptionists
users
...
...
Clinics.Backend/Persistence/Repositories/Users/UserRepository.cs
View file @
f89e1817
...
...
@@ -76,6 +76,45 @@ public class UserRepository : Repositroy<User>, IUserRepository
}
#
endregion
#
region
Change
password
public
async
Task
<
Result
>
ChangePassword
(
User
user
,
string
password
)
{
try
{
var
updatePasswordResult
=
user
.
SetHashedPassword
(
_passwordHasher
.
Hash
(
password
));
if
(
updatePasswordResult
.
IsFailure
)
return
Result
.
Failure
(
updatePasswordResult
.
Error
);
_context
.
Set
<
User
>().
Update
(
user
);
await
_context
.
SaveChangesAsync
();
return
Result
.
Success
();
}
catch
(
Exception
)
{
return
Result
.
Failure
(
PersistenceErrors
.
UnableToCompleteTransaction
);
}
}
#
endregion
#
region
Change
username
public
async
Task
<
Result
>
ChangeUserName
(
User
user
,
string
userName
)
{
try
{
var
updateUserNameResult
=
user
.
UpdateUserName
(
userName
);
if
(
updateUserNameResult
.
IsFailure
)
return
Result
.
Failure
(
updateUserNameResult
.
Error
);
_context
.
Set
<
User
>().
Update
(
user
);
await
_context
.
SaveChangesAsync
();
return
Result
.
Success
();
}
catch
(
Exception
)
{
return
Result
.
Failure
(
PersistenceErrors
.
UnableToCompleteTransaction
);
}
}
#
endregion
#
region
Doctor
users
#
region
Get
doctor
user
by
user
name
full
...
...
@@ -158,6 +197,22 @@ public class UserRepository : Repositroy<User>, IUserRepository
}
#
endregion
#
region
Update
doctor
user
public
async
Task
<
Result
>
UpdateDoctorUserAsync
(
DoctorUser
doctorUser
)
{
try
{
_context
.
Set
<
DoctorUser
>().
Update
(
doctorUser
);
await
_context
.
SaveChangesAsync
();
return
Result
.
Success
();
}
catch
(
Exception
)
{
return
Result
.
Failure
(
PersistenceErrors
.
UnableToCompleteTransaction
);
}
}
#
endregion
#
endregion
#
region
Receptionist
users
...
...
Clinics.Backend/Presentation/Controllers/UsersController.cs
View file @
f89e1817
using
Application.Users.Commands.Login
;
using
Application.Users.Commands.RegisterDoctor
;
using
Application.Users.Commands.RegisterReceptionist
;
using
Application.Users.Commands.UpdateDoctorPersonalInfo
;
using
Application.Users.Commands.UpdateDoctorUser
;
using
Application.Users.Queries.GetAllDoctorUsers
;
using
Application.Users.Queries.GetAllReceptionistsUsers
;
using
Application.Users.Queries.GetDoctorUserById
;
...
...
@@ -70,6 +72,27 @@ public class UsersController : ApiController
return
HandleFailure
(
result
);
return
Ok
(
result
.
Value
);
}
[
Authorize
(
Roles
=
Roles
.
AdminName
)]
[
HttpPut
(
"Doctors"
)]
public
async
Task
<
IActionResult
>
UpdateDoctorPersonalInfo
([
FromBody
]
UpdateDoctorPersonalInfoCommand
command
)
{
var
result
=
await
_sender
.
Send
(
command
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
();
}
[
Authorize
(
Roles
=
Roles
.
AdminName
)]
[
HttpPut
(
"Doctors/Users"
)]
public
async
Task
<
IActionResult
>
UpdateDoctorUser
([
FromBody
]
UpdateDoctorUserCommand
command
)
{
var
result
=
await
_sender
.
Send
(
command
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
();
}
#
endregion
#
region
Receptionist
...
...
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