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
10de6317
Commit
10de6317
authored
Aug 31, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add get phones, add phone by user id for doctor
parent
5c9ea6fe
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
155 additions
and
5 deletions
+155
-5
AddPhoneNumberByUserIdCommand.cs
...s/AddPhoneNumberByUserId/AddPhoneNumberByUserIdCommand.cs
+11
-0
AddPhoneNumberByUserIdHandler.cs
...s/AddPhoneNumberByUserId/AddPhoneNumberByUserIdHandler.cs
+46
-0
GetDoctorPhonesByUserIdQuery.cs
...Queries/GetPhonesByUserId/GetDoctorPhonesByUserIdQuery.cs
+8
-0
GetDoctorPhonesByUserIdQueryHandler.cs
.../GetPhonesByUserId/GetDoctorPhonesByUserIdQueryHandler.cs
+31
-0
GetDoctorPhonesByUserIdResponse.cs
...ries/GetPhonesByUserId/GetDoctorPhonesByUserIdResponse.cs
+30
-0
DoctorsRepository.cs
...end/Persistence/Repositories/Doctors/DoctorsRepository.cs
+2
-2
UserRepository.cs
....Backend/Persistence/Repositories/Users/UserRepository.cs
+3
-2
DoctorsController.cs
...ics.Backend/Presentation/Controllers/DoctorsController.cs
+24
-1
No files found.
Clinics.Backend/Application/Doctors/Commands/AddPhoneNumberByUserId/AddPhoneNumberByUserIdCommand.cs
0 → 100644
View file @
10de6317
using
Application.Abstractions.CQRS.Commands
;
namespace
Application.Doctors.Commands.AddPhoneNumberByUserId
;
public
class
AddPhoneNumberByUserIdCommand
:
ICommand
{
public
int
DoctorUserId
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Phone
{
get
;
set
;
}
=
null
!;
}
Clinics.Backend/Application/Doctors/Commands/AddPhoneNumberByUserId/AddPhoneNumberByUserIdHandler.cs
0 → 100644
View file @
10de6317
using
Application.Abstractions.CQRS.Commands
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
namespace
Application.Doctors.Commands.AddPhoneNumberByUserId
;
public
class
AddPhoneNumberByUserIdHandler
:
CommandHandlerBase
<
AddPhoneNumberByUserIdCommand
>
{
#
region
CTOR
DI
private
readonly
IUserRepository
_userRepository
;
private
readonly
IDoctorsRepository
_doctorsRepository
;
public
AddPhoneNumberByUserIdHandler
(
IUnitOfWork
unitOfWork
,
IUserRepository
userRepository
,
IDoctorsRepository
doctorsRepository
)
:
base
(
unitOfWork
)
{
_userRepository
=
userRepository
;
_doctorsRepository
=
doctorsRepository
;
}
#
endregion
public
override
async
Task
<
Result
>
HandleHelper
(
AddPhoneNumberByUserIdCommand
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
Doctor
from
persistence
var
doctorFromPersistenceResult
=
await
_userRepository
.
GetDoctorByDoctorUserIdAsync
(
request
.
DoctorUserId
);
if
(
doctorFromPersistenceResult
.
IsFailure
)
return
Result
.
Failure
(
doctorFromPersistenceResult
.
Error
);
var
doctor
=
doctorFromPersistenceResult
.
Value
;
#
endregion
#
region
2.
Add
phone
number
var
addPhoneNumberResult
=
doctor
.
AddPhone
(
request
.
Phone
,
request
.
Name
);
if
(
addPhoneNumberResult
.
IsFailure
)
return
Result
.
Failure
(
addPhoneNumberResult
.
Error
);
#
endregion
#
region
3.
save
updates
var
saveUpdatesResult
=
await
_doctorsRepository
.
UpdateAsync
(
doctor
);
if
(
saveUpdatesResult
.
IsFailure
)
return
Result
.
Failure
(
saveUpdatesResult
.
Error
);
#
endregion
return
Result
.
Success
();
}
}
Clinics.Backend/Application/Doctors/Queries/GetPhonesByUserId/GetDoctorPhonesByUserIdQuery.cs
0 → 100644
View file @
10de6317
using
Application.Abstractions.CQRS.Queries
;
namespace
Application.Doctors.Queries.GetPhonesByUserId
;
public
class
GetDoctorPhonesByUserIdQuery
:
IQuery
<
GetDoctorPhonesByUserIdResponse
>
{
public
int
DoctorUserId
{
get
;
set
;
}
}
Clinics.Backend/Application/Doctors/Queries/GetPhonesByUserId/GetDoctorPhonesByUserIdQueryHandler.cs
0 → 100644
View file @
10de6317
using
Application.Abstractions.CQRS.Queries
;
using
Domain.Repositories
;
using
Domain.Shared
;
namespace
Application.Doctors.Queries.GetPhonesByUserId
;
public
class
GetDoctorPhonesByUserIdQueryHandler
:
IQueryHandler
<
GetDoctorPhonesByUserIdQuery
,
GetDoctorPhonesByUserIdResponse
>
{
#
region
CTOR
DI
private
readonly
IUserRepository
_userRepository
;
public
GetDoctorPhonesByUserIdQueryHandler
(
IUserRepository
userRepository
)
{
_userRepository
=
userRepository
;
}
#
endregion
public
async
Task
<
Result
<
GetDoctorPhonesByUserIdResponse
>>
Handle
(
GetDoctorPhonesByUserIdQuery
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
doctor
from
persistence
var
doctorFromPersistenceResult
=
await
_userRepository
.
GetDoctorByDoctorUserIdAsync
(
request
.
DoctorUserId
);
if
(
doctorFromPersistenceResult
.
IsFailure
)
return
Result
.
Failure
<
GetDoctorPhonesByUserIdResponse
>(
doctorFromPersistenceResult
.
Error
);
var
doctor
=
doctorFromPersistenceResult
.
Value
;
#
endregion
// Generate response
return
Result
.
Success
<
GetDoctorPhonesByUserIdResponse
>(
GetDoctorPhonesByUserIdResponse
.
GetResponse
(
doctor
));
}
}
Clinics.Backend/Application/Doctors/Queries/GetPhonesByUserId/GetDoctorPhonesByUserIdResponse.cs
0 → 100644
View file @
10de6317
using
Domain.Entities.People.Doctors
;
namespace
Application.Doctors.Queries.GetPhonesByUserId
;
public
class
GetDoctorPhonesByUserIdResponse
{
public
class
GetDoctorPhonesByUserIdResponseItem
{
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Phone
{
get
;
set
;
}
=
null
!;
}
public
ICollection
<
GetDoctorPhonesByUserIdResponseItem
>
Phones
{
get
;
set
;
}
=
null
!;
public
static
GetDoctorPhonesByUserIdResponse
GetResponse
(
Doctor
doctor
)
{
List
<
GetDoctorPhonesByUserIdResponseItem
>
response
=
new
();
foreach
(
var
doctorPhone
in
doctor
.
Phones
)
{
response
.
Add
(
new
GetDoctorPhonesByUserIdResponseItem
{
Name
=
doctorPhone
.
Name
!,
Phone
=
doctorPhone
.
Phone
,
});
}
return
new
GetDoctorPhonesByUserIdResponse
{
Phones
=
response
};
}
}
Clinics.Backend/Persistence/Repositories/Doctors/DoctorsRepository.cs
View file @
10de6317
...
@@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore;
...
@@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore;
using
Persistence.Context
;
using
Persistence.Context
;
using
Persistence.Repositories.Base
;
using
Persistence.Repositories.Base
;
using
Persistence.Repositories.Doctors.Specifications
;
using
Persistence.Repositories.Doctors.Specifications
;
using
System.Collections.Generic
;
namespace
Persistence.Repositories.Doctors
;
namespace
Persistence.Repositories.Doctors
;
...
@@ -38,7 +37,8 @@ public class DoctorsRepository : Repositroy<Doctor>, IDoctorsRepository
...
@@ -38,7 +37,8 @@ public class DoctorsRepository : Repositroy<Doctor>, IDoctorsRepository
#
region
Update
method
#
region
Update
method
public
override
Task
<
Result
>
UpdateAsync
(
Doctor
entity
)
public
override
Task
<
Result
>
UpdateAsync
(
Doctor
entity
)
{
{
_context
.
Entry
(
entity
.
Status
).
State
=
EntityState
.
Unchanged
;
if
(
entity
.
Status
is
not
null
)
_context
.
Entry
(
entity
.
Status
).
State
=
EntityState
.
Unchanged
;
return
base
.
UpdateAsync
(
entity
);
return
base
.
UpdateAsync
(
entity
);
}
}
#
endregion
#
endregion
...
...
Clinics.Backend/Persistence/Repositories/Users/UserRepository.cs
View file @
10de6317
...
@@ -216,14 +216,15 @@ public class UserRepository : Repositroy<User>, IUserRepository
...
@@ -216,14 +216,15 @@ public class UserRepository : Repositroy<User>, IUserRepository
}
}
#
endregion
#
endregion
#
region
Get
Doctor
by
doctor
user
#
region
Get
Doctor
by
doctor
user
id
public
async
Task
<
Result
<
Doctor
>>
GetDoctorByDoctorUserIdAsync
(
int
doctorUserId
)
public
async
Task
<
Result
<
Doctor
>>
GetDoctorByDoctorUserIdAsync
(
int
doctorUserId
)
{
{
try
try
{
{
var
query
=
_context
.
Set
<
DoctorUser
>()
var
query
=
_context
.
Set
<
DoctorUser
>()
.
Where
(
doctorUser
=>
doctorUser
.
Id
==
doctorUserId
)
.
Where
(
doctorUser
=>
doctorUser
.
Id
==
doctorUserId
)
.
Include
(
doctorUser
=>
doctorUser
.
Doctor
);
.
Include
(
doctorUser
=>
doctorUser
.
Doctor
)
.
ThenInclude
(
doctor
=>
doctor
.
Phones
);
var
result
=
await
query
.
FirstAsync
();
var
result
=
await
query
.
FirstAsync
();
return
result
.
Doctor
;
return
result
.
Doctor
;
}
}
...
...
Clinics.Backend/Presentation/Controllers/DoctorsController.cs
View file @
10de6317
using
Application.Doctors.Commands.ChangeStatusByUserId
;
using
Application.Doctors.Commands.AddPhoneNumberByUserId
;
using
Application.Doctors.Commands.ChangeStatusByUserId
;
using
Application.Doctors.Queries.GetAllDoctors
;
using
Application.Doctors.Queries.GetAllDoctors
;
using
Application.Doctors.Queries.GetPhonesByUserId
;
using
Application.Doctors.Queries.GetStatusByUserId
;
using
Application.Doctors.Queries.GetStatusByUserId
;
using
Application.Employees.Queries.GetAvailable
;
using
Application.Employees.Queries.GetAvailable
;
using
Domain.Entities.Identity.UserRoles
;
using
Domain.Entities.Identity.UserRoles
;
...
@@ -62,4 +64,25 @@ public class DoctorsController : ApiController
...
@@ -62,4 +64,25 @@ public class DoctorsController : ApiController
return
HandleFailure
(
result
);
return
HandleFailure
(
result
);
return
Ok
();
return
Ok
();
}
}
//[Authorize(Roles = Roles.DoctorName)]
[
HttpGet
(
"Phones/{id:int}"
)]
public
async
Task
<
IActionResult
>
GetPhonesByUserId
([
FromRoute
(
Name
=
"id"
)]
int
doctorUserId
)
{
var
query
=
new
GetDoctorPhonesByUserIdQuery
{
DoctorUserId
=
doctorUserId
};
var
result
=
await
_sender
.
Send
(
query
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
(
result
.
Value
);
}
//[Authorize(Roles = Roles.DoctorName)]
[
HttpPost
(
"Phones"
)]
public
async
Task
<
IActionResult
>
AddPhoneByUserId
([
FromBody
]
AddPhoneNumberByUserIdCommand
command
)
{
var
result
=
await
_sender
.
Send
(
command
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
();
}
}
}
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