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
a741124b
Commit
a741124b
authored
Aug 25, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add get available doctors query
parent
90825204
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
0 deletions
+102
-0
GetAvailableDoctorsHandler.cs
...loyees/Queries/GetAvailable/GetAvailableDoctorsHandler.cs
+29
-0
GetAvailableDoctorsQuery.cs
...mployees/Queries/GetAvailable/GetAvailableDoctorsQuery.cs
+7
-0
GetAvailableDoctorsResponse.cs
...oyees/Queries/GetAvailable/GetAvailableDoctorsResponse.cs
+31
-0
IDoctorsRepository.cs
Clinics.Backend/Domain/Repositories/IDoctorsRepository.cs
+4
-0
DoctorsRepository.cs
...end/Persistence/Repositories/Doctors/DoctorsRepository.cs
+19
-0
DoctorsController.cs
...ics.Backend/Presentation/Controllers/DoctorsController.cs
+12
-0
No files found.
Clinics.Backend/Application/Employees/Queries/GetAvailable/GetAvailableDoctorsHandler.cs
0 → 100644
View file @
a741124b
using
Application.Abstractions.CQRS.Queries
;
using
Domain.Repositories
;
using
Domain.Shared
;
namespace
Application.Employees.Queries.GetAvailable
;
public
class
GetAvailableDoctorsHandler
:
IQueryHandler
<
GetAvailableDoctorsQuery
,
GetAvailableDoctorsResponse
>
{
#
region
CTOR
DI
private
readonly
IDoctorsRepository
_doctorsRepository
;
public
GetAvailableDoctorsHandler
(
IDoctorsRepository
repository
)
{
_doctorsRepository
=
repository
;
}
#
endregion
public
async
Task
<
Result
<
GetAvailableDoctorsResponse
>>
Handle
(
GetAvailableDoctorsQuery
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
data
from
persistence
var
doctorsFromPersistence
=
await
_doctorsRepository
.
GetAvailableDoctors
();
if
(
doctorsFromPersistence
.
IsFailure
)
return
Result
.
Failure
<
GetAvailableDoctorsResponse
>(
doctorsFromPersistence
.
Error
);
var
doctors
=
doctorsFromPersistence
.
Value
;
#
endregion
return
GetAvailableDoctorsResponse
.
GetResponse
(
doctors
);
}
}
Clinics.Backend/Application/Employees/Queries/GetAvailable/GetAvailableDoctorsQuery.cs
0 → 100644
View file @
a741124b
using
Application.Abstractions.CQRS.Queries
;
namespace
Application.Employees.Queries.GetAvailable
;
public
class
GetAvailableDoctorsQuery
:
IQuery
<
GetAvailableDoctorsResponse
>
{
}
Clinics.Backend/Application/Employees/Queries/GetAvailable/GetAvailableDoctorsResponse.cs
0 → 100644
View file @
a741124b
using
Domain.Entities.People.Doctors
;
namespace
Application.Employees.Queries.GetAvailable
;
public
class
GetAvailableDoctorsResponse
{
public
class
GetAvailableDoctorsResponseItem
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
=
null
!;
}
public
ICollection
<
GetAvailableDoctorsResponseItem
>
AvailableDoctors
{
get
;
set
;
}
=
null
!;
public
static
GetAvailableDoctorsResponse
GetResponse
(
ICollection
<
Doctor
>
doctors
)
{
List
<
GetAvailableDoctorsResponseItem
>
response
=
new
();
foreach
(
var
doctor
in
doctors
)
{
var
responseItem
=
new
GetAvailableDoctorsResponseItem
{
Id
=
doctor
.
Id
,
Name
=
doctor
.
PersonalInfo
.
FullName
};
response
.
Add
(
responseItem
);
}
return
new
GetAvailableDoctorsResponse
{
AvailableDoctors
=
response
};
}
}
Clinics.Backend/Domain/Repositories/IDoctorsRepository.cs
View file @
a741124b
using
Domain.Entities.People.Doctors
;
using
Domain.Entities.People.Doctors
;
using
Domain.Repositories.Base
;
using
Domain.Repositories.Base
;
using
Domain.Shared
;
namespace
Domain.Repositories
;
namespace
Domain.Repositories
;
public
interface
IDoctorsRepository
:
IRepository
<
Doctor
>
public
interface
IDoctorsRepository
:
IRepository
<
Doctor
>
{
{
#
region
Get
available
public
Task
<
Result
<
ICollection
<
Doctor
>>>
GetAvailableDoctors
();
#
endregion
}
}
Clinics.Backend/Persistence/Repositories/Doctors/DoctorsRepository.cs
View file @
a741124b
using
Domain.Entities.People.Doctors
;
using
Domain.Entities.People.Doctors
;
using
Domain.Entities.People.Doctors.Shared.DoctorStatusValues
;
using
Domain.Errors
;
using
Domain.Errors
;
using
Domain.Repositories
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.Shared
;
...
@@ -33,4 +34,22 @@ public class DoctorsRepository : Repositroy<Doctor>, IDoctorsRepository
...
@@ -33,4 +34,22 @@ public class DoctorsRepository : Repositroy<Doctor>, IDoctorsRepository
}
}
#
endregion
#
endregion
#
region
Get
available
public
async
Task
<
Result
<
ICollection
<
Doctor
>>>
GetAvailableDoctors
()
{
try
{
var
query
=
_context
.
Set
<
Doctor
>()
.
Include
(
doctor
=>
doctor
.
Status
)
.
Where
(
doctor
=>
doctor
.
Status
==
DoctorStatuses
.
Available
)
.
Include
(
doctor
=>
doctor
.
PersonalInfo
);
var
result
=
await
query
.
ToListAsync
();
return
result
;
}
catch
(
Exception
)
{
return
Result
.
Failure
<
ICollection
<
Doctor
>>(
PersistenceErrors
.
Unknown
);
}
}
#
endregion
}
}
Clinics.Backend/Presentation/Controllers/DoctorsController.cs
View file @
a741124b
using
Application.Doctors.Queries.GetAllDoctors
;
using
Application.Doctors.Queries.GetAllDoctors
;
using
Application.Employees.Queries.GetAvailable
;
using
MediatR
;
using
MediatR
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
Presentation.Controllers.Base
;
using
Presentation.Controllers.Base
;
...
@@ -25,4 +26,15 @@ public class DoctorsController : ApiController
...
@@ -25,4 +26,15 @@ public class DoctorsController : ApiController
return
HandleFailure
(
result
);
return
HandleFailure
(
result
);
return
Ok
(
result
.
Value
);
return
Ok
(
result
.
Value
);
}
}
//[Authorize(Roles = Roles.ReceptionistName)]
[
HttpGet
(
"Available"
)]
public
async
Task
<
IActionResult
>
GetAllAvailable
()
{
var
query
=
new
GetAvailableDoctorsQuery
();
var
result
=
await
_sender
.
Send
(
query
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
(
result
.
Value
);
}
}
}
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