Skip to content

Commit

Permalink
handler (#72)
Browse files Browse the repository at this point in the history
* handler

* cleanup
  • Loading branch information
mlapaglia authored Jun 15, 2021
1 parent a26c607 commit a61e5fe
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using OpenAlprWebhookProcessor.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -31,17 +32,15 @@ public async Task<SearchLicensePlateResponse> HandleAsync(

if (request.StrictMatch)
{
dbRequest = dbRequest.Where(x => x.BestNumber.Contains(request.PlateNumber));
dbRequest = dbRequest.Where(x => x.BestNumber == request.PlateNumber);
}
else if (request.RegexSearchEnabled)
{
dbRequest = dbRequest.Where(x => Regex.IsMatch(x.BestNumber, request.PlateNumber));
}
else
{
dbRequest = dbRequest.Where(x =>
x.BestNumber.Contains(request.PlateNumber)
|| x.PossibleNumbers.Contains(request.PlateNumber));
dbRequest = dbRequest.Where(x => x.PossibleNumbers.Contains(request.PlateNumber));
}
}

Expand Down Expand Up @@ -76,7 +75,7 @@ public async Task<SearchLicensePlateResponse> HandleAsync(
}
}

var totalCount = await dbRequest.CountAsync(cancellationToken);
var totalCount = dbRequest.Count();

dbRequest = dbRequest
.OrderByDescending(x => x.ReceivedOnEpoch)
Expand Down Expand Up @@ -106,9 +105,9 @@ public async Task<SearchLicensePlateResponse> HandleAsync(

private async Task<List<string>> GetPlatesToAlertAsync(CancellationToken cancellationToken)
{
return (await _processerContext.Alerts.ToListAsync(cancellationToken))
return (await _processerContext.Alerts
.Select(x => x.PlateNumber)
.ToList();
.ToListAsync(cancellationToken));
}
}
}

0 comments on commit a61e5fe

Please sign in to comment.