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

Commit 44f6ed8

Browse files
committed
night
1 parent a332804 commit 44f6ed8

26 files changed

Lines changed: 2233 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public DomainToViewModelMappingProfile()
3131
CreateMap<Claim, ClaimViewModel>(MemberList.Destination);
3232
CreateMap<Role, RoleViewModel>(MemberList.Destination);
3333
CreateMap<UserLogin, UserLoginViewModel>(MemberList.Destination);
34+
3435
}
3536
}
3637
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
using Jp.Application.ViewModels.ApiResouceViewModels;
55
using Jp.Application.ViewModels.ClientsViewModels;
66
using Jp.Application.ViewModels.IdentityResourceViewModels;
7+
using Jp.Application.ViewModels.RoleViewModels;
78
using Jp.Application.ViewModels.UserViewModels;
89
using Jp.Domain.Commands.ApiResource;
910
using Jp.Domain.Commands.Client;
1011
using Jp.Domain.Commands.IdentityResource;
1112
using Jp.Domain.Commands.PersistedGrant;
13+
using Jp.Domain.Commands.Role;
1214
using Jp.Domain.Commands.User;
1315
using Jp.Domain.Commands.UserManagement;
1416

@@ -82,6 +84,10 @@ public ViewModelToDomainMappingProfile()
8284
CreateMap<RemoveApiScopeViewModel, RemoveApiScopeCommand>().ConstructUsing(c => new RemoveApiScopeCommand(c.Id, c.ResourceName));
8385
CreateMap<SaveApiScopeViewModel, SaveApiScopeCommand>().ConstructUsing(c => new SaveApiScopeCommand(c.ResourceName, c.Name, c.Description, c.DisplayName, c.Emphasize, c.ShowInDiscoveryDocument, c.UserClaims));
8486

87+
/*
88+
* Role commands
89+
*/
90+
CreateMap<RemoveRoleViewModel, RemoveRoleCommand>().ConstructUsing(c => new RemoveRoleCommand(c.Name));
8591

8692
}
8793
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
using System.Text;
44
using System.Threading.Tasks;
55
using Jp.Application.ViewModels;
6+
using Jp.Application.ViewModels.RoleViewModels;
67

78
namespace Jp.Application.Interfaces
89
{
910
public interface IRoleManagerAppService: IDisposable
1011
{
1112
Task<IEnumerable<RoleViewModel>> GetAllRoles();
13+
Task Remove(RemoveRoleViewModel model);
1214
}
1315
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Threading.Tasks;
4-
using AutoMapper;
1+
using AutoMapper;
52
using Jp.Application.Interfaces;
63
using Jp.Application.ViewModels;
74
using Jp.Domain.Core.Bus;
85
using Jp.Domain.Interfaces;
9-
using Jp.Domain.Models;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Threading.Tasks;
9+
using Jp.Application.ViewModels.RoleViewModels;
10+
using Jp.Domain.Commands.Role;
1011

1112
namespace Jp.Application.Services
1213
{
@@ -29,8 +30,6 @@ IEventStoreRepository eventStoreRepository
2930
_eventStoreRepository = eventStoreRepository;
3031
}
3132

32-
33-
3433
public void Dispose()
3534
{
3635
GC.SuppressFinalize(this);
@@ -40,5 +39,11 @@ public async Task<IEnumerable<RoleViewModel>> GetAllRoles()
4039
{
4140
return _mapper.Map<IEnumerable<RoleViewModel>>(await _roleService.GetAllRoles());
4241
}
42+
43+
public Task Remove(RemoveRoleViewModel model)
44+
{
45+
var command = _mapper.Map<RemoveRoleCommand>(model);
46+
return Bus.SendCommand(command);
47+
}
4348
}
4449
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace Jp.Application.ViewModels.RoleViewModels
4+
{
5+
public class RemoveRoleViewModel
6+
{
7+
[Required]
8+
public string Name { get; set; }
9+
}
10+
}

src/Backend/Jp.Application/ViewModels/RoleViewModel.cs renamed to src/Backend/Jp.Application/ViewModels/RoleViewModels/RoleViewModel.cs

File renamed without changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Jp.Domain.Commands.Role;
2+
using Jp.Domain.Core.Bus;
3+
using Jp.Domain.Core.Notifications;
4+
using Jp.Domain.Events.Role;
5+
using Jp.Domain.Interfaces;
6+
using MediatR;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace Jp.Domain.CommandHandlers
11+
{
12+
public class RoleCommandHandler : CommandHandler,
13+
IRequestHandler<RemoveRoleCommand>
14+
{
15+
private readonly IRoleService _roleService;
16+
17+
public RoleCommandHandler(
18+
IUnitOfWork uow,
19+
IMediatorHandler bus,
20+
INotificationHandler<DomainNotification> notifications,
21+
IRoleService roleService) : base(uow, bus, notifications)
22+
{
23+
_roleService = roleService;
24+
}
25+
26+
public async Task Handle(RemoveRoleCommand request, CancellationToken cancellationToken)
27+
{
28+
if (!request.IsValid())
29+
{
30+
NotifyValidationErrors(request);
31+
return;
32+
}
33+
34+
// Businness logic here
35+
await _roleService.Remove(request.Name);
36+
37+
if (Commit())
38+
{
39+
await Bus.RaiseEvent(new RoleRemovedEvent(request.Name));
40+
}
41+
}
42+
}
43+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Jp.Domain.Validations.Role;
2+
3+
namespace Jp.Domain.Commands.Role
4+
{
5+
public class RemoveRoleCommand: RoleCommand
6+
{
7+
public RemoveRoleCommand(string name)
8+
{
9+
Name = name;
10+
}
11+
12+
public override bool IsValid()
13+
{
14+
ValidationResult = new RemoveRoleCommandValidation().Validate(this);
15+
return ValidationResult.IsValid;
16+
}
17+
}
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Jp.Domain.Core.Commands;
2+
3+
namespace Jp.Domain.Commands.Role
4+
{
5+
public abstract class RoleCommand : Command
6+
{
7+
public string Name { get; set; }
8+
}
9+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Jp.Domain.Core.Events;
5+
6+
namespace Jp.Domain.Events.Role
7+
{
8+
public class RoleRemovedEvent : Event
9+
{
10+
public string Name { get; }
11+
12+
public RoleRemovedEvent(string name)
13+
{
14+
Name = name;
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)