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
23f45a3d
Commit
23f45a3d
authored
Jul 28, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Customer Domain Use Cases.
parent
1ac943e4
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
288 additions
and
9 deletions
+288
-9
AddressDTO.cs
PSManagement.Application/Customers/Common/AddressDTO.cs
+14
-0
ContactInfoDTO.cs
PSManagement.Application/Customers/Common/ContactInfoDTO.cs
+12
-0
CustomerDTO.cs
PSManagement.Application/Customers/Common/CustomerDTO.cs
+18
-0
CustomerCreatedEventHandler.cs
...plication/Customers/Events/CustomerCreatedEventHandler.cs
+21
-0
AddContactInfoCommand.cs
...UseCases/Commands/AddContactInfo/AddContactInfoCommand.cs
+13
-0
AddContactInfoCommandHandler.cs
...s/Commands/AddContactInfo/AddContactInfoCommandHandler.cs
+37
-0
CreateCustomerCommand.cs
...UseCases/Commands/CreateCustomer/CreateCustomerCommand.cs
+6
-4
CreateCustomerCommandHandler.cs
...s/Commands/CreateCustomer/CreateCustomerCommandHandler.cs
+13
-4
DeleteCustomerCommand.cs
...UseCases/Commands/DeleteCustomer/DeleteCustomerCommand.cs
+13
-0
DeleteCustomerCommandHandler.cs
...s/Commands/DeleteCustomer/DeleteCustomerCommandHandler.cs
+38
-0
UpdateCustomerCommand.cs
...UseCases/Commands/UpdateCustomer/UpdateCustomerCommand.cs
+21
-0
UpdateCustomerCommandHandler.cs
...s/Commands/UpdateCustomer/UpdateCustomerCommandHandler.cs
+37
-0
DependencyInjection.cs
PSManagement.Application/DI/DependencyInjection.cs
+4
-0
CustomerMapperConfiguration.cs
...gement.Application/Mappers/CustomerMapperConfiguration.cs
+24
-0
PSManagement.Application.csproj
PSManagement.Application/PSManagement.Application.csproj
+4
-1
LoginRequest.cs
...agement.Contracts/Authentication/Requests/LoginRequest.cs
+13
-0
No files found.
PSManagement.Application/Customers/Common/AddressDTO.cs
0 → 100644
View file @
23f45a3d
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Customers.Common
{
public
record
AddressDTO
(
int
StreetNumber
,
int
ZipCode
,
String
StreetName
,
String
City
);
}
PSManagement.Application/Customers/Common/ContactInfoDTO.cs
0 → 100644
View file @
23f45a3d
using
PSManagement.Domain.Customers.ValueObjects
;
using
System
;
namespace
PSManagement.Application.Customers.Common
{
public
class
ContactInfoDTO
{
public
String
ConatctValue
{
get
;
set
;
}
public
String
ContactTpe
{
get
;
set
;
}
}
}
\ No newline at end of file
PSManagement.Application/Customers/Common/CustomerDTO.cs
0 → 100644
View file @
23f45a3d
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Customers.Common
{
public
class
CustomerDTO
{
public
int
Id
{
get
;
set
;
}
public
String
CustomerName
{
get
;
set
;
}
public
AddressDTO
Address
{
get
;
set
;
}
public
String
Email
{
get
;
set
;
}
public
IEnumerable
<
ContactInfoDTO
>
ContactInfo
{
get
;
private
set
;
}
}
}
PSManagement.Application/Customers/Events/CustomerCreatedEventHandler.cs
0 → 100644
View file @
23f45a3d
using
PSManagement.Domain.Customers.DomainEvents
;
using
PSManagement.SharedKernel.DomainEvents
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Customers.Events
{
public
class
CustomerCreatedEventHandler
:
IDomainEventHandler
<
CutsomerCreatedEvent
>
{
public
async
Task
Handle
(
CutsomerCreatedEvent
notification
,
CancellationToken
cancellationToken
)
{
Console
.
WriteLine
(
"fdgfg"
);
}
}
}
PSManagement.Application/Customers/UseCases/Commands/AddContactInfo/AddContactInfoCommand.cs
0 → 100644
View file @
23f45a3d
using
FluentResults
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
PSManagement.SharedKernel.Repositories
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
namespace
PSManagement.Application.Customers.UseCases.Commands.AddContactInfo
{
public
record
AddContactInfoCommand
(
int
CustomerId
,
String
ContactType
,
String
ContactValue
)
:
ICommand
<
Result
>;
}
PSManagement.Application/Customers/UseCases/Commands/AddContactInfo/AddContactInfoCommandHandler.cs
0 → 100644
View file @
23f45a3d
using
FluentResults
;
using
PSManagement.Domain.Customers.Aggregate
;
using
PSManagement.Domain.Customers.DomainErrors
;
using
PSManagement.Domain.Customers.Entities
;
using
PSManagement.Domain.Customers.Repositories
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Customers.UseCases.Commands.AddContactInfo
{
public
class
AddContactInfoCommandHandler
:
ICommandHandler
<
AddContactInfoCommand
,
Result
>
{
private
readonly
ICustomersRepository
_customersRepository
;
public
AddContactInfoCommandHandler
(
ICustomersRepository
customersRepository
)
{
_customersRepository
=
customersRepository
;
}
public
async
Task
<
Result
>
Handle
(
AddContactInfoCommand
request
,
CancellationToken
cancellationToken
)
{
Customer
customer
=
await
_customersRepository
.
GetByIdAsync
(
request
.
CustomerId
);
if
(
customer
is
null
)
{
return
Result
.
Fail
(
CustomerErrors
.
InvalidEntryError
);
}
ContactInfo
contact
=
new
ContactInfo
(
request
.
ContactValue
,
request
.
ContactType
);
customer
.
AddContactInfo
(
contact
);
await
_customersRepository
.
UpdateAsync
(
customer
);
return
Result
.
Ok
();
}
}
}
PSManagement.Application/Customers/UseCases/Commands/CreateCustomer/CreateCustomerCommand.cs
View file @
23f45a3d
using
FluentResults
;
using
FluentResults
;
using
PSManagement.Application.Customers.Common
;
using
PSManagement.Domain.Customers.Aggregate
;
using
PSManagement.Domain.Customers.Aggregate
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
PSManagement.SharedKernel.CQRS.Command
;
...
@@ -10,9 +11,10 @@ using System.Threading.Tasks;
...
@@ -10,9 +11,10 @@ using System.Threading.Tasks;
namespace
PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
namespace
PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
{
{
public
record
CreateCustomerCommand
(
public
record
CreateCustomerCommand
(
String
CustomerName
,
string
CustomerName
,
Address
Address
string
Email
,
AddressDTO
Address
)
:
ICommand
<
Result
<
int
>>;
)
:
ICommand
<
Result
<
int
>>;
}
}
PSManagement.Application/Customers/UseCases/Commands/CreateCustomer/CreateCustomerCommandHandler.cs
View file @
23f45a3d
using
FluentResults
;
using
AutoMapper
;
using
FluentResults
;
using
PSManagement.Domain.Customers.Aggregate
;
using
PSManagement.Domain.Customers.Aggregate
;
using
PSManagement.Domain.Customers.DomainEvents
;
using
PSManagement.Domain.Customers.Repositories
;
using
PSManagement.Domain.Customers.Repositories
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
...
@@ -14,16 +17,22 @@ namespace PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
...
@@ -14,16 +17,22 @@ namespace PSManagement.Application.Customers.UseCases.Commands.CreateCustomer
public
class
CreateCustomerCommandHandler
:
ICommandHandler
<
CreateCustomerCommand
,
Result
<
int
>>
public
class
CreateCustomerCommandHandler
:
ICommandHandler
<
CreateCustomerCommand
,
Result
<
int
>>
{
{
private
readonly
ICustomersRepository
_customerRepository
;
private
readonly
ICustomersRepository
_customerRepository
;
public
CreateCustomerCommandHandler
(
ICustomersRepository
customerRepository
)
private
readonly
IMapper
_mapper
;
public
CreateCustomerCommandHandler
(
ICustomersRepository
customerRepository
,
IMapper
mapper
)
{
{
_customerRepository
=
customerRepository
;
_customerRepository
=
customerRepository
;
_mapper
=
mapper
;
}
}
public
async
Task
<
Result
<
int
>>
Handle
(
CreateCustomerCommand
request
,
CancellationToken
cancellationToken
)
public
async
Task
<
Result
<
int
>>
Handle
(
CreateCustomerCommand
request
,
CancellationToken
cancellationToken
)
{
{
Customer
customer
=
new
Customer
(
request
.
CustomerName
,
request
.
Address
);
Customer
customer
=
new
(
request
.
CustomerName
,
_mapper
.
Map
<
Address
>(
request
.
Address
),
request
.
Email
);
customer
=
await
_customerRepository
.
AddAsync
(
customer
);
customer
.
AddDomainEvent
(
new
CutsomerCreatedEvent
(
customer
.
Id
,
customer
.
CustomerName
));
await
_customerRepository
.
AddAsync
(
customer
);
return
Result
.
Ok
(
customer
.
Id
);
return
Result
.
Ok
(
customer
.
Id
);
}
}
}
}
...
...
PSManagement.Application/Customers/UseCases/Commands/DeleteCustomer/DeleteCustomerCommand.cs
0 → 100644
View file @
23f45a3d
using
FluentResults
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Customers.UseCases.Commands.DeleteCustomer
{
public
record
DeleteCustomerCommand
(
int
CustomerId
)
:
ICommand
<
Result
>;
}
PSManagement.Application/Customers/UseCases/Commands/DeleteCustomer/DeleteCustomerCommandHandler.cs
0 → 100644
View file @
23f45a3d
using
FluentResults
;
using
PSManagement.Domain.Customers.Aggregate
;
using
PSManagement.Domain.Customers.DomainErrors
;
using
PSManagement.Domain.Customers.Repositories
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Customers.UseCases.Commands.DeleteCustomer
{
public
class
DeleteCustomerCommandHandler
:
ICommandHandler
<
DeleteCustomerCommand
,
Result
>
{
private
readonly
ICustomersRepository
_customersRepository
;
public
DeleteCustomerCommandHandler
(
ICustomersRepository
customersRepository
)
{
_customersRepository
=
customersRepository
;
}
public
async
Task
<
Result
>
Handle
(
DeleteCustomerCommand
request
,
CancellationToken
cancellationToken
)
{
Customer
customer
=
await
_customersRepository
.
GetByIdAsync
(
request
.
CustomerId
);
if
(
customer
is
null
)
{
return
Result
.
Fail
(
CustomerErrors
.
InvalidEntryError
);
}
await
_customersRepository
.
DeleteAsync
(
customer
);
return
Result
.
Ok
();
}
}
}
PSManagement.Application/Customers/UseCases/Commands/UpdateCustomer/UpdateCustomerCommand.cs
0 → 100644
View file @
23f45a3d
using
FluentResults
;
using
PSManagement.Application.Customers.Common
;
using
PSManagement.Domain.Customers.Aggregate
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer
{
public
record
UpdateCustomerCommand
(
int
CustomerId
,
String
CustomerName
,
String
Email
,
AddressDTO
Address
)
:
ICommand
<
Result
>;
}
PSManagement.Application/Customers/UseCases/Commands/UpdateCustomer/UpdateCustomerCommandHandler.cs
0 → 100644
View file @
23f45a3d
using
AutoMapper
;
using
FluentResults
;
using
PSManagement.Domain.Customers.Aggregate
;
using
PSManagement.Domain.Customers.DomainEvents
;
using
PSManagement.Domain.Customers.Repositories
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
PSManagement.SharedKernel.CQRS.Command
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer
{
public
class
UpdateCustomerCommandHandler
:
ICommandHandler
<
UpdateCustomerCommand
,
Result
>
{
private
readonly
ICustomersRepository
_customerRepository
;
private
readonly
IMapper
_mapper
;
public
UpdateCustomerCommandHandler
(
ICustomersRepository
customerRepository
,
IMapper
mapper
)
{
_customerRepository
=
customerRepository
;
_mapper
=
mapper
;
}
public
async
Task
<
Result
>
Handle
(
UpdateCustomerCommand
request
,
CancellationToken
cancellationToken
)
{
Customer
customer
=
new
(
request
.
CustomerName
,
_mapper
.
Map
<
Address
>(
request
.
Address
),
request
.
Email
);
customer
.
Id
=
request
.
CustomerId
;
await
_customerRepository
.
UpdateAsync
(
customer
);
return
Result
.
Ok
();
}
}
}
PSManagement.Application/DI/DependencyInjection.cs
View file @
23f45a3d
...
@@ -3,6 +3,8 @@ using Microsoft.Extensions.DependencyInjection;
...
@@ -3,6 +3,8 @@ using Microsoft.Extensions.DependencyInjection;
using
PSManagement.Application.Contracts.Authentication
;
using
PSManagement.Application.Contracts.Authentication
;
using
MediatR
;
using
MediatR
;
using
System.Reflection
;
using
System.Reflection
;
using
AutoMapper
;
using
PSManagement.Application.Mappers
;
namespace
PSManagement.Application.DI
namespace
PSManagement.Application.DI
{
{
...
@@ -13,6 +15,8 @@ namespace PSManagement.Application.DI
...
@@ -13,6 +15,8 @@ namespace PSManagement.Application.DI
//services.AddMediatR();
//services.AddMediatR();
services
.
AddMediatR
(
Assembly
.
GetExecutingAssembly
());
services
.
AddMediatR
(
Assembly
.
GetExecutingAssembly
());
services
.
AddAutoMapper
(
typeof
(
CustomerMapperConfiguration
));
return
services
;
return
services
;
}
}
...
...
PSManagement.Application/Mappers/CustomerMapperConfiguration.cs
0 → 100644
View file @
23f45a3d
using
AutoMapper
;
using
PSManagement.Application.Customers.Common
;
using
PSManagement.Domain.Customers.Aggregate
;
using
PSManagement.Domain.Customers.Entities
;
using
PSManagement.Domain.Customers.ValueObjects
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
PSManagement.Application.Mappers
{
class
CustomerMapperConfiguration
:
Profile
{
public
CustomerMapperConfiguration
()
{
CreateMap
<
AddressDTO
,
Address
>().
ReverseMap
();
CreateMap
<
CustomerDTO
,
Customer
>().
ReverseMap
();
CreateMap
<
ContactInfoDTO
,
ContactInfo
>().
ReverseMap
();
}
}
}
PSManagement.Application/PSManagement.Application.csproj
View file @
23f45a3d
...
@@ -7,10 +7,13 @@
...
@@ -7,10 +7,13 @@
<ItemGroup>
<ItemGroup>
<Folder Include="Abstraction\" />
<Folder Include="Abstraction\" />
<Folder Include="Behaviors\AuthorizationBehavior\" />
<Folder Include="Behaviors\AuthorizationBehavior\" />
<Folder Include="Services\" />
<Folder Include="Customers\UseCases\Queries\ListAllCustomers\" />
<Folder Include="Customers\UseCases\Queries\GetCustomer\" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<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="MediatR" Version="5.1.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="5.1.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="5.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
...
...
PSManagement.Contracts/Authentication/Requests/LoginRequest.cs
0 → 100644
View file @
23f45a3d
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
PSManagement.Contracts.Authentication
{
public
record
LoginRequest
(
String
Email
,
String
PassWord
);
}
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