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
97f00868
Commit
97f00868
authored
Aug 25, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add get by id query for employee
parent
91db3405
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
0 deletions
+103
-0
GetEmployeeByIdHandler.cs
...ation/Employees/Queries/GetById/GetEmployeeByIdHandler.cs
+32
-0
GetEmployeeByIdQuery.cs
...ication/Employees/Queries/GetById/GetEmployeeByIdQuery.cs
+8
-0
GetEmployeeByIdResponse.cs
...tion/Employees/Queries/GetById/GetEmployeeByIdResponse.cs
+32
-0
EmployeesRepository.cs
...Persistence/Repositories/Employees/EmployeesRepository.cs
+18
-0
EmployeesController.cs
...s.Backend/Presentation/Controllers/EmployeesController.cs
+13
-0
No files found.
Clinics.Backend/Application/Employees/Queries/GetById/GetEmployeeByIdHandler.cs
0 → 100644
View file @
97f00868
using
Application.Abstractions.CQRS.Queries
;
using
Application.Employees.Queries.GetBySerialNumber
;
using
Domain.Repositories
;
using
Domain.Shared
;
namespace
Application.Employees.Queries.GetById
;
public
class
GetEmployeeByIdHandler
:
IQueryHandler
<
GetEmployeeByIdQuery
,
GetEmployeeByIdResponse
>
{
#
region
CTOR
DI
private
readonly
IEmployeesRepository
_employeesRepository
;
public
GetEmployeeByIdHandler
(
IEmployeesRepository
employeesRepository
)
{
_employeesRepository
=
employeesRepository
;
}
#
endregion
public
async
Task
<
Result
<
GetEmployeeByIdResponse
>>
Handle
(
GetEmployeeByIdQuery
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
from
persistence
var
employeeFromPersistenceResult
=
await
_employeesRepository
.
GetByIdAsync
(
request
.
Id
);
if
(
employeeFromPersistenceResult
.
IsFailure
)
return
Result
.
Failure
<
GetEmployeeByIdResponse
>(
employeeFromPersistenceResult
.
Error
);
var
employee
=
employeeFromPersistenceResult
.
Value
;
#
endregion
return
Result
.
Success
<
GetEmployeeByIdResponse
>
(
GetEmployeeByIdResponse
.
GetResponse
(
employee
));
}
}
Clinics.Backend/Application/Employees/Queries/GetById/GetEmployeeByIdQuery.cs
0 → 100644
View file @
97f00868
using
Application.Abstractions.CQRS.Queries
;
namespace
Application.Employees.Queries.GetById
;
public
class
GetEmployeeByIdQuery
:
IQuery
<
GetEmployeeByIdResponse
>
{
public
int
Id
{
get
;
set
;
}
}
Clinics.Backend/Application/Employees/Queries/GetById/GetEmployeeByIdResponse.cs
0 → 100644
View file @
97f00868
using
Application.Employees.Queries.GetBySerialNumber
;
using
Domain.Entities.People.Employees
;
namespace
Application.Employees.Queries.GetById
;
public
class
GetEmployeeByIdResponse
{
public
int
Id
{
get
;
set
;
}
public
string
FirstName
{
get
;
set
;
}
=
null
!;
public
string
MiddleName
{
get
;
set
;
}
=
null
!;
public
string
LastName
{
get
;
set
;
}
=
null
!;
public
string
Gender
{
get
;
set
;
}
=
null
!;
public
DateOnly
DateOfBirth
{
get
;
set
;
}
public
string
SerialNumber
{
get
;
set
;
}
=
null
!;
public
string
CenterStatus
{
get
;
set
;
}
=
null
!;
public
static
GetEmployeeByIdResponse
GetResponse
(
Employee
employee
)
{
return
new
GetEmployeeByIdResponse
{
Id
=
employee
.
Id
,
FirstName
=
employee
.
Patient
.
PersonalInfo
.
FirstName
,
MiddleName
=
employee
.
Patient
.
PersonalInfo
.
MiddleName
,
LastName
=
employee
.
Patient
.
PersonalInfo
.
LastName
,
Gender
=
employee
.
Patient
.
Gender
.
Name
,
DateOfBirth
=
employee
.
Patient
.
DateOfBirth
,
SerialNumber
=
employee
.
SerialNumber
,
CenterStatus
=
employee
.
CenterStatus
};
}
}
Clinics.Backend/Persistence/Repositories/Employees/EmployeesRepository.cs
View file @
97f00868
...
...
@@ -21,6 +21,23 @@ public class EmployeesRepository : Repositroy<Employee>, IEmployeesRepository
}
#
endregion
#
region
Read
methods
public
override
async
Task
<
Result
<
Employee
>>
GetByIdAsync
(
int
id
)
{
try
{
var
query
=
_context
.
Set
<
Employee
>()
.
Where
(
employee
=>
employee
.
Id
==
id
);
var
result
=
await
query
.
FirstAsync
();
return
await
GetEmployeeBySerialNumberAsync
(
result
.
SerialNumber
);
}
catch
(
Exception
)
{
return
Result
.
Failure
<
Employee
>(
PersistenceErrors
.
NotFound
);
}
}
#
endregion
#
region
Get
by
serial
Number
public
async
Task
<
Result
<
Employee
>>
GetEmployeeBySerialNumberAsync
(
string
serialNumber
)
{
...
...
@@ -36,5 +53,6 @@ public class EmployeesRepository : Repositroy<Employee>, IEmployeesRepository
return
Result
.
Failure
<
Employee
>(
DomainErrors
.
SerialNumberNotFound
);
return
Result
.
Success
(
result
.
First
());
}
#
endregion
}
Clinics.Backend/Presentation/Controllers/EmployeesController.cs
View file @
97f00868
using
Application.Employees.Commands.AttachFamilyMemberToEmployee
;
using
Application.Employees.Commands.CreateEmployee
;
using
Application.Employees.Queries.GetById
;
using
Application.Employees.Queries.GetBySerialNumber
;
using
Domain.Entities.Identity.UserRoles
;
using
MediatR
;
...
...
@@ -39,6 +40,18 @@ public class EmployeesController : ApiController
return
Ok
(
result
.
Value
);
}
//[Authorize(Roles = Roles.ReceptionistName)]
[
HttpGet
(
"{id:int}"
)]
// It's a get, but serial number shouldn't be sent via routing, so we'll use post
public
async
Task
<
IActionResult
>
GetById
([
FromRoute
]
int
id
)
{
var
query
=
new
GetEmployeeByIdQuery
{
Id
=
id
};
var
result
=
await
_sender
.
Send
(
query
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
(
result
.
Value
);
}
//[Authorize(Roles = Roles.ReceptionistName)]
[
HttpPut
(
"FamilyMembers"
)]
public
async
Task
<
IActionResult
>
AttachFamilyMember
([
FromBody
]
AttachFamilyMemberToEmployeeCommand
command
)
...
...
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