-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
952 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Server/OneTrueError.Api/Core/Applications/Commands/DeleteApplication.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using DotNetCqs; | ||
|
||
namespace OneTrueError.Api.Core.Applications.Commands | ||
{ | ||
/// <summary> | ||
/// Delete an existing application including of all its data. | ||
/// </summary> | ||
public class DeleteApplication : Command | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="DeleteApplication" />. | ||
/// </summary> | ||
/// <param name="id">application id</param> | ||
public DeleteApplication(int id) | ||
{ | ||
if (id <= 0) throw new ArgumentOutOfRangeException("id"); | ||
Id = id; | ||
} | ||
|
||
/// <summary> | ||
/// Gets id of the application to delete. | ||
/// </summary> | ||
public int Id { get; private set; } | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Server/OneTrueError.Api/Core/Applications/Events/ApplicationDeleted.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using DotNetCqs; | ||
|
||
namespace OneTrueError.Api.Core.Applications.Events | ||
{ | ||
/// <summary> | ||
/// An application have been deleted. | ||
/// </summary> | ||
public class ApplicationDeleted : ApplicationEvent | ||
{ | ||
/// <summary> | ||
/// Key used when uploading reports | ||
/// </summary> | ||
public string AppKey { get; set; } | ||
|
||
/// <summary> | ||
/// Database PK | ||
/// </summary> | ||
public int ApplicationId { get; set; } | ||
|
||
/// <summary> | ||
/// Name of the application | ||
/// </summary> | ||
public string ApplicationName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Server/OneTrueError.App/Core/ApiKeys/Events/ApplicationDeletedHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using DotNetCqs; | ||
using Griffin.Container; | ||
using OneTrueError.Api.Core.Applications.Events; | ||
|
||
namespace OneTrueError.App.Core.ApiKeys.Events | ||
{ | ||
/// <summary> | ||
/// Will either delete an entire apikey (if the only association is with the given application) or just remove the | ||
/// application mapping. | ||
/// </summary> | ||
[Component(RegisterAsSelf = true)] | ||
public class ApplicationDeletedHandler : IApplicationEventSubscriber<ApplicationDeleted> | ||
{ | ||
private readonly IApiKeyRepository _repository; | ||
|
||
/// <summary> | ||
/// Creates a new instance of <see cref="ApplicationDeletedHandler"/>. | ||
/// </summary> | ||
/// <param name="repository">repos</param> | ||
public ApplicationDeletedHandler(IApiKeyRepository repository) | ||
{ | ||
if (repository == null) throw new ArgumentNullException("repository"); | ||
_repository = repository; | ||
} | ||
|
||
public async Task HandleAsync(ApplicationDeleted e) | ||
{ | ||
var apps = await _repository.GetForApplicationAsync(e.ApplicationId); | ||
foreach (var apiKey in apps) | ||
{ | ||
if (apiKey.AllowedApplications.Count() == 1) | ||
await _repository.DeleteAsync(apiKey.Id); | ||
else | ||
await _repository.DeleteApplicationMappingAsync(apiKey.Id, e.ApplicationId); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Server/OneTrueError.App/Core/Applications/CommandHandlers/DeleteApplicationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Threading.Tasks; | ||
using DotNetCqs; | ||
using Griffin.Container; | ||
using OneTrueError.Api.Core.Applications.Commands; | ||
using OneTrueError.Api.Core.Applications.Events; | ||
|
||
namespace OneTrueError.App.Core.Applications.CommandHandlers | ||
{ | ||
/// <summary> | ||
/// Handler for <see cref="DeleteApplication"/>. | ||
/// </summary> | ||
[Component(RegisterAsSelf = true)] | ||
public class DeleteApplicationHandler : ICommandHandler<DeleteApplication> | ||
{ | ||
private readonly IEventBus _eventBus; | ||
private readonly IApplicationRepository _repository; | ||
|
||
/// <summary> | ||
/// Creates a new instance of <see cref="DeleteApplicationHandler"/>. | ||
/// </summary> | ||
/// <param name="repository">used to delete the application</param> | ||
/// <param name="eventBus">to publish ApplicationDeleted</param> | ||
public DeleteApplicationHandler(IApplicationRepository repository, IEventBus eventBus) | ||
{ | ||
_repository = repository; | ||
_eventBus = eventBus; | ||
} | ||
|
||
public async Task ExecuteAsync(DeleteApplication command) | ||
{ | ||
var app = await _repository.GetByIdAsync(command.Id); | ||
await _repository.DeleteAsync(command.Id); | ||
var evt = new ApplicationDeleted {ApplicationName = app.Name, ApplicationId = app.Id, AppKey = app.AppKey}; | ||
await _eventBus.PublishAsync(evt); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Server/OneTrueError.App/Core/Notifications/EventHandlers/ApplicationDeletedHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using DotNetCqs; | ||
using Griffin.Container; | ||
using Griffin.Data; | ||
using OneTrueError.Api.Core.Applications.Events; | ||
|
||
namespace OneTrueError.App.Core.Notifications.EventHandlers | ||
{ | ||
/// <summary> | ||
/// Will delete all reports for the given application | ||
/// </summary> | ||
[Component(RegisterAsSelf = true)] | ||
public class ApplicationDeletedHandler : IApplicationEventSubscriber<ApplicationDeleted> | ||
{ | ||
private IAdoNetUnitOfWork _uow; | ||
|
||
/// <summary> | ||
/// Creates a new instance of <see cref="ApplicationDeletedHandler"/>. | ||
/// </summary> | ||
public ApplicationDeletedHandler(IAdoNetUnitOfWork uow) | ||
{ | ||
if (uow == null) throw new ArgumentNullException("uow"); | ||
_uow = uow; | ||
} | ||
|
||
public Task HandleAsync(ApplicationDeleted e) | ||
{ | ||
_uow.ExecuteNonQuery("DELETE FROM UserNotificationSettings WHERE ApplicationId = @id", new { id = e.ApplicationId }); | ||
return Task.FromResult<object>(null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.