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
c43d428a
Commit
c43d428a
authored
Aug 22, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add get doctors, receps users queries
parent
f2ce0f95
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
258 additions
and
15 deletions
+258
-15
GetAllDoctorUsersHandler.cs
...ers/Queries/GetAllDoctorUsers/GetAllDoctorUsersHandler.cs
+34
-0
GetAllDoctorUsersQuery.cs
...Users/Queries/GetAllDoctorUsers/GetAllDoctorUsersQuery.cs
+7
-0
GetAllDoctorUsersResponse.cs
...rs/Queries/GetAllDoctorUsers/GetAllDoctorUsersResponse.cs
+37
-0
GetAllReceptionistUsersHandler.cs
...etAllReceptionistsUsers/GetAllReceptionistUsersHandler.cs
+35
-0
GetAllReceptionistUsersQuery.cs
.../GetAllReceptionistsUsers/GetAllReceptionistUsersQuery.cs
+7
-0
GetAllReceptionistUsersResponse.cs
...tAllReceptionistsUsers/GetAllReceptionistUsersResponse.cs
+35
-0
PersistenceErrors.cs
Clinics.Backend/Domain/Errors/PersistenceErrors.cs
+3
-0
IUserRepository.cs
Clinics.Backend/Domain/Repositories/IUserRepository.cs
+19
-2
UserRepository.cs
....Backend/Persistence/Repositories/Users/UserRepository.cs
+57
-12
UsersController.cs
Clinics.Backend/Presentation/Controllers/UsersController.cs
+24
-1
No files found.
Clinics.Backend/Application/Users/Queries/GetAllDoctorUsers/GetAllDoctorUsersHandler.cs
0 → 100644
View file @
c43d428a
using
Application.Abstractions.CQRS.Queries
;
using
Domain.Repositories
;
using
Domain.Shared
;
namespace
Application.Users.Queries.GetAllDoctorUsers
;
public
class
GetAllDoctorUsersHandler
:
IQueryHandler
<
GetAllDoctorUsersQuery
,
GetAllDoctorUsersResponse
>
{
#
region
Ctor
DI
private
readonly
IUserRepository
_userRepository
;
public
GetAllDoctorUsersHandler
(
IUserRepository
userRepository
)
{
_userRepository
=
userRepository
;
}
#
endregion
public
async
Task
<
Result
<
GetAllDoctorUsersResponse
>>
Handle
(
GetAllDoctorUsersQuery
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
users
from
DB
var
doctorUsersFromDbResult
=
await
_userRepository
.
GetAllDoctorUsersAsync
();
if
(
doctorUsersFromDbResult
.
IsFailure
)
return
Result
.
Failure
<
GetAllDoctorUsersResponse
>(
doctorUsersFromDbResult
.
Error
);
#
endregion
#
region
2.
Generate
response
var
response
=
GetAllDoctorUsersResponse
.
GetResponse
(
doctorUsersFromDbResult
.
Value
);
if
(
response
.
IsFailure
)
return
Result
.
Failure
<
GetAllDoctorUsersResponse
>(
response
.
Error
);
#
endregion
return
Result
.
Success
(
response
.
Value
);
}
}
Clinics.Backend/Application/Users/Queries/GetAllDoctorUsers/GetAllDoctorUsersQuery.cs
0 → 100644
View file @
c43d428a
using
Application.Abstractions.CQRS.Queries
;
namespace
Application.Users.Queries.GetAllDoctorUsers
;
public
class
GetAllDoctorUsersQuery
:
IQuery
<
GetAllDoctorUsersResponse
>
{
}
Clinics.Backend/Application/Users/Queries/GetAllDoctorUsers/GetAllDoctorUsersResponse.cs
0 → 100644
View file @
c43d428a
using
Domain.Entities.Identity.Users
;
using
Domain.Errors
;
using
Domain.Shared
;
namespace
Application.Users.Queries.GetAllDoctorUsers
;
public
class
GetAllDoctorUsersResponse
{
public
class
GetAllDoctorUsersResponseItem
{
public
string
UserName
{
get
;
set
;
}
=
null
!;
public
string
FullName
{
get
;
set
;
}
=
null
!;
}
public
ICollection
<
GetAllDoctorUsersResponseItem
>
DoctorUsers
{
get
;
set
;
}
=
[];
public
static
Result
<
GetAllDoctorUsersResponse
>
GetResponse
(
ICollection
<
DoctorUser
>
doctorUsers
)
{
List
<
GetAllDoctorUsersResponseItem
>
result
=
new
();
foreach
(
var
doctorUser
in
doctorUsers
)
{
if
(
doctorUser
.
User
is
null
||
doctorUser
.
Doctor
.
PersonalInfo
is
null
)
return
Result
.
Failure
<
GetAllDoctorUsersResponse
>(
PersistenceErrors
.
NotFound
);
var
doctorUserItem
=
new
GetAllDoctorUsersResponseItem
{
FullName
=
doctorUser
.
Doctor
.
PersonalInfo
.
FullName
,
UserName
=
doctorUser
.
User
.
UserName
};
result
.
Add
(
doctorUserItem
);
}
return
new
GetAllDoctorUsersResponse
{
DoctorUsers
=
result
};
}
}
Clinics.Backend/Application/Users/Queries/GetAllReceptionistsUsers/GetAllReceptionistUsersHandler.cs
0 → 100644
View file @
c43d428a
using
Application.Abstractions.CQRS.Queries
;
using
Domain.Repositories
;
using
Domain.Shared
;
namespace
Application.Users.Queries.GetAllReceptionistsUsers
;
public
class
GetAllReceptionistUsersHandler
:
IQueryHandler
<
GetAllReceptionistUsersQuery
,
GetAllReceptionistUsersResponse
>
{
#
region
CTOR
DI
private
readonly
IUserRepository
_userRepository
;
public
GetAllReceptionistUsersHandler
(
IUserRepository
userRepository
)
{
_userRepository
=
userRepository
;
}
#
endregion
public
async
Task
<
Result
<
GetAllReceptionistUsersResponse
>>
Handle
(
GetAllReceptionistUsersQuery
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
users
from
DB
var
receptionistUsersFromDbResult
=
await
_userRepository
.
GetAllReceptionistUsersAsync
();
if
(
receptionistUsersFromDbResult
.
IsFailure
)
return
Result
.
Failure
<
GetAllReceptionistUsersResponse
>(
receptionistUsersFromDbResult
.
Error
);
#
endregion
#
region
2.
Generate
response
var
response
=
GetAllReceptionistUsersResponse
.
GetResponse
(
receptionistUsersFromDbResult
.
Value
);
if
(
response
.
IsFailure
)
return
Result
.
Failure
<
GetAllReceptionistUsersResponse
>(
response
.
Error
);
#
endregion
return
Result
.
Success
<
GetAllReceptionistUsersResponse
>(
response
.
Value
);
// Or just return response.Value
}
}
Clinics.Backend/Application/Users/Queries/GetAllReceptionistsUsers/GetAllReceptionistUsersQuery.cs
0 → 100644
View file @
c43d428a
using
Application.Abstractions.CQRS.Queries
;
namespace
Application.Users.Queries.GetAllReceptionistsUsers
;
public
class
GetAllReceptionistUsersQuery
:
IQuery
<
GetAllReceptionistUsersResponse
>
{
}
Clinics.Backend/Application/Users/Queries/GetAllReceptionistsUsers/GetAllReceptionistUsersResponse.cs
0 → 100644
View file @
c43d428a
using
Domain.Entities.Identity.Users
;
using
Domain.Errors
;
using
Domain.Shared
;
namespace
Application.Users.Queries.GetAllReceptionistsUsers
;
public
class
GetAllReceptionistUsersResponse
{
public
class
GetAllReceptionistUsersResponseItem
{
public
string
UserName
{
get
;
set
;
}
=
null
!;
public
string
FullName
{
get
;
set
;
}
=
null
!;
}
public
ICollection
<
GetAllReceptionistUsersResponseItem
>
DoctorUsers
{
get
;
set
;
}
=
[];
public
static
Result
<
GetAllReceptionistUsersResponse
>
GetResponse
(
ICollection
<
ReceptionistUser
>
receptionistUsers
)
{
List
<
GetAllReceptionistUsersResponseItem
>
result
=
new
();
foreach
(
var
receptionistUser
in
receptionistUsers
)
{
if
(
receptionistUser
.
User
is
null
||
receptionistUser
.
PersonalInfo
is
null
)
return
Result
.
Failure
<
GetAllReceptionistUsersResponse
>(
PersistenceErrors
.
NotFound
);
var
receptionistUserItem
=
new
GetAllReceptionistUsersResponseItem
{
UserName
=
receptionistUser
.
User
.
UserName
,
FullName
=
receptionistUser
.
PersonalInfo
.
FullName
};
result
.
Add
(
receptionistUserItem
);
}
return
new
GetAllReceptionistUsersResponse
{
DoctorUsers
=
result
};
}
}
Clinics.Backend/Domain/Errors/PersistenceErrors.cs
View file @
c43d428a
...
@@ -18,4 +18,7 @@ public static class PersistenceErrors
...
@@ -18,4 +18,7 @@ public static class PersistenceErrors
public
static
Error
NotFound
=>
public
static
Error
NotFound
=>
new
(
"Persistence.NotFound"
,
"الغرض المطلوب غير موجود"
);
new
(
"Persistence.NotFound"
,
"الغرض المطلوب غير موجود"
);
public
static
Error
Unknown
=>
new
(
"Persistence.Unknown"
,
"حدث خطأ غير متوقع"
);
}
}
Clinics.Backend/Domain/Repositories/IUserRepository.cs
View file @
c43d428a
...
@@ -13,18 +13,32 @@ public interface IUserRepository : IRepository<User>
...
@@ -13,18 +13,32 @@ 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
Doctor
users
#
region
Get
doctor
user
by
user
name
full
#
region
Get
doctor
user
by
user
name
full
public
Task
<
Result
<
DoctorUser
>>
GetDoctorUserByUserNameFullAsync
(
string
userName
);
public
Task
<
Result
<
DoctorUser
>>
GetDoctorUserByUserNameFullAsync
(
string
userName
);
#
endregion
#
endregion
#
region
Get
all
doctors
public
Task
<
Result
<
ICollection
<
DoctorUser
>>>
GetAllDoctorUsersAsync
();
#
endregion
#
region
Register
doctor
public
Task
<
Result
<
DoctorUser
>>
RegisterDoctorAsync
(
DoctorUser
doctorUser
);
#
endregion
#
endregion
#
region
Receptionists
users
#
region
Get
receptionist
user
by
user
name
full
#
region
Get
receptionist
user
by
user
name
full
public
Task
<
Result
<
ReceptionistUser
>>
GetReceptionistUserByUserNameFullAsync
(
string
userName
);
public
Task
<
Result
<
ReceptionistUser
>>
GetReceptionistUserByUserNameFullAsync
(
string
userName
);
#
endregion
#
endregion
#
region
Register
doctor
#
region
Get
all
Receptionist
Users
public
Task
<
Result
<
DoctorUser
>>
RegisterDoctorAsync
(
DoctorUser
doctorUser
);
public
Task
<
Result
<
ICollection
<
ReceptionistUser
>>>
GetAllReceptionistUsersAsync
(
);
#
endregion
#
endregion
#
region
Register
receptionist
#
region
Register
receptionist
...
@@ -32,4 +46,7 @@ public interface IUserRepository : IRepository<User>
...
@@ -32,4 +46,7 @@ public interface IUserRepository : IRepository<User>
#
endregion
#
endregion
#
endregion
}
}
Clinics.Backend/Persistence/Repositories/Users/UserRepository.cs
View file @
c43d428a
...
@@ -61,6 +61,8 @@ public class UserRepository : Repositroy<User>, IUserRepository
...
@@ -61,6 +61,8 @@ public class UserRepository : Repositroy<User>, IUserRepository
}
}
#
endregion
#
endregion
#
region
Doctor
users
#
region
Get
doctor
user
by
user
name
full
#
region
Get
doctor
user
by
user
name
full
public
async
Task
<
Result
<
DoctorUser
>>
GetDoctorUserByUserNameFullAsync
(
string
username
)
public
async
Task
<
Result
<
DoctorUser
>>
GetDoctorUserByUserNameFullAsync
(
string
username
)
{
{
...
@@ -81,6 +83,50 @@ public class UserRepository : Repositroy<User>, IUserRepository
...
@@ -81,6 +83,50 @@ public class UserRepository : Repositroy<User>, IUserRepository
}
}
#
endregion
#
endregion
#
region
Get
all
doctors
public
async
Task
<
Result
<
ICollection
<
DoctorUser
>>>
GetAllDoctorUsersAsync
()
{
try
{
var
query
=
_context
.
Set
<
DoctorUser
>()
.
Include
(
doctroUser
=>
doctroUser
.
User
)
.
Include
(
doctorUser
=>
doctorUser
.
Doctor
)
.
ThenInclude
(
doctor
=>
doctor
.
PersonalInfo
);
return
await
query
.
ToListAsync
();
}
catch
(
Exception
)
{
return
Result
.
Failure
<
ICollection
<
DoctorUser
>>(
PersistenceErrors
.
Unknown
);
}
}
#
endregion
#
region
Register
doctor
public
async
Task
<
Result
<
DoctorUser
>>
RegisterDoctorAsync
(
DoctorUser
doctorUser
)
{
_context
.
Entry
(
doctorUser
.
User
.
Role
).
State
=
EntityState
.
Unchanged
;
_context
.
Entry
(
doctorUser
.
Doctor
.
Status
).
State
=
EntityState
.
Unchanged
;
var
passwordResult
=
doctorUser
.
User
.
SetHashedPassword
(
_passwordHasher
.
Hash
(
doctorUser
.
User
.
HashedPassword
));
if
(
passwordResult
.
IsFailure
)
return
Result
.
Failure
<
DoctorUser
>(
passwordResult
.
Error
);
try
{
var
createdDoctorUser
=
await
_context
.
Set
<
DoctorUser
>().
AddAsync
(
doctorUser
);
await
_context
.
SaveChangesAsync
();
return
createdDoctorUser
.
Entity
;
}
catch
(
Exception
)
{
return
Result
.
Failure
<
DoctorUser
>(
IdentityErrors
.
UnableToRegister
);
}
}
#
endregion
#
endregion
#
region
Receptionist
users
#
region
Get
receptionist
user
by
user
name
full
#
region
Get
receptionist
user
by
user
name
full
public
async
Task
<
Result
<
ReceptionistUser
>>
GetReceptionistUserByUserNameFullAsync
(
string
username
)
public
async
Task
<
Result
<
ReceptionistUser
>>
GetReceptionistUserByUserNameFullAsync
(
string
username
)
{
{
...
@@ -100,24 +146,20 @@ public class UserRepository : Repositroy<User>, IUserRepository
...
@@ -100,24 +146,20 @@ public class UserRepository : Repositroy<User>, IUserRepository
}
}
#
endregion
#
endregion
#
region
Register
doctor
#
region
GetAll
public
async
Task
<
Result
<
DoctorUser
>>
RegisterDoctorAsync
(
DoctorUser
doctorUser
)
public
async
Task
<
Result
<
ICollection
<
ReceptionistUser
>>>
GetAllReceptionistUsersAsync
(
)
{
{
_context
.
Entry
(
doctorUser
.
User
.
Role
).
State
=
EntityState
.
Unchanged
;
// Tip: you can apply specification pattern here
_context
.
Entry
(
doctorUser
.
Doctor
.
Status
).
State
=
EntityState
.
Unchanged
;
var
passwordResult
=
doctorUser
.
User
.
SetHashedPassword
(
_passwordHasher
.
Hash
(
doctorUser
.
User
.
HashedPassword
));
if
(
passwordResult
.
IsFailure
)
return
Result
.
Failure
<
DoctorUser
>(
passwordResult
.
Error
);
try
try
{
{
var
createdDoctorUser
=
await
_context
.
Set
<
DoctorUser
>().
AddAsync
(
doctorUser
);
var
query
=
_context
.
Set
<
ReceptionistUser
>()
await
_context
.
SaveChangesAsync
();
.
Include
(
receptionistUser
=>
receptionistUser
.
User
)
return
createdDoctorUser
.
Entity
;
.
Include
(
receptionistUser
=>
receptionistUser
.
PersonalInfo
);
return
await
query
.
ToListAsync
();
}
}
catch
(
Exception
)
catch
(
Exception
)
{
{
return
Result
.
Failure
<
DoctorUser
>(
IdentityErrors
.
UnableToRegister
);
return
Result
.
Failure
<
ICollection
<
ReceptionistUser
>>(
PersistenceErrors
.
Unknown
);
}
}
}
}
#
endregion
#
endregion
...
@@ -144,4 +186,7 @@ public class UserRepository : Repositroy<User>, IUserRepository
...
@@ -144,4 +186,7 @@ public class UserRepository : Repositroy<User>, IUserRepository
}
}
#
endregion
#
endregion
#
endregion
}
}
Clinics.Backend/Presentation/Controllers/UsersController.cs
View file @
c43d428a
using
Application.Users.Commands.Login
;
using
Application.Users.Commands.Login
;
using
Application.Users.Commands.RegisterDoctor
;
using
Application.Users.Commands.RegisterDoctor
;
using
Application.Users.Commands.RegisterReceptionist
;
using
Application.Users.Commands.RegisterReceptionist
;
using
Application.Users.Queries.GetAllDoctorUsers
;
using
Application.Users.Queries.GetAllReceptionistsUsers
;
using
Domain.Entities.Identity.UserRoles
;
using
Domain.Entities.Identity.UserRoles
;
using
MediatR
;
using
MediatR
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Authorization
;
...
@@ -45,11 +47,22 @@ public class UsersController : ApiController
...
@@ -45,11 +47,22 @@ public class UsersController : ApiController
return
Ok
(
result
.
Value
);
return
Ok
(
result
.
Value
);
}
}
[
Authorize
(
Roles
=
Roles
.
AdminName
)]
[
HttpGet
(
"Doctors"
)]
public
async
Task
<
IActionResult
>
GetAllDoctorUsers
()
{
var
query
=
new
GetAllDoctorUsersQuery
();
var
result
=
await
_sender
.
Send
(
query
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
(
result
.
Value
);
}
#
endregion
#
endregion
#
region
Receptionist
#
region
Receptionist
[
Authorize
(
Roles
=
Roles
.
AdminName
)]
[
Authorize
(
Roles
=
Roles
.
AdminName
)]
[
HttpPost
(
"Receptionist"
)]
[
HttpPost
(
"Receptionist
s
"
)]
public
async
Task
<
IActionResult
>
RegisterReceptionist
([
FromBody
]
RegisterReceptionistCommand
command
)
public
async
Task
<
IActionResult
>
RegisterReceptionist
([
FromBody
]
RegisterReceptionistCommand
command
)
{
{
var
result
=
await
_sender
.
Send
(
command
);
var
result
=
await
_sender
.
Send
(
command
);
...
@@ -59,6 +72,16 @@ public class UsersController : ApiController
...
@@ -59,6 +72,16 @@ public class UsersController : ApiController
return
Ok
(
result
.
Value
);
return
Ok
(
result
.
Value
);
}
}
[
Authorize
(
Roles
=
Roles
.
AdminName
)]
[
HttpGet
(
"Receptionists"
)]
public
async
Task
<
IActionResult
>
GetAllReceptionistUsers
()
{
var
query
=
new
GetAllReceptionistUsersQuery
();
var
result
=
await
_sender
.
Send
(
query
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
(
result
.
Value
);
}
#
endregion
#
endregion
...
...
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