Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
ProjectsStatusManagement
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
hasan.bahjat
ProjectsStatusManagement
Commits
1fcab024
Commit
1fcab024
authored
Jul 28, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Customer Domain Clontrollers.
parent
23f45a3d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
157 additions
and
42 deletions
+157
-42
CustomersController.cs
...nagement.Api/Controllers/Customers/CustomersController.cs
+43
-3
DependencyInjection.cs
PSManagement.Api/DI/DependencyInjection.cs
+84
-0
CustomerMapperConfiguration.cs
PSManagement.Api/Mappers/CustomerMapperConfiguration.cs
+26
-0
PSManagement.Api.csproj
PSManagement.Api/PSManagement.Api.csproj
+2
-0
Startup.cs
PSManagement.Api/Startup.cs
+2
-39
No files found.
PSManagement.Api/Controllers/Customers/CustomersController.cs
View file @
1fcab024
...
...
@@ -9,6 +9,10 @@ using MediatR;
using
PSManagement.Contracts.Customers.Requests
;
using
PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
AutoMapper
;
using
PSManagement.Application.Customers.UseCases.Commands.AddContactInfo
;
using
PSManagement.Application.Customers.UseCases.Commands.DeleteCustomer
;
using
PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer
;
namespace
PSManagement.Api.Controllers.Customers
{
...
...
@@ -18,21 +22,57 @@ namespace PSManagement.Api.Controllers.Customers
public
class
CustomersController
:
ControllerBase
{
private
readonly
IMediator
_sender
;
private
readonly
IMapper
_mapper
;
public
CustomersController
(
IMediator
sender
)
public
CustomersController
(
IMediator
sender
,
IMapper
mapper
)
{
_sender
=
sender
;
_mapper
=
mapper
;
}
[
HttpPost
]
public
async
Task
<
IActionResult
>
CreateCustomer
(
CreateCustomerRequest
request
)
{
Address
address
=
new
Address
(
request
.
City
,
request
.
StreetName
,
request
.
ZipCode
,
request
.
StreetNumber
);
var
command
=
new
CreateCustomerCommand
(
request
.
CustomerName
,
address
);
var
command
=
_mapper
.
Map
<
CreateCustomerCommand
>(
request
);
var
result
=
await
_sender
.
Send
(
command
);
return
Ok
(
result
);
}
[
HttpDelete
]
public
async
Task
<
IActionResult
>
DeleteCustomer
(
DeleteCustomerRequest
request
)
{
var
command
=
_mapper
.
Map
<
DeleteCustomerCommand
>(
request
);
var
result
=
await
_sender
.
Send
(
command
);
return
Ok
(
result
);
}
[
HttpPut
]
public
async
Task
<
IActionResult
>
UpdateCustomer
(
UpdateCustomerRequest
request
)
{
var
command
=
_mapper
.
Map
<
UpdateCustomerCommand
>(
request
);
var
result
=
await
_sender
.
Send
(
command
);
return
Ok
(
result
);
}
[
HttpPost
(
"AddContactInfo"
)]
public
async
Task
<
IActionResult
>
AddContactInfo
(
AddContactInfoRequest
request
)
{
var
command
=
_mapper
.
Map
<
AddContactInfoCommand
>(
request
);
var
result
=
await
_sender
.
Send
(
command
);
return
Ok
(
result
);
}
}
}
PSManagement.Api/DI/DependencyInjection.cs
0 → 100644
View file @
1fcab024
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
PSManagement.Application.Contracts.Authentication
;
using
MediatR
;
using
System.Reflection
;
using
Microsoft.OpenApi.Models
;
using
System
;
using
AutoMapper
;
using
PSManagement.Api.Mappers
;
namespace
PSManagement.Api.DI
{
public
static
class
DependencyInjection
{
public
static
IServiceCollection
AddAPI
(
this
IServiceCollection
services
)
{
services
.
AddControllers
();
services
.
AddApiSwagger
();
services
.
AddApiCors
();
services
.
AddScoped
<
Mapper
>();
services
.
AddAutoMapper
(
typeof
(
CustomerMapperConfiguration
));
return
services
;
}
private
static
IServiceCollection
AddApiSwagger
(
this
IServiceCollection
services
)
{
services
.
AddSwaggerGen
(
options
=>
{
options
.
SwaggerDoc
(
"v1"
,
new
OpenApiInfo
{
Title
=
"PSManagement.Api"
,
Version
=
"v1"
});
options
.
AddSecurityDefinition
(
"Bearer"
,
new
OpenApiSecurityScheme
()
{
Name
=
"Authorization"
,
In
=
ParameterLocation
.
Header
,
Type
=
SecuritySchemeType
.
Http
,
Scheme
=
"Bearer"
});
options
.
AddSecurityRequirement
(
new
OpenApiSecurityRequirement
{
{
new
OpenApiSecurityScheme
{
Reference
=
new
OpenApiReference
{
Type
=
ReferenceType
.
SecurityScheme
,
Id
=
"Bearer"
}
},
Array
.
Empty
<
string
>()
}
});
});
return
services
;
}
private
static
IServiceCollection
AddApiCors
(
this
IServiceCollection
services
)
{
services
.
AddCors
(
options
=>
{
options
.
AddPolicy
(
"AllowFrontend"
,
builder
=>
builder
.
WithOrigins
(
"http://localhost:4200"
)
// Add your frontend URL here
.
AllowAnyHeader
()
.
AllowAnyMethod
()
.
AllowCredentials
());
});
return
services
;
}
}
}
PSManagement.Api/Mappers/CustomerMapperConfiguration.cs
0 → 100644
View file @
1fcab024
using
AutoMapper
;
using
PSManagement.Application.Customers.Common
;
using
PSManagement.Application.Customers.UseCases.Commands.AddContactInfo
;
using
PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
;
using
PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer
;
using
PSManagement.Contracts.Customers.Requests
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
PSManagement.Api.Mappers
{
public
class
CustomerMapperConfiguration
:
Profile
{
public
CustomerMapperConfiguration
()
{
CreateMap
<
CreateCustomerRequest
,
CreateCustomerCommand
>().
ReverseMap
();
CreateMap
<
UpdateCustomerCommand
,
UpdateCustomerRequest
>().
ReverseMap
();
CreateMap
<
AddContactInfoRequest
,
AddContactInfoCommand
>().
ReverseMap
();
CreateMap
<
AddressRecord
,
AddressDTO
>().
ReverseMap
();
}
}
}
PSManagement.Api/PSManagement.Api.csproj
View file @
1fcab024
...
...
@@ -5,6 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="7.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="5.0.1" />
<PackageReference Include="MediatR" Version="5.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.17">
<PrivateAssets>all</PrivateAssets>
...
...
PSManagement.Api/Startup.cs
View file @
1fcab024
...
...
@@ -14,6 +14,7 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Threading.Tasks
;
using
PSManagement.Infrastructure.Persistence.DI
;
using
PSManagement.Api.DI
;
namespace
PSManagement.Api
{
...
...
@@ -32,50 +33,12 @@ namespace PSManagement.Api
// adding dependency injection
services
.
AddAPI
()
.
AddPresentation
()
.
AddApplication
()
.
AddInfrastructure
(
Configuration
)
.
AddPersistence
(
Configuration
);
services
.
AddControllers
();
services
.
AddCors
(
options
=>
{
options
.
AddPolicy
(
"AllowFrontend"
,
builder
=>
builder
.
WithOrigins
(
"http://localhost:4200"
)
// Add your frontend URL here
.
AllowAnyHeader
()
.
AllowAnyMethod
()
.
AllowCredentials
());
});
services
.
AddSwaggerGen
(
options
=>
{
options
.
SwaggerDoc
(
"v1"
,
new
OpenApiInfo
{
Title
=
"PSManagement.Api"
,
Version
=
"v1"
});
options
.
AddSecurityDefinition
(
"Bearer"
,
new
OpenApiSecurityScheme
()
{
Name
=
"Authorization"
,
In
=
ParameterLocation
.
Header
,
Type
=
SecuritySchemeType
.
Http
,
Scheme
=
"Bearer"
});
options
.
AddSecurityRequirement
(
new
OpenApiSecurityRequirement
{
{
new
OpenApiSecurityScheme
{
Reference
=
new
OpenApiReference
{
Type
=
ReferenceType
.
SecurityScheme
,
Id
=
"Bearer"
}
},
Array
.
Empty
<
string
>()
}
});
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
...
...
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