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

Commit 73bf7e1

Browse files
committed
grants
1 parent e0b77bd commit 73bf7e1

51 files changed

Lines changed: 7058 additions & 23 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Backend/Jp.Application/AutoMapper/DomainToViewModelMappingProfile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class DomainToViewModelMappingProfile : Profile
1515
{
1616
public DomainToViewModelMappingProfile()
1717
{
18+
CreateMap<PersistedGrant, PersistedGrantViewModel>();
1819
CreateMap<ApiResource, ApiResourceListViewModel>();
1920
CreateMap<User, UserViewModel>().ForMember(a => a.Password, o => o.Ignore()).ForMember(a => a.ConfirmPassword, o => o.Ignore());
2021
CreateMap<StoredEvent, EventHistoryData>().ConstructUsing(a => new EventHistoryData() { Action = a.MessageType, Id = a.Id.ToString(), Details = a.Data, When = a.Timestamp.ToString(CultureInfo.InvariantCulture), Who = a.User });
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using Jp.Application.ViewModels;
6+
7+
namespace Jp.Application.Interfaces
8+
{
9+
public interface IPersistedGrantAppService: IDisposable
10+
{
11+
Task<IEnumerable<PersistedGrantViewModel>> GetPersistedGrants();
12+
}
13+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using AutoMapper;
2+
using Jp.Application.Interfaces;
3+
using Jp.Application.ViewModels;
4+
using Jp.Domain.Core.Bus;
5+
using Jp.Domain.Interfaces;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Threading.Tasks;
10+
11+
namespace Jp.Application.Services
12+
{
13+
public class PersistedGrantAppService : IPersistedGrantAppService
14+
{
15+
private IMapper _mapper;
16+
private IEventStoreRepository _eventStoreRepository;
17+
private readonly IPersistedGrantRepository _persistedGrantRepository;
18+
public IMediatorHandler Bus { get; set; }
19+
20+
public PersistedGrantAppService(IMapper mapper,
21+
IMediatorHandler bus,
22+
IEventStoreRepository eventStoreRepository,
23+
IPersistedGrantRepository persistedGrantRepository)
24+
{
25+
_mapper = mapper;
26+
Bus = bus;
27+
_eventStoreRepository = eventStoreRepository;
28+
_persistedGrantRepository = persistedGrantRepository;
29+
}
30+
31+
public async Task<IEnumerable<PersistedGrantViewModel>> GetPersistedGrants()
32+
{
33+
var resultado = await _persistedGrantRepository.GetGrants();
34+
return resultado.Select(s => _mapper.Map<PersistedGrantViewModel>(s));
35+
}
36+
public void Dispose()
37+
{
38+
GC.SuppressFinalize(this);
39+
}
40+
}
41+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
namespace Jp.Application.ViewModels
5+
{
6+
public class PersistedGrantViewModel
7+
{
8+
}
9+
}
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.PersistedGrant;
5+
using Jp.Domain.Core.Bus;
6+
using Jp.Domain.Core.Notifications;
7+
using Jp.Domain.Events.PersistedGrant;
8+
using Jp.Domain.Interfaces;
9+
using Jp.Domain.Models;
10+
using MediatR;
11+
12+
namespace Jp.Domain.CommandHandlers
13+
{
14+
public class PersistedGrantCommandHandler : CommandHandler,
15+
IRequestHandler<RegisterPersistedGrantCommand>
16+
{
17+
private readonly IPersistedGrantRepository _persistedGrantRepository;
18+
19+
public PersistedGrantCommandHandler(
20+
IUnitOfWork uow,
21+
IMediatorHandler bus,
22+
INotificationHandler<DomainNotification> notifications,
23+
IPersistedGrantRepository persistedGrantRepository) : base(uow, bus, notifications)
24+
{
25+
_persistedGrantRepository = persistedGrantRepository;
26+
}
27+
28+
29+
public async Task Handle(RegisterPersistedGrantCommand request, CancellationToken cancellationToken)
30+
{
31+
if (!request.IsValid())
32+
{
33+
NotifyValidationErrors(request);
34+
return;
35+
}
36+
37+
// Businness logic here
38+
39+
//if (Commit())
40+
//{
41+
// await Bus.RaiseEvent(new PersistedGrantRegisteredEvent(PersistedGrant.Id));
42+
//}
43+
44+
return;
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.PersistedGrant
5+
{
6+
public abstract class PersistedGrantCommand : 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.PersistedGrant;
2+
3+
namespace Jp.Domain.Commands.PersistedGrant
4+
{
5+
public class RegisterPersistedGrantCommand : PersistedGrantCommand
6+
{
7+
public RegisterPersistedGrantCommand()
8+
{
9+
10+
}
11+
12+
public override bool IsValid()
13+
{
14+
ValidationResult = new RegisterPersistedGrantCommandValidation().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 Jp.Domain.Validations.PersistedGrant;
2+
3+
namespace Jp.Domain.Commands.PersistedGrant
4+
{
5+
public class RemovePersistedGrantCommand : PersistedGrantCommand
6+
{
7+
public RemovePersistedGrantCommand()
8+
{
9+
10+
}
11+
12+
public override bool IsValid()
13+
{
14+
ValidationResult = new RemovePersistedGrantCommandValidation().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 Jp.Domain.Validations.PersistedGrant;
2+
3+
namespace Jp.Domain.Commands.PersistedGrant
4+
{
5+
public class UpdatePersistedGrantCommand : PersistedGrantCommand
6+
{
7+
public UpdatePersistedGrantCommand()
8+
{
9+
10+
}
11+
12+
public override bool IsValid()
13+
{
14+
ValidationResult = new UpdatePersistedGrantCommandValidation().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 Jp.Domain.Events.PersistedGrant;
2+
using MediatR;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
6+
namespace Jp.Domain.EventHandlers
7+
{
8+
9+
public class PersistedGrantEventHandler :
10+
INotificationHandler<PersistedGrantRegisteredEvent>
11+
{
12+
public Task Handle(PersistedGrantRegisteredEvent notification, CancellationToken cancellationToken)
13+
{
14+
return Task.CompletedTask;
15+
}
16+
17+
}
18+
}

0 commit comments

Comments
 (0)