-
Notifications
You must be signed in to change notification settings - Fork 6
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
16 changed files
with
251 additions
and
45 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
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 |
---|---|---|
@@ -1,50 +1,75 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using OpenAlprWebhookProcessor.Alerts.Pushover; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenAlprWebhookProcessor.Alerts | ||
{ | ||
[Authorize] | ||
[ApiController] | ||
[Route("alerts")] | ||
public class AlertsController : Controller | ||
{ | ||
private readonly GetAlertsRequestHandler _getAlertsRequestHandler; | ||
|
||
private readonly UpsertAlertsRequestHandler _upsertAlertsRequestHandler; | ||
|
||
private readonly UpsertPushoverRequestHandler _upsertPushoverRequestHandler; | ||
private readonly UpsertPushoverClientRequestHandler _upsertPushoverRequestHandler; | ||
|
||
private readonly GetPushoverClientRequestHandler _getPushoverClientRequestHandler; | ||
|
||
private readonly TestPushoverClientRequestHandler _testPushoverClientRequestHandler; | ||
|
||
public AlertsController( | ||
GetAlertsRequestHandler getAlertsRequestHandler, | ||
UpsertAlertsRequestHandler upsertAlertsRequestHandler, | ||
UpsertPushoverRequestHandler upsertPushoverRequestHandler) | ||
UpsertPushoverClientRequestHandler upsertPushoverRequestHandler, | ||
GetPushoverClientRequestHandler getPushoverClientRequestHandler, | ||
TestPushoverClientRequestHandler testPushoverClientRequestHandler) | ||
{ | ||
_getAlertsRequestHandler = getAlertsRequestHandler; | ||
_upsertAlertsRequestHandler = upsertAlertsRequestHandler; | ||
_upsertPushoverRequestHandler = upsertPushoverRequestHandler; | ||
_getPushoverClientRequestHandler = getPushoverClientRequestHandler; | ||
_testPushoverClientRequestHandler = testPushoverClientRequestHandler; | ||
} | ||
|
||
[HttpPost("alerts/add")] | ||
[HttpPost("add")] | ||
public async Task AddAlert([FromBody] Alert alert) | ||
{ | ||
await _upsertAlertsRequestHandler.AddAlertAsync(alert); | ||
} | ||
|
||
[HttpPost("alerts")] | ||
[HttpPost] | ||
public async Task UpsertAlerts([FromBody] List<Alert> alerts) | ||
{ | ||
await _upsertAlertsRequestHandler.UpsertAlertsAsync(alerts); | ||
} | ||
|
||
[HttpGet("alerts")] | ||
[HttpGet] | ||
public async Task<List<Alert>> GetAlerts(CancellationToken cancellationToken) | ||
{ | ||
return await _getAlertsRequestHandler.HandleAsync(cancellationToken); | ||
} | ||
|
||
[HttpPost("pushover")] | ||
public async Task UpsertPushover([FromBody] UpsertPushoverRequest request) | ||
public async Task UpsertPushover([FromBody] PushoverRequest request) | ||
{ | ||
await _upsertPushoverRequestHandler.HandleAsync(request); | ||
} | ||
|
||
[HttpPost("pushover/test")] | ||
public async Task UpsertPushover(CancellationToken cancellationToken) | ||
{ | ||
await _testPushoverClientRequestHandler.HandleAsync(cancellationToken); | ||
} | ||
|
||
[HttpGet("pushover")] | ||
public async Task<PushoverRequest> GetPushover(CancellationToken cancellationToken) | ||
{ | ||
return await _getPushoverClientRequestHandler.HandleAsync(cancellationToken); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenAlprWebhookProcessor.Alerts | ||
{ | ||
public interface IAlertClient | ||
{ | ||
Task SendAlertAsync(Alert alert); | ||
Task SendAlertAsync( | ||
Alert alert, | ||
string base64PreviewJpeg, | ||
CancellationToken cancellationToken); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
OpenAlprWebhookProcessor/Alerts/Pushover/GetPushoverClientRequestHandler.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,35 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using OpenAlprWebhookProcessor.Data; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenAlprWebhookProcessor.Alerts.Pushover | ||
{ | ||
public class GetPushoverClientRequestHandler | ||
{ | ||
private readonly ProcessorContext _processorContext; | ||
|
||
public GetPushoverClientRequestHandler(ProcessorContext processorContext) | ||
{ | ||
_processorContext = processorContext; | ||
} | ||
|
||
public async Task<PushoverRequest> HandleAsync(CancellationToken cancellationToken) | ||
{ | ||
var client = await _processorContext.PushoverAlertClients.FirstOrDefaultAsync(cancellationToken); | ||
|
||
if (client == null) | ||
{ | ||
return new PushoverRequest(); | ||
} | ||
|
||
return new PushoverRequest() | ||
{ | ||
ApiToken = client.ApiToken, | ||
IsEnabled = client.IsEnabled, | ||
SendPlatePreviewEnabled = client.SendPlatePreview, | ||
UserKey = client.UserKey, | ||
}; | ||
} | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
.../Alerts/Pushover/UpsertPushoverRequest.cs → ...cessor/Alerts/Pushover/PushoverRequest.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
namespace OpenAlprWebhookProcessor.Alerts.Pushover | ||
{ | ||
public class UpsertPushoverRequest | ||
public class PushoverRequest | ||
{ | ||
public bool IsEnabled { get; set; } | ||
|
||
public string UserKey { get; set; } | ||
|
||
public string ApiToken { get; set; } | ||
|
||
public bool SendPlatePreview { get; set; } | ||
public bool SendPlatePreviewEnabled { get; set; } | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
OpenAlprWebhookProcessor/Alerts/Pushover/TestPushoverClientRequestHandler.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,40 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using OpenAlprWebhookProcessor.Data; | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenAlprWebhookProcessor.Alerts.Pushover | ||
{ | ||
public class TestPushoverClientRequestHandler | ||
{ | ||
private readonly ProcessorContext _processorContext; | ||
|
||
private readonly IAlertClient _alertClient; | ||
|
||
public TestPushoverClientRequestHandler(ProcessorContext processorContext, | ||
IAlertClient alertClient) | ||
{ | ||
_processorContext = processorContext; | ||
_alertClient = alertClient; | ||
} | ||
|
||
public async Task HandleAsync(CancellationToken cancellationToken) | ||
{ | ||
var testPlateGroup = await _processorContext.PlateGroups | ||
.Where(x => x.Jpeg != null) | ||
.FirstOrDefaultAsync(cancellationToken); | ||
|
||
await _alertClient.SendAlertAsync(new Alert() | ||
{ | ||
Description = "was seen on " + DateTimeOffset.Now.ToString("g"), | ||
Id = testPlateGroup.Id, | ||
PlateNumber = testPlateGroup.BestNumber, | ||
StrictMatch = false, | ||
}, | ||
testPlateGroup.Jpeg, | ||
cancellationToken); | ||
} | ||
} | ||
} |
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
17 changes: 9 additions & 8 deletions
17
OpenAlprWebhookProcessor/ClientApp/src/app/settings/alerts/pushover/pushover.component.html
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 |
---|---|---|
@@ -1,31 +1,32 @@ | ||
<div style="margin:16px;" fxLayout="row wrap" fxLayout="row wrap" fxLayoutGap=20px> | ||
<div style="margin:16px;" fxLayout="row wrap" fxLayout="row wrap" fxLayoutGap=20px *ngIf="client"> | ||
<mat-card> | ||
<mat-card-header style="justify-content: space-between;"> | ||
<mat-card-title>Pushover</mat-card-title> | ||
<mat-card-subtitle>https://pushover.net/</mat-card-subtitle> | ||
<mat-slide-toggle | ||
style="padding-top: 10px;" | ||
[(ngModel)]="isEnabled"></mat-slide-toggle> | ||
[(ngModel)]="client.isEnabled"></mat-slide-toggle> | ||
</mat-card-header> | ||
<mat-card-content *ngIf="isEnabled" [@inOutAnimation]> | ||
<mat-card-content *ngIf="client.isEnabled" [@inOutAnimation]> | ||
<div style="margin:16px;" fxLayout="row wrap" fxLayout="row wrap" fxLayoutGap=20px> | ||
<mat-form-field fxFlex="80"> | ||
<mat-label>User Key</mat-label> | ||
<input matInput [(ngModel)]="userKey"> | ||
<input matInput [(ngModel)]="client.userKey"> | ||
<mat-icon matTooltip="The pushover user key, found on the profile page" style="cursor:default" matSuffix>help_center</mat-icon> | ||
</mat-form-field> | ||
<mat-form-field fxFlex="80"> | ||
<mat-label>API Token</mat-label> | ||
<input matInput [(ngModel)]="apiToken"> | ||
<input matInput [(ngModel)]="client.apiToken"> | ||
<mat-icon matTooltip="The pushover api token, found under 'Your Applications' on the profile page" style="cursor:default" matSuffix>help_center</mat-icon> | ||
</mat-form-field> | ||
<div> | ||
<mat-checkbox [(ngModel)]="sendPlatePreviewEnabled">Send Plate Preview Image</mat-checkbox> | ||
<mat-checkbox [(ngModel)]="client.sendPlatePreviewEnabled">Send Plate Preview Image</mat-checkbox> | ||
</div> | ||
</div> | ||
</mat-card-content> | ||
<mat-card-actions align="end" *ngIf="isEnabled" [@inOutAnimation]> | ||
<button mat-button>Save</button> | ||
<mat-card-actions align="end" *ngIf="client.isEnabled" [@inOutAnimation]> | ||
<button mat-button (click)="testClient();" [disabled]="isTesting">Test</button> | ||
<button mat-button (click)="saveClient();" [disabled]="isSaving">Save</button> | ||
</mat-card-actions> | ||
</mat-card> | ||
</div> |
Oops, something went wrong.