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

Commit e2474f6

Browse files
committed
Api Resource
1 parent d17ed4c commit e2474f6

88 files changed

Lines changed: 4618 additions & 176950 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
using System.Globalization;
2-
using AutoMapper;
1+
using AutoMapper;
32
using IdentityServer4.Models;
43
using Jp.Application.EventSourcedNormalizers;
54
using Jp.Application.ViewModels;
65
using Jp.Application.ViewModels.ClientsViewModels;
76
using Jp.Application.ViewModels.IdentityResourceViewModels;
87
using Jp.Domain.Core.Events;
98
using Jp.Domain.Models;
9+
using System.Globalization;
1010

1111
namespace Jp.Application.AutoMapper
1212
{
1313
public class DomainToViewModelMappingProfile : Profile
1414
{
1515
public DomainToViewModelMappingProfile()
1616
{
17-
CreateMap<ApiResource, ApiResourceViewModel>();
17+
CreateMap<ApiResource, ApiResourceListViewModel>();
1818
CreateMap<User, UserViewModel>().ForMember(a => a.Password, o => o.Ignore()).ForMember(a => a.ConfirmPassword, o => o.Ignore());
1919
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 });
2020
CreateMap<Client, ClientListViewModel>(MemberList.Destination);

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using AutoMapper;
22
using IdentityServer4.Models;
33
using Jp.Application.ViewModels;
4+
using Jp.Application.ViewModels.ApiResouceViewModels;
45
using Jp.Application.ViewModels.ClientsViewModels;
56
using Jp.Application.ViewModels.IdentityResourceViewModels;
7+
using Jp.Domain.Commands.ApiResource;
68
using Jp.Domain.Commands.Client;
79
using Jp.Domain.Commands.IdentityResource;
810
using Jp.Domain.Commands.User;
@@ -39,7 +41,7 @@ public ViewModelToDomainMappingProfile()
3941
* Client commands
4042
*/
4143
CreateMap<Client, UpdateClientCommand>().ConstructUsing(c => new UpdateClientCommand(c));
42-
CreateMap<RemoveSecretViewModel, RemoveSecretCommand>().ConstructUsing(c => new RemoveSecretCommand(c.Id, c.ClientId));
44+
CreateMap<RemoveClientSecretViewModel, RemoveClientSecretCommand>().ConstructUsing(c => new RemoveClientSecretCommand(c.Id, c.ClientId));
4345
CreateMap<RemovePropertyViewModel, RemovePropertyCommand>().ConstructUsing(c => new RemovePropertyCommand(c.Id, c.ClientId));
4446
CreateMap<SaveClientSecretViewModel, SaveClientSecretCommand>().ConstructUsing(c => new SaveClientSecretCommand(c.ClientId, c.Description, c.Value, c.Type, c.Expiration, (int)c.Hash.GetValueOrDefault(HashType.Sha256)));
4547
CreateMap<SaveClientPropertyViewModel, SaveClientPropertyCommand>().ConstructUsing(c => new SaveClientPropertyCommand(c.ClientId, c.Key, c.Value));
@@ -57,6 +59,16 @@ public ViewModelToDomainMappingProfile()
5759
CreateMap<IdentityResource, UpdateIdentityResourceCommand>().ConstructUsing(c => new UpdateIdentityResourceCommand(c));
5860
CreateMap<RemoveIdentityResourceViewModel, RemoveIdentityResourceCommand>().ConstructUsing(c => new RemoveIdentityResourceCommand(c.Name));
5961

62+
/*
63+
* Api Resource commands
64+
*/
65+
CreateMap<ApiResource, RegisterApiResourceCommand>().ConstructUsing(c => new RegisterApiResourceCommand(c));
66+
CreateMap<ApiResource, UpdateApiResourceCommand>().ConstructUsing(c => new UpdateApiResourceCommand(c));
67+
CreateMap<RemoveApiResourceViewModel, RemoveApiResourceCommand>().ConstructUsing(c => new RemoveApiResourceCommand(c.Name));
68+
69+
CreateMap<SaveApiSecretViewModel, SaveApiSecretCommand>().ConstructUsing(c => new SaveApiSecretCommand(c.ResourceName, c.Description, c.Value, c.Type, c.Expiration, (int)c.Hash.GetValueOrDefault(HashType.Sha256)));
70+
CreateMap<RemoveApiSecretViewModel, RemoveApiSecretCommand>().ConstructUsing(c => new RemoveApiSecretCommand(c.Id, c.ResourceName));
71+
6072

6173
}
6274
}

src/Backend/Jp.Application/Interfaces/IApiResourceAppService.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
using System.Threading.Tasks;
55
using IdentityServer4.Models;
66
using Jp.Application.ViewModels;
7+
using Jp.Application.ViewModels.ApiResouceViewModels;
8+
using Jp.Application.ViewModels.ClientsViewModels;
9+
using Jp.Application.ViewModels.IdentityResourceViewModels;
710

811
namespace Jp.Application.Interfaces
912
{
1013
public interface IApiResourceAppService: IDisposable
1114
{
12-
Task<IEnumerable<ApiResource>> GetApiResources();
15+
Task<IEnumerable<ApiResourceListViewModel>> GetApiResources();
16+
Task<ApiResource> GetDetails(string name);
17+
Task Save(ApiResource model);
18+
Task Update(ApiResource model);
19+
Task Remove(RemoveApiResourceViewModel model);
20+
Task<IEnumerable<SecretViewModel>> GetSecrets(string name);
21+
Task RemoveSecret(RemoveApiSecretViewModel model);
22+
Task SaveSecret(SaveApiSecretViewModel model);
1323
}
1424
}

src/Backend/Jp.Application/Interfaces/IClientAppService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
44
using IdentityServer4.Models;
5+
using Jp.Application.ViewModels;
56
using Jp.Application.ViewModels.ClientsViewModels;
67

78
namespace Jp.Application.Interfaces
@@ -12,7 +13,7 @@ public interface IClientAppService: IDisposable
1213
Task<Client> GetClientDetails(string clientId);
1314
Task Update(Client client);
1415
Task<IEnumerable<SecretViewModel>> GetSecrets(string clientId);
15-
Task RemoveSecret(RemoveSecretViewModel model);
16+
Task RemoveSecret(RemoveClientSecretViewModel model);
1617
Task SaveSecret(SaveClientSecretViewModel model);
1718
Task<IEnumerable<ClientPropertyViewModel>> GetProperties(string clientId);
1819
Task RemoveProperty(RemovePropertyViewModel model);

src/Backend/Jp.Application/Services/ApiResourceAppService.cs

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
using IdentityServer4.Models;
88
using Jp.Application.Interfaces;
99
using Jp.Application.ViewModels;
10+
using Jp.Application.ViewModels.ApiResouceViewModels;
11+
using Jp.Application.ViewModels.IdentityResourceViewModels;
12+
using Jp.Domain.Commands.ApiResource;
1013
using Jp.Domain.Core.Bus;
1114
using Jp.Domain.Interfaces;
1215

@@ -17,25 +20,71 @@ public class ApiResourceAppService : IApiResourceAppService
1720
private IMapper _mapper;
1821
private IEventStoreRepository _eventStoreRepository;
1922
private readonly IApiResourceRepository _apiResourceRepository;
23+
private readonly IApiSecretRepository _secretRepository;
2024
public IMediatorHandler Bus { get; set; }
2125

2226
public ApiResourceAppService(IMapper mapper,
2327
IMediatorHandler bus,
2428
IEventStoreRepository eventStoreRepository,
25-
IApiResourceRepository apiResourceRepository)
29+
IApiResourceRepository apiResourceRepository,
30+
IApiSecretRepository secretRepository)
2631
{
2732
_mapper = mapper;
2833
Bus = bus;
2934
_eventStoreRepository = eventStoreRepository;
3035
_apiResourceRepository = apiResourceRepository;
36+
_secretRepository = secretRepository;
3137
}
3238

39+
public Task<IEnumerable<ApiResourceListViewModel>> GetApiResources()
40+
{
41+
var resultado = _apiResourceRepository.GetAll().Select(s => _mapper.Map<ApiResourceListViewModel>(s)).ToList();
42+
return Task.FromResult<IEnumerable<ApiResourceListViewModel>>(resultado);
43+
}
44+
45+
public async Task<ApiResource> GetDetails(string name)
46+
{
47+
var resultado = await _apiResourceRepository.GetByName(name);
48+
return resultado.ToModel();
49+
}
50+
51+
public Task Save(ApiResource model)
52+
{
53+
var command = _mapper.Map<RegisterApiResourceCommand>(model);
54+
return Bus.SendCommand(command);
55+
}
56+
57+
public Task Update(ApiResource model)
58+
{
59+
var command = _mapper.Map<UpdateApiResourceCommand>(model);
60+
return Bus.SendCommand(command);
61+
62+
}
3363

34-
public Task<IEnumerable<ApiResource>> GetApiResources()
64+
public Task Remove(RemoveApiResourceViewModel model)
3565
{
36-
var resultado = _apiResourceRepository.GetAll().Select(a => a.ToModel()).ToList();
37-
return Task.FromResult<IEnumerable<ApiResource>>(resultado);
66+
var command = _mapper.Map<RemoveApiResourceCommand>(model);
67+
return Bus.SendCommand(command);
3868
}
69+
70+
public async Task<IEnumerable<SecretViewModel>> GetSecrets(string name)
71+
{
72+
return _mapper.Map<IEnumerable<SecretViewModel>>(await _secretRepository.GetByApiName(name));
73+
}
74+
75+
public Task RemoveSecret(RemoveApiSecretViewModel model)
76+
{
77+
var registerCommand = _mapper.Map<RemoveApiSecretCommand>(model);
78+
return Bus.SendCommand(registerCommand);
79+
}
80+
81+
public Task SaveSecret(SaveApiSecretViewModel model)
82+
{
83+
var registerCommand = _mapper.Map<SaveApiSecretCommand>(model);
84+
return Bus.SendCommand(registerCommand);
85+
}
86+
87+
3988
public void Dispose()
4089
{
4190
GC.SuppressFinalize(this);

src/Backend/Jp.Application/Services/ClientAppService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using IdentityServer4.EntityFramework.Mappers;
77
using IdentityServer4.Models;
88
using Jp.Application.Interfaces;
9+
using Jp.Application.ViewModels;
910
using Jp.Application.ViewModels.ClientsViewModels;
1011
using Jp.Domain.Commands.Client;
1112
using Jp.Domain.Core.Bus;
@@ -63,9 +64,9 @@ public async Task<IEnumerable<SecretViewModel>> GetSecrets(string clientId)
6364
return _mapper.Map<IEnumerable<SecretViewModel>>(await _clientSecretRepository.GetByClientId(clientId));
6465
}
6566

66-
public Task RemoveSecret(RemoveSecretViewModel model)
67+
public Task RemoveSecret(RemoveClientSecretViewModel model)
6768
{
68-
var registerCommand = _mapper.Map<RemoveSecretCommand>(model);
69+
var registerCommand = _mapper.Map<RemoveClientSecretCommand>(model);
6970
return Bus.SendCommand(registerCommand);
7071
}
7172

src/Backend/Jp.Application/Services/ScopesAppService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public class ScopesAppService : IScopesAppService
1313
{
1414
private IMapper _mapper;
1515
private IEventStoreRepository _eventStoreRepository;
16-
private readonly IIdentityResourcesRepository _identityResourcesRepository;
16+
private readonly IIdentityResourceRepository _identityResourcesRepository;
1717
private readonly IApiResourceRepository _apiResourceRepository;
1818
public IMediatorHandler Bus { get; set; }
1919

2020
public ScopesAppService(IMapper mapper,
2121
IMediatorHandler bus,
2222
IEventStoreRepository eventStoreRepository,
23-
IIdentityResourcesRepository identityResourcesRepository,
23+
IIdentityResourceRepository identityResourcesRepository,
2424
IApiResourceRepository apiResourceRepository)
2525
{
2626
_mapper = mapper;
@@ -29,8 +29,7 @@ public ScopesAppService(IMapper mapper,
2929
_identityResourcesRepository = identityResourcesRepository;
3030
_apiResourceRepository = apiResourceRepository;
3131
}
32-
33-
32+
3433

3534
public void Dispose()
3635
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
namespace Jp.Application.ViewModels
5+
{
6+
public class ApiResourceListViewModel
7+
{
8+
public string Name { get; set; }
9+
public string Description { get; set; }
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace Jp.Application.ViewModels.IdentityResourceViewModels
4+
{
5+
public class RemoveApiResourceViewModel
6+
{
7+
[Required]
8+
public string Name { get; set; }
9+
}
10+
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace Jp.Application.ViewModels.ApiResouceViewModels
4+
{
5+
6+
public class RemoveApiSecretViewModel
7+
{
8+
[Required]
9+
public int Id { get; set; }
10+
[Required]
11+
public string ResourceName { get; set; }
12+
}
13+
}

0 commit comments

Comments
 (0)