Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Identity #443

Merged
merged 18 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 29 additions & 39 deletions postman/dotnet.webapi.boilerplate.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "794f24b5-0c2b-41d5-9a27-9de067c7e47c",
"_postman_id": "4998314c-b6f5-4e57-9fe1-63ddcae7bc78",
"name": "dotnet.webapi.boilerplate",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
Expand Down Expand Up @@ -81,14 +81,12 @@
}
},
"url": {
"raw": "{{url}}/identity/register/",
"raw": "{{url}}/profile",
"host": [
"{{url}}"
],
"path": [
"identity",
"register",
""
"profile"
]
}
},
Expand All @@ -100,13 +98,12 @@
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/roles/all",
"raw": "{{url}}/roles",
"host": [
"{{url}}"
],
"path": [
"roles",
"all"
"roles"
]
}
},
Expand All @@ -127,31 +124,29 @@
}
},
"url": {
"raw": "{{url}}/roles/",
"raw": "{{url}}/roles",
"host": [
"{{url}}"
],
"path": [
"roles",
""
"roles"
]
}
},
"response": []
},
{
"name": "get-user-permissions",
"name": "get-my-permissions",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/users/72aa9336-fab0-4634-b5ab-a842e95dcea9/permissions",
"raw": "{{url}}/personal/permissions",
"host": [
"{{url}}"
],
"path": [
"users",
"72aa9336-fab0-4634-b5ab-a842e95dcea9",
"personal",
"permissions"
]
}
Expand All @@ -164,12 +159,11 @@
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/identity/profile",
"raw": "{{url}}/profile",
"host": [
"{{url}}"
],
"path": [
"identity",
"profile"
]
}
Expand Down Expand Up @@ -210,12 +204,13 @@
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/audit-logs",
"raw": "{{url}}/personal/logs",
"host": [
"{{url}}"
],
"path": [
"audit-logs"
"personal",
"logs"
]
}
},
Expand Down Expand Up @@ -252,14 +247,13 @@
}
},
"url": {
"raw": "{{url}}/identity/forgot-password/",
"raw": "{{url}}/profile/forgot-password",
"host": [
"{{url}}"
],
"path": [
"identity",
"forgot-password",
""
"profile",
"forgot-password"
]
}
},
Expand All @@ -286,14 +280,13 @@
}
},
"url": {
"raw": "{{url}}/identity/reset-password/",
"raw": "{{url}}/profile/reset-password",
"host": [
"{{url}}"
],
"path": [
"identity",
"reset-password",
""
"profile",
"reset-password"
]
}
},
Expand Down Expand Up @@ -644,13 +637,12 @@
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/tenants/",
"raw": "{{url}}/tenants",
"host": [
"{{url}}"
],
"path": [
"tenants",
""
"tenants"
]
}
},
Expand All @@ -671,13 +663,12 @@
}
},
"url": {
"raw": "{{url}}/tenants/",
"raw": "{{url}}/tenants",
"host": [
"{{url}}"
],
"path": [
"tenants",
""
"tenants"
]
}
},
Expand Down Expand Up @@ -777,13 +768,12 @@
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/health/",
"raw": "{{url}}/health",
"host": [
"{{url}}"
],
"path": [
"health",
""
"health"
]
}
},
Expand All @@ -795,18 +785,18 @@
"name": "General",
"item": [
{
"name": "stats",
"name": "dashboard",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/v1/stats",
"raw": "{{url}}/v1/dashboard",
"host": [
"{{url}}"
],
"path": [
"v1",
"stats"
"dashboard"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public ProductCreatedEventHandler(ILogger<ProductCreatedEventHandler> logger)

public Task Handle(EventNotification<EntityCreatedEvent<Product>> notification, CancellationToken cancellationToken)
{
_logger.LogInformation("{event} Triggered", notification.DomainEvent.GetType().Name);
_logger.LogInformation("{event} Triggered", notification.Event.GetType().Name);
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public ProductDeletedEventHandler(ILogger<ProductDeletedEventHandler> logger)

public Task Handle(EventNotification<EntityDeletedEvent<Product>> notification, CancellationToken cancellationToken)
{
_logger.LogInformation("{event} Triggered", notification.DomainEvent.GetType().Name);
_logger.LogInformation("{event} Triggered", notification.Event.GetType().Name);
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public ProductUpdatedEventHandler(ILogger<ProductUpdatedEventHandler> logger)

public Task Handle(EventNotification<EntityUpdatedEvent<Product>> notification, CancellationToken cancellationToken)
{
_logger.LogInformation("{event} Triggered", notification.DomainEvent.GetType().Name);
_logger.LogInformation("{event} Triggered", notification.Event.GetType().Name);
return Task.CompletedTask;
}
}
11 changes: 4 additions & 7 deletions src/Core/Application/Common/Events/EventNotification.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
namespace FSH.WebApi.Application.Common.Events;

public class EventNotification<T> : INotification
where T : DomainEvent
public class EventNotification<TDomainEvent> : INotification
where TDomainEvent : DomainEvent
{
public EventNotification(T domainEvent)
{
DomainEvent = domainEvent;
}
public EventNotification(TDomainEvent domainEvent) => Event = domainEvent;

public T DomainEvent { get; }
public TDomainEvent Event { get; }
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using FSH.WebApi.Domain.Common.Events;
using FSH.WebApi.Domain.Identity;

namespace FSH.WebApi.Application.Dashboard;

// TODO: handle registered users and registered roles create/delete
public class SendStatsChangedNotificationHandler :
INotificationHandler<EventNotification<EntityCreatedEvent<Brand>>>,
INotificationHandler<EventNotification<EntityDeletedEvent<Brand>>>,
INotificationHandler<EventNotification<EntityCreatedEvent<Product>>>,
INotificationHandler<EventNotification<EntityDeletedEvent<Product>>>
INotificationHandler<EventNotification<EntityDeletedEvent<Product>>>,
INotificationHandler<EventNotification<ApplicationRoleCreatedEvent>>,
INotificationHandler<EventNotification<ApplicationRoleDeletedEvent>>,
INotificationHandler<EventNotification<ApplicationUserCreatedEvent>>
{
private readonly ILogger<SendStatsChangedNotificationHandler> _logger;
private readonly INotificationService _notificationService;
Expand All @@ -16,16 +19,19 @@ public SendStatsChangedNotificationHandler(ILogger<SendStatsChangedNotificationH
(_logger, _notificationService) = (logger, notificationService);

public Task Handle(EventNotification<EntityCreatedEvent<Brand>> notification, CancellationToken cancellationToken) =>
SendStatsChangedNotification(notification.DomainEvent, cancellationToken);

SendStatsChangedNotification(notification.Event, cancellationToken);
public Task Handle(EventNotification<EntityDeletedEvent<Brand>> notification, CancellationToken cancellationToken) =>
SendStatsChangedNotification(notification.DomainEvent, cancellationToken);

SendStatsChangedNotification(notification.Event, cancellationToken);
public Task Handle(EventNotification<EntityCreatedEvent<Product>> notification, CancellationToken cancellationToken) =>
SendStatsChangedNotification(notification.DomainEvent, cancellationToken);

SendStatsChangedNotification(notification.Event, cancellationToken);
public Task Handle(EventNotification<EntityDeletedEvent<Product>> notification, CancellationToken cancellationToken) =>
SendStatsChangedNotification(notification.DomainEvent, cancellationToken);
SendStatsChangedNotification(notification.Event, cancellationToken);
public Task Handle(EventNotification<ApplicationRoleCreatedEvent> notification, CancellationToken cancellationToken) =>
SendStatsChangedNotification(notification.Event, cancellationToken);
public Task Handle(EventNotification<ApplicationRoleDeletedEvent> notification, CancellationToken cancellationToken) =>
SendStatsChangedNotification(notification.Event, cancellationToken);
public Task Handle(EventNotification<ApplicationUserCreatedEvent> notification, CancellationToken cancellationToken) =>
SendStatsChangedNotification(notification.Event, cancellationToken);

private Task SendStatsChangedNotification(DomainEvent domainEvent, CancellationToken cancellationToken)
{
Expand Down
18 changes: 0 additions & 18 deletions src/Core/Application/Identity/RoleClaims/IRoleClaimsService.cs

This file was deleted.

18 changes: 0 additions & 18 deletions src/Core/Application/Identity/RoleClaims/RoleClaimDto.cs

This file was deleted.

19 changes: 0 additions & 19 deletions src/Core/Application/Identity/RoleClaims/RoleClaimRequest.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
namespace FSH.WebApi.Application.Identity.Roles;

public class RoleRequest
public class CreateOrUpdateRoleRequest
{
public string? Id { get; set; }
public string Name { get; set; } = default!;
public string? Description { get; set; }
}

public class RoleRequestValidator : CustomValidator<RoleRequest>
public class CreateOrUpdateRoleRequestValidator : CustomValidator<CreateOrUpdateRoleRequest>
{
public RoleRequestValidator(IRoleService roleService, IStringLocalizer<RoleRequestValidator> localizer)
{
public CreateOrUpdateRoleRequestValidator(IRoleService roleService, IStringLocalizer<CreateOrUpdateRoleRequestValidator> localizer) =>
RuleFor(r => r.Name)
.NotEmpty()
.MustAsync(async (role, name, _) => !await roleService.ExistsAsync(name, role.Id))
.WithMessage(localizer["Similar Role already exists."]);
}
}
Loading