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
98a22859
Commit
98a22859
authored
Aug 22, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add verification for unique username on register
parent
49d2f2e6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
4 deletions
+42
-4
RegisterDoctorHandler.cs
...on/Users/Commands/RegisterDoctor/RegisterDoctorHandler.cs
+10
-1
RegisterReceptionistCommandHandler.cs
...egisterReceptionist/RegisterReceptionistCommandHandler.cs
+10
-1
IdentityErrors.cs
Clinics.Backend/Domain/Errors/IdentityErrors.cs
+1
-0
PersistenceErrors.cs
Clinics.Backend/Domain/Errors/PersistenceErrors.cs
+2
-2
IUserRepository.cs
Clinics.Backend/Domain/Repositories/IUserRepository.cs
+4
-0
UserRepository.cs
....Backend/Persistence/Repositories/Users/UserRepository.cs
+15
-0
No files found.
Clinics.Backend/Application/Users/Commands/RegisterDoctor/RegisterDoctorHandler.cs
View file @
98a22859
using
Application.Abstractions.CQRS.Commands
;
using
Application.Abstractions.CQRS.Commands
;
using
Domain.Entities.Identity.Users
;
using
Domain.Entities.Identity.Users
;
using
Domain.Errors
;
using
Domain.Repositories
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
using
Domain.UnitOfWork
;
...
@@ -30,7 +31,15 @@ public class RegisterDoctorHandler : CommandHandlerBase<RegisterDoctorCommand, R
...
@@ -30,7 +31,15 @@ public class RegisterDoctorHandler : CommandHandlerBase<RegisterDoctorCommand, R
return
Result
.
Failure
<
RegisterDoctorResponse
>(
doctorUserResult
.
Error
);
return
Result
.
Failure
<
RegisterDoctorResponse
>(
doctorUserResult
.
Error
);
#
endregion
#
endregion
#
region
2.
Register
(
save
to
DB
)
#
region
2.
Verify
unique
username
var
uniqueUserNameResult
=
await
_userRepository
.
IsUserNameAvailableAsunc
(
request
.
UserName
);
if
(
uniqueUserNameResult
.
IsFailure
)
return
Result
.
Failure
<
RegisterDoctorResponse
>(
uniqueUserNameResult
.
Error
);
if
(
uniqueUserNameResult
.
Value
==
false
)
return
Result
.
Failure
<
RegisterDoctorResponse
>(
IdentityErrors
.
TakenUserName
);
#
endregion
#
region
3.
Register
(
save
to
DB
)
var
registerResult
=
await
_userRepository
.
RegisterDoctorAsync
(
doctorUserResult
.
Value
);
var
registerResult
=
await
_userRepository
.
RegisterDoctorAsync
(
doctorUserResult
.
Value
);
if
(
registerResult
.
IsFailure
)
if
(
registerResult
.
IsFailure
)
return
Result
.
Failure
<
RegisterDoctorResponse
>(
registerResult
.
Error
);
return
Result
.
Failure
<
RegisterDoctorResponse
>(
registerResult
.
Error
);
...
...
Clinics.Backend/Application/Users/Commands/RegisterReceptionist/RegisterReceptionistCommandHandler.cs
View file @
98a22859
using
Application.Abstractions.CQRS.Commands
;
using
Application.Abstractions.CQRS.Commands
;
using
Application.Users.Commands.RegisterDoctor
;
using
Application.Users.Commands.RegisterDoctor
;
using
Domain.Entities.Identity.Users
;
using
Domain.Entities.Identity.Users
;
using
Domain.Errors
;
using
Domain.Repositories
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
using
Domain.UnitOfWork
;
...
@@ -31,7 +32,15 @@ public class RegisterReceptionistCommandHandler : CommandHandlerBase<RegisterRec
...
@@ -31,7 +32,15 @@ public class RegisterReceptionistCommandHandler : CommandHandlerBase<RegisterRec
return
Result
.
Failure
<
RegisterReceptionistResponse
>(
receptionistUserResult
.
Error
);
return
Result
.
Failure
<
RegisterReceptionistResponse
>(
receptionistUserResult
.
Error
);
#
endregion
#
endregion
#
region
2.
Register
(
save
to
DB
)
#
region
2.
Verify
unique
username
var
uniqueUserNameResult
=
await
_userRepository
.
IsUserNameAvailableAsunc
(
request
.
UserName
);
if
(
uniqueUserNameResult
.
IsFailure
)
return
Result
.
Failure
<
RegisterReceptionistResponse
>(
uniqueUserNameResult
.
Error
);
if
(
uniqueUserNameResult
.
Value
==
false
)
return
Result
.
Failure
<
RegisterReceptionistResponse
>(
IdentityErrors
.
TakenUserName
);
#
endregion
#
region
3.
Register
(
save
to
DB
)
var
registerResult
=
await
_userRepository
.
RegisterReceptionistAsync
(
receptionistUserResult
.
Value
);
var
registerResult
=
await
_userRepository
.
RegisterReceptionistAsync
(
receptionistUserResult
.
Value
);
if
(
registerResult
.
IsFailure
)
if
(
registerResult
.
IsFailure
)
return
Result
.
Failure
<
RegisterReceptionistResponse
>(
registerResult
.
Error
);
return
Result
.
Failure
<
RegisterReceptionistResponse
>(
registerResult
.
Error
);
...
...
Clinics.Backend/Domain/Errors/IdentityErrors.cs
View file @
98a22859
...
@@ -7,5 +7,6 @@ public static class IdentityErrors
...
@@ -7,5 +7,6 @@ public static class IdentityErrors
public
static
Error
InvalidRole
=>
new
(
"Identity.InvalidRole"
,
"Role specified for user is invalid"
);
public
static
Error
InvalidRole
=>
new
(
"Identity.InvalidRole"
,
"Role specified for user is invalid"
);
public
static
Error
NotFound
=>
new
(
"Identity.NotFound"
,
"المستخدم غير مسجّل في النظام"
);
public
static
Error
NotFound
=>
new
(
"Identity.NotFound"
,
"المستخدم غير مسجّل في النظام"
);
public
static
Error
PasswordMismatch
=>
new
(
"Identity.PasswordMismatch"
,
"كلمة السر غير صحيحة"
);
public
static
Error
PasswordMismatch
=>
new
(
"Identity.PasswordMismatch"
,
"كلمة السر غير صحيحة"
);
public
static
Error
TakenUserName
=>
new
(
"Identity.TakenUserName"
,
"يوجد مستخدم آخر له نفس اسم المستخدم"
);
public
static
Error
UnableToRegister
=>
new
(
"Identity.UnableToRegister"
,
"تعذر تسجيل المستخدم"
);
public
static
Error
UnableToRegister
=>
new
(
"Identity.UnableToRegister"
,
"تعذر تسجيل المستخدم"
);
}
}
Clinics.Backend/Domain/Errors/PersistenceErrors.cs
View file @
98a22859
...
@@ -5,7 +5,7 @@ namespace Domain.Errors;
...
@@ -5,7 +5,7 @@ namespace Domain.Errors;
public
static
class
PersistenceErrors
public
static
class
PersistenceErrors
{
{
public
static
Error
UnableToCompleteTransaction
=>
public
static
Error
UnableToCompleteTransaction
=>
new
(
"Persistence.UnableToCompleteTransaction"
,
"حدثت مشكلة عند الاتصال مع قاعدة البيانات"
);
new
(
"Persistence.UnableToCompleteTransaction"
,
"
لم يتم تنفيذ العملية،
حدثت مشكلة عند الاتصال مع قاعدة البيانات"
);
public
static
Error
UnableToCreate
=>
public
static
Error
UnableToCreate
=>
new
(
"Persistence.UnableToCreate"
,
"فشلت عملية الإضافة"
);
new
(
"Persistence.UnableToCreate"
,
"فشلت عملية الإضافة"
);
...
@@ -20,5 +20,5 @@ public static class PersistenceErrors
...
@@ -20,5 +20,5 @@ public static class PersistenceErrors
new
(
"Persistence.NotFound"
,
"الغرض المطلوب غير موجود"
);
new
(
"Persistence.NotFound"
,
"الغرض المطلوب غير موجود"
);
public
static
Error
Unknown
=>
public
static
Error
Unknown
=>
new
(
"Persistence.Unknown"
,
"حدث
خطأ غير متوقع
"
);
new
(
"Persistence.Unknown"
,
"حدث
ت مشكلة عند الاتصال مع قاعدة البيانات
"
);
}
}
Clinics.Backend/Domain/Repositories/IUserRepository.cs
View file @
98a22859
...
@@ -13,6 +13,10 @@ public interface IUserRepository : IRepository<User>
...
@@ -13,6 +13,10 @@ public interface IUserRepository : IRepository<User>
public
Task
<
Result
<
User
?>>
VerifyPasswordAsync
(
string
userName
,
string
password
);
public
Task
<
Result
<
User
?>>
VerifyPasswordAsync
(
string
userName
,
string
password
);
#
endregion
#
endregion
#
region
Available
username
public
Task
<
Result
<
bool
>>
IsUserNameAvailableAsunc
(
string
userName
);
#
endregion
#
region
Doctor
users
#
region
Doctor
users
#
region
Get
doctor
user
by
user
name
full
#
region
Get
doctor
user
by
user
name
full
...
...
Clinics.Backend/Persistence/Repositories/Users/UserRepository.cs
View file @
98a22859
...
@@ -61,6 +61,21 @@ public class UserRepository : Repositroy<User>, IUserRepository
...
@@ -61,6 +61,21 @@ public class UserRepository : Repositroy<User>, IUserRepository
}
}
#
endregion
#
endregion
#
region
Available
username
public
async
Task
<
Result
<
bool
>>
IsUserNameAvailableAsunc
(
string
userName
)
{
try
{
var
query
=
_context
.
Set
<
User
>().
Where
(
user
=>
user
.
UserName
==
userName
);
return
(
await
query
.
ToListAsync
()).
Count
==
0
;
}
catch
(
Exception
)
{
return
Result
.
Failure
<
bool
>(
PersistenceErrors
.
Unknown
);
}
}
#
endregion
#
region
Doctor
users
#
region
Doctor
users
#
region
Get
doctor
user
by
user
name
full
#
region
Get
doctor
user
by
user
name
full
...
...
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