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
0df5c192
Commit
0df5c192
authored
Aug 31, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add seed employees from API
parent
b35741bc
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
186 additions
and
21 deletions
+186
-21
API.csproj
Clinics.Backend/API/API.csproj
+1
-0
Program.cs
Clinics.Backend/API/Program.cs
+3
-1
SeedEmployeesHelper.cs
...ics.Backend/API/SeedDatabaseHelper/SeedEmployeesHelper.cs
+41
-0
Clinics.Backend.sln
Clinics.Backend/Clinics.Backend.sln
+7
-0
Genders.cs
...end/Domain/Entities/People/Shared/GenderValues/Genders.cs
+4
-20
AssemblyReference.cs
Clinics.Backend/EmployeesAPI/AssemblyReference.cs
+8
-0
APILink.cs
Clinics.Backend/EmployeesAPI/Configuration/APILink.cs
+6
-0
EmployeeResponse.cs
Clinics.Backend/EmployeesAPI/Contracts/EmployeeResponse.cs
+33
-0
EmployeesAPI.csproj
Clinics.Backend/EmployeesAPI/EmployeesAPI.csproj
+14
-0
EmployeesAPIServices.cs
...ics.Backend/EmployeesAPI/Services/EmployeesAPIServices.cs
+60
-0
IEmployeesAPIServices.cs
...cs.Backend/EmployeesAPI/Services/IEmployeesAPIServices.cs
+9
-0
No files found.
Clinics.Backend/API/API.csproj
View file @
0df5c192
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
<ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Application\Application.csproj" />
<ProjectReference Include="..\Application\Application.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\EmployeesAPI\EmployeesAPI.csproj" />
<ProjectReference Include="..\Infrastructure\NotificationsService.csproj" />
<ProjectReference Include="..\Infrastructure\NotificationsService.csproj" />
<ProjectReference Include="..\MedicinesAPI\MedicinesAPI.csproj" />
<ProjectReference Include="..\MedicinesAPI\MedicinesAPI.csproj" />
<ProjectReference Include="..\Persistence\Persistence.csproj" />
<ProjectReference Include="..\Persistence\Persistence.csproj" />
...
...
Clinics.Backend/API/Program.cs
View file @
0df5c192
...
@@ -61,7 +61,8 @@ builder
...
@@ -61,7 +61,8 @@ builder
.
FromAssemblies
(
.
FromAssemblies
(
Persistence
.
AssemblyReference
.
Assembly
,
Persistence
.
AssemblyReference
.
Assembly
,
NotificationsService
.
AssemblyReference
.
Assembly
,
NotificationsService
.
AssemblyReference
.
Assembly
,
MedicinesAPI
.
AssemblyReference
.
Assembly
MedicinesAPI
.
AssemblyReference
.
Assembly
,
EmployeesAPI
.
AssemblyReference
.
Assembly
)
)
.
AddClasses
(
false
)
.
AddClasses
(
false
)
.
AsImplementedInterfaces
()
.
AsImplementedInterfaces
()
...
@@ -133,6 +134,7 @@ var app = builder.Build();
...
@@ -133,6 +134,7 @@ var app = builder.Build();
await
SeedHelper
.
Seed
(
app
);
await
SeedHelper
.
Seed
(
app
);
await
SeedAdminUserHelper
.
Seed
(
app
);
await
SeedAdminUserHelper
.
Seed
(
app
);
await
SeedMedicinesHelper
.
Seed
(
app
);
await
SeedMedicinesHelper
.
Seed
(
app
);
await
SeedEmployeesHelper
.
Seed
(
app
);
#endregion
#endregion
// Configure the HTTP request pipeline.
// Configure the HTTP request pipeline.
...
...
Clinics.Backend/API/SeedDatabaseHelper/SeedEmployeesHelper.cs
0 → 100644
View file @
0df5c192
using
Domain.Entities.People.Employees
;
using
EmployeesAPI.Services
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
namespace
API.SeedDatabaseHelper
;
public
class
SeedEmployeesHelper
{
public
static
async
Task
Seed
(
IApplicationBuilder
applicationBuilder
)
{
using
(
var
serviceScope
=
applicationBuilder
.
ApplicationServices
.
CreateScope
())
{
var
employeesAPIServices
=
serviceScope
.
ServiceProvider
.
GetService
<
IEmployeesAPIServices
>();
var
context
=
serviceScope
.
ServiceProvider
.
GetService
<
ClinicsDbContext
>();
if
(
employeesAPIServices
is
not
null
&&
context
is
not
null
)
{
var
currentCount
=
(
await
context
.
Set
<
Employee
>().
ToListAsync
()).
Count
;
if
(
currentCount
==
0
)
{
var
employeesResult
=
await
employeesAPIServices
.
GetAll
();
if
(
employeesResult
.
IsSuccess
)
{
var
employees
=
employeesResult
.
Value
;
foreach
(
var
employee
in
employees
)
{
context
.
Entry
(
employee
.
Patient
.
Gender
).
State
=
EntityState
.
Unchanged
;
context
.
Set
<
Employee
>().
Add
(
employee
);
}
await
context
.
SaveChangesAsync
();
}
else
{
Console
.
WriteLine
(
$"Error seeding employees:
{
employeesResult
.
Error
}
"
);
}
}
}
}
}
}
\ No newline at end of file
Clinics.Backend/Clinics.Backend.sln
View file @
0df5c192
...
@@ -35,6 +35,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{C6
...
@@ -35,6 +35,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{C6
EndProject
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DataPersistence", "DataPersistence", "{2776718C-A689-415D-9E65-0DBE61F0C66F}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DataPersistence", "DataPersistence", "{2776718C-A689-415D-9E65-0DBE61F0C66F}"
EndProject
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeesAPI", "EmployeesAPI\EmployeesAPI.csproj", "{4CDBB65C-33AB-41EC-A423-5F5CF71E8D2B}"
EndProject
Global
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Any CPU = Debug|Any CPU
...
@@ -73,6 +75,10 @@ Global
...
@@ -73,6 +75,10 @@ Global
{D0573185-52B8-4091-B3B2-BD8D354C715C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0573185-52B8-4091-B3B2-BD8D354C715C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0573185-52B8-4091-B3B2-BD8D354C715C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0573185-52B8-4091-B3B2-BD8D354C715C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0573185-52B8-4091-B3B2-BD8D354C715C}.Release|Any CPU.Build.0 = Release|Any CPU
{D0573185-52B8-4091-B3B2-BD8D354C715C}.Release|Any CPU.Build.0 = Release|Any CPU
{4CDBB65C-33AB-41EC-A423-5F5CF71E8D2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4CDBB65C-33AB-41EC-A423-5F5CF71E8D2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4CDBB65C-33AB-41EC-A423-5F5CF71E8D2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4CDBB65C-33AB-41EC-A423-5F5CF71E8D2B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
HideSolutionNode = FALSE
...
@@ -92,6 +98,7 @@ Global
...
@@ -92,6 +98,7 @@ Global
{D0573185-52B8-4091-B3B2-BD8D354C715C} = {74A202AC-94B8-40C0-B308-CCCEAED898CF}
{D0573185-52B8-4091-B3B2-BD8D354C715C} = {74A202AC-94B8-40C0-B308-CCCEAED898CF}
{C6BE3A7A-3C92-414E-ACFF-4A61E829273F} = {FDA56BCD-A53D-4BA1-A59D-3F44FA32DDD7}
{C6BE3A7A-3C92-414E-ACFF-4A61E829273F} = {FDA56BCD-A53D-4BA1-A59D-3F44FA32DDD7}
{2776718C-A689-415D-9E65-0DBE61F0C66F} = {FDA56BCD-A53D-4BA1-A59D-3F44FA32DDD7}
{2776718C-A689-415D-9E65-0DBE61F0C66F} = {FDA56BCD-A53D-4BA1-A59D-3F44FA32DDD7}
{4CDBB65C-33AB-41EC-A423-5F5CF71E8D2B} = {74A202AC-94B8-40C0-B308-CCCEAED898CF}
EndGlobalSection
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E9FC9252-1283-485F-8F84-3574CFA12633}
SolutionGuid = {E9FC9252-1283-485F-8F84-3574CFA12633}
...
...
Clinics.Backend/Domain/Entities/People/Shared/GenderValues/Genders.cs
View file @
0df5c192
...
@@ -8,27 +8,11 @@ public static class Genders
...
@@ -8,27 +8,11 @@ public static class Genders
public
static
int
Count
=>
2
;
public
static
int
Count
=>
2
;
public
static
Gender
Male
private
readonly
static
Gender
_male
=
Gender
.
Create
(
"ذكر"
,
1
).
Value
;
{
public
static
Gender
Male
=>
_male
;
get
{
var
result
=
Gender
.
Create
(
"ذكر"
,
1
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
Gender
>();
return
result
.
Value
;
}
}
public
static
Gender
Female
private
readonly
static
Gender
_female
=
Gender
.
Create
(
"أنثى"
,
2
).
Value
;
{
public
static
Gender
Female
=>
_female
;
get
{
var
result
=
Gender
.
Create
(
"أنثى"
,
2
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
Gender
>();
return
result
.
Value
;
}
}
#
endregion
#
endregion
}
}
Clinics.Backend/EmployeesAPI/AssemblyReference.cs
0 → 100644
View file @
0df5c192
using
System.Reflection
;
namespace
EmployeesAPI
;
public
class
AssemblyReference
{
public
static
readonly
Assembly
Assembly
=
typeof
(
AssemblyReference
).
Assembly
;
}
Clinics.Backend/EmployeesAPI/Configuration/APILink.cs
0 → 100644
View file @
0df5c192
namespace
EmployeesAPI.Configuration
;
public
static
class
APILink
{
public
static
readonly
string
Link
=
"http://localhost:9002/employees"
;
}
Clinics.Backend/EmployeesAPI/Contracts/EmployeeResponse.cs
0 → 100644
View file @
0df5c192
using
Domain.Entities.People.Employees
;
using
Domain.Errors
;
using
Domain.Shared
;
namespace
EmployeesAPI.Contracts
;
public
class
EmployeeResponse
{
public
string
FirstName
{
get
;
set
;
}
=
null
!;
public
string
MiddleName
{
get
;
set
;
}
=
null
!;
public
string
LastName
{
get
;
set
;
}
=
null
!;
public
string
DateOfBirth
{
get
;
set
;
}
=
null
!;
public
string
Gender
{
get
;
set
;
}
=
null
!;
public
string
SerialNumber
{
get
;
set
;
}
=
null
!;
public
string
CenterStatus
{
get
;
set
;
}
=
null
!;
public
string
Id
{
get
;
set
;
}
=
null
!;
public
Result
<
Employee
>
GetEmployee
()
{
DateOnly
dateOfBirth
=
new
();
var
dateOfBirthResult
=
DateOnly
.
TryParse
(
DateOfBirth
,
out
dateOfBirth
);
if
(!
dateOfBirthResult
)
return
Result
.
Failure
<
Employee
>(
DomainErrors
.
InvalidValuesError
);
var
employeeCreateResult
=
Employee
.
Create
(
FirstName
,
MiddleName
,
LastName
,
dateOfBirth
,
Gender
,
SerialNumber
,
CenterStatus
);
if
(
employeeCreateResult
.
IsFailure
)
return
Result
.
Failure
<
Employee
>(
employeeCreateResult
.
Error
);
return
employeeCreateResult
.
Value
;
}
}
Clinics.Backend/EmployeesAPI/EmployeesAPI.csproj
0 → 100644
View file @
0df5c192
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Application\Application.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>
</Project>
Clinics.Backend/EmployeesAPI/Services/EmployeesAPIServices.cs
0 → 100644
View file @
0df5c192
using
Domain.Entities.People.Employees
;
using
Domain.Errors
;
using
Domain.Shared
;
using
EmployeesAPI.Configuration
;
using
EmployeesAPI.Contracts
;
using
System.Text.Json
;
namespace
EmployeesAPI.Services
;
internal
class
EmployeesAPIServices
:
IEmployeesAPIServices
{
#
region
Http
client
DI
private
readonly
HttpClient
_httpClient
;
public
EmployeesAPIServices
(
HttpClient
httpClient
)
{
_httpClient
=
httpClient
;
}
#
endregion
public
async
Task
<
Result
<
ICollection
<
Employee
>>>
GetAll
()
{
try
{
// Get response
var
response
=
await
_httpClient
.
GetAsync
(
APILink
.
Link
);
response
.
EnsureSuccessStatusCode
();
// Parse response
var
responseBody
=
await
response
.
Content
.
ReadAsStringAsync
();
var
employeesResponses
=
JsonSerializer
.
Deserialize
<
EmployeeResponse
[
]>
(
responseBody
,
new
JsonSerializerOptions
{
PropertyNameCaseInsensitive
=
true
}
// id in Json, Id in contract class
);
List
<
Employee
>
employees
=
new
();
if
(
employeesResponses
is
not
null
)
{
foreach
(
var
employeeResponse
in
employeesResponses
)
{
Result
<
Employee
>
employeeResult
=
employeeResponse
.
GetEmployee
();
if
(
employeeResult
.
IsFailure
)
return
Result
.
Failure
<
ICollection
<
Employee
>>(
employeeResult
.
Error
);
employees
.
Add
(
employeeResult
.
Value
);
}
return
employees
;
}
else
{
return
Result
.
Failure
<
ICollection
<
Employee
>>(
APIErrors
.
NoData
);
}
}
catch
(
Exception
)
{
return
Result
.
Failure
<
ICollection
<
Employee
>>(
APIErrors
.
UnableToConnect
);
}
}
}
Clinics.Backend/EmployeesAPI/Services/IEmployeesAPIServices.cs
0 → 100644
View file @
0df5c192
using
Domain.Entities.People.Employees
;
using
Domain.Shared
;
namespace
EmployeesAPI.Services
;
public
interface
IEmployeesAPIServices
{
public
Task
<
Result
<
ICollection
<
Employee
>>>
GetAll
();
}
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