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
123aa6d2
Commit
123aa6d2
authored
Aug 23, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add get doctor user by id
parent
e29d8df0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
109 additions
and
0 deletions
+109
-0
GetDoctorUserByIdHandler.cs
...ers/Queries/GetDoctorUserById/GetDoctorUserByIdHandler.cs
+34
-0
GetDoctorUserByIdQuery.cs
...Users/Queries/GetDoctorUserById/GetDoctorUserByIdQuery.cs
+8
-0
GetDoctorUserByIdResponse.cs
...rs/Queries/GetDoctorUserById/GetDoctorUserByIdResponse.cs
+31
-0
IUserRepository.cs
Clinics.Backend/Domain/Repositories/IUserRepository.cs
+4
-0
UserRepository.cs
....Backend/Persistence/Repositories/Users/UserRepository.cs
+20
-0
UsersController.cs
Clinics.Backend/Presentation/Controllers/UsersController.cs
+12
-0
No files found.
Clinics.Backend/Application/Users/Queries/GetDoctorUserById/GetDoctorUserByIdHandler.cs
0 → 100644
View file @
123aa6d2
using
Application.Abstractions.CQRS.Queries
;
using
Domain.Repositories
;
using
Domain.Shared
;
namespace
Application.Users.Queries.GetDoctorUserById
;
public
class
GetDoctorUserByIdHandler
:
IQueryHandler
<
GetDoctorUserByIdQuery
,
GetDoctorUserByIdResponse
>
{
#
region
CTOD
DI
private
readonly
IUserRepository
_userRepository
;
public
GetDoctorUserByIdHandler
(
IUserRepository
userRepository
)
{
_userRepository
=
userRepository
;
}
#
endregion
public
async
Task
<
Result
<
GetDoctorUserByIdResponse
>>
Handle
(
GetDoctorUserByIdQuery
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
doctor
user
from
DB
var
doctorUserFromDbResult
=
await
_userRepository
.
GetDoctorUserByIdAsync
(
request
.
Id
);
if
(
doctorUserFromDbResult
.
IsFailure
)
return
Result
.
Failure
<
GetDoctorUserByIdResponse
>(
doctorUserFromDbResult
.
Error
);
#
endregion
#
region
2.
Generate
response
var
response
=
GetDoctorUserByIdResponse
.
GetResponse
(
doctorUserFromDbResult
.
Value
);
if
(
response
.
IsFailure
)
return
Result
.
Failure
<
GetDoctorUserByIdResponse
>(
response
.
Error
);
#
endregion
return
Result
.
Success
<
GetDoctorUserByIdResponse
>(
response
.
Value
);
}
}
Clinics.Backend/Application/Users/Queries/GetDoctorUserById/GetDoctorUserByIdQuery.cs
0 → 100644
View file @
123aa6d2
using
Application.Abstractions.CQRS.Queries
;
namespace
Application.Users.Queries.GetDoctorUserById
;
public
class
GetDoctorUserByIdQuery
:
IQuery
<
GetDoctorUserByIdResponse
>
{
public
int
Id
{
get
;
set
;
}
}
Clinics.Backend/Application/Users/Queries/GetDoctorUserById/GetDoctorUserByIdResponse.cs
0 → 100644
View file @
123aa6d2
using
Domain.Entities.Identity.Users
;
using
Domain.Errors
;
using
Domain.Shared
;
namespace
Application.Users.Queries.GetDoctorUserById
;
public
class
GetDoctorUserByIdResponse
{
public
int
Id
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
=
null
!;
public
string
FirstName
{
get
;
set
;
}
=
null
!;
public
string
MiddleName
{
get
;
set
;
}
=
null
!;
public
string
LastName
{
get
;
set
;
}
=
null
!;
public
static
Result
<
GetDoctorUserByIdResponse
>
GetResponse
(
DoctorUser
doctorUser
)
{
if
(
doctorUser
.
Id
<=
0
||
doctorUser
.
User
is
null
||
doctorUser
.
Doctor
is
null
)
return
Result
.
Failure
<
GetDoctorUserByIdResponse
>(
PersistenceErrors
.
NotFound
);
if
(
doctorUser
.
Doctor
.
PersonalInfo
is
null
)
return
Result
.
Failure
<
GetDoctorUserByIdResponse
>(
PersistenceErrors
.
NotFound
);
return
new
GetDoctorUserByIdResponse
{
Id
=
doctorUser
.
Id
,
UserName
=
doctorUser
.
User
.
UserName
,
FirstName
=
doctorUser
.
Doctor
.
PersonalInfo
.
FirstName
,
MiddleName
=
doctorUser
.
Doctor
.
PersonalInfo
.
MiddleName
,
LastName
=
doctorUser
.
Doctor
.
PersonalInfo
.
LastName
,
};
}
}
Clinics.Backend/Domain/Repositories/IUserRepository.cs
View file @
123aa6d2
...
...
@@ -28,6 +28,10 @@ public interface IUserRepository : IRepository<User>
public
Task
<
Result
<
ICollection
<
DoctorUser
>>>
GetAllDoctorUsersAsync
();
#
endregion
#
region
Get
doctor
user
by
id
public
Task
<
Result
<
DoctorUser
>>
GetDoctorUserByIdAsync
(
int
id
);
#
endregion
#
region
Register
doctor
public
Task
<
Result
<
DoctorUser
>>
RegisterDoctorAsync
(
DoctorUser
doctorUser
);
#
endregion
...
...
Clinics.Backend/Persistence/Repositories/Users/UserRepository.cs
View file @
123aa6d2
...
...
@@ -116,6 +116,26 @@ public class UserRepository : Repositroy<User>, IUserRepository
}
#
endregion
#
region
Get
doctor
user
by
id
public
async
Task
<
Result
<
DoctorUser
>>
GetDoctorUserByIdAsync
(
int
id
)
{
try
{
var
query
=
_context
.
Set
<
DoctorUser
>()
.
Where
(
doctorUser
=>
doctorUser
.
Id
==
id
)
.
Include
(
doctorUser
=>
doctorUser
.
User
)
.
Include
(
doctorUser
=>
doctorUser
.
Doctor
)
.
ThenInclude
(
doctor
=>
doctor
.
PersonalInfo
);
return
await
query
.
FirstAsync
();
}
catch
(
Exception
)
{
return
Result
.
Failure
<
DoctorUser
>(
PersistenceErrors
.
NotFound
);
}
}
#
endregion
#
region
Register
doctor
public
async
Task
<
Result
<
DoctorUser
>>
RegisterDoctorAsync
(
DoctorUser
doctorUser
)
{
...
...
Clinics.Backend/Presentation/Controllers/UsersController.cs
View file @
123aa6d2
...
...
@@ -3,6 +3,7 @@ using Application.Users.Commands.RegisterDoctor;
using
Application.Users.Commands.RegisterReceptionist
;
using
Application.Users.Queries.GetAllDoctorUsers
;
using
Application.Users.Queries.GetAllReceptionistsUsers
;
using
Application.Users.Queries.GetDoctorUserById
;
using
Domain.Entities.Identity.UserRoles
;
using
MediatR
;
using
Microsoft.AspNetCore.Authorization
;
...
...
@@ -58,6 +59,17 @@ public class UsersController : ApiController
return
HandleFailure
(
result
);
return
Ok
(
result
.
Value
);
}
[
Authorize
(
Roles
=
Roles
.
AdminName
)]
[
HttpGet
(
"Doctors/{id:int}"
)]
public
async
Task
<
IActionResult
>
GetDoctorUserById
([
FromRoute
(
Name
=
"id"
)]
int
id
)
{
var
query
=
new
GetDoctorUserByIdQuery
{
Id
=
id
};
var
result
=
await
_sender
.
Send
(
query
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
(
result
.
Value
);
}
#
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