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
11a6100c
Commit
11a6100c
authored
Aug 26, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add get medicines with prefix query
parent
39457335
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
166 additions
and
0 deletions
+166
-0
Application.csproj
Clinics.Backend/Application/Application.csproj
+1
-0
GetAllMedicinesWithPrefixHandler.cs
...ries/GetAllWithPrefix/GetAllMedicinesWithPrefixHandler.cs
+29
-0
GetAllMedicinesWithPrefixQuery.cs
...ueries/GetAllWithPrefix/GetAllMedicinesWithPrefixQuery.cs
+8
-0
GetAllMedicinesWithPrefixResponse.cs
...ies/GetAllWithPrefix/GetAllMedicinesWithPrefixResponse.cs
+38
-0
IMedicinesRepository.cs
Clinics.Backend/Domain/Repositories/IMedicinesRepository.cs
+13
-0
MedicinesRepository.cs
...Persistence/Repositories/Medicines/MedicinesRepository.cs
+41
-0
MedicinesController.cs
...s.Backend/Presentation/Controllers/MedicinesController.cs
+36
-0
No files found.
Clinics.Backend/Application/Application.csproj
View file @
11a6100c
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Folder Include="Medicines\Commands\" />
<Folder Include="Visits\Commands\" />
<Folder Include="Visits\Commands\" />
</ItemGroup>
</ItemGroup>
</Project>
</Project>
Clinics.Backend/Application/Medicines/Queries/GetAllWithPrefix/GetAllMedicinesWithPrefixHandler.cs
0 → 100644
View file @
11a6100c
using
Application.Abstractions.CQRS.Queries
;
using
Domain.Repositories
;
using
Domain.Shared
;
namespace
Application.Medicines.Queries.GetAllWithPrefix
;
public
class
GetAllMedicinesWithPrefixHandler
:
IQueryHandler
<
GetAllMedicinesWithPrefixQuery
,
GetAllMedicinesWithPrefixResponse
>
{
#
region
CTOR
DI
private
readonly
IMedicinesRepository
_medicinesRepository
;
public
GetAllMedicinesWithPrefixHandler
(
IMedicinesRepository
medicinesRepository
)
{
_medicinesRepository
=
medicinesRepository
;
}
#
endregion
public
async
Task
<
Result
<
GetAllMedicinesWithPrefixResponse
>>
Handle
(
GetAllMedicinesWithPrefixQuery
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
data
from
persistence
var
medicinesFromPersistence
=
await
_medicinesRepository
.
GetAllWithPrefix
(
request
.
Prefix
);
if
(
medicinesFromPersistence
.
IsFailure
)
return
Result
.
Failure
<
GetAllMedicinesWithPrefixResponse
>(
medicinesFromPersistence
.
Error
);
var
medicines
=
medicinesFromPersistence
.
Value
;
#
endregion
return
Result
.
Success
<
GetAllMedicinesWithPrefixResponse
>(
GetAllMedicinesWithPrefixResponse
.
GetResponse
(
medicines
));
}
}
Clinics.Backend/Application/Medicines/Queries/GetAllWithPrefix/GetAllMedicinesWithPrefixQuery.cs
0 → 100644
View file @
11a6100c
using
Application.Abstractions.CQRS.Queries
;
namespace
Application.Medicines.Queries.GetAllWithPrefix
;
public
class
GetAllMedicinesWithPrefixQuery
:
IQuery
<
GetAllMedicinesWithPrefixResponse
>
{
public
string
?
Prefix
{
get
;
set
;
}
=
null
;
}
Clinics.Backend/Application/Medicines/Queries/GetAllWithPrefix/GetAllMedicinesWithPrefixResponse.cs
0 → 100644
View file @
11a6100c
using
Domain.Entities.Medicals.Medicines
;
namespace
Application.Medicines.Queries.GetAllWithPrefix
;
public
class
GetAllMedicinesWithPrefixResponse
{
public
class
GetAllMedicinesWithPrefixResponseItem
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Form
{
get
;
set
;
}
=
null
!;
public
int
Amount
{
get
;
set
;
}
public
decimal
Dosage
{
get
;
set
;
}
}
public
ICollection
<
GetAllMedicinesWithPrefixResponseItem
>
Medicines
{
get
;
set
;
}
=
null
!;
public
static
GetAllMedicinesWithPrefixResponse
GetResponse
(
ICollection
<
Medicine
>
medicines
)
{
List
<
GetAllMedicinesWithPrefixResponseItem
>
result
=
new
();
foreach
(
Medicine
medicine
in
medicines
)
{
result
.
Add
(
new
GetAllMedicinesWithPrefixResponseItem
{
Id
=
medicine
.
Id
,
Name
=
medicine
.
Name
,
Form
=
medicine
.
MedicineForm
.
Name
,
Amount
=
medicine
.
Amount
,
Dosage
=
medicine
.
Dosage
});
}
return
new
GetAllMedicinesWithPrefixResponse
{
Medicines
=
result
};
}
}
Clinics.Backend/Domain/Repositories/IMedicinesRepository.cs
0 → 100644
View file @
11a6100c
using
Domain.Entities.Medicals.Medicines
;
using
Domain.Repositories.Base
;
using
Domain.Shared
;
namespace
Domain.Repositories
;
public
interface
IMedicinesRepository
:
IRepository
<
Medicine
>
{
#
region
Get
all
with
prefix
public
Task
<
Result
<
ICollection
<
Medicine
>>>
GetAllWithPrefix
(
string
?
prefix
=
null
);
#
endregion
}
Clinics.Backend/Persistence/Repositories/Medicines/MedicinesRepository.cs
0 → 100644
View file @
11a6100c
using
Domain.Entities.Medicals.Medicines
;
using
Domain.Errors
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
using
Persistence.Repositories.Base
;
namespace
Persistence.Repositories.Medicines
;
public
class
MedicinesRepository
:
Repositroy
<
Medicine
>,
IMedicinesRepository
{
#
region
CTOR
DI
for
context
public
MedicinesRepository
(
ClinicsDbContext
context
)
:
base
(
context
)
{
}
#
endregion
#
region
Get
all
with
prefix
public
async
Task
<
Result
<
ICollection
<
Medicine
>>>
GetAllWithPrefix
(
string
?
prefix
=
null
)
{
try
{
var
query
=
_context
.
Set
<
Medicine
>().
AsQueryable
();
if
(
prefix
is
not
null
)
{
query
=
query
.
Where
(
medicine
=>
medicine
.
Name
.
ToLower
().
StartsWith
(
prefix
.
ToLower
()));
}
query
=
query
.
OrderBy
(
medicine
=>
medicine
.
Name
)
.
Include
(
medicine
=>
medicine
.
MedicineForm
);
return
await
query
.
ToListAsync
();
}
catch
(
Exception
)
{
return
Result
.
Failure
<
ICollection
<
Medicine
>>(
PersistenceErrors
.
Unknown
);
}
}
#
endregion
}
Clinics.Backend/Presentation/Controllers/MedicinesController.cs
0 → 100644
View file @
11a6100c
using
Application.Doctors.Commands.ChangeStatusByUserId
;
using
Application.Doctors.Queries.GetAllDoctors
;
using
Application.Doctors.Queries.GetStatusByUserId
;
using
Application.Employees.Queries.GetAvailable
;
using
Application.Medicines.Queries.GetAllWithPrefix
;
using
Domain.Entities.Identity.UserRoles
;
using
MediatR
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Mvc
;
using
Presentation.Controllers.Base
;
namespace
Presentation.Controllers
;
[Route("api/Medicines")]
public
class
MedicinesController
:
ApiController
{
#
region
DI
for
MeditR
sender
public
MedicinesController
(
ISender
sender
)
:
base
(
sender
)
{
}
#
endregion
//[Authorize(Roles = Roles.DoctorName)]
[
HttpGet
]
public
async
Task
<
IActionResult
>
GetAllWithPrefix
([
FromQuery
]
string
?
prefix
=
null
)
{
var
query
=
new
GetAllMedicinesWithPrefixQuery
{
Prefix
=
prefix
};
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