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

add regulatedPlaceType as a search query property #243

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions Src/DfT.DTRO/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using DfT.DTRO.Models.DataBase;

namespace DfT.DTRO.Controllers;

/// <summary>
Expand Down Expand Up @@ -58,7 +56,7 @@ public async Task<ActionResult<PaginatedResponse<DtroSearchResult>>> SearchDtros
try
{
appId = await _appIdMapperService.GetAppId(HttpContext);
PaginatedResponse<DtroSearchResult> response = await _searchService.SearchAsync(body);
var response = await _searchService.SearchAsync(body);
await _metricsService.IncrementMetric(MetricType.Search, appId);
_logger.LogInformation($"'{nameof(SearchDtros)}' method called and body '{body}'");
_loggingExtension.LogInformation(
Expand Down
14 changes: 12 additions & 2 deletions Src/DfT.DTRO/DAL/DtroDal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ public async Task AssignDtroOwnership(Guid id, int assignToTraId, string correla
expressionsToConjunct.Add(it => it.RegulationTypes.Contains(query.RegulationType));
}

if (query.RegulatedPlaceType is not null)
{
expressionsToConjunct.Add(it => it.RegulatedPlaceTypes.Contains(query.RegulatedPlaceType));
}

if (query.OrderReportingPoint is not null)
{
expressionsToConjunct.Add(it => it.OrderReportingPoints.Contains(query.OrderReportingPoint));
Expand Down Expand Up @@ -394,6 +399,11 @@ public async Task AssignDtroOwnership(Guid id, int assignToTraId, string correla
expressionsToConjunct.Add(it => it.RegulationTypes.Contains(search.RegulationType));
}

if (search.RegulatedPlaceType is not null)
{
expressionsToConjunct.Add(it => it.RegulatedPlaceTypes.Contains(search.RegulatedPlaceType));
}

if (search.OrderReportingPoint is not null)
{
expressionsToConjunct.Add(it => it.OrderReportingPoints.Contains(search.OrderReportingPoint));
Expand All @@ -420,7 +430,7 @@ public async Task AssignDtroOwnership(Guid id, int assignToTraId, string correla
ComparisonOperator.LessThanOrEqual => it => it.RegulationStart <= value,
ComparisonOperator.GreaterThan => it => it.RegulationStart > value,
ComparisonOperator.GreaterThanOrEqual => it => it.RegulationStart >= value,
_ => throw new InvalidOperationException("Unsupported comparison operator.")
var _ => throw new InvalidOperationException("Unsupported comparison operator.")
};

expressionsToConjunct.Add(expr);
Expand All @@ -437,7 +447,7 @@ public async Task AssignDtroOwnership(Guid id, int assignToTraId, string correla
ComparisonOperator.LessThanOrEqual => (it) => it.RegulationEnd <= value,
ComparisonOperator.GreaterThan => (it) => it.RegulationEnd > value,
ComparisonOperator.GreaterThanOrEqual => (it) => it.RegulationEnd >= value,
_ => throw new InvalidOperationException("Unsupported comparison operator.")
var _ => throw new InvalidOperationException("Unsupported comparison operator.")
};

expressionsToConjunct.Add(expr);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DfT.DTRO.Migrations
{
public partial class AddRegulatedPlaceTypesDtroProperty : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Prefix",
table: "DtroUsers",
type: "character varying(20)",
maxLength: 20,
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(20)",
oldMaxLength: 20);

migrationBuilder.AddColumn<List<string>>(
name: "RegulatedPlaceTypes",
table: "Dtros",
type: "text[]",
nullable: true);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "RegulatedPlaceTypes",
table: "Dtros");

migrationBuilder.AlterColumn<string>(
name: "Prefix",
table: "DtroUsers",
type: "character varying(20)",
maxLength: 20,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "character varying(20)",
oldMaxLength: 20,
oldNullable: true);
}
}
}
Loading
Loading