Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit 2f0cc9e

Browse files
committed
IdentityResource
1 parent 7926ca4 commit 2f0cc9e

31 files changed

Lines changed: 4654 additions & 25 deletions

src/Backend/Jp.Application/Interfaces/IIdentityResourcesAppService.cs renamed to src/Backend/Jp.Application/Interfaces/IIdentityResourceAppService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
namespace Jp.Application.Interfaces
99
{
10-
public interface IIdentityResourcesAppService: IDisposable
10+
public interface IIdentityResourceAppService: IDisposable
1111
{
12-
Task<IEnumerable<IdentityResource>> GetIdentityResourcess();
13-
12+
Task<IEnumerable<IdentityResource>> GetIdentityResources();
1413
}
1514
}

src/Backend/Jp.Application/Jp.Application.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@
2020
</Reference>
2121
</ItemGroup>
2222

23+
<ItemGroup>
24+
<Folder Include="ViewModels\IdentityResourceViewModels\" />
25+
</ItemGroup>
26+
2327
</Project>

src/Backend/Jp.Application/Services/IdentityResourcesAppService.cs renamed to src/Backend/Jp.Application/Services/IdentityResourceAppService.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,30 @@
1212

1313
namespace Jp.Application.Services
1414
{
15-
public class IdentityResourcesAppService : IIdentityResourcesAppService
15+
public class IdentityResourceAppService : IIdentityResourceAppService
1616
{
1717
private IMapper _mapper;
1818
private IEventStoreRepository _eventStoreRepository;
19-
private readonly IIdentityResourcesRepository _identityResourcesRepository;
19+
private readonly IIdentityResourceRepository _identityResourceRepository;
2020
public IMediatorHandler Bus { get; set; }
2121

22-
public IdentityResourcesAppService(IMapper mapper,
22+
public IdentityResourceAppService(IMapper mapper,
2323
IMediatorHandler bus,
2424
IEventStoreRepository eventStoreRepository,
25-
IIdentityResourcesRepository identityResourcesRepository)
25+
IIdentityResourceRepository identityResourceRepository)
2626
{
2727
_mapper = mapper;
2828
Bus = bus;
2929
_eventStoreRepository = eventStoreRepository;
30-
_identityResourcesRepository = identityResourcesRepository;
30+
_identityResourceRepository = identityResourceRepository;
3131
}
3232

3333

34-
public Task<IEnumerable<IdentityResource>> GetIdentityResourcess()
34+
public Task<IEnumerable<IdentityResource>> GetIdentityResources()
3535
{
36-
var resultado = _identityResourcesRepository.GetAll().Select(id => id.ToModel()).ToList();
36+
var resultado = _identityResourceRepository.GetAll().Select(s => s.ToModel()).ToList();
3737
return Task.FromResult<IEnumerable<IdentityResource>>(resultado);
3838
}
39-
40-
4139
public void Dispose()
4240
{
4341
GC.SuppressFinalize(this);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Jp.Domain.Commands.IdentityResource;
5+
using Jp.Domain.Core.Bus;
6+
using Jp.Domain.Core.Notifications;
7+
using Jp.Domain.Events.IdentityResource;
8+
using Jp.Domain.Interfaces;
9+
using Jp.Domain.Models;
10+
using MediatR;
11+
12+
namespace Jp.Domain.CommandHandlers
13+
{
14+
public class IdentityResourceCommandHandler : CommandHandler,
15+
IRequestHandler<RegisterIdentityResourceCommand>
16+
{
17+
private readonly IIdentityResourceRepository _identityResourceRepository;
18+
19+
public IdentityResourceCommandHandler(
20+
IUnitOfWork uow,
21+
IMediatorHandler bus,
22+
INotificationHandler<DomainNotification> notifications,
23+
IIdentityResourceRepository identityResourceRepository) : base(uow, bus, notifications)
24+
{
25+
_identityResourceRepository = identityResourceRepository;
26+
}
27+
28+
29+
public Task Handle(RegisterIdentityResourceCommand request, CancellationToken cancellationToken)
30+
{
31+
if (!request.IsValid())
32+
{
33+
NotifyValidationErrors(request);
34+
return Task.CompletedTask;
35+
}
36+
37+
// Businness logic here
38+
39+
//if (Commit())
40+
//{
41+
// Bus.RaiseEvent(new IdentityResourceRegisteredEvent(IdentityResource.Id));
42+
//}
43+
44+
return Task.CompletedTask;
45+
}
46+
47+
}
48+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using Jp.Domain.Core.Commands;
3+
4+
namespace Jp.Domain.Commands.IdentityResource
5+
{
6+
public abstract class IdentityResourceCommand : Command
7+
{
8+
9+
10+
11+
}
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Jp.Domain.Validations.IdentityResource;
2+
3+
namespace Jp.Domain.Commands.IdentityResource
4+
{
5+
public class RegisterIdentityResourceCommand : IdentityResourceCommand
6+
{
7+
public RegisterIdentityResourceCommand()
8+
{
9+
10+
}
11+
12+
public override bool IsValid()
13+
{
14+
ValidationResult = new RegisterIdentityResourceCommandValidation().Validate(this);
15+
return ValidationResult.IsValid;
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
using Jp.Domain.Events.IdentityResource;
4+
using MediatR;
5+
6+
namespace Jp.Domain.EventHandlers
7+
{
8+
9+
public class IdentityResourceEventHandler :
10+
INotificationHandler<IdentityResourceRegisteredEvent>
11+
{
12+
public Task Handle(IdentityResourceRegisteredEvent notification, CancellationToken cancellationToken)
13+
{
14+
return Task.CompletedTask;
15+
}
16+
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using Jp.Domain.Commands.IdentityResource;
3+
using Jp.Domain.Core.Events;
4+
5+
namespace Jp.Domain.Events.IdentityResource
6+
{
7+
public class IdentityResourceRegisteredEvent : Event
8+
{
9+
public RegisterIdentityResourceCommand Request { get; }
10+
11+
public IdentityResourceRegisteredEvent(Guid aggregateId, RegisterIdentityResourceCommand request)
12+
{
13+
AggregateId = aggregateId;
14+
Request = request;
15+
}
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using IdentityServer4.EntityFramework.Entities;
2+
3+
namespace Jp.Domain.Interfaces
4+
{
5+
public interface IIdentityResourceRepository : IRepository<IdentityResource>
6+
{
7+
}
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using FluentValidation;
3+
using Jp.Domain.Commands.IdentityResource;
4+
5+
namespace Jp.Domain.Validations.IdentityResource
6+
{
7+
public abstract class IdentityResourceValidation<T> : AbstractValidator<T> where T : IdentityResourceCommand
8+
{
9+
10+
}
11+
}

0 commit comments

Comments
 (0)