Skip to content

Commit 16cadeb

Browse files
committed
Incidents can now be deleted
1 parent cbff896 commit 16cadeb

File tree

11 files changed

+154
-11
lines changed

11 files changed

+154
-11
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
3+
namespace Coderr.Server.Api.Core.Incidents.Commands
4+
{
5+
/// <summary>
6+
/// Delete incidents (old, created in dev environment etc)
7+
/// </summary>
8+
[Message]
9+
public class DeleteIncident
10+
{
11+
/// <summary>
12+
/// Creates a new instance of <see cref="DeleteIncident" />.
13+
/// </summary>
14+
/// <param name="incidentId">incident to delete</param>
15+
/// <param name="areYouSure">should be "yes"</param>
16+
public DeleteIncident(int incidentId, string areYouSure)
17+
{
18+
if (incidentId <= 0) throw new ArgumentOutOfRangeException(nameof(incidentId));
19+
if (areYouSure != "yes")
20+
throw new ArgumentOutOfRangeException(nameof(areYouSure), areYouSure, "Must be 'yes'.");
21+
IncidentId = incidentId;
22+
AreYouSure = areYouSure;
23+
}
24+
25+
public int IncidentId { get; private set; }
26+
public int? UserId { get; set; }
27+
28+
public DateTime? DeletedAtUtc { get; set; }
29+
public string AreYouSure { get; private set; }
30+
}
31+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Coderr.Server.Api.Core.Incidents.Events
6+
{
7+
[Event]
8+
public class IncidentDeleted
9+
{
10+
public IncidentDeleted(int incidentId, int userId, DateTime deletedAtUtc)
11+
{
12+
if (incidentId <= 0) throw new ArgumentOutOfRangeException(nameof(incidentId));
13+
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));
14+
15+
IncidentId = incidentId;
16+
DeletedById = userId;
17+
DeletedAtUtc = deletedAtUtc;
18+
}
19+
20+
protected IncidentDeleted()
21+
{
22+
23+
}
24+
25+
public int IncidentId { get;private set; }
26+
27+
public int DeletedById { get; set; }
28+
public DateTime DeletedAtUtc { get; private set; }
29+
}
30+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Coderr.Server.Abstractions.Security;
4+
using Coderr.Server.Api.Core.Incidents.Commands;
5+
using Coderr.Server.Api.Core.Incidents.Events;
6+
using Coderr.Server.Domain.Core.Incidents;
7+
using DotNetCqs;
8+
9+
namespace Coderr.Server.App.Core.Incidents.Commands
10+
{
11+
/// <summary>
12+
/// Handler for <see cref="DeleteIncident" />
13+
/// </summary>
14+
public class DeleteIncidentHandler : IMessageHandler<DeleteIncident>
15+
{
16+
private readonly IIncidentRepository _repository;
17+
18+
public DeleteIncidentHandler(IIncidentRepository repository)
19+
{
20+
_repository = repository;
21+
}
22+
23+
public async Task HandleAsync(IMessageContext context, DeleteIncident message)
24+
{
25+
var incident = await _repository.GetAsync(message.IncidentId);
26+
await _repository.Delete(message.IncidentId);
27+
28+
var evt = new IncidentDeleted(message.IncidentId, message.UserId ?? context.Principal.GetAccountId(),
29+
message.DeletedAtUtc ?? DateTime.UtcNow);
30+
await context.SendAsync(evt);
31+
}
32+
}
33+
}

src/Server/Coderr.Server.App/Modules/History/Events/IncidentAssignedHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ public async Task HandleAsync(IMessageContext context, IncidentAssigned message)
2828
await _repository.CreateAsync(entry);
2929
}
3030
}
31-
}
31+
}git

src/Server/Coderr.Server.Domain/Core/Incidents/IIncidentRepository.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ namespace Coderr.Server.Domain.Core.Incidents
99
/// </summary>
1010
public interface IIncidentRepository
1111
{
12+
/// <summary>
13+
/// Delete an incident
14+
/// </summary>
15+
/// <param name="incidentId">id</param>
16+
/// <returns></returns>
17+
Task Delete(int incidentId);
18+
1219
/// <summary>
1320
/// Get incident
1421
/// </summary>

src/Server/Coderr.Server.SqlServer/Core/Incidents/IncidentRepository.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public IncidentRepository(IAdoNetUnitOfWork uow)
2424

2525
public async Task UpdateAsync(Incident incident)
2626
{
27-
using (var cmd = (DbCommand) _uow.CreateCommand())
27+
using (var cmd = (DbCommand)_uow.CreateCommand())
2828
{
2929
cmd.CommandText =
3030
@"UPDATE Incidents SET
@@ -59,12 +59,12 @@ public async Task UpdateAsync(Incident incident)
5959

6060
public async Task<int> GetTotalCountForAppInfoAsync(int applicationId)
6161
{
62-
using (var cmd = (DbCommand) _uow.CreateCommand())
62+
using (var cmd = (DbCommand)_uow.CreateCommand())
6363
{
6464
cmd.CommandText =
6565
@"SELECT CAST(count(*) as int) FROM Incidents WHERE ApplicationId = @ApplicationId";
6666
cmd.AddParameter("ApplicationId", applicationId);
67-
var result = (int) await cmd.ExecuteScalarAsync();
67+
var result = (int)await cmd.ExecuteScalarAsync();
6868
return result;
6969
}
7070
}
@@ -84,9 +84,20 @@ public Task<IList<Incident>> GetManyAsync(IEnumerable<int> incidentIds)
8484
}
8585
}
8686

87+
public async Task Delete(int incidentId)
88+
{
89+
using (var cmd = (DbCommand)_uow.CreateCommand())
90+
{
91+
cmd.CommandText =
92+
@"DELETE FROM Incidents WHERE Id = @id";
93+
cmd.AddParameter("Id", incidentId);
94+
await cmd.ExecuteNonQueryAsync();
95+
}
96+
}
97+
8798
public Task<Incident> GetAsync(int id)
8899
{
89-
using (var cmd = (DbCommand) _uow.CreateCommand())
100+
using (var cmd = (DbCommand)_uow.CreateCommand())
90101
{
91102
cmd.CommandText =
92103
"SELECT TOP 1 * FROM Incidents WHERE Id = @id";
@@ -107,7 +118,7 @@ public Incident Find(int id)
107118
return cmd.FirstOrDefault(new IncidentMapper());
108119
}
109120
}
110-
121+
111122
public Incident Get(int id)
112123
{
113124
using (var cmd = _uow.CreateCommand())

src/Server/Coderr.Server.Web/ClientApp/components/analyze/incidents/incident.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default class AnalyzeIncidentComponent extends Vue {
2727
currentCollectionName: string = '';
2828

2929
created() {
30+
this.incidentId = parseInt(this.$route.params.incidentId, 10);
3031
}
3132

3233
mounted() {

src/Server/Coderr.Server.Web/ClientApp/components/discover/incidents/search.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,13 @@ export default class IncidentSearchComponent extends Vue {
320320
setTimeout(() => { this.search() }, 1000);
321321
}
322322

323-
closeSelectedIncidents() {
323+
deleteSelectedIncidents() {
324324
const elems = document.querySelectorAll('#searchTable tbody input[type="checkbox"]:checked');
325325
for (let i = 0; i < elems.length; i++) {
326326
const elem = <HTMLInputElement>elems[i];
327-
this.incidentService$.close(parseInt(elem.value), "Mass close from search.");
327+
this.incidentService$.delete(parseInt(elem.value), "yes");
328328
}
329-
AppRoot.notify('All selected incidents have closed.');
329+
AppRoot.notify('All selected incidents have deleted.');
330330
setTimeout(() => { this.search() }, 1000);
331331
}
332332

src/Server/Coderr.Server.Web/ClientApp/components/discover/incidents/search.vue.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
</div>
126126
<div v-else>
127127
<button class="btn btn-blue" v-on:click.prevent="assignAllToMe">Assign selected incidents to me</button>
128-
<button class="btn btn-light" v-on:click.prevent="closeSelectedIncidents">Close selected incidents</button>
128+
<button class="btn btn-light" v-on:click.prevent="deleteSelectedIncidents">Delete selected incidents</button>
129129
</div>
130130
</div>
131131
</div>

src/Server/Coderr.Server.Web/ClientApp/dto/Core/Incidents.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ export class CloseIncident
198198
public UserId: number;
199199
public ApplicationVersion: string;
200200
}
201+
export class DeleteIncident {
202+
public static TYPE_NAME: string = 'DeleteIncident';
203+
public AreYouSure: string;
204+
public IncidentId: number;
205+
}
201206
export class IgnoreIncident
202207
{
203208
public static TYPE_NAME: string = 'IgnoreIncident';

0 commit comments

Comments
 (0)